From 03c4b2e9880765746bd47520d613515336a3f679 Mon Sep 17 00:00:00 2001 From: chrislu Date: Fri, 22 Dec 2023 14:16:23 -0800 Subject: [PATCH] correct lock accounting possibly fix https://github.com/seaweedfs/seaweedfs/issues/5082 --- weed/util/lock_table.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/weed/util/lock_table.go b/weed/util/lock_table.go index bf3da7c37..efc4114e7 100644 --- a/weed/util/lock_table.go +++ b/weed/util/lock_table.go @@ -132,6 +132,12 @@ func (lt *LockTable[T]) ReleaseLock(key T, lock *ActiveLock) { } } + if lock.lockType == ExclusiveLock { + entry.activeExclusiveLockOwnerCount-- + } else { + entry.activeSharedLockOwnerCount-- + } + // If there are no waiters, release the lock if len(entry.waiters) == 0 && entry.activeExclusiveLockOwnerCount <= 0 && entry.activeSharedLockOwnerCount <= 0 { delete(lt.locks, key) @@ -146,11 +152,6 @@ func (lt *LockTable[T]) ReleaseLock(key T, lock *ActiveLock) { fmt.Printf("\n") } } - if lock.lockType == ExclusiveLock { - entry.activeExclusiveLockOwnerCount-- - } else { - entry.activeSharedLockOwnerCount-- - } // Notify the next waiter entry.cond.Broadcast()