/// <inheritdoc/> public override bool AdmitCommit(long currentTail, bool metadataChanged) { var now = stopwatch.ElapsedMilliseconds; while (true) { var lastSeenMilli = lastAdmittedMilli; var lastSeenAddress = lastAdmittedAddress; if (now - lastSeenMilli < thresholdMilli && currentTail - lastSeenAddress < thresholdRange) { // Only allow spawning of task if no other task is already underway if (Interlocked.CompareExchange(ref shouldRetry, 1, 0) == 0) { Task.Run(async() => { await Task.Delay(TimeSpan.FromMilliseconds(thresholdMilli)); shouldRetry = 0; log.Commit(); }); } return(false); } if (Interlocked.CompareExchange(ref lastAdmittedMilli, now, lastSeenMilli) == lastSeenMilli && Interlocked.CompareExchange(ref lastAdmittedAddress, currentTail, lastSeenAddress) == lastSeenAddress) { return(true); } } }
/// <inheritdoc/> public override void OnCommitFinished(FasterLogRecoveryInfo info) { Interlocked.Decrement(ref commitInProgress); if (shouldRetry) { shouldRetry = false; log.Commit(); } }