@ -119,26 +119,26 @@ func verifyRPCLockInfoResponse(l lockStateCase, rpcLockInfoMap map[string]*Syste
}
}
// Asserts the lock counter from the global ns Mutex inmemory lock with the expected one.
// Asserts the lock counter from the global globalNS Mutex inmemory lock with the expected one.
func verifyGlobalLockStats ( l lockStateCase , t * testing . T , testNum int ) {
ns Mutex. lockMapMutex . Lock ( )
globalNS Mutex. lockMapMutex . Lock ( )
// Verifying the lock stats.
if ns Mutex. globalLockCounter != int64 ( l . expectedGlobalLockCount ) {
if globalNS Mutex. globalLockCounter != int64 ( l . expectedGlobalLockCount ) {
t . Errorf ( "Test %d: Expected the global lock counter to be %v, but got %v" , testNum , int64 ( l . expectedGlobalLockCount ) ,
ns Mutex. globalLockCounter )
globalNS Mutex. globalLockCounter )
}
// verify the count for total blocked locks.
if ns Mutex. blockedCounter != int64 ( l . expectedBlockedLockCount ) {
if globalNS Mutex. blockedCounter != int64 ( l . expectedBlockedLockCount ) {
t . Errorf ( "Test %d: Expected the total blocked lock counter to be %v, but got %v" , testNum , int64 ( l . expectedBlockedLockCount ) ,
ns Mutex. blockedCounter )
globalNS Mutex. blockedCounter )
}
// verify the count for total running locks.
if ns Mutex. runningLockCounter != int64 ( l . expectedRunningLockCount ) {
if globalNS Mutex. runningLockCounter != int64 ( l . expectedRunningLockCount ) {
t . Errorf ( "Test %d: Expected the total running lock counter to be %v, but got %v" , testNum , int64 ( l . expectedRunningLockCount ) ,
ns Mutex. runningLockCounter )
globalNS Mutex. runningLockCounter )
}
ns Mutex. lockMapMutex . Unlock ( )
globalNS Mutex. lockMapMutex . Unlock ( )
// Verifying again with the JSON response of the lock info.
// Verifying the lock stats.
sysLockState , err := getSystemLockState ( )
@ -164,35 +164,35 @@ func verifyGlobalLockStats(l lockStateCase, t *testing.T, testNum int) {
// Verify the lock counter for entries of given <volume, path> pair.
func verifyLockStats ( l lockStateCase , t * testing . T , testNum int ) {
ns Mutex. lockMapMutex . Lock ( )
defer ns Mutex. lockMapMutex . Unlock ( )
globalNS Mutex. lockMapMutex . Lock ( )
defer globalNS Mutex. lockMapMutex . Unlock ( )
param := nsParam { l . volume , l . path }
// Verify the total locks (blocked+running) for given <vol,path> pair.
if ns Mutex. debugLockMap [ param ] . ref != int64 ( l . expectedVolPathLockCount ) {
if globalNS Mutex. debugLockMap [ param ] . ref != 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 ) , ns Mutex. debugLockMap [ param ] . ref )
param . volume , param . path , int64 ( l . expectedVolPathLockCount ) , globalNS Mutex. debugLockMap [ param ] . ref )
}
// Verify the total running locks for given <volume, path> pair.
if ns Mutex. debugLockMap [ param ] . running != int64 ( l . expectedVolPathRunningCount ) {
if globalNS Mutex. debugLockMap [ param ] . running != 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 ) , ns Mutex. debugLockMap [ param ] . running )
int64 ( l . expectedVolPathRunningCount ) , globalNS Mutex. debugLockMap [ param ] . running )
}
// Verify the total blocked locks for givne <volume, path> pair.
if ns Mutex. debugLockMap [ param ] . blocked != int64 ( l . expectedVolPathBlockCount ) {
if globalNS Mutex. debugLockMap [ param ] . 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 ) , ns Mutex. debugLockMap [ param ] . blocked )
int64 ( l . expectedVolPathBlockCount ) , globalNS Mutex. debugLockMap [ param ] . blocked )
}
}
// verifyLockState - function which asserts the expected lock info in the system with the actual values in the ns Mutex.
// verifyLockState - function which asserts the expected lock info in the system with the actual values in the globalNS Mutex.
func verifyLockState ( l lockStateCase , t * testing . T , testNum int ) {
param := nsParam { l . volume , l . path }
verifyGlobalLockStats ( l , t , testNum )
ns Mutex. lockMapMutex . Lock ( )
globalNS Mutex. lockMapMutex . Lock ( )
// Verifying the lock statuS fields.
if debugLockMap , ok := ns Mutex. debugLockMap [ param ] ; ok {
if debugLockMap , ok := globalNS Mutex. debugLockMap [ param ] ; ok {
if lockInfo , ok := debugLockMap . lockInfo [ l . opsID ] ; ok {
// Validating the lock type filed in the debug lock information.
if l . readLock {
@ -222,7 +222,7 @@ func verifyLockState(l lockStateCase, t *testing.T, testNum int) {
t . Errorf ( "Test case %d: Debug lock entry for volume: %s, path: %s doesn't exist" , testNum , param . volume , param . path )
}
// verifyLockStats holds its own lock.
ns Mutex. lockMapMutex . Unlock ( )
globalNS Mutex. lockMapMutex . Unlock ( )
// verify the lock count.
verifyLockStats ( l , t , testNum )
@ -319,7 +319,7 @@ func TestNsLockMapStatusBlockedToRunning(t *testing.T) {
param := nsParam { testCases [ 0 ] . volume , testCases [ 0 ] . path }
// Testing before the initialization done.
// Since the data structures for
actualErr := ns Mutex. statusBlockedToRunning ( param , testCases [ 0 ] . lockSource ,
actualErr := globalNS Mutex. statusBlockedToRunning ( param , testCases [ 0 ] . lockSource ,
testCases [ 0 ] . opsID , testCases [ 0 ] . readLock )
expectedErr := LockInfoVolPathMissing { testCases [ 0 ] . volume , testCases [ 0 ] . path }
@ -327,14 +327,14 @@ func TestNsLockMapStatusBlockedToRunning(t *testing.T) {
t . Fatalf ( "Errors mismatch: Expected \"%s\", got \"%s\"" , expectedErr , actualErr )
}
ns Mutex = & nsLockMap {
globalNS Mutex = & nsLockMap {
// entries of <volume,path> -> stateInfo of locks, for instrumentation purpose.
debugLockMap : make ( map [ nsParam ] * debugLockInfoPerVolumePath ) ,
lockMap : make ( map [ nsParam ] * nsLock ) ,
}
// Entry for <volume, path> pair is set to nil. Should fail with `errLockNotInitialized`.
ns Mutex. debugLockMap [ param ] = nil
actualErr = ns Mutex. statusBlockedToRunning ( param , testCases [ 0 ] . lockSource ,
globalNS Mutex. debugLockMap [ param ] = nil
actualErr = globalNS Mutex. statusBlockedToRunning ( param , testCases [ 0 ] . lockSource ,
testCases [ 0 ] . opsID , testCases [ 0 ] . readLock )
if errorCause ( actualErr ) != errLockNotInitialized {
@ -342,14 +342,14 @@ func TestNsLockMapStatusBlockedToRunning(t *testing.T) {
}
// Setting the lock info the be `nil`.
ns Mutex. debugLockMap [ param ] = & debugLockInfoPerVolumePath {
globalNS Mutex. debugLockMap [ param ] = & debugLockInfoPerVolumePath {
lockInfo : nil , // setting the lockinfo to nil.
ref : 0 ,
blocked : 0 ,
running : 0 ,
}
actualErr = ns Mutex. statusBlockedToRunning ( param , testCases [ 0 ] . lockSource ,
actualErr = globalNS Mutex. statusBlockedToRunning ( param , testCases [ 0 ] . lockSource ,
testCases [ 0 ] . opsID , testCases [ 0 ] . readLock )
expectedOpsErr := LockInfoOpsIDNotFound { testCases [ 0 ] . volume , testCases [ 0 ] . path , testCases [ 0 ] . opsID }
@ -359,7 +359,7 @@ func TestNsLockMapStatusBlockedToRunning(t *testing.T) {
// Next case: ase whether an attempt to change the state of the lock to "Running" done,
// but the initial state if already "Running". Such an attempt should fail
ns Mutex. debugLockMap [ param ] = & debugLockInfoPerVolumePath {
globalNS Mutex. debugLockMap [ param ] = & debugLockInfoPerVolumePath {
lockInfo : make ( map [ string ] debugLockInfo ) ,
ref : 0 ,
blocked : 0 ,
@ -368,13 +368,13 @@ func TestNsLockMapStatusBlockedToRunning(t *testing.T) {
// 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".
ns Mutex. debugLockMap [ param ] . lockInfo [ testCases [ 0 ] . opsID ] = debugLockInfo {
globalNS Mutex. debugLockMap [ param ] . lockInfo [ testCases [ 0 ] . opsID ] = debugLockInfo {
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`.
since : time . Now ( ) . UTC ( ) ,
}
actualErr = ns Mutex. statusBlockedToRunning ( param , testCases [ 0 ] . lockSource ,
actualErr = globalNS Mutex. statusBlockedToRunning ( param , testCases [ 0 ] . lockSource ,
testCases [ 0 ] . opsID , testCases [ 0 ] . readLock )
expectedBlockErr := LockInfoStateNotBlocked { testCases [ 0 ] . volume , testCases [ 0 ] . path , testCases [ 0 ] . opsID }
@ -390,22 +390,22 @@ func TestNsLockMapStatusBlockedToRunning(t *testing.T) {
param := nsParam { testCase . volume , testCase . path }
// status of the lock to be set to "Blocked", before setting Blocked->Running.
if testCase . setBlocked {
ns Mutex. lockMapMutex . Lock ( )
err := ns Mutex. statusNoneToBlocked ( param , testCase . lockSource , testCase . opsID , testCase . readLock )
globalNS Mutex. lockMapMutex . Lock ( )
err := globalNS Mutex. statusNoneToBlocked ( param , testCase . lockSource , testCase . opsID , testCase . readLock )
if err != nil {
t . Fatalf ( "Test %d: Initializing the initial state to Blocked failed <ERROR> %s" , i + 1 , err )
}
ns Mutex. lockMapMutex . Unlock ( )
globalNS Mutex. lockMapMutex . Unlock ( )
}
// invoking the method under test.
actualErr = ns Mutex. statusBlockedToRunning ( param , testCase . lockSource , testCase . opsID , testCase . readLock )
actualErr = globalNS Mutex. statusBlockedToRunning ( param , testCase . lockSource , testCase . opsID , testCase . readLock )
if errorCause ( actualErr ) != testCase . expectedErr {
t . Fatalf ( "Test %d: Errors mismatch: Expected: \"%s\", got: \"%s\"" , i + 1 , testCase . expectedErr , actualErr )
}
// In case of no error proceed with validating the lock state information.
if actualErr == nil {
// debug entry for given <volume, path> pair should exist.
if debugLockMap , ok := ns Mutex. debugLockMap [ param ] ; ok {
if debugLockMap , ok := globalNS Mutex. debugLockMap [ param ] ; ok {
if lockInfo , ok := debugLockMap . lockInfo [ testCase . opsID ] ; ok {
// Validating the lock type filed in the debug lock information.
if testCase . readLock {
@ -514,7 +514,7 @@ func TestNsLockMapStatusNoneToBlocked(t *testing.T) {
param := nsParam { testCases [ 0 ] . volume , testCases [ 0 ] . path }
// Testing before the initialization done.
// Since the data structures for
actualErr := ns Mutex. statusBlockedToRunning ( param , testCases [ 0 ] . lockSource ,
actualErr := globalNS Mutex. statusBlockedToRunning ( param , testCases [ 0 ] . lockSource ,
testCases [ 0 ] . opsID , testCases [ 0 ] . readLock )
expectedErr := LockInfoVolPathMissing { testCases [ 0 ] . volume , testCases [ 0 ] . path }
@ -524,13 +524,13 @@ func TestNsLockMapStatusNoneToBlocked(t *testing.T) {
// Iterate over the cases and assert the result.
for i , testCase := range testCases {
ns Mutex. lockMapMutex . Lock ( )
globalNS Mutex. lockMapMutex . Lock ( )
param := nsParam { testCase . volume , testCase . path }
actualErr := ns Mutex. statusNoneToBlocked ( param , testCase . lockSource , testCase . opsID , testCase . readLock )
actualErr := globalNS Mutex. statusNoneToBlocked ( param , testCase . lockSource , testCase . opsID , testCase . readLock )
if actualErr != testCase . expectedErr {
t . Fatalf ( "Test %d: Errors mismatch: Expected: \"%s\", got: \"%s\"" , i + 1 , testCase . expectedErr , actualErr )
}
ns Mutex. lockMapMutex . Unlock ( )
globalNS Mutex. lockMapMutex . Unlock ( )
if actualErr == nil {
verifyLockState ( testCase , t , i + 1 )
}
@ -559,7 +559,7 @@ func TestNsLockMapDeleteLockInfoEntryForOps(t *testing.T) {
param := nsParam { testCases [ 0 ] . volume , testCases [ 0 ] . path }
// Testing before the initialization done.
actualErr := ns Mutex. deleteLockInfoEntryForOps ( param , testCases [ 0 ] . opsID )
actualErr := globalNS Mutex. deleteLockInfoEntryForOps ( param , testCases [ 0 ] . opsID )
expectedErr := LockInfoVolPathMissing { testCases [ 0 ] . volume , testCases [ 0 ] . path }
if errorCause ( actualErr ) != expectedErr {
@ -568,17 +568,17 @@ func TestNsLockMapDeleteLockInfoEntryForOps(t *testing.T) {
// Case - 2.
// Lock state is set to Running and then an attempt to delete the info for non-existent opsID done.
ns Mutex. lockMapMutex . Lock ( )
err := ns Mutex. statusNoneToBlocked ( param , testCases [ 0 ] . lockSource , testCases [ 0 ] . opsID , testCases [ 0 ] . readLock )
globalNS Mutex. lockMapMutex . Lock ( )
err := globalNS Mutex. statusNoneToBlocked ( param , testCases [ 0 ] . lockSource , testCases [ 0 ] . opsID , testCases [ 0 ] . readLock )
if err != nil {
t . Fatalf ( "Setting lock status to Blocked failed: <ERROR> %s" , err )
}
ns Mutex. lockMapMutex . Unlock ( )
err = ns Mutex. statusBlockedToRunning ( param , testCases [ 0 ] . lockSource , testCases [ 0 ] . opsID , testCases [ 0 ] . readLock )
globalNS Mutex. lockMapMutex . Unlock ( )
err = globalNS Mutex. statusBlockedToRunning ( param , testCases [ 0 ] . lockSource , testCases [ 0 ] . opsID , testCases [ 0 ] . readLock )
if err != nil {
t . Fatalf ( "Setting lock status to Running failed: <ERROR> %s" , err )
}
actualErr = ns Mutex. deleteLockInfoEntryForOps ( param , "non-existent-OpsID" )
actualErr = globalNS Mutex. deleteLockInfoEntryForOps ( param , "non-existent-OpsID" )
expectedOpsIDErr := LockInfoOpsIDNotFound { param . volume , param . path , "non-existent-OpsID" }
if errorCause ( actualErr ) != expectedOpsIDErr {
@ -589,7 +589,7 @@ func TestNsLockMapDeleteLockInfoEntryForOps(t *testing.T) {
// All metrics should be 0 after deleting the entry.
// Verify that the entry the opsID exists.
if debugLockMap , ok := ns Mutex. debugLockMap [ param ] ; ok {
if debugLockMap , ok := globalNS Mutex. debugLockMap [ param ] ; ok {
if _ , ok := debugLockMap . lockInfo [ testCases [ 0 ] . opsID ] ; ! ok {
t . Fatalf ( "Entry for OpsID \"%s\" in <volume> %s, <path> %s should have existed. " , testCases [ 0 ] . opsID , param . volume , param . path )
}
@ -597,27 +597,27 @@ func TestNsLockMapDeleteLockInfoEntryForOps(t *testing.T) {
t . Fatalf ( "Entry for <volume> %s, <path> %s should have existed. " , param . volume , param . path )
}
actualErr = ns Mutex. deleteLockInfoEntryForOps ( param , testCases [ 0 ] . opsID )
actualErr = globalNS Mutex. deleteLockInfoEntryForOps ( param , testCases [ 0 ] . opsID )
if actualErr != nil {
t . Fatalf ( "Expected the error to be <nil>, but got <ERROR> %s" , actualErr )
}
// Verify that the entry for the opsId doesn't exists.
if debugLockMap , ok := ns Mutex. debugLockMap [ param ] ; ok {
if debugLockMap , ok := globalNS Mutex. debugLockMap [ param ] ; ok {
if _ , ok := debugLockMap . lockInfo [ testCases [ 0 ] . opsID ] ; ok {
t . Fatalf ( "The entry for opsID \"%s\" should have been deleted" , testCases [ 0 ] . opsID )
}
} else {
t . Fatalf ( "Entry for <volume> %s, <path> %s should have existed. " , param . volume , param . path )
}
if ns Mutex. runningLockCounter != int64 ( 0 ) {
t . Errorf ( "Expected the count of total running locks to be %v, but got %v" , int64 ( 0 ) , ns Mutex. runningLockCounter )
if globalNS Mutex. runningLockCounter != int64 ( 0 ) {
t . Errorf ( "Expected the count of total running locks to be %v, but got %v" , int64 ( 0 ) , globalNS Mutex. runningLockCounter )
}
if ns Mutex. blockedCounter != int64 ( 0 ) {
t . Errorf ( "Expected the count of total blocked locks to be %v, but got %v" , int64 ( 0 ) , ns Mutex. blockedCounter )
if globalNS Mutex. blockedCounter != int64 ( 0 ) {
t . Errorf ( "Expected the count of total blocked locks to be %v, but got %v" , int64 ( 0 ) , globalNS Mutex. blockedCounter )
}
if ns Mutex. globalLockCounter != int64 ( 0 ) {
t . Errorf ( "Expected the count of all locks to be %v, but got %v" , int64 ( 0 ) , ns Mutex. globalLockCounter )
if globalNS Mutex. globalLockCounter != int64 ( 0 ) {
t . Errorf ( "Expected the count of all locks to be %v, but got %v" , int64 ( 0 ) , globalNS Mutex. globalLockCounter )
}
}
@ -643,7 +643,7 @@ func TestNsLockMapDeleteLockInfoEntryForVolumePath(t *testing.T) {
// Case where an attempt to delete the entry for non-existent <volume, path> pair is done.
// Set the status of the lock to blocked and then to running.
param := nsParam { testCases [ 0 ] . volume , testCases [ 0 ] . path }
actualErr := ns Mutex. deleteLockInfoEntryForVolumePath ( param )
actualErr := globalNS Mutex. deleteLockInfoEntryForVolumePath ( param )
expectedNilErr := LockInfoVolPathMissing { param . volume , param . path }
if errorCause ( actualErr ) != expectedNilErr {
t . Fatalf ( "Errors mismatch: Expected \"%s\", got \"%s\"" , expectedNilErr , actualErr )
@ -654,39 +654,39 @@ func TestNsLockMapDeleteLockInfoEntryForVolumePath(t *testing.T) {
// All metrics should be 0 after deleting the entry.
// Registering the entry first.
ns Mutex. lockMapMutex . Lock ( )
err := ns Mutex. statusNoneToBlocked ( param , testCases [ 0 ] . lockSource , testCases [ 0 ] . opsID , testCases [ 0 ] . readLock )
globalNS Mutex. lockMapMutex . Lock ( )
err := globalNS Mutex. statusNoneToBlocked ( param , testCases [ 0 ] . lockSource , testCases [ 0 ] . opsID , testCases [ 0 ] . readLock )
if err != nil {
t . Fatalf ( "Setting lock status to Blocked failed: <ERROR> %s" , err )
}
ns Mutex. lockMapMutex . Unlock ( )
err = ns Mutex. statusBlockedToRunning ( param , testCases [ 0 ] . lockSource , testCases [ 0 ] . opsID , testCases [ 0 ] . readLock )
globalNS Mutex. lockMapMutex . Unlock ( )
err = globalNS Mutex. statusBlockedToRunning ( param , testCases [ 0 ] . lockSource , testCases [ 0 ] . opsID , testCases [ 0 ] . readLock )
if err != nil {
t . Fatalf ( "Setting lock status to Running failed: <ERROR> %s" , err )
}
// Verify that the entry the for given <volume, path> exists.
if _ , ok := ns Mutex. debugLockMap [ param ] ; ! ok {
if _ , ok := globalNS Mutex. debugLockMap [ param ] ; ! ok {
t . Fatalf ( "Entry for <volume> %s, <path> %s should have existed." , param . volume , param . path )
}
// first delete the entry for the operation ID.
_ = ns Mutex. deleteLockInfoEntryForOps ( param , testCases [ 0 ] . opsID )
actualErr = ns Mutex. deleteLockInfoEntryForVolumePath ( param )
_ = globalNS Mutex. deleteLockInfoEntryForOps ( param , testCases [ 0 ] . opsID )
actualErr = globalNS Mutex. deleteLockInfoEntryForVolumePath ( param )
if actualErr != nil {
t . Fatalf ( "Expected the error to be <nil>, but got <ERROR> %s" , actualErr )
}
// Verify that the entry for the opsId doesn't exists.
if _ , ok := ns Mutex. debugLockMap [ param ] ; ok {
if _ , ok := globalNS Mutex. debugLockMap [ param ] ; ok {
t . Fatalf ( "Entry for <volume> %s, <path> %s should have been deleted. " , param . volume , param . path )
}
// The lock count values should be 0.
if ns Mutex. runningLockCounter != int64 ( 0 ) {
t . Errorf ( "Expected the count of total running locks to be %v, but got %v" , int64 ( 0 ) , ns Mutex. runningLockCounter )
if globalNS Mutex. runningLockCounter != int64 ( 0 ) {
t . Errorf ( "Expected the count of total running locks to be %v, but got %v" , int64 ( 0 ) , globalNS Mutex. runningLockCounter )
}
if ns Mutex. blockedCounter != int64 ( 0 ) {
t . Errorf ( "Expected the count of total blocked locks to be %v, but got %v" , int64 ( 0 ) , ns Mutex. blockedCounter )
if globalNS Mutex. blockedCounter != int64 ( 0 ) {
t . Errorf ( "Expected the count of total blocked locks to be %v, but got %v" , int64 ( 0 ) , globalNS Mutex. blockedCounter )
}
if ns Mutex. globalLockCounter != int64 ( 0 ) {
t . Errorf ( "Expected the count of all locks to be %v, but got %v" , int64 ( 0 ) , ns Mutex. globalLockCounter )
if globalNS Mutex. globalLockCounter != int64 ( 0 ) {
t . Errorf ( "Expected the count of all locks to be %v, but got %v" , int64 ( 0 ) , globalNS Mutex. globalLockCounter )
}
}