Node should clear a lock internally that the lock owner don't recognize (#12782)

If a lock owner says the lock is expired, all nodes should remove the
lock internally immediately.
This commit is contained in:
Anis Elleuch 2021-07-26 07:42:23 +01:00 committed by Harshavardhana
parent b1c731c448
commit 83676a0bc2

View File

@ -22,6 +22,7 @@ import (
"errors" "errors"
"math/rand" "math/rand"
"net/http" "net/http"
"net/url"
"path" "path"
"sort" "sort"
"strconv" "strconv"
@ -303,6 +304,7 @@ func lockMaintenance(ctx context.Context, interval time.Duration) error {
for lendpoint, nlrips := range getLongLivedLocks(interval) { for lendpoint, nlrips := range getLongLivedLocks(interval) {
nlripsMap := make(map[string]nlock, len(nlrips)) nlripsMap := make(map[string]nlock, len(nlrips))
for _, nlrip := range nlrips { for _, nlrip := range nlrips {
expiredInOwner := false
for _, c := range allLockersFn() { for _, c := range allLockersFn() {
if !c.IsOnline() || c == nil { if !c.IsOnline() || c == nil {
continue continue
@ -325,11 +327,18 @@ func lockMaintenance(ctx context.Context, interval time.Duration) error {
if !expired { if !expired {
updateNlocks(nlripsMap, nlrip.name, nlrip.lri.Writer) updateNlocks(nlripsMap, nlrip.name, nlrip.lri.Writer)
} else {
// Check if the lock owner still recognizes the lock
u, err := url.Parse(c.String())
if err == nil && u.Host == nlrip.lri.Owner {
expiredInOwner = true
}
} }
} }
// less than the quorum, we have locks expired. // Remove the lock if Less than the quorum or the lock owner does not recognize it
if nlripsMap[nlrip.name].locks < nlrip.lri.Quorum { if expiredInOwner || nlripsMap[nlrip.name].locks < nlrip.lri.Quorum {
// Purge the stale entry if it exists. // Purge the stale entry if it exists.
globalLockServers[lendpoint].removeEntryIfExists(nlrip) globalLockServers[lendpoint].removeEntryIfExists(nlrip)
} }