mirror of
https://github.com/minio/minio.git
synced 2025-11-07 21:02:58 -05:00
New dsync and added ForceUnlock to lock rpc server (#2956)
* Update dsync and added ForceUnlock function * Added test cases for ForceUnlock
This commit is contained in:
@@ -252,6 +252,23 @@ func (l *lockServer) RUnlock(args *LockArgs, reply *bool) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ForceUnlock - rpc handler for force unlock operation.
|
||||
func (l *lockServer) ForceUnlock(args *LockArgs, reply *bool) error {
|
||||
l.mutex.Lock()
|
||||
defer l.mutex.Unlock()
|
||||
if err := l.validateLockArgs(args); err != nil {
|
||||
return err
|
||||
}
|
||||
if len(args.UID) != 0 {
|
||||
return fmt.Errorf("ForceUnlock called with non-empty UID: %s", args.UID)
|
||||
}
|
||||
if _, ok := l.lockMap[args.Name]; ok { // Only clear lock when set
|
||||
delete(l.lockMap, args.Name) // Remove the lock (irrespective of write or read lock)
|
||||
}
|
||||
*reply = true
|
||||
return nil
|
||||
}
|
||||
|
||||
// Expired - rpc handler for expired lock status.
|
||||
func (l *lockServer) Expired(args *LockArgs, reply *bool) error {
|
||||
l.mutex.Lock()
|
||||
|
||||
@@ -326,6 +326,74 @@ func TestLockRpcServerRUnlock(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Test ForceUnlock functionality
|
||||
func TestLockRpcServerForceUnlock(t *testing.T) {
|
||||
|
||||
timestamp := time.Now().UTC()
|
||||
testPath, locker, token := createLockTestServer(t)
|
||||
defer removeAll(testPath)
|
||||
|
||||
laForce := LockArgs{
|
||||
Name: "name",
|
||||
Token: token,
|
||||
Timestamp: timestamp,
|
||||
Node: "node",
|
||||
RPCPath: "rpc-path",
|
||||
UID: "1234-5678",
|
||||
}
|
||||
|
||||
// First test that UID should be empty
|
||||
var result bool
|
||||
err := locker.ForceUnlock(&laForce, &result)
|
||||
if err == nil {
|
||||
t.Errorf("Expected error, got %#v", nil)
|
||||
}
|
||||
|
||||
// Then test force unlock of a lock that does not exist (not returning an error)
|
||||
laForce.UID = ""
|
||||
err = locker.ForceUnlock(&laForce, &result)
|
||||
if err != nil {
|
||||
t.Errorf("Expected no error, got %#v", err)
|
||||
}
|
||||
|
||||
la := LockArgs{
|
||||
Name: "name",
|
||||
Token: token,
|
||||
Timestamp: timestamp,
|
||||
Node: "node",
|
||||
RPCPath: "rpc-path",
|
||||
UID: "0123-4567",
|
||||
}
|
||||
|
||||
// Create lock ... (so that we can force unlock)
|
||||
err = locker.Lock(&la, &result)
|
||||
if err != nil {
|
||||
t.Errorf("Expected %#v, got %#v", nil, err)
|
||||
} else if !result {
|
||||
t.Errorf("Expected %#v, got %#v", true, result)
|
||||
}
|
||||
|
||||
// Forcefully unlock the lock (not returning an error)
|
||||
err = locker.ForceUnlock(&laForce, &result)
|
||||
if err != nil {
|
||||
t.Errorf("Expected no error, got %#v", err)
|
||||
}
|
||||
|
||||
// Try to get lock again (should be granted)
|
||||
err = locker.Lock(&la, &result)
|
||||
if err != nil {
|
||||
t.Errorf("Expected %#v, got %#v", nil, err)
|
||||
} else if !result {
|
||||
t.Errorf("Expected %#v, got %#v", true, result)
|
||||
}
|
||||
|
||||
// Finally forcefully unlock the lock once again
|
||||
err = locker.ForceUnlock(&laForce, &result)
|
||||
if err != nil {
|
||||
t.Errorf("Expected no error, got %#v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Test Expired functionality
|
||||
func TestLockRpcServerExpired(t *testing.T) {
|
||||
timestamp := time.Now().UTC()
|
||||
|
||||
Reference in New Issue
Block a user