From c7ca791c580fe87af1d4535d18e2504f636e4aa5 Mon Sep 17 00:00:00 2001 From: kannappanr <30541348+kannappanr@users.noreply.github.com> Date: Wed, 4 Mar 2020 16:06:17 -0800 Subject: [PATCH] fix: lock expiry on zoned setups (#9084) lock ownership is limited to endpoints on first zone, as we do not hold locks on other zones in an expanded setup. current code unintentionally expired active locks when it couldn't see ownership from the secondary zone which leads to unexpected bugs as locking fails to work as expected. --- cmd/lock-rest-server.go | 69 +++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 34 deletions(-) diff --git a/cmd/lock-rest-server.go b/cmd/lock-rest-server.go index 4ece6c401..9764780aa 100644 --- a/cmd/lock-rest-server.go +++ b/cmd/lock-rest-server.go @@ -247,42 +247,43 @@ func lockMaintenance(ctx context.Context, interval time.Duration, objAPI ObjectL // Get list of long lived locks to check for staleness. for lendpoint, nlrips := range getLongLivedLocks(interval) { for _, nlrip := range nlrips { - for _, ep := range globalEndpoints { - for _, endpoint := range ep.Endpoints { - if endpoint.String() == lendpoint.String() { - continue - } - - c := newLockAPI(endpoint) - if !c.IsOnline() { - continue - } - - // Call back to original server verify whether the lock is - // still active (based on name & uid) - expired, err := c.Expired(dsync.LockArgs{ - UID: nlrip.lri.UID, - Resources: []string{nlrip.name}, - }) - - if err != nil { - c.Close() - continue - } - - // For successful response, verify if lock was indeed active or stale. - if expired { - // The lock is no longer active at server that originated - // the lock, attempt to remove the lock. - globalLockServers[lendpoint].mutex.Lock() - // Purge the stale entry if it exists. - globalLockServers[lendpoint].removeEntryIfExists(nlrip) - globalLockServers[lendpoint].mutex.Unlock() - } - - // Close the connection regardless of the call response. + // Locks are only held on first zone, make sure that + // we only look for ownership of locks from endpoints + // on first zone. + for _, endpoint := range globalEndpoints[0].Endpoints { + if endpoint.String() == lendpoint.String() { + continue + } + + c := newLockAPI(endpoint) + if !c.IsOnline() { + continue + } + + // Call back to original server verify whether the lock is + // still active (based on name & uid) + expired, err := c.Expired(dsync.LockArgs{ + UID: nlrip.lri.UID, + Resources: []string{nlrip.name}, + }) + + if err != nil { c.Close() + continue + } + + // For successful response, verify if lock was indeed active or stale. + if expired { + // The lock is no longer active at server that originated + // the lock, attempt to remove the lock. + globalLockServers[lendpoint].mutex.Lock() + // Purge the stale entry if it exists. + globalLockServers[lendpoint].removeEntryIfExists(nlrip) + globalLockServers[lendpoint].mutex.Unlock() } + + // Close the connection regardless of the call response. + c.Close() } } }