Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ReadyToCompletePendingAsync for client to check if there is somet… #269

Merged
merged 2 commits into from
May 29, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion cs/src/core/ClientSession/ClientSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,8 @@ public void Refresh()
}

/// <summary>
/// Sync complete outstanding pending operations
/// Sync complete all outstanding pending operations
/// Async operations (ReadAsync) must be completed individually
/// </summary>
/// <param name="spinWait">Spin-wait for all pending operations on session to complete</param>
/// <param name="spinWaitForCommit">Extend spin-wait until ongoing commit/checkpoint, if any, completes</param>
Expand Down Expand Up @@ -365,6 +366,22 @@ public async ValueTask CompletePendingAsync(bool waitForCommit = false, Cancella
await WaitForCommitAsync(token);
}

/// <summary>
/// Check if at least one request is ready for CompletePending to be called on
/// Returns completed immediately if there are no outstanding requests
/// </summary>
/// <param name="token"></param>
/// <returns></returns>
public async ValueTask ReadyToCompletePendingAsync(CancellationToken token = default)
{
token.ThrowIfCancellationRequested();

if (fht.epoch.ThisInstanceProtected())
throw new NotSupportedException("Async operations not supported over protected epoch");

await fht.ReadyToCompletePendingAsync(this, token);
}

/// <summary>
/// Wait for commit of all operations completed until the current point in session.
/// Does not itself issue checkpoint/commits.
Expand Down
24 changes: 24 additions & 0 deletions cs/src/core/ClientSession/FASTERAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,30 @@ public partial class FasterKV<Key, Value, Input, Output, Context, Functions> : F
where Value : new()
where Functions : IFunctions<Key, Value, Input, Output, Context>
{

/// <summary>
/// Check if at least one request is ready for CompletePending to operate on
/// </summary>
/// <param name="clientSession"></param>
/// <param name="token"></param>
/// <returns></returns>
internal async ValueTask ReadyToCompletePendingAsync(ClientSession<Key, Value, Input, Output, Context, Functions> clientSession, CancellationToken token = default)
{
#region Previous pending requests
if (!RelaxedCPR)
{
if (clientSession.ctx.phase == Phase.IN_PROGRESS || clientSession.ctx.phase == Phase.WAIT_PENDING)
{
if (clientSession.ctx.prevCtx.ioPendingRequests.Count != 0)
await clientSession.ctx.prevCtx.readyResponses.WaitForEntryAsync();
badrishc marked this conversation as resolved.
Show resolved Hide resolved
}
}
#endregion

if (clientSession.ctx.ioPendingRequests.Count != 0)
await clientSession.ctx.readyResponses.WaitForEntryAsync();
badrishc marked this conversation as resolved.
Show resolved Hide resolved
}

/// <summary>
/// Complete outstanding pending operations that were issued synchronously
/// Async operations (e.g., ReadAsync) need to be completed individually
Expand Down
10 changes: 10 additions & 0 deletions cs/src/core/Utilities/AsyncQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ public async Task<T> DequeueAsync(CancellationToken cancellationToken = default)
}
}

/// <summary>
/// Wait for queue to have at least one entry
/// </summary>
/// <param name="token"></param>
/// <returns></returns>
public async Task WaitForEntryAsync(CancellationToken token = default)
{
await semaphore.WaitAsync(token);
}

/// <summary>
/// Try dequeue (if item exists)
/// </summary>
Expand Down