From 36fd317eb2a9674aac366f1b513a67562e330e6a Mon Sep 17 00:00:00 2001 From: Krishnan Parthasarathi Date: Mon, 26 Dec 2016 23:59:55 +0530 Subject: [PATCH] Clean up lock-instrumentation and improve comments (#3499) - Add a lockStat type to group counters - Remove unnecessary helper functions - Fix stats computation on force unlock - Removed unnecessary checks and cleaned up comments --- cmd/lock-instrument.go | 205 ++++++++++++++---------------------- cmd/lock-instrument_test.go | 83 +++++++-------- cmd/lock-stat.go | 49 +++++++++ cmd/lockinfo-handlers.go | 12 +-- cmd/namespace-lock.go | 7 +- 5 files changed, 176 insertions(+), 180 deletions(-) create mode 100644 cmd/lock-stat.go diff --git a/cmd/lock-instrument.go b/cmd/lock-instrument.go index 7c00ba6bd..0b5fea730 100644 --- a/cmd/lock-instrument.go +++ b/cmd/lock-instrument.go @@ -17,7 +17,6 @@ package cmd import ( - "errors" "fmt" "time" ) @@ -36,59 +35,39 @@ const ( debugWLockStr lockType = "WLock" ) -// Struct containing information of status (ready/running/blocked) of an operation with given operation ID. +// debugLockInfo - represents a single lock's information, uniquely identified by opsID. +// See debugLockInfoPerVolumePath for more context. type debugLockInfo struct { // "RLock" or "WLock". lType lockType - // Contains the trace of the function which invoked the lock, obtained from runtime. + // Contains the backtrace of incl. the function which called (r)(un)lock. lockSource string - // Status can be running/ready/blocked. + // Status can be running/blocked. status statusType - // Time info of the since how long the status holds true. + // Time of last status update. since time.Time } -// debugLockInfo - container for storing locking information for unique copy -// (volume,path) pair. ref variable holds the reference count for locks held for. -// `ref` values helps us understand the n locks held for given pair. -// `running` value helps us understand the total successful locks held (not blocked) -// for given pair and the operation is under execution. `blocked` -// value helps us understand the total number of operations blocked waiting on -// locks for given pair. +// debugLockInfoPerVolumePath - lock state information on all locks held on (volume, path). type debugLockInfoPerVolumePath struct { - ref int64 // running + blocked operations. - running int64 // count of successful lock acquire and running operations. - blocked int64 // count of number of operations blocked waiting on lock. - lockInfo map[string]debugLockInfo // map of [opsID] debugLockInfo{operation, status, since} . + counters *lockStat // Holds stats of lock held on (volume, path) + lockInfo map[string]debugLockInfo // Lock information per operation ID. } -// returns an instance of debugLockInfo. -// need to create this for every unique pair of {volume,path}. -// total locks, number of calls blocked on locks, and number of successful locks held but not unlocked yet. -func newDebugLockInfoPerVolumePath() *debugLockInfoPerVolumePath { - return &debugLockInfoPerVolumePath{ - lockInfo: make(map[string]debugLockInfo), - ref: 0, - blocked: 0, - running: 0, - } -} - -// LockInfoOriginNotFound - While changing the state of the lock info its important that the entry for -// lock at a given origin exists, if not `LockInfoOriginNotFound` is returned. -type LockInfoOriginNotFound struct { +// LockInfoOriginMismatch - represents error when lock origin don't match. +type LockInfoOriginMismatch struct { volume string path string opsID string lockSource string } -func (l LockInfoOriginNotFound) Error() string { - return fmt.Sprintf("No lock state stored for the lock origined at \"%s\", for %s, %s, %s", +func (l LockInfoOriginMismatch) Error() string { + return fmt.Sprintf("No lock state stored for the lock originated at \"%s\", for %s, %s, %s", l.lockSource, l.volume, l.path, l.opsID) } -// LockInfoVolPathMissing - Error interface. Returned when the info the +// LockInfoVolPathMissing - represents error when lock information is missing for a given (volume, path). type LockInfoVolPathMissing struct { volume string path string @@ -98,8 +77,7 @@ func (l LockInfoVolPathMissing) Error() string { return fmt.Sprintf("No entry in debug Lock Map for Volume: %s, path: %s", l.volume, l.path) } -// LockInfoOpsIDNotFound - Returned when the lock state info exists, but the entry for -// given operation ID doesn't exist. +// LockInfoOpsIDNotFound - represents error when lock info entry for a given operation ID doesn't exist. type LockInfoOpsIDNotFound struct { volume string path string @@ -110,8 +88,7 @@ func (l LockInfoOpsIDNotFound) Error() string { return fmt.Sprintf("No entry in lock info for %s, %s, %s", l.opsID, l.volume, l.path) } -// LockInfoStateNotBlocked - When an attempt to change the state of the lock form `blocked` to `running` is done, -// its necessary that the state before the transsition is "blocked", otherwise LockInfoStateNotBlocked returned. +// LockInfoStateNotBlocked - represents error when lock info isn't in blocked state when it should be. type LockInfoStateNotBlocked struct { volume string path string @@ -122,146 +99,126 @@ func (l LockInfoStateNotBlocked) Error() string { return fmt.Sprintf("Lock state should be \"Blocked\" for %s, %s, %s", l.volume, l.path, l.opsID) } -var errLockNotInitialized = errors.New("Debug lockMap not initialized") - -// Initialize lock info volume path. +// Initialize lock info for given (volume, path). func (n *nsLockMap) initLockInfoForVolumePath(param nsParam) { - n.debugLockMap[param] = newDebugLockInfoPerVolumePath() + n.debugLockMap[param] = &debugLockInfoPerVolumePath{ + lockInfo: make(map[string]debugLockInfo), + counters: &lockStat{}, + } } // Change the state of the lock from Blocked to Running. 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 function is called outside nsLockMap.mutex.Lock(), so must be held explicitly. n.lockMapMutex.Lock() defer n.lockMapMutex.Unlock() - // new state info to be set for the lock. - newLockInfo := debugLockInfo{ - lockSource: lockSource, - status: runningStatus, - since: time.Now().UTC(), - } - - // Set lock type. - if readLock { - newLockInfo.lType = debugRLockStr - } else { - newLockInfo.lType = debugWLockStr - } - // Check whether the lock info entry for pair already exists and its not `nil`. - debugLockMap, ok := n.debugLockMap[param] + // Check whether the lock info entry for pair already exists. + _, ok := n.debugLockMap[param] if !ok { - // The lock state info foe given pair should already exist. - // If not return `LockInfoVolPathMissing`. return traceError(LockInfoVolPathMissing{param.volume, param.path}) } - // ``debugLockMap`` entry containing lock info for `param ` is `nil`. - if debugLockMap == nil { - return traceError(errLockNotInitialized) - } + + // Check whether lock info entry for the given `opsID` exists. lockInfo, ok := n.debugLockMap[param].lockInfo[opsID] if !ok { - // The lock info entry for given `opsID` should already exist for given pair. - // If not return `LockInfoOpsIDNotFound`. return traceError(LockInfoOpsIDNotFound{param.volume, param.path, opsID}) } - // The entry for the lock origined at `lockSource` should already exist. If not return `LockInfoOriginNotFound`. + + // Check whether lockSource is same. if lockInfo.lockSource != lockSource { - return traceError(LockInfoOriginNotFound{param.volume, param.path, opsID, lockSource}) + return traceError(LockInfoOriginMismatch{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 be set to "Blocked". if lockInfo.status != blockedStatus { return traceError(LockInfoStateNotBlocked{param.volume, param.path, opsID}) } - // All checks finished. Changing the status of the operation from blocked to running and updating the time. - n.debugLockMap[param].lockInfo[opsID] = newLockInfo + // Change lock status to running and update the time. + n.debugLockMap[param].lockInfo[opsID] = newDebugLockInfo(lockSource, runningStatus, readLock) - // After locking unblocks decrease the blocked counter. - n.blockedCounter-- - // Increase the running counter. - n.runningLockCounter++ - n.debugLockMap[param].blocked-- - n.debugLockMap[param].running++ + // Update global lock stats. + n.counters.lockGranted() + // Update (volume, pair) lock stats. + n.debugLockMap[param].counters.lockGranted() return nil } -// Change the state of the lock from Ready to Blocked. -func (n *nsLockMap) statusNoneToBlocked(param nsParam, lockSource, opsID string, readLock bool) error { - newLockInfo := debugLockInfo{ - lockSource: lockSource, - status: blockedStatus, - since: time.Now().UTC(), - } +// newDebugLockInfo - Constructs a debugLockInfo value given lock source, status and type. +func newDebugLockInfo(lockSource string, status statusType, readLock bool) debugLockInfo { + lType := debugRLockStr if readLock { - newLockInfo.lType = debugRLockStr + lType = debugRLockStr } else { - newLockInfo.lType = debugWLockStr + lType = debugWLockStr + } + return debugLockInfo{ + lockSource: lockSource, + lType: lType, + status: status, + since: time.Now().UTC(), } +} - lockInfo, ok := n.debugLockMap[param] +// Change the state of the lock to Blocked. +func (n *nsLockMap) statusNoneToBlocked(param nsParam, lockSource, opsID string, readLock bool) error { + _, ok := n.debugLockMap[param] if !ok { - // State info entry for the given doesn't exist, initializing it. - n.initLockInfoForVolumePath(param) - } - if lockInfo == nil { - // *lockInfo is nil, initialize here. + // Lock info entry for (volume, pair) doesn't exist, initialize it. n.initLockInfoForVolumePath(param) } - // lockInfo is a map[string]debugLockInfo, which holds map[OperationID]{status,time, origin} of the lock. - if n.debugLockMap[param].lockInfo == nil { - n.debugLockMap[param].lockInfo = make(map[string]debugLockInfo) - } - // The status of the operation with the given operation ID is marked blocked till its gets unblocked from the lock. - n.debugLockMap[param].lockInfo[opsID] = newLockInfo - // Increment the Global lock counter. - n.globalLockCounter++ - // Increment the counter for number of blocked opertions, decrement it after the locking unblocks. - n.blockedCounter++ - // increment the reference of the lock for the given pair. - n.debugLockMap[param].ref++ - // increment the blocked counter for the given pair. - n.debugLockMap[param].blocked++ + // Mark lock status blocked for given opsID. + n.debugLockMap[param].lockInfo[opsID] = newDebugLockInfo(lockSource, blockedStatus, readLock) + // Update global lock stats. + n.counters.lockWaiting() + // Update (volume, path) lock stats. + n.debugLockMap[param].counters.lockWaiting() return nil } -// deleteLockInfoEntry - Deletes the lock state information for given -// pair. Called when nsLk.ref count is 0. +// deleteLockInfoEntry - Deletes the lock information for given (volume, path). +// Called when nsLk.ref count is 0. func (n *nsLockMap) deleteLockInfoEntryForVolumePath(param nsParam) error { // delete the lock info for the given operation. if _, found := n.debugLockMap[param]; !found { return traceError(LockInfoVolPathMissing{param.volume, param.path}) } - // Remove from the map if there are no more references for the given (volume,path) pair. + + // The following stats update is relevant only in case of a + // ForceUnlock. In case of the last unlock on a (volume, + // path), this would be a no-op. + volumePathLocks := n.debugLockMap[param] + for _, lockInfo := range volumePathLocks.lockInfo { + granted := lockInfo.status == runningStatus + // Update global and (volume, path) stats. + n.counters.lockRemoved(granted) + volumePathLocks.counters.lockRemoved(granted) + } delete(n.debugLockMap, param) return nil } -// deleteLockInfoEntry - Deletes the entry for given opsID in the lock state information -// of given pair. Called when the nsLk ref count for the given -// pair is not 0. +// deleteLockInfoEntry - Deletes lock info entry for given opsID. +// Called when the nsLk ref count for the given (volume, path) is +// not 0. func (n *nsLockMap) deleteLockInfoEntryForOps(param nsParam, opsID string) error { // delete the lock info for the given operation. infoMap, found := n.debugLockMap[param] if !found { return traceError(LockInfoVolPathMissing{param.volume, param.path}) } - // The opertion finished holding the lock on the resource, remove + // The operation finished holding the lock on the resource, remove // the entry for the given operation with the operation ID. - _, foundInfo := infoMap.lockInfo[opsID] + opsIDLock, foundInfo := infoMap.lockInfo[opsID] if !foundInfo { - // Unlock request with invalid opertion ID not accepted. + // Unlock request with invalid operation ID not accepted. return traceError(LockInfoOpsIDNotFound{param.volume, param.path, opsID}) } - // Decrease the global running and lock reference counter. - n.runningLockCounter-- - n.globalLockCounter-- - // Decrease the lock referee counter for the lock info for given pair. - // Decrease the running operation number. Its assumed that the operation is over - // once an attempt to release the lock is made. - infoMap.running-- - // Decrease the total reference count of locks jeld on pair. - infoMap.ref-- + // Update global and (volume, path) lock status. + granted := opsIDLock.status == runningStatus + n.counters.lockRemoved(granted) + infoMap.counters.lockRemoved(granted) delete(infoMap.lockInfo, opsID) return nil } diff --git a/cmd/lock-instrument_test.go b/cmd/lock-instrument_test.go index fe33341a1..503dc7876 100644 --- a/cmd/lock-instrument_test.go +++ b/cmd/lock-instrument_test.go @@ -124,19 +124,19 @@ func verifyGlobalLockStats(l lockStateCase, t *testing.T, testNum int) { globalNSMutex.lockMapMutex.Lock() // Verifying the lock stats. - if globalNSMutex.globalLockCounter != int64(l.expectedGlobalLockCount) { + if globalNSMutex.counters.total != int64(l.expectedGlobalLockCount) { t.Errorf("Test %d: Expected the global lock counter to be %v, but got %v", testNum, int64(l.expectedGlobalLockCount), - globalNSMutex.globalLockCounter) + globalNSMutex.counters.total) } // verify the count for total blocked locks. - if globalNSMutex.blockedCounter != int64(l.expectedBlockedLockCount) { + if globalNSMutex.counters.blocked != int64(l.expectedBlockedLockCount) { t.Errorf("Test %d: Expected the total blocked lock counter to be %v, but got %v", testNum, int64(l.expectedBlockedLockCount), - globalNSMutex.blockedCounter) + globalNSMutex.counters.blocked) } // verify the count for total running locks. - if globalNSMutex.runningLockCounter != int64(l.expectedRunningLockCount) { + if globalNSMutex.counters.granted != int64(l.expectedRunningLockCount) { t.Errorf("Test %d: Expected the total running lock counter to be %v, but got %v", testNum, int64(l.expectedRunningLockCount), - globalNSMutex.runningLockCounter) + globalNSMutex.counters.granted) } globalNSMutex.lockMapMutex.Unlock() // Verifying again with the JSON response of the lock info. @@ -169,19 +169,19 @@ func verifyLockStats(l lockStateCase, t *testing.T, testNum int) { param := nsParam{l.volume, l.path} // Verify the total locks (blocked+running) for given pair. - if globalNSMutex.debugLockMap[param].ref != int64(l.expectedVolPathLockCount) { + if globalNSMutex.debugLockMap[param].counters.total != int64(l.expectedVolPathLockCount) { t.Errorf("Test %d: Expected the total lock count for volume: \"%s\", path: \"%s\" to be %v, but got %v", testNum, - param.volume, param.path, int64(l.expectedVolPathLockCount), globalNSMutex.debugLockMap[param].ref) + param.volume, param.path, int64(l.expectedVolPathLockCount), globalNSMutex.debugLockMap[param].counters.total) } // Verify the total running locks for given pair. - if globalNSMutex.debugLockMap[param].running != int64(l.expectedVolPathRunningCount) { + if globalNSMutex.debugLockMap[param].counters.granted != int64(l.expectedVolPathRunningCount) { t.Errorf("Test %d: Expected the total running locks for volume: \"%s\", path: \"%s\" to be %v, but got %v", testNum, param.volume, param.path, - int64(l.expectedVolPathRunningCount), globalNSMutex.debugLockMap[param].running) + int64(l.expectedVolPathRunningCount), globalNSMutex.debugLockMap[param].counters.granted) } // Verify the total blocked locks for givne pair. - if globalNSMutex.debugLockMap[param].blocked != int64(l.expectedVolPathBlockCount) { + if globalNSMutex.debugLockMap[param].counters.blocked != int64(l.expectedVolPathBlockCount) { t.Errorf("Test %d: Expected the total blocked locks for volume: \"%s\", path: \"%s\" to be %v, but got %v", testNum, param.volume, param.path, - int64(l.expectedVolPathBlockCount), globalNSMutex.debugLockMap[param].blocked) + int64(l.expectedVolPathBlockCount), globalNSMutex.debugLockMap[param].counters.blocked) } } @@ -230,16 +230,19 @@ func verifyLockState(l lockStateCase, t *testing.T, testNum int) { // TestNewDebugLockInfoPerVolumePath - Validates the values initialized by newDebugLockInfoPerVolumePath(). func TestNewDebugLockInfoPerVolumePath(t *testing.T) { - lockInfo := newDebugLockInfoPerVolumePath() + lockInfo := &debugLockInfoPerVolumePath{ + lockInfo: make(map[string]debugLockInfo), + counters: &lockStat{}, + } - if lockInfo.ref != 0 { - t.Errorf("Expected initial reference value of total locks to be 0, got %d", lockInfo.ref) + if lockInfo.counters.total != 0 { + t.Errorf("Expected initial reference value of total locks to be 0, got %d", lockInfo.counters.total) } - if lockInfo.blocked != 0 { - t.Errorf("Expected initial reference of blocked locks to be 0, got %d", lockInfo.blocked) + if lockInfo.counters.blocked != 0 { + t.Errorf("Expected initial reference of blocked locks to be 0, got %d", lockInfo.counters.blocked) } - if lockInfo.running != 0 { - t.Errorf("Expected initial reference value of held locks to be 0, got %d", lockInfo.running) + if lockInfo.counters.granted != 0 { + t.Errorf("Expected initial reference value of held locks to be 0, got %d", lockInfo.counters.granted) } } @@ -300,7 +303,7 @@ func TestNsLockMapStatusBlockedToRunning(t *testing.T) { readLock: true, setBlocked: false, // expected metrics. - expectedErr: LockInfoOriginNotFound{"my-bucket", "my-object", "abcd1234", "Bad Origin"}, + expectedErr: LockInfoOriginMismatch{"my-bucket", "my-object", "abcd1234", "Bad Origin"}, }, // Test case - 5. // Test case with write lock. @@ -332,21 +335,11 @@ func TestNsLockMapStatusBlockedToRunning(t *testing.T) { debugLockMap: make(map[nsParam]*debugLockInfoPerVolumePath), lockMap: make(map[nsParam]*nsLock), } - // Entry for pair is set to nil. Should fail with `errLockNotInitialized`. - globalNSMutex.debugLockMap[param] = nil - actualErr = globalNSMutex.statusBlockedToRunning(param, testCases[0].lockSource, - testCases[0].opsID, testCases[0].readLock) - - if errorCause(actualErr) != errLockNotInitialized { - t.Fatalf("Errors mismatch: Expected \"%s\", got \"%s\"", errLockNotInitialized, actualErr) - } // Setting the lock info the be `nil`. globalNSMutex.debugLockMap[param] = &debugLockInfoPerVolumePath{ lockInfo: nil, // setting the lockinfo to nil. - ref: 0, - blocked: 0, - running: 0, + counters: &lockStat{}, } actualErr = globalNSMutex.statusBlockedToRunning(param, testCases[0].lockSource, @@ -361,9 +354,7 @@ func TestNsLockMapStatusBlockedToRunning(t *testing.T) { // but the initial state if already "Running". Such an attempt should fail globalNSMutex.debugLockMap[param] = &debugLockInfoPerVolumePath{ lockInfo: make(map[string]debugLockInfo), - ref: 0, - blocked: 0, - running: 0, + counters: &lockStat{}, } // Setting the status of the lock to be "Running". @@ -610,14 +601,14 @@ func TestNsLockMapDeleteLockInfoEntryForOps(t *testing.T) { } else { t.Fatalf("Entry for %s, %s should have existed. ", param.volume, param.path) } - if globalNSMutex.runningLockCounter != int64(0) { - t.Errorf("Expected the count of total running locks to be %v, but got %v", int64(0), globalNSMutex.runningLockCounter) + if globalNSMutex.counters.granted != int64(0) { + t.Errorf("Expected the count of total running locks to be %v, but got %v", int64(0), globalNSMutex.counters.granted) } - if globalNSMutex.blockedCounter != int64(0) { - t.Errorf("Expected the count of total blocked locks to be %v, but got %v", int64(0), globalNSMutex.blockedCounter) + if globalNSMutex.counters.blocked != int64(0) { + t.Errorf("Expected the count of total blocked locks to be %v, but got %v", int64(0), globalNSMutex.counters.blocked) } - if globalNSMutex.globalLockCounter != int64(0) { - t.Errorf("Expected the count of all locks to be %v, but got %v", int64(0), globalNSMutex.globalLockCounter) + if globalNSMutex.counters.total != int64(0) { + t.Errorf("Expected the count of all locks to be %v, but got %v", int64(0), globalNSMutex.counters.total) } } @@ -680,13 +671,13 @@ func TestNsLockMapDeleteLockInfoEntryForVolumePath(t *testing.T) { t.Fatalf("Entry for %s, %s should have been deleted. ", param.volume, param.path) } // The lock count values should be 0. - if globalNSMutex.runningLockCounter != int64(0) { - t.Errorf("Expected the count of total running locks to be %v, but got %v", int64(0), globalNSMutex.runningLockCounter) + if globalNSMutex.counters.granted != int64(0) { + t.Errorf("Expected the count of total running locks to be %v, but got %v", int64(0), globalNSMutex.counters.granted) } - if globalNSMutex.blockedCounter != int64(0) { - t.Errorf("Expected the count of total blocked locks to be %v, but got %v", int64(0), globalNSMutex.blockedCounter) + if globalNSMutex.counters.blocked != int64(0) { + t.Errorf("Expected the count of total blocked locks to be %v, but got %v", int64(0), globalNSMutex.counters.blocked) } - if globalNSMutex.globalLockCounter != int64(0) { - t.Errorf("Expected the count of all locks to be %v, but got %v", int64(0), globalNSMutex.globalLockCounter) + if globalNSMutex.counters.total != int64(0) { + t.Errorf("Expected the count of all locks to be %v, but got %v", int64(0), globalNSMutex.counters.total) } } diff --git a/cmd/lock-stat.go b/cmd/lock-stat.go new file mode 100644 index 000000000..67d91d2ac --- /dev/null +++ b/cmd/lock-stat.go @@ -0,0 +1,49 @@ +/* + * Minio Cloud Storage, (C) 2016 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package cmd + +// lockStat - encapsulates total, blocked and granted lock counts. +type lockStat struct { + total int64 + blocked int64 + granted int64 +} + +// lockWaiting - updates lock stat when a lock becomes blocked. +func (ls *lockStat) lockWaiting() { + ls.blocked++ + ls.total++ +} + +// lockGranted - updates lock stat when a lock is granted. +func (ls *lockStat) lockGranted() { + ls.blocked-- + ls.granted++ +} + +// lockRemoved - updates lock stat when a lock is removed, by Unlock +// or ForceUnlock. +func (ls *lockStat) lockRemoved(granted bool) { + if granted { + ls.granted-- + ls.total-- + + } else { + ls.blocked-- + ls.total-- + } +} diff --git a/cmd/lockinfo-handlers.go b/cmd/lockinfo-handlers.go index 2ed1b58a5..50f7429b6 100644 --- a/cmd/lockinfo-handlers.go +++ b/cmd/lockinfo-handlers.go @@ -66,17 +66,17 @@ func getSystemLockState() (SystemLockState, error) { lockState := SystemLockState{} - lockState.TotalBlockedLocks = globalNSMutex.blockedCounter - lockState.TotalLocks = globalNSMutex.globalLockCounter - lockState.TotalAcquiredLocks = globalNSMutex.runningLockCounter + lockState.TotalBlockedLocks = globalNSMutex.counters.blocked + lockState.TotalLocks = globalNSMutex.counters.total + lockState.TotalAcquiredLocks = globalNSMutex.counters.granted for param, debugLock := range globalNSMutex.debugLockMap { volLockInfo := VolumeLockInfo{} volLockInfo.Bucket = param.volume volLockInfo.Object = param.path - volLockInfo.LocksOnObject = debugLock.ref - volLockInfo.TotalBlockedLocks = debugLock.blocked - volLockInfo.LocksAcquiredOnObject = debugLock.running + volLockInfo.LocksOnObject = debugLock.counters.total + volLockInfo.TotalBlockedLocks = debugLock.counters.blocked + volLockInfo.LocksAcquiredOnObject = debugLock.counters.granted for opsID, lockInfo := range debugLock.lockInfo { volLockInfo.LockDetailsOnObject = append(volLockInfo.LockDetailsOnObject, OpsLockState{ OperationID: opsID, diff --git a/cmd/namespace-lock.go b/cmd/namespace-lock.go index 9f9ba73a5..b59261408 100644 --- a/cmd/namespace-lock.go +++ b/cmd/namespace-lock.go @@ -61,6 +61,7 @@ func initNSLock(isDistXL bool) { globalNSMutex = &nsLockMap{ isDistXL: isDistXL, lockMap: make(map[nsParam]*nsLock), + counters: &lockStat{}, } // Initialize nsLockMap with entry for instrumentation information. @@ -91,10 +92,8 @@ type nsLock struct { // Unlock, RLock and RUnlock. type nsLockMap struct { // Lock counter used for lock debugging. - globalLockCounter int64 // Total locks held. - blockedCounter int64 // Total operations blocked waiting for locks. - runningLockCounter int64 // Total locks held but not released yet. - debugLockMap map[nsParam]*debugLockInfoPerVolumePath // Info for instrumentation on locks. + counters *lockStat + debugLockMap map[nsParam]*debugLockInfoPerVolumePath // Info for instrumentation on locks. // Indicates whether the locking service is part // of a distributed setup or not.