Skip to content

Commit

Permalink
Client: add ConfigureAwait(false)
Browse files Browse the repository at this point in the history
  • Loading branch information
KrzysFR committed Jun 30, 2024
1 parent 269d285 commit 70bf619
Show file tree
Hide file tree
Showing 14 changed files with 122 additions and 120 deletions.
34 changes: 17 additions & 17 deletions FoundationDB.Client/Fdb.Bulk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ async Task CommitBatch()

if (bodyAsync != null)
{
await bodyAsync(item, trans);
await bodyAsync(item, trans).ConfigureAwait(false);
}
else
{
Expand Down Expand Up @@ -771,7 +771,7 @@ async Task CommitBatch()
chunk.CopyTo(offset, batch, 0, batch.Length);
if (bodyAsync != null)
{
await bodyAsync(batch, trans);
await bodyAsync(batch, trans).ConfigureAwait(false);
}
else
{
Expand Down Expand Up @@ -800,7 +800,7 @@ async Task CommitBatch()
chunk.CopyTo(offset, batch, 0, batch.Length);
if (bodyAsync != null)
{
await bodyAsync(batch, trans);
await bodyAsync(batch, trans).ConfigureAwait(false);
}
else
{
Expand Down Expand Up @@ -1218,15 +1218,15 @@ CancellationToken ct
var sw = Stopwatch.StartNew();
if (bodyAsyncWithContextAndState != null)
{
localValue = await bodyAsyncWithContextAndState(items, ctx, localValue);
localValue = await bodyAsyncWithContextAndState(items, ctx, localValue).ConfigureAwait(false);
}
else if (bodyWithContextAndState != null)
{
localValue = bodyWithContextAndState(items, ctx, localValue);
}
else if (bodyAsyncWithContext != null)
{
await bodyAsyncWithContext(items, ctx);
await bodyAsyncWithContext(items, ctx).ConfigureAwait(false);
}
else
{
Expand Down Expand Up @@ -1280,7 +1280,7 @@ CancellationToken ct
}
else
{ // the error may be retry-able...
await trans.OnErrorAsync(error.Code);
await trans.OnErrorAsync(error.Code).ConfigureAwait(false);
ctx.GenerationTimer.Restart();
ctx.Generation++;
//REVIEW: magical number!
Expand Down Expand Up @@ -1412,7 +1412,7 @@ public static async Task<long> ExportAsync(IFdbDatabase db, KeySelector begin, K

using (var tr = db.BeginReadOnlyTransaction(ct))
{
await reset(tr);
await reset(tr).ConfigureAwait(false);

//TODO: make options configurable!
var options = new FdbRangeOptions
Expand All @@ -1426,7 +1426,7 @@ public static async Task<long> ExportAsync(IFdbDatabase db, KeySelector begin, K
long waitForFetch = 0;

// read the first batch
var page = await FetchNextBatchAsync(tr, begin, end, options, reset);
var page = await FetchNextBatchAsync(tr, begin, end, options, reset).ConfigureAwait(false);
++waitForFetch;

while (page.HasMore)
Expand All @@ -1438,20 +1438,20 @@ public static async Task<long> ExportAsync(IFdbDatabase db, KeySelector begin, K
if (page.Count > 0)
{
ct.ThrowIfCancellationRequested();
await handler(page.Items, count, ct);
await handler(page.Items, count, ct).ConfigureAwait(false);
++chunks;
count += page.Count;
}

if (next.Status != TaskStatus.RanToCompletion) ++waitForFetch;
page = await next;
page = await next.ConfigureAwait(false);
}

// process the last page, if any
if (page.Count > 0)
{
ct.ThrowIfCancellationRequested();
await handler(page.Items, count, ct);
await handler(page.Items, count, ct).ConfigureAwait(false);
++chunks;
count += page.Count;
}
Expand Down Expand Up @@ -1542,7 +1542,7 @@ public static async Task<long> ExportAsync<TSubspace>(IFdbDatabase db, ISubspace
// should export be lower priority? TODO: make if configurable!
tr.Options.WithPriorityBatch();
var folder = await path.Resolve(tr);
var folder = await path.Resolve(tr).ConfigureAwait(false);
if (previous.IsNull)
{
if (folder == null) throw new InvalidOperationException($"Failed to export the content of subspace {path} because it was not found.");
Expand All @@ -1565,7 +1565,7 @@ public static async Task<long> ExportAsync<TSubspace>(IFdbDatabase db, ISubspace

using (var tr = db.BeginReadOnlyTransaction(ct))
{
await reset(tr);
await reset(tr).ConfigureAwait(false);

//TODO: make options configurable!
var options = new FdbRangeOptions
Expand All @@ -1579,7 +1579,7 @@ public static async Task<long> ExportAsync<TSubspace>(IFdbDatabase db, ISubspace
long waitForFetch = 0;

// read the first batch
var page = await FetchNextBatchAsync(tr, begin, end, options, reset);
var page = await FetchNextBatchAsync(tr, begin, end, options, reset).ConfigureAwait(false);
++waitForFetch;

while (page.HasMore)
Expand All @@ -1591,20 +1591,20 @@ public static async Task<long> ExportAsync<TSubspace>(IFdbDatabase db, ISubspace
if (page.Count > 0)
{
ct.ThrowIfCancellationRequested();
await handler(page.Items, location, count, ct);
await handler(page.Items, location, count, ct).ConfigureAwait(false);
++chunks;
count += page.Count;
}

if (next.Status != TaskStatus.RanToCompletion) ++waitForFetch;
page = await next;
page = await next.ConfigureAwait(false);
}

// process the last page, if any
if (page.Count > 0)
{
ct.ThrowIfCancellationRequested();
await handler(page.Items, location, count, ct);
await handler(page.Items, location, count, ct).ConfigureAwait(false);
++chunks;
count += page.Count;
}
Expand Down
4 changes: 2 additions & 2 deletions FoundationDB.Client/Fdb.System.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public static class System
long rv = 0;
if (doc.ContainsKey("cluster"))
{
rv = await trans.GetReadVersionAsync();
rv = await trans.GetReadVersionAsync().ConfigureAwait(false);
}

return new FdbSystemStatus(doc, rv, data);
Expand Down Expand Up @@ -407,7 +407,7 @@ public static async Task<List<Slice>> GetBoundaryKeysAsync(IFdbReadOnlyTransacti
//TODO: we may need to also copy options like RetryLimit and Timeout ?
return GetBoundaryKeysInternalAsync(shadow, beginInclusive, endExclusive);
}, trans.Cancellation);
}, trans.Cancellation).ConfigureAwait(false);
}

/// <summary>Returns a list of keys k such that <paramref name="beginInclusive"/> &lt;= k &lt; <paramref name="endExclusive"/> and k is located at the start of a contiguous range stored on a single server</summary>
Expand Down
2 changes: 1 addition & 1 deletion FoundationDB.Client/Fdb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ internal static async Task<IFdbDatabase> OpenInternalAsync(FdbConnectionOptions

if (hasPartition)
{ // open the partition, and switch the root of the db
await Fdb.Directory.SwitchToNamedPartitionAsync(db, root.Path, ct);
await Fdb.Directory.SwitchToNamedPartitionAsync(db, root.Path, ct).ConfigureAwait(false);
}

success = true;
Expand Down
41 changes: 20 additions & 21 deletions FoundationDB.Client/FdbOperationContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public sealed class FdbOperationContext : IDisposable
public FdbError PreviousError { get; private set; }

/// <summary>Stopwatch that is started at the creation of the transaction, and stopped when it commits or gets disposed</summary>
private ValueStopwatch Clock; //REVIEW: must be a field!
private ValueStopwatch Clock; // must be a field!

/// <summary>Duration of all the previous attempts before the current one (starts at 0, and gets updated at each reset/retry)</summary>
internal TimeSpan BaseDuration { get; private set; }
Expand Down Expand Up @@ -1062,7 +1062,7 @@ internal static async Task<TResult> ExecuteInternal<TState, TIntermediate, TResu
}
}

if (!await context.ValidateValueChecksSlow(valueChecks, ignoreFailedTasks: false))
if (!await context.ValidateValueChecksSlow(valueChecks, ignoreFailedTasks: false).ConfigureAwait(false))
{
if (currentActivity != null)
{
Expand Down Expand Up @@ -1145,26 +1145,26 @@ internal static async Task<TResult> ExecuteInternal<TState, TIntermediate, TResu

case Func<IFdbReadOnlyTransaction, TIntermediate, Task<TResult>> f:
{
result = await f(trans, intermediate!);
result = await f(trans, intermediate!).ConfigureAwait(false);
hasResult = true;
break;
}
case Func<IFdbReadOnlyTransaction, TIntermediate, ValueTask<TResult>> f:
{
result = await f(trans, intermediate!);
result = await f(trans, intermediate!).ConfigureAwait(false);
hasResult = true;
break;
}
case Func<IFdbReadOnlyTransaction, TResult, Task> f:
{
if (!hasResult) throw new ArgumentException("Success handler requires the result to be computed by the loop handler.", nameof(success));
await f(trans, result);
await f(trans, result).ConfigureAwait(false);
break;
}
case Func<IFdbReadOnlyTransaction, TResult, ValueTask> f:
{
if (!hasResult) throw new ArgumentException("Success handler requires the result to be computed by the loop handler.", nameof(success));
await f(trans, result);
await f(trans, result).ConfigureAwait(false);
break;
}
case Func<IFdbReadOnlyTransaction, TIntermediate, TResult> f:
Expand All @@ -1175,26 +1175,26 @@ internal static async Task<TResult> ExecuteInternal<TState, TIntermediate, TResu
}
case Func<IFdbReadOnlyTransaction, Task<TResult>> f:
{
result = await f(trans);
result = await f(trans).ConfigureAwait(false);
hasResult = true;
break;
}
case Func<IFdbReadOnlyTransaction, ValueTask<TResult>> f:
{
result = await f(trans);
result = await f(trans).ConfigureAwait(false);
hasResult = true;
break;
}
case Func<IFdbReadOnlyTransaction, Task> f:
{
await f(trans);
await f(trans).ConfigureAwait(false);
result = default!;
hasResult = true;
break;
}
case Func<IFdbReadOnlyTransaction, ValueTask> f:
{
await f(trans);
await f(trans).ConfigureAwait(false);
result = default!;
hasResult = true;
break;
Expand Down Expand Up @@ -1223,26 +1223,26 @@ internal static async Task<TResult> ExecuteInternal<TState, TIntermediate, TResu

case Func<IFdbTransaction, TIntermediate, Task<TResult>> f:
{
result = await f(trans, intermediate!);
result = await f(trans, intermediate!).ConfigureAwait(false);
hasResult = true;
break;
}
case Func<IFdbTransaction, TIntermediate, ValueTask<TResult>> f:
{
result = await f(trans, intermediate!);
result = await f(trans, intermediate!).ConfigureAwait(false);
hasResult = true;
break;
}
case Func<IFdbTransaction, TResult, Task> f:
{
if (!hasResult) throw new ArgumentException("Success handler requires the result to be computed by the loop handler.", nameof(success));
await f(trans, result);
await f(trans, result).ConfigureAwait(false);
break;
}
case Func<IFdbTransaction, TResult, ValueTask> f:
{
if (!hasResult) throw new ArgumentException("Success handler requires the result to be computed by the loop handler.", nameof(success));
await f(trans, result);
await f(trans, result).ConfigureAwait(false);
break;
}
case Func<IFdbTransaction, TIntermediate, TResult> f:
Expand All @@ -1253,26 +1253,26 @@ internal static async Task<TResult> ExecuteInternal<TState, TIntermediate, TResu
}
case Func<IFdbTransaction, Task<TResult>> f:
{
result = await f(trans);
result = await f(trans).ConfigureAwait(false);
hasResult = true;
break;
}
case Func<IFdbTransaction, ValueTask<TResult>> f:
{
result = await f(trans);
result = await f(trans).ConfigureAwait(false);
hasResult = true;
break;
}
case Func<IFdbTransaction, Task> f:
{
await f(trans);
await f(trans).ConfigureAwait(false);
result = default!;
hasResult = true;
break;
}
case Func<IFdbTransaction, ValueTask> f:
{
await f(trans);
await f(trans).ConfigureAwait(false);
result = default!;
hasResult = true;
break;
Expand Down Expand Up @@ -1344,7 +1344,7 @@ internal static async Task<TResult> ExecuteInternal<TState, TIntermediate, TResu
{ // we need to resolve any check that would still have passed before the error

context.FailedValueCheckTags?.Clear();
if (!await context.ValidateValueChecks(ignoreFailedTasks: true))
if (!await context.ValidateValueChecks(ignoreFailedTasks: true).ConfigureAwait(false))
{
// we don't override the original error, though!
}
Expand Down Expand Up @@ -1398,7 +1398,7 @@ internal static async Task<TResult> ExecuteInternal<TState, TIntermediate, TResu
if (!hasRunValueChecks)
{
context.FailedValueCheckTags?.Clear();
if (!await context.ValidateValueChecks(ignoreFailedTasks: false))
if (!await context.ValidateValueChecks(ignoreFailedTasks: false).ConfigureAwait(false))
{
try
{
Expand Down Expand Up @@ -1531,5 +1531,4 @@ public enum FdbValueCheckResult
Failed = 2,
}


}
12 changes: 6 additions & 6 deletions FoundationDB.Client/FdbRangeQuery.ResultIterator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,7 @@ protected override AsyncIterator<T> Clone()
protected override ValueTask<bool> OnFirstAsync()
{
// on first call, setup the page iterator
if (m_chunkIterator == null)
{
m_chunkIterator = new PagingIterator(m_query, m_transaction).GetAsyncEnumerator(m_ct, m_mode);
}
m_chunkIterator ??= new PagingIterator(m_query, m_transaction).GetAsyncEnumerator(m_ct, m_mode);
return new ValueTask<bool>(true);
}

Expand Down Expand Up @@ -151,7 +148,7 @@ private async ValueTask<bool> ReadAnotherBatchAsync()
Debug.WriteLine("No more chunks from page iterator");
#endif
m_outOfChunks = true;
return await Completed();
return await Completed().ConfigureAwait(false);
}

private bool ProcessNextItem()
Expand Down Expand Up @@ -191,7 +188,10 @@ protected override async ValueTask Cleanup()
{
try
{
if (m_chunkIterator != null) await m_chunkIterator.DisposeAsync();
if (m_chunkIterator != null)
{
await m_chunkIterator.DisposeAsync().ConfigureAwait(false);
}
}
finally
{
Expand Down
8 changes: 4 additions & 4 deletions FoundationDB.Client/FdbRangeQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -495,10 +495,9 @@ internal async Task<bool> AnyOrNoneAsync(bool any)
if ((this.TargetBytes ?? 0) != 0 || (this.Mode != FdbStreamingMode.Iterator && this.Mode != FdbStreamingMode.Exact))
{ // fallback to the default implementation
// ReSharper disable InvokeAsExtensionMethod
if (any)
return await AsyncEnumerable.AnyAsync(this, this.Transaction.Cancellation);
else
return await AsyncEnumerable.NoneAsync(this, this.Transaction.Cancellation);
return any
? await AsyncEnumerable.AnyAsync(this, this.Transaction.Cancellation).ConfigureAwait(false)
: await AsyncEnumerable.NoneAsync(this, this.Transaction.Cancellation).ConfigureAwait(false);
// ReSharper restore InvokeAsExtensionMethod
}

Expand All @@ -521,6 +520,7 @@ public override string ToString()
}

/// <summary>Extension methods for <see cref="FdbRangeQuery{T}"/></summary>
[PublicAPI]
public static class FdbRangeQueryExtensions
{

Expand Down
Loading

0 comments on commit 70bf619

Please sign in to comment.