Skip to content

Commit

Permalink
[C#] FasterLog CommitAsync wait if no new commit done (#753)
Browse files Browse the repository at this point in the history
  • Loading branch information
badrishc authored Oct 6, 2022
1 parent 6feb670 commit 4c6bd9d
Showing 1 changed file with 47 additions and 13 deletions.
60 changes: 47 additions & 13 deletions cs/src/core/FasterLog/FasterLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -931,14 +931,29 @@ public bool CommitStrongly(out long commitTail, out long actualCommitNum, bool s
public async ValueTask CommitAsync(CancellationToken token = default)
{
token.ThrowIfCancellationRequested();

// Take a lower-bound of the content of this commit in case our request is filtered but we need to wait
var tail = TailAddress;
var lastCommit = commitNum;

var task = CommitTask;
if (!CommitInternal(out var tailAddress, out var actualCommitNum, true, null, -1, null))
return;
var success = CommitInternal(out var actualTail, out var actualCommitNum, true, null, -1, null);

while (CommittedUntilAddress < tailAddress || persistedCommitNum < actualCommitNum)
if (success)
{
var linkedCommitInfo = await task.WithCancellationAsync(token).ConfigureAwait(false);
task = linkedCommitInfo.NextTask;
while (CommittedUntilAddress < actualTail || persistedCommitNum < actualCommitNum)
{
var linkedCommitInfo = await task.WithCancellationAsync(token).ConfigureAwait(false);
task = linkedCommitInfo.NextTask;
}
}
else
{
while (CommittedUntilAddress < tail || persistedCommitNum < lastCommit)
{
var linkedCommitInfo = await task.WithCancellationAsync(token).ConfigureAwait(false);
task = linkedCommitInfo.NextTask;
}
}
}

Expand All @@ -951,18 +966,37 @@ public async ValueTask CommitAsync(CancellationToken token = default)
public async ValueTask<Task<LinkedCommitInfo>> CommitAsync(Task<LinkedCommitInfo> prevCommitTask, CancellationToken token = default)
{
token.ThrowIfCancellationRequested();

// Take a lower-bound of the content of this commit in case our request is filtered but we need to spin
var tail = TailAddress;
var lastCommit = commitNum;

if (prevCommitTask == null) prevCommitTask = CommitTask;

if (!CommitInternal(out var tailAddress, out var actualCommitNum, true, null, -1, null))
return prevCommitTask;
var success = CommitInternal(out var actualTail, out var actualCommitNum, true, null, -1, null);

while (CommittedUntilAddress < tailAddress || persistedCommitNum < actualCommitNum)

if (success)
{
var linkedCommitInfo = await prevCommitTask.WithCancellationAsync(token).ConfigureAwait(false);
if (linkedCommitInfo.CommitInfo.UntilAddress < tailAddress || persistedCommitNum < actualCommitNum)
prevCommitTask = linkedCommitInfo.NextTask;
else
return linkedCommitInfo.NextTask;
while (CommittedUntilAddress < actualTail || persistedCommitNum < actualCommitNum)
{
var linkedCommitInfo = await prevCommitTask.WithCancellationAsync(token).ConfigureAwait(false);
if (linkedCommitInfo.CommitInfo.UntilAddress < actualTail || persistedCommitNum < actualCommitNum)
prevCommitTask = linkedCommitInfo.NextTask;
else
return linkedCommitInfo.NextTask;
}
}
else
{
while (CommittedUntilAddress < tail || persistedCommitNum < lastCommit)
{
var linkedCommitInfo = await prevCommitTask.WithCancellationAsync(token).ConfigureAwait(false);
if (linkedCommitInfo.CommitInfo.UntilAddress < actualTail || persistedCommitNum < actualCommitNum)
prevCommitTask = linkedCommitInfo.NextTask;
else
return linkedCommitInfo.NextTask;
}
}

return prevCommitTask;
Expand Down

0 comments on commit 4c6bd9d

Please sign in to comment.