diff --git a/cs/src/core/Index/Common/RecordInfo.cs b/cs/src/core/Index/Common/RecordInfo.cs index b1ffc6b05..9b2bb89dc 100644 --- a/cs/src/core/Index/Common/RecordInfo.cs +++ b/cs/src/core/Index/Common/RecordInfo.cs @@ -141,7 +141,8 @@ public bool TryLockExclusive() for (; ; Thread.Yield()) { long expected_word = word; - Debug.Assert(!IsClosedWord(expected_word), "Should not be X locking closed records, pt 1"); + if (IsClosedWord(expected_word)) + return false; if ((expected_word & kExclusiveLockBitMask) == 0) { if (expected_word == Interlocked.CompareExchange(ref word, expected_word | kExclusiveLockBitMask, expected_word)) @@ -198,7 +199,8 @@ public bool TryLockShared() for (; ; Thread.Yield()) { long expected_word = word; - Debug.Assert(!IsClosedWord(expected_word), "Should not be S locking closed records"); + if (IsClosedWord(expected_word)) + return false; if (((expected_word & kExclusiveLockBitMask) == 0) // not exclusively locked && (expected_word & kSharedLockMaskInWord) != kSharedLockMaskInWord) // shared lock is not full { diff --git a/cs/src/core/Index/FASTER/Implementation/ConditionalCopyToTail.cs b/cs/src/core/Index/FASTER/Implementation/ConditionalCopyToTail.cs index 48ad0da00..3a9e40197 100644 --- a/cs/src/core/Index/FASTER/Implementation/ConditionalCopyToTail.cs +++ b/cs/src/core/Index/FASTER/Implementation/ConditionalCopyToTail.cs @@ -12,7 +12,7 @@ public unsafe partial class FasterKV : FasterBase, IFasterKV(FasterSession fasterSession, ref PendingContext pendingContext, ref Key key, ref Input input, ref Value value, ref Output output, ref Context userContext, long lsn, - ref OperationStackContext stackCtx, WriteReason writeReason) + ref OperationStackContext stackCtx, WriteReason writeReason, bool callerHasLock = false) where FasterSession : IFasterSession { // We are called by one of ReadFromImmutable, CompactionConditionalCopyToTail, or ContinueConditionalCopyToTail, and stackCtx is set up for the first try. @@ -22,7 +22,7 @@ private OperationStatus ConditionalCopyToTail(fasterSession, ref key, ref stackCtx, out OperationStatus status)) + if (callerHasLock || TryTransientSLock(fasterSession, ref key, ref stackCtx, out OperationStatus status)) { try { @@ -32,7 +32,8 @@ private OperationStatus ConditionalCopyToTail(fasterSession, ref key, ref stackCtx); + if (!callerHasLock) + TransientSUnlock(fasterSession, ref key, ref stackCtx); } } if (!HandleImmediateRetryStatus(status, fasterSession, ref pendingContext)) diff --git a/cs/src/core/Index/FASTER/Implementation/ContinuePending.cs b/cs/src/core/Index/FASTER/Implementation/ContinuePending.cs index e3e66c53d..b68724a19 100644 --- a/cs/src/core/Index/FASTER/Implementation/ContinuePending.cs +++ b/cs/src/core/Index/FASTER/Implementation/ContinuePending.cs @@ -114,7 +114,7 @@ internal OperationStatus ContinuePendingRead