public async ValueTask DisposeAsync() { try { await m_iterator.DisposeAsync(); } finally { m_transaction.Dispose(); } }
public void Dispose() { try { m_iterator.Dispose(); } finally { m_transaction.Dispose(); } }
protected virtual void Dispose(bool disposing) { if (!m_disposed) { m_disposed = true; if (disposing && m_owner) { m_transaction.Dispose(); } } }
private static async Task BenchSerialWriteAsync(IFdbDatabase db, int N, CancellationToken ct) { // read a lot of small keys, one by one var location = db.Partition("hello"); var sw = Stopwatch.StartNew(); IFdbTransaction trans = null; try { for (int i = 0; i < N; i++) { if (trans == null) { trans = db.BeginTransaction(ct); } trans.Set(location.Pack(i), Slice.FromInt32(i)); if (trans.Size > 100 * 1024) { await trans.CommitAsync(); trans.Dispose(); trans = null; } } await trans.CommitAsync(); } finally { if (trans != null) { trans.Dispose(); } } sw.Stop(); Console.WriteLine("Took " + sw.Elapsed + " to read " + N + " items (" + FormatTimeMicro(sw.Elapsed.TotalMilliseconds / N) + "/read)"); }
internal static IAsyncEnumerator <T> GetEnumerator(FdbAsyncSequenceQuery <T> sequence, AsyncIterationHint mode) { var generator = sequence.CompileSequence(sequence.Expression); if (sequence.Transaction != null) { var source = generator(sequence.Transaction); Contract.Assert(source != null); return(source is IConfigurableAsyncEnumerable <T> configurable?configurable.GetAsyncEnumerator(sequence.Transaction.Cancellation, mode) : source.GetAsyncEnumerator(sequence.Transaction.Cancellation)); } //BUGBUG: how do we get a CancellationToken without a transaction? var ct = CancellationToken.None; IFdbTransaction? trans = null; IAsyncEnumerator <T>?iterator = null; bool success = true; try { #warning Fix async begin transaction! trans = sequence.Database !.BeginTransactionAsync(ct).GetAwaiter().GetResult(); //HACKHACK: BUGBUG: async! var source = generator(trans); Contract.Assert(source != null); iterator = source is IConfigurableAsyncEnumerable <T> configurable?configurable.GetAsyncEnumerator(ct, mode) : source.GetAsyncEnumerator(ct); return(new TransactionIterator(trans, iterator)); } catch (Exception) { success = false; throw; } finally { if (!success) { //BUGBUG: we have to block on the async disposable :( iterator?.DisposeAsync().GetAwaiter().GetResult(); trans?.Dispose(); } } }
internal static IFdbAsyncEnumerator <T> GetEnumerator([NotNull] FdbAsyncSequenceQuery <T> sequence, FdbAsyncMode mode) { var generator = sequence.CompileSequence(sequence.Expression); if (sequence.Transaction != null) { return(generator(sequence.Transaction).GetEnumerator(mode)); } //BUGBUG: how do we get a CancellationToken without a transaction? var ct = CancellationToken.None; IFdbTransaction trans = null; IFdbAsyncEnumerator <T> iterator = null; bool success = true; try { trans = sequence.Database.BeginTransaction(ct); iterator = generator(trans).GetEnumerator(); return(new TransactionIterator(trans, iterator)); } catch (Exception) { success = false; throw; } finally { if (!success) { if (iterator != null) { iterator.Dispose(); } if (trans != null) { trans.Dispose(); } } } }
internal static IAsyncEnumerator <T> GetEnumerator([NotNull] FdbAsyncSequenceQuery <T> sequence, AsyncIterationHint mode) { var generator = sequence.CompileSequence(sequence.Expression); if (sequence.Transaction != null) { var source = generator(sequence.Transaction); Contract.Assert(source != null); return(source is IConfigurableAsyncEnumerable <T> configurable?configurable.GetAsyncEnumerator(sequence.Transaction.Cancellation, mode) : source.GetAsyncEnumerator()); } //BUGBUG: how do we get a CancellationToken without a transaction? var ct = CancellationToken.None; IFdbTransaction trans = null; IAsyncEnumerator <T> iterator = null; bool success = true; try { trans = sequence.Database.BeginTransaction(ct); var source = generator(trans); Contract.Assert(source != null); iterator = source is IConfigurableAsyncEnumerable <T> configurable?configurable.GetAsyncEnumerator(ct, mode) : source.GetAsyncEnumerator(); return(new TransactionIterator(trans, iterator)); } catch (Exception) { success = false; throw; } finally { if (!success) { iterator?.Dispose(); trans?.Dispose(); } } }
private static async Task BenchSerialWriteAsync(IFdbDatabase db, int N, CancellationToken ct) { // read a lot of small keys, one by one Console.WriteLine($"=== BenchSerialWrite(N={N:N0}) ==="); var location = db.Root.ByKey("hello"); var sw = Stopwatch.StartNew(); IFdbTransaction trans = null; IDynamicKeySubspace subspace = null; try { for (int i = 0; i < N; i++) { if (trans == null) { trans = await db.BeginTransactionAsync(ct); subspace = await location.Resolve(trans); } trans.Set(subspace.Encode(i), Slice.FromInt32(i)); if (trans.Size > 100 * 1024) { await trans.CommitAsync(); trans.Dispose(); trans = null; } } await trans.CommitAsync(); } finally { trans?.Dispose(); } sw.Stop(); Console.WriteLine($"Took {sw.Elapsed.TotalSeconds:N3} sec to read {N:N0} items ({FormatTimeMicro(sw.Elapsed.TotalMilliseconds / N)}/read, {N/sw.Elapsed.TotalSeconds:N0} read/sec)"); Console.WriteLine(); }