logs: Do not log common successful errors. (#3340)

Errors like `BucketNotFound`, `BucketExists` shouldn't be logged.

Fixes #3229
master
Harshavardhana 8 years ago committed by GitHub
parent c667d20dfc
commit d711ff454e
  1. 1
      cmd/config-migrate.go
  2. 2
      cmd/config-v10.go
  3. 20
      cmd/lock-instrument.go
  4. 58
      cmd/lock-instrument_test.go
  5. 4
      cmd/lockinfo-handlers.go
  6. 31
      cmd/logger.go
  7. 14
      cmd/logger_test.go
  8. 22
      cmd/namespace-lock.go
  9. 12
      cmd/namespace-lock_test.go

@ -486,6 +486,7 @@ func migrateV8ToV9() error {
srvConfig.Region = "us-east-1" srvConfig.Region = "us-east-1"
} }
srvConfig.Logger.Console = cv8.Logger.Console srvConfig.Logger.Console = cv8.Logger.Console
srvConfig.Logger.Console.Level = "error"
srvConfig.Logger.File = cv8.Logger.File srvConfig.Logger.File = cv8.Logger.File
srvConfig.Logger.Syslog = cv8.Logger.Syslog srvConfig.Logger.Syslog = cv8.Logger.Syslog

@ -54,7 +54,7 @@ func initConfig() (bool, error) {
// Enable console logger by default on a fresh run. // Enable console logger by default on a fresh run.
srvCfg.Logger.Console = consoleLogger{ srvCfg.Logger.Console = consoleLogger{
Enable: true, Enable: true,
Level: "fatal", Level: "error",
} }
// Make sure to initialize notification configs. // Make sure to initialize notification configs.

@ -41,7 +41,7 @@ type debugLockInfo struct {
// "RLock" or "WLock". // "RLock" or "WLock".
lType lockType lType lockType
// Contains the trace of the function which invoked the lock, obtained from runtime. // Contains the trace of the function which invoked the lock, obtained from runtime.
lockOrigin string lockSource string
// Status can be running/ready/blocked. // Status can be running/ready/blocked.
status statusType status statusType
// Time info of the since how long the status holds true. // Time info of the since how long the status holds true.
@ -80,12 +80,12 @@ type LockInfoOriginNotFound struct {
volume string volume string
path string path string
opsID string opsID string
lockOrigin string lockSource string
} }
func (l LockInfoOriginNotFound) Error() string { func (l LockInfoOriginNotFound) Error() string {
return fmt.Sprintf("No lock state stored for the lock origined at \"%s\", for <volume> %s, <path> %s, <opsID> %s", return fmt.Sprintf("No lock state stored for the lock origined at \"%s\", for <volume> %s, <path> %s, <opsID> %s",
l.lockOrigin, l.volume, l.path, l.opsID) l.lockSource, l.volume, l.path, l.opsID)
} }
// LockInfoVolPathMissing - Error interface. Returned when the info the // LockInfoVolPathMissing - Error interface. Returned when the info the
@ -130,13 +130,13 @@ func (n *nsLockMap) initLockInfoForVolumePath(param nsParam) {
} }
// Change the state of the lock from Blocked to Running. // Change the state of the lock from Blocked to Running.
func (n *nsLockMap) statusBlockedToRunning(param nsParam, lockOrigin, opsID string, readLock bool) error { func (n *nsLockMap) statusBlockedToRunning(param nsParam, lockSource, opsID string, readLock bool) error {
// This operation is not executed under the scope nsLockMap.mutex.Lock(), lock has to be explicitly held here. // This operation is not executed under the scope nsLockMap.mutex.Lock(), lock has to be explicitly held here.
n.lockMapMutex.Lock() n.lockMapMutex.Lock()
defer n.lockMapMutex.Unlock() defer n.lockMapMutex.Unlock()
// new state info to be set for the lock. // new state info to be set for the lock.
newLockInfo := debugLockInfo{ newLockInfo := debugLockInfo{
lockOrigin: lockOrigin, lockSource: lockSource,
status: runningStatus, status: runningStatus,
since: time.Now().UTC(), since: time.Now().UTC(),
} }
@ -165,9 +165,9 @@ func (n *nsLockMap) statusBlockedToRunning(param nsParam, lockOrigin, opsID stri
// If not return `LockInfoOpsIDNotFound`. // If not return `LockInfoOpsIDNotFound`.
return traceError(LockInfoOpsIDNotFound{param.volume, param.path, opsID}) return traceError(LockInfoOpsIDNotFound{param.volume, param.path, opsID})
} }
// The entry for the lock origined at `lockOrigin` should already exist. If not return `LockInfoOriginNotFound`. // The entry for the lock origined at `lockSource` should already exist. If not return `LockInfoOriginNotFound`.
if lockInfo.lockOrigin != lockOrigin { if lockInfo.lockSource != lockSource {
return traceError(LockInfoOriginNotFound{param.volume, param.path, opsID, lockOrigin}) return traceError(LockInfoOriginNotFound{param.volume, param.path, opsID, lockSource})
} }
// Status of the lock should already be set to "Blocked". If not return `LockInfoStateNotBlocked`. // Status of the lock should already be set to "Blocked". If not return `LockInfoStateNotBlocked`.
if lockInfo.status != blockedStatus { if lockInfo.status != blockedStatus {
@ -186,9 +186,9 @@ func (n *nsLockMap) statusBlockedToRunning(param nsParam, lockOrigin, opsID stri
} }
// Change the state of the lock from Ready to Blocked. // Change the state of the lock from Ready to Blocked.
func (n *nsLockMap) statusNoneToBlocked(param nsParam, lockOrigin, opsID string, readLock bool) error { func (n *nsLockMap) statusNoneToBlocked(param nsParam, lockSource, opsID string, readLock bool) error {
newLockInfo := debugLockInfo{ newLockInfo := debugLockInfo{
lockOrigin: lockOrigin, lockSource: lockSource,
status: blockedStatus, status: blockedStatus,
since: time.Now().UTC(), since: time.Now().UTC(),
} }

@ -24,7 +24,7 @@ import (
type lockStateCase struct { type lockStateCase struct {
volume string volume string
path string path string
lockOrigin string lockSource string
opsID string opsID string
readLock bool // lock type. readLock bool // lock type.
setBlocked bool // initialize the initial state to blocked. setBlocked bool // initialize the initial state to blocked.
@ -206,8 +206,8 @@ func verifyLockState(l lockStateCase, t *testing.T, testNum int) {
} }
// // validating the lock origin. // // validating the lock origin.
// if l.lockOrigin != lockInfo.lockOrigin { // if l.lockSource != lockInfo.lockSource {
// t.Fatalf("Test %d: Expected the lock origin info to be \"%s\", but got \"%s\"", testNum, l.lockOrigin, lockInfo.lockOrigin) // t.Fatalf("Test %d: Expected the lock origin info to be \"%s\", but got \"%s\"", testNum, l.lockSource, lockInfo.lockSource)
// } // }
// validating the status of the lock. // validating the status of the lock.
if lockInfo.status != l.expectedLockStatus { if lockInfo.status != l.expectedLockStatus {
@ -248,7 +248,7 @@ func TestNsLockMapStatusBlockedToRunning(t *testing.T) {
testCases := []struct { testCases := []struct {
volume string volume string
path string path string
lockOrigin string lockSource string
opsID string opsID string
readLock bool // Read lock type. readLock bool // Read lock type.
setBlocked bool // Initialize the initial state to blocked. setBlocked bool // Initialize the initial state to blocked.
@ -258,7 +258,7 @@ func TestNsLockMapStatusBlockedToRunning(t *testing.T) {
{ {
volume: "my-bucket", volume: "my-bucket",
path: "my-object", path: "my-object",
lockOrigin: "/home/vadmeste/work/go/src/github.com/minio/minio/xl-v1-object.go:683 +0x2a", lockSource: "/home/vadmeste/work/go/src/github.com/minio/minio/xl-v1-object.go:683 +0x2a",
opsID: "abcd1234", opsID: "abcd1234",
readLock: true, readLock: true,
setBlocked: true, setBlocked: true,
@ -271,7 +271,7 @@ func TestNsLockMapStatusBlockedToRunning(t *testing.T) {
{ {
volume: "my-bucket", volume: "my-bucket",
path: "my-object-2", path: "my-object-2",
lockOrigin: "/home/vadmeste/work/go/src/github.com/minio/minio/xl-v1-object.go:683 +0x2a", lockSource: "/home/vadmeste/work/go/src/github.com/minio/minio/xl-v1-object.go:683 +0x2a",
opsID: "abcd1234", opsID: "abcd1234",
readLock: false, readLock: false,
setBlocked: false, setBlocked: false,
@ -283,7 +283,7 @@ func TestNsLockMapStatusBlockedToRunning(t *testing.T) {
{ {
volume: "my-bucket", volume: "my-bucket",
path: "my-object", path: "my-object",
lockOrigin: "/home/vadmeste/work/go/src/github.com/minio/minio/xl-v1-object.go:683 +0x2a", lockSource: "/home/vadmeste/work/go/src/github.com/minio/minio/xl-v1-object.go:683 +0x2a",
opsID: "ops-Id-not-registered", opsID: "ops-Id-not-registered",
readLock: true, readLock: true,
setBlocked: false, setBlocked: false,
@ -295,7 +295,7 @@ func TestNsLockMapStatusBlockedToRunning(t *testing.T) {
{ {
volume: "my-bucket", volume: "my-bucket",
path: "my-object", path: "my-object",
lockOrigin: "Bad Origin", lockSource: "Bad Origin",
opsID: "abcd1234", opsID: "abcd1234",
readLock: true, readLock: true,
setBlocked: false, setBlocked: false,
@ -307,7 +307,7 @@ func TestNsLockMapStatusBlockedToRunning(t *testing.T) {
{ {
volume: "my-bucket", volume: "my-bucket",
path: "my-object", path: "my-object",
lockOrigin: "/home/vadmeste/work/go/src/github.com/minio/minio/xl-v1-object.go:683 +0x2a", lockSource: "/home/vadmeste/work/go/src/github.com/minio/minio/xl-v1-object.go:683 +0x2a",
opsID: "abcd1234", opsID: "abcd1234",
readLock: false, readLock: false,
setBlocked: true, setBlocked: true,
@ -319,7 +319,7 @@ func TestNsLockMapStatusBlockedToRunning(t *testing.T) {
param := nsParam{testCases[0].volume, testCases[0].path} param := nsParam{testCases[0].volume, testCases[0].path}
// Testing before the initialization done. // Testing before the initialization done.
// Since the data structures for // Since the data structures for
actualErr := nsMutex.statusBlockedToRunning(param, testCases[0].lockOrigin, actualErr := nsMutex.statusBlockedToRunning(param, testCases[0].lockSource,
testCases[0].opsID, testCases[0].readLock) testCases[0].opsID, testCases[0].readLock)
expectedErr := LockInfoVolPathMissing{testCases[0].volume, testCases[0].path} expectedErr := LockInfoVolPathMissing{testCases[0].volume, testCases[0].path}
@ -334,7 +334,7 @@ func TestNsLockMapStatusBlockedToRunning(t *testing.T) {
} }
// Entry for <volume, path> pair is set to nil. Should fail with `errLockNotInitialized`. // Entry for <volume, path> pair is set to nil. Should fail with `errLockNotInitialized`.
nsMutex.debugLockMap[param] = nil nsMutex.debugLockMap[param] = nil
actualErr = nsMutex.statusBlockedToRunning(param, testCases[0].lockOrigin, actualErr = nsMutex.statusBlockedToRunning(param, testCases[0].lockSource,
testCases[0].opsID, testCases[0].readLock) testCases[0].opsID, testCases[0].readLock)
if errorCause(actualErr) != errLockNotInitialized { if errorCause(actualErr) != errLockNotInitialized {
@ -349,7 +349,7 @@ func TestNsLockMapStatusBlockedToRunning(t *testing.T) {
running: 0, running: 0,
} }
actualErr = nsMutex.statusBlockedToRunning(param, testCases[0].lockOrigin, actualErr = nsMutex.statusBlockedToRunning(param, testCases[0].lockSource,
testCases[0].opsID, testCases[0].readLock) testCases[0].opsID, testCases[0].readLock)
expectedOpsErr := LockInfoOpsIDNotFound{testCases[0].volume, testCases[0].path, testCases[0].opsID} expectedOpsErr := LockInfoOpsIDNotFound{testCases[0].volume, testCases[0].path, testCases[0].opsID}
@ -369,12 +369,12 @@ func TestNsLockMapStatusBlockedToRunning(t *testing.T) {
// Setting the status of the lock to be "Running". // Setting the status of the lock to be "Running".
// The initial state of the lock should set to "Blocked", otherwise its not possible to change the state from "Blocked" -> "Running". // The initial state of the lock should set to "Blocked", otherwise its not possible to change the state from "Blocked" -> "Running".
nsMutex.debugLockMap[param].lockInfo[testCases[0].opsID] = debugLockInfo{ nsMutex.debugLockMap[param].lockInfo[testCases[0].opsID] = debugLockInfo{
lockOrigin: "/home/vadmeste/work/go/src/github.com/minio/minio/xl-v1-object.go:683 +0x2a", lockSource: "/home/vadmeste/work/go/src/github.com/minio/minio/xl-v1-object.go:683 +0x2a",
status: "Running", // State set to "Running". Should fail with `LockInfoStateNotBlocked`. status: "Running", // State set to "Running". Should fail with `LockInfoStateNotBlocked`.
since: time.Now().UTC(), since: time.Now().UTC(),
} }
actualErr = nsMutex.statusBlockedToRunning(param, testCases[0].lockOrigin, actualErr = nsMutex.statusBlockedToRunning(param, testCases[0].lockSource,
testCases[0].opsID, testCases[0].readLock) testCases[0].opsID, testCases[0].readLock)
expectedBlockErr := LockInfoStateNotBlocked{testCases[0].volume, testCases[0].path, testCases[0].opsID} expectedBlockErr := LockInfoStateNotBlocked{testCases[0].volume, testCases[0].path, testCases[0].opsID}
@ -391,14 +391,14 @@ func TestNsLockMapStatusBlockedToRunning(t *testing.T) {
// status of the lock to be set to "Blocked", before setting Blocked->Running. // status of the lock to be set to "Blocked", before setting Blocked->Running.
if testCase.setBlocked { if testCase.setBlocked {
nsMutex.lockMapMutex.Lock() nsMutex.lockMapMutex.Lock()
err := nsMutex.statusNoneToBlocked(param, testCase.lockOrigin, testCase.opsID, testCase.readLock) err := nsMutex.statusNoneToBlocked(param, testCase.lockSource, testCase.opsID, testCase.readLock)
if err != nil { if err != nil {
t.Fatalf("Test %d: Initializing the initial state to Blocked failed <ERROR> %s", i+1, err) t.Fatalf("Test %d: Initializing the initial state to Blocked failed <ERROR> %s", i+1, err)
} }
nsMutex.lockMapMutex.Unlock() nsMutex.lockMapMutex.Unlock()
} }
// invoking the method under test. // invoking the method under test.
actualErr = nsMutex.statusBlockedToRunning(param, testCase.lockOrigin, testCase.opsID, testCase.readLock) actualErr = nsMutex.statusBlockedToRunning(param, testCase.lockSource, testCase.opsID, testCase.readLock)
if errorCause(actualErr) != testCase.expectedErr { if errorCause(actualErr) != testCase.expectedErr {
t.Fatalf("Test %d: Errors mismatch: Expected: \"%s\", got: \"%s\"", i+1, testCase.expectedErr, actualErr) t.Fatalf("Test %d: Errors mismatch: Expected: \"%s\", got: \"%s\"", i+1, testCase.expectedErr, actualErr)
} }
@ -419,8 +419,8 @@ func TestNsLockMapStatusBlockedToRunning(t *testing.T) {
} }
// validating the lock origin. // validating the lock origin.
if testCase.lockOrigin != lockInfo.lockOrigin { if testCase.lockSource != lockInfo.lockSource {
t.Errorf("Test %d: Expected the lock origin info to be \"%s\", but got \"%s\"", i+1, testCase.lockOrigin, lockInfo.lockOrigin) t.Errorf("Test %d: Expected the lock origin info to be \"%s\", but got \"%s\"", i+1, testCase.lockSource, lockInfo.lockSource)
} }
// validating the status of the lock. // validating the status of the lock.
if lockInfo.status != runningStatus { if lockInfo.status != runningStatus {
@ -448,7 +448,7 @@ func TestNsLockMapStatusNoneToBlocked(t *testing.T) {
volume: "my-bucket", volume: "my-bucket",
path: "my-object", path: "my-object",
lockOrigin: "/home/vadmeste/work/go/src/github.com/minio/minio/xl-v1-object.go:683 +0x2a", lockSource: "/home/vadmeste/work/go/src/github.com/minio/minio/xl-v1-object.go:683 +0x2a",
opsID: "abcd1234", opsID: "abcd1234",
readLock: true, readLock: true,
// expected metrics. // expected metrics.
@ -470,7 +470,7 @@ func TestNsLockMapStatusNoneToBlocked(t *testing.T) {
volume: "my-bucket", volume: "my-bucket",
path: "my-object-2", path: "my-object-2",
lockOrigin: "/home/vadmeste/work/go/src/github.com/minio/minio/xl-v1-object.go:683 +0x2a", lockSource: "/home/vadmeste/work/go/src/github.com/minio/minio/xl-v1-object.go:683 +0x2a",
opsID: "abcd1234", opsID: "abcd1234",
readLock: false, readLock: false,
// expected metrics. // expected metrics.
@ -491,7 +491,7 @@ func TestNsLockMapStatusNoneToBlocked(t *testing.T) {
{ {
volume: "my-bucket", volume: "my-bucket",
path: "my-object", path: "my-object",
lockOrigin: "/home/vadmeste/work/go/src/github.com/minio/minio/xl-v1-object.go:683 +0x2a", lockSource: "/home/vadmeste/work/go/src/github.com/minio/minio/xl-v1-object.go:683 +0x2a",
opsID: "ops-Id-not-registered", opsID: "ops-Id-not-registered",
readLock: true, readLock: true,
// expected metrics. // expected metrics.
@ -514,7 +514,7 @@ func TestNsLockMapStatusNoneToBlocked(t *testing.T) {
param := nsParam{testCases[0].volume, testCases[0].path} param := nsParam{testCases[0].volume, testCases[0].path}
// Testing before the initialization done. // Testing before the initialization done.
// Since the data structures for // Since the data structures for
actualErr := nsMutex.statusBlockedToRunning(param, testCases[0].lockOrigin, actualErr := nsMutex.statusBlockedToRunning(param, testCases[0].lockSource,
testCases[0].opsID, testCases[0].readLock) testCases[0].opsID, testCases[0].readLock)
expectedErr := LockInfoVolPathMissing{testCases[0].volume, testCases[0].path} expectedErr := LockInfoVolPathMissing{testCases[0].volume, testCases[0].path}
@ -526,7 +526,7 @@ func TestNsLockMapStatusNoneToBlocked(t *testing.T) {
for i, testCase := range testCases { for i, testCase := range testCases {
nsMutex.lockMapMutex.Lock() nsMutex.lockMapMutex.Lock()
param := nsParam{testCase.volume, testCase.path} param := nsParam{testCase.volume, testCase.path}
actualErr := nsMutex.statusNoneToBlocked(param, testCase.lockOrigin, testCase.opsID, testCase.readLock) actualErr := nsMutex.statusNoneToBlocked(param, testCase.lockSource, testCase.opsID, testCase.readLock)
if actualErr != testCase.expectedErr { if actualErr != testCase.expectedErr {
t.Fatalf("Test %d: Errors mismatch: Expected: \"%s\", got: \"%s\"", i+1, testCase.expectedErr, actualErr) t.Fatalf("Test %d: Errors mismatch: Expected: \"%s\", got: \"%s\"", i+1, testCase.expectedErr, actualErr)
} }
@ -544,7 +544,7 @@ func TestNsLockMapDeleteLockInfoEntryForOps(t *testing.T) {
{ {
volume: "my-bucket", volume: "my-bucket",
path: "my-object", path: "my-object",
lockOrigin: "/home/vadmeste/work/go/src/github.com/minio/minio/xl-v1-object.go:683 +0x2a", lockSource: "/home/vadmeste/work/go/src/github.com/minio/minio/xl-v1-object.go:683 +0x2a",
opsID: "abcd1234", opsID: "abcd1234",
readLock: true, readLock: true,
// expected metrics. // expected metrics.
@ -569,12 +569,12 @@ func TestNsLockMapDeleteLockInfoEntryForOps(t *testing.T) {
// Case - 2. // Case - 2.
// Lock state is set to Running and then an attempt to delete the info for non-existent opsID done. // Lock state is set to Running and then an attempt to delete the info for non-existent opsID done.
nsMutex.lockMapMutex.Lock() nsMutex.lockMapMutex.Lock()
err := nsMutex.statusNoneToBlocked(param, testCases[0].lockOrigin, testCases[0].opsID, testCases[0].readLock) err := nsMutex.statusNoneToBlocked(param, testCases[0].lockSource, testCases[0].opsID, testCases[0].readLock)
if err != nil { if err != nil {
t.Fatalf("Setting lock status to Blocked failed: <ERROR> %s", err) t.Fatalf("Setting lock status to Blocked failed: <ERROR> %s", err)
} }
nsMutex.lockMapMutex.Unlock() nsMutex.lockMapMutex.Unlock()
err = nsMutex.statusBlockedToRunning(param, testCases[0].lockOrigin, testCases[0].opsID, testCases[0].readLock) err = nsMutex.statusBlockedToRunning(param, testCases[0].lockSource, testCases[0].opsID, testCases[0].readLock)
if err != nil { if err != nil {
t.Fatalf("Setting lock status to Running failed: <ERROR> %s", err) t.Fatalf("Setting lock status to Running failed: <ERROR> %s", err)
} }
@ -629,7 +629,7 @@ func TestNsLockMapDeleteLockInfoEntryForVolumePath(t *testing.T) {
{ {
volume: "my-bucket", volume: "my-bucket",
path: "my-object", path: "my-object",
lockOrigin: "/home/vadmeste/work/go/src/github.com/minio/minio/xl-v1-object.go:683 +0x2a", lockSource: "/home/vadmeste/work/go/src/github.com/minio/minio/xl-v1-object.go:683 +0x2a",
opsID: "abcd1234", opsID: "abcd1234",
readLock: true, readLock: true,
// expected metrics. // expected metrics.
@ -655,12 +655,12 @@ func TestNsLockMapDeleteLockInfoEntryForVolumePath(t *testing.T) {
// Registering the entry first. // Registering the entry first.
nsMutex.lockMapMutex.Lock() nsMutex.lockMapMutex.Lock()
err := nsMutex.statusNoneToBlocked(param, testCases[0].lockOrigin, testCases[0].opsID, testCases[0].readLock) err := nsMutex.statusNoneToBlocked(param, testCases[0].lockSource, testCases[0].opsID, testCases[0].readLock)
if err != nil { if err != nil {
t.Fatalf("Setting lock status to Blocked failed: <ERROR> %s", err) t.Fatalf("Setting lock status to Blocked failed: <ERROR> %s", err)
} }
nsMutex.lockMapMutex.Unlock() nsMutex.lockMapMutex.Unlock()
err = nsMutex.statusBlockedToRunning(param, testCases[0].lockOrigin, testCases[0].opsID, testCases[0].readLock) err = nsMutex.statusBlockedToRunning(param, testCases[0].lockSource, testCases[0].opsID, testCases[0].readLock)
if err != nil { if err != nil {
t.Fatalf("Setting lock status to Running failed: <ERROR> %s", err) t.Fatalf("Setting lock status to Running failed: <ERROR> %s", err)
} }

@ -52,7 +52,7 @@ type VolumeLockInfo struct {
// structure to fill in status information for each operation with given operation ID. // structure to fill in status information for each operation with given operation ID.
type OpsLockState struct { type OpsLockState struct {
OperationID string `json:"opsID"` // String containing operation ID. OperationID string `json:"opsID"` // String containing operation ID.
LockOrigin string `json:"lockOrigin"` // Operation type (GetObject, PutObject...) LockSource string `json:"lockSource"` // Operation type (GetObject, PutObject...)
LockType lockType `json:"lockType"` // Lock type (RLock, WLock) LockType lockType `json:"lockType"` // Lock type (RLock, WLock)
Status statusType `json:"status"` // Status can be Running/Ready/Blocked. Status statusType `json:"status"` // Status can be Running/Ready/Blocked.
Since time.Time `json:"statusSince"` // Time when the lock was initially held. Since time.Time `json:"statusSince"` // Time when the lock was initially held.
@ -80,7 +80,7 @@ func getSystemLockState() (SystemLockState, error) {
for opsID, lockInfo := range debugLock.lockInfo { for opsID, lockInfo := range debugLock.lockInfo {
volLockInfo.LockDetailsOnObject = append(volLockInfo.LockDetailsOnObject, OpsLockState{ volLockInfo.LockDetailsOnObject = append(volLockInfo.LockDetailsOnObject, OpsLockState{
OperationID: opsID, OperationID: opsID,
LockOrigin: lockInfo.lockOrigin, LockSource: lockInfo.lockSource,
LockType: lockInfo.lType, LockType: lockInfo.lType,
Status: lockInfo.status, Status: lockInfo.status,
Since: lockInfo.since, Since: lockInfo.since,

@ -45,7 +45,7 @@ type logger struct {
} }
// Get file, line, function name of the caller. // Get file, line, function name of the caller.
func callerLocation() string { func callerSource() string {
pc, file, line, success := runtime.Caller(2) pc, file, line, success := runtime.Caller(2)
if !success { if !success {
file = "<unknown>" file = "<unknown>"
@ -59,12 +59,12 @@ func callerLocation() string {
// errorIf synonymous with fatalIf but doesn't exit on error != nil // errorIf synonymous with fatalIf but doesn't exit on error != nil
func errorIf(err error, msg string, data ...interface{}) { func errorIf(err error, msg string, data ...interface{}) {
if err == nil { if err == nil || !isErrLogged(err) {
return return
} }
location := callerLocation() source := callerSource()
fields := logrus.Fields{ fields := logrus.Fields{
"location": location, "source": source,
"cause": err.Error(), "cause": err.Error(),
} }
if e, ok := err.(*Error); ok { if e, ok := err.(*Error); ok {
@ -78,12 +78,12 @@ func errorIf(err error, msg string, data ...interface{}) {
// fatalIf wrapper function which takes error and prints jsonic error messages. // fatalIf wrapper function which takes error and prints jsonic error messages.
func fatalIf(err error, msg string, data ...interface{}) { func fatalIf(err error, msg string, data ...interface{}) {
if err == nil { if err == nil || !isErrLogged(err) {
return return
} }
location := callerLocation() source := callerSource()
fields := logrus.Fields{ fields := logrus.Fields{
"location": location, "source": source,
"cause": err.Error(), "cause": err.Error(),
} }
if e, ok := err.(*Error); ok { if e, ok := err.(*Error); ok {
@ -93,3 +93,20 @@ func fatalIf(err error, msg string, data ...interface{}) {
log.WithFields(fields).Fatalf(msg, data...) log.WithFields(fields).Fatalf(msg, data...)
} }
} }
// returns false if error is not supposed to be logged.
func isErrLogged(err error) (ok bool) {
ok = true
err = errorCause(err)
switch err.(type) {
case BucketNotFound, BucketNotEmpty, BucketExists:
ok = false
case ObjectNotFound, ObjectExistsAsDirectory:
ok = false
case BucketPolicyNotFound, InvalidUploadID:
ok = false
case BadDigest:
ok = false
}
return ok
}

@ -25,13 +25,13 @@ import (
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
) )
// Tests callerLocation. // Tests callerSource.
func TestCallerLocation(t *testing.T) { func TestCallerSource(t *testing.T) {
currentLocation := func() string { return callerLocation() } currentSource := func() string { return callerSource() }
gotLocation := currentLocation() gotSource := currentSource()
expectedLocation := "[logger_test.go:31:TestCallerLocation()]" expectedSource := "[logger_test.go:31:TestCallerSource()]"
if gotLocation != expectedLocation { if gotSource != expectedSource {
t.Errorf("expected : %s, got : %s", expectedLocation, gotLocation) t.Errorf("expected : %s, got : %s", expectedSource, gotSource)
} }
} }

@ -104,7 +104,7 @@ type nsLockMap struct {
} }
// Lock the namespace resource. // Lock the namespace resource.
func (n *nsLockMap) lock(volume, path string, lockOrigin, opsID string, readLock bool) { func (n *nsLockMap) lock(volume, path string, lockSource, opsID string, readLock bool) {
var nsLk *nsLock var nsLk *nsLock
n.lockMapMutex.Lock() n.lockMapMutex.Lock()
@ -128,7 +128,7 @@ func (n *nsLockMap) lock(volume, path string, lockOrigin, opsID string, readLock
// pair of <volume, path> and <OperationID> till the lock // pair of <volume, path> and <OperationID> till the lock
// unblocks. The lock for accessing `nsMutex` is held inside // unblocks. The lock for accessing `nsMutex` is held inside
// the function itself. // the function itself.
if err := n.statusNoneToBlocked(param, lockOrigin, opsID, readLock); err != nil { if err := n.statusNoneToBlocked(param, lockSource, opsID, readLock); err != nil {
errorIf(err, "Failed to set lock state to blocked") errorIf(err, "Failed to set lock state to blocked")
} }
@ -145,7 +145,7 @@ func (n *nsLockMap) lock(volume, path string, lockOrigin, opsID string, readLock
// Changing the status of the operation from blocked to // Changing the status of the operation from blocked to
// running. change the state of the lock to be running (from // running. change the state of the lock to be running (from
// blocked) for the given pair of <volume, path> and <OperationID>. // blocked) for the given pair of <volume, path> and <OperationID>.
if err := n.statusBlockedToRunning(param, lockOrigin, opsID, readLock); err != nil { if err := n.statusBlockedToRunning(param, lockSource, opsID, readLock); err != nil {
errorIf(err, "Failed to set the lock state to running") errorIf(err, "Failed to set the lock state to running")
} }
} }
@ -196,8 +196,8 @@ func (n *nsLockMap) unlock(volume, path, opsID string, readLock bool) {
func (n *nsLockMap) Lock(volume, path, opsID string) { func (n *nsLockMap) Lock(volume, path, opsID string) {
readLock := false // This is a write lock. readLock := false // This is a write lock.
lockLocation := callerLocation() // Useful for debugging lockSource := callerSource() // Useful for debugging
n.lock(volume, path, lockLocation, opsID, readLock) n.lock(volume, path, lockSource, opsID, readLock)
} }
// Unlock - unlocks any previously acquired write locks. // Unlock - unlocks any previously acquired write locks.
@ -210,8 +210,8 @@ func (n *nsLockMap) Unlock(volume, path, opsID string) {
func (n *nsLockMap) RLock(volume, path, opsID string) { func (n *nsLockMap) RLock(volume, path, opsID string) {
readLock := true readLock := true
lockLocation := callerLocation() // Useful for debugging lockSource := callerSource() // Useful for debugging
n.lock(volume, path, lockLocation, opsID, readLock) n.lock(volume, path, lockSource, opsID, readLock)
} }
// RUnlock - unlocks any previously acquired read locks. // RUnlock - unlocks any previously acquired read locks.
@ -272,9 +272,9 @@ func (n *nsLockMap) NewNSLock(volume, path string) *lockInstance {
// Lock - block until write lock is taken. // Lock - block until write lock is taken.
func (li *lockInstance) Lock() { func (li *lockInstance) Lock() {
lockLocation := callerLocation() lockSource := callerSource()
readLock := false readLock := false
li.n.lock(li.volume, li.path, lockLocation, li.opsID, readLock) li.n.lock(li.volume, li.path, lockSource, li.opsID, readLock)
} }
// Unlock - block until write lock is released. // Unlock - block until write lock is released.
@ -285,9 +285,9 @@ func (li *lockInstance) Unlock() {
// RLock - block until read lock is taken. // RLock - block until read lock is taken.
func (li *lockInstance) RLock() { func (li *lockInstance) RLock() {
lockLocation := callerLocation() lockSource := callerSource()
readLock := true readLock := true
li.n.lock(li.volume, li.path, lockLocation, li.opsID, readLock) li.n.lock(li.volume, li.path, lockSource, li.opsID, readLock)
} }
// RUnlock - block until read lock is released. // RUnlock - block until read lock is released.

@ -141,7 +141,7 @@ func TestLockStats(t *testing.T) {
path: "my-object", path: "my-object",
opsID: "0", opsID: "0",
readLock: true, readLock: true,
lockOrigin: "[lock held] in github.com/minio/minio/cmd.TestLockStats[/Users/hackintoshrao/mycode/go/src/github.com/minio/minio/cmd/namespace-lock_test.go:298]", lockSource: "[lock held] in github.com/minio/minio/cmd.TestLockStats[/Users/hackintoshrao/mycode/go/src/github.com/minio/minio/cmd/namespace-lock_test.go:298]",
// expected metrics. // expected metrics.
expectedErr: nil, expectedErr: nil,
expectedLockStatus: "Running", expectedLockStatus: "Running",
@ -162,7 +162,7 @@ func TestLockStats(t *testing.T) {
path: "my-object", path: "my-object",
opsID: "6", opsID: "6",
readLock: true, readLock: true,
lockOrigin: "[lock held] in github.com/minio/minio/cmd.TestLockStats[/Users/hackintoshrao/mycode/go/src/github.com/minio/minio/cmd/namespace-lock_test.go:298]", lockSource: "[lock held] in github.com/minio/minio/cmd.TestLockStats[/Users/hackintoshrao/mycode/go/src/github.com/minio/minio/cmd/namespace-lock_test.go:298]",
// expected metrics. // expected metrics.
expectedErr: nil, expectedErr: nil,
expectedLockStatus: "Running", expectedLockStatus: "Running",
@ -182,7 +182,7 @@ func TestLockStats(t *testing.T) {
path: "my-object", path: "my-object",
opsID: "10", opsID: "10",
readLock: false, readLock: false,
lockOrigin: "[lock held] in github.com/minio/minio/cmd.TestLockStats[/Users/hackintoshrao/mycode/go/src/github.com/minio/minio/cmd/namespace-lock_test.go:298]", lockSource: "[lock held] in github.com/minio/minio/cmd.TestLockStats[/Users/hackintoshrao/mycode/go/src/github.com/minio/minio/cmd/namespace-lock_test.go:298]",
// expected metrics. // expected metrics.
expectedErr: nil, expectedErr: nil,
expectedLockStatus: "Running", expectedLockStatus: "Running",
@ -219,7 +219,7 @@ func TestLockStats(t *testing.T) {
path: "my-object", path: "my-object",
opsID: "11", opsID: "11",
readLock: false, readLock: false,
lockOrigin: "[lock held] in github.com/minio/minio/cmd.TestLockStats[/Users/hackintoshrao/mycode/go/src/github.com/minio/minio/cmd/namespace-lock_test.go:298]", lockSource: "[lock held] in github.com/minio/minio/cmd.TestLockStats[/Users/hackintoshrao/mycode/go/src/github.com/minio/minio/cmd/namespace-lock_test.go:298]",
// expected metrics. // expected metrics.
expectedErr: nil, expectedErr: nil,
expectedLockStatus: "Running", expectedLockStatus: "Running",
@ -244,7 +244,7 @@ func TestLockStats(t *testing.T) {
readLock: false, readLock: false,
// write lock is held at line 318. // write lock is held at line 318.
// this confirms that we are looking the right write lock. // this confirms that we are looking the right write lock.
lockOrigin: "[lock held] in github.com/minio/minio/cmd.TestLockStats.func2[/Users/hackintoshrao/mycode/go/src/github.com/minio/minio/cmd/namespace-lock_test.go:318]", lockSource: "[lock held] in github.com/minio/minio/cmd.TestLockStats.func2[/Users/hackintoshrao/mycode/go/src/github.com/minio/minio/cmd/namespace-lock_test.go:318]",
// expected metrics. // expected metrics.
expectedErr: nil, expectedErr: nil,
expectedLockStatus: "Blocked", expectedLockStatus: "Blocked",
@ -268,7 +268,7 @@ func TestLockStats(t *testing.T) {
path: "my-object", path: "my-object",
opsID: "9", opsID: "9",
readLock: true, readLock: true,
lockOrigin: "[lock held] in github.com/minio/minio/cmd.TestLockStats.func2[/Users/hackintoshrao/mycode/go/src/github.com/minio/minio/cmd/namespace-lock_test.go:318]", lockSource: "[lock held] in github.com/minio/minio/cmd.TestLockStats.func2[/Users/hackintoshrao/mycode/go/src/github.com/minio/minio/cmd/namespace-lock_test.go:318]",
// expected metrics. // expected metrics.
expectedErr: nil, expectedErr: nil,
expectedLockStatus: "Running", expectedLockStatus: "Running",

Loading…
Cancel
Save