mirror of
https://github.com/minio/minio.git
synced 2024-12-26 23:25:54 -05:00
59e1d94770
The problem in current code was we were removing an entry from a lock lockerMap without considering the fact that different entry for same resource is a possibility due the nature of locks that can be acquired in parallel before we decide if the lock is considered stale A sequence of events is as follows - Lock("resource") - lockMaintenance(finds a long lived lock in this "resource") - Owner node rebooted which now retruns Expired() as true for this "resource" - Unlock("resource") which succeeded in quorum - Now by this time application retried and acquired a new Lock() on the same "resource" - Now that we have Expired() true from the previous call, we proceed to purge the entry from the local lockMap() local lockMap reports a different entry for the expired UID which results in a spurious log entry. This PR removes this logging as this situation is an expected scenario.
97 lines
3.1 KiB
Go
97 lines
3.1 KiB
Go
/*
|
|
* MinIO Cloud Storage, (C) 2019 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
|
|
|
|
import (
|
|
"path"
|
|
"time"
|
|
)
|
|
|
|
const lockRESTVersion = "v1"
|
|
const lockRESTPath = minioReservedBucketPath + "/lock/" + lockRESTVersion
|
|
|
|
var lockServicePath = path.Join(minioReservedBucketPath, lockServiceSubPath)
|
|
|
|
const (
|
|
lockRESTMethodLock = "lock"
|
|
lockRESTMethodRLock = "rlock"
|
|
lockRESTMethodUnlock = "unlock"
|
|
lockRESTMethodRUnlock = "runlock"
|
|
lockRESTMethodForceUnlock = "forceunlock"
|
|
lockRESTMethodExpired = "expired"
|
|
)
|
|
|
|
// nameLockRequesterInfoPair is a helper type for lock maintenance
|
|
type nameLockRequesterInfoPair struct {
|
|
name string
|
|
lri lockRequesterInfo
|
|
}
|
|
|
|
type lockResponse struct {
|
|
Success bool
|
|
}
|
|
|
|
// Similar to removeEntry but only removes an entry only if the lock entry exists in map.
|
|
func (l *localLocker) removeEntryIfExists(nlrip nameLockRequesterInfoPair) {
|
|
// Check if entry is still in map (could have been removed altogether by 'concurrent' (R)Unlock of last entry)
|
|
if lri, ok := l.lockMap[nlrip.name]; ok {
|
|
// Even if the entry exists, it may not be the same entry which was
|
|
// considered as expired, so we simply an attempt to remove it if its
|
|
// not possible there is nothing we need to do.
|
|
l.removeEntry(nlrip.name, nlrip.lri.UID, &lri)
|
|
}
|
|
}
|
|
|
|
// removeEntry based on the uid of the lock message, removes a single entry from the
|
|
// lockRequesterInfo array or the whole array from the map (in case of a write lock
|
|
// or last read lock)
|
|
func (l *localLocker) removeEntry(name, uid string, lri *[]lockRequesterInfo) bool {
|
|
// Find correct entry to remove based on uid.
|
|
for index, entry := range *lri {
|
|
if entry.UID == uid {
|
|
if len(*lri) == 1 {
|
|
// Remove the write lock.
|
|
delete(l.lockMap, name)
|
|
} else {
|
|
// Remove the appropriate read lock.
|
|
*lri = append((*lri)[:index], (*lri)[index+1:]...)
|
|
l.lockMap[name] = *lri
|
|
}
|
|
return true
|
|
}
|
|
}
|
|
|
|
// None found return false, perhaps entry removed in previous run.
|
|
return false
|
|
}
|
|
|
|
// getLongLivedLocks returns locks that are older than a certain time and
|
|
// have not been 'checked' for validity too soon enough
|
|
func getLongLivedLocks(m map[string][]lockRequesterInfo, interval time.Duration) []nameLockRequesterInfoPair {
|
|
rslt := []nameLockRequesterInfoPair{}
|
|
for name, lriArray := range m {
|
|
for idx := range lriArray {
|
|
// Check whether enough time has gone by since last check
|
|
if time.Since(lriArray[idx].TimeLastCheck) >= interval {
|
|
rslt = append(rslt, nameLockRequesterInfoPair{name: name, lri: lriArray[idx]})
|
|
lriArray[idx].TimeLastCheck = UTCNow()
|
|
}
|
|
}
|
|
}
|
|
return rslt
|
|
}
|