public override IFdbTransaction BeginTransaction(FdbTransactionMode mode, CancellationToken cancellationToken = default(CancellationToken), FdbOperationContext context = null) { return new FdbLoggedTransaction( base.BeginTransaction(mode, cancellationToken, context), true, this.OnCommitted ); }
/// <summary>Start a new transaction on this database</summary> /// <param name="mode">Mode of the new transaction (read-only, read-write, ...)</param> /// <param name="ct">Optional cancellation token that can abort all pending async operations started by this transaction.</param> /// <param name="context">If not null, attach the new transaction to an existing context.</param> /// <returns>New transaction instance that can read from or write to the database.</returns> /// <remarks>You MUST call Dispose() on the transaction when you are done with it. You SHOULD wrap it in a 'using' statement to ensure that it is disposed in all cases.</remarks> /// <example> /// using(var tr = db.BeginTransaction(CancellationToken.None)) /// { /// tr.Set(Slice.FromString("Hello"), Slice.FromString("World")); /// tr.Clear(Slice.FromString("OldValue")); /// await tr.CommitAsync(); /// }</example> public IFdbTransaction BeginTransaction(FdbTransactionMode mode, CancellationToken ct, FdbOperationContext context = null) { ct.ThrowIfCancellationRequested(); if (context == null) { context = new FdbOperationContext(this, mode, ct); } return(CreateNewTransaction(context)); }
/// <summary>Create a new logged transaction</summary> public override IFdbTransaction BeginTransaction(FdbTransactionMode mode, CancellationToken cancellationToken = default(CancellationToken), FdbOperationContext context = null) { return(new FdbLoggedTransaction( base.BeginTransaction(mode, cancellationToken, context), true, this.OnCommitted, this.LoggingOptions )); }
/// <summary>Start a new transaction on this database</summary> /// <param name="mode">Mode of the new transaction (read-only, read-write, ...)</param> /// <param name="ct">Optional cancellation token that can abort all pending async operations started by this transaction.</param> /// <param name="context">If not null, attach the new transaction to an existing context.</param> /// <returns>New transaction instance that can read from or write to the database.</returns> /// <remarks>You MUST call Dispose() on the transaction when you are done with it. You SHOULD wrap it in a 'using' statement to ensure that it is disposed in all cases.</remarks> /// <example> /// using(var tr = db.BeginTransaction(CancellationToken.None)) /// { /// tr.Set(Slice.FromString("Hello"), Slice.FromString("World")); /// tr.Clear(Slice.FromString("OldValue")); /// await tr.CommitAsync(); /// }</example> public ValueTask <IFdbTransaction> BeginTransactionAsync(FdbTransactionMode mode, CancellationToken ct, FdbOperationContext?context = null) { ct.ThrowIfCancellationRequested(); if (context == null) { context = new FdbOperationContext(this, mode, ct); } return(new ValueTask <IFdbTransaction>(CreateNewTransaction(context))); }
public virtual IFdbTransaction BeginTransaction(FdbTransactionMode mode, CancellationToken ct = default(CancellationToken), FdbOperationContext context = null) { ThrowIfDisposed(); // enforce read-only mode! if (m_readOnly) { mode |= FdbTransactionMode.ReadOnly; } if (context == null) { context = new FdbOperationContext(this, mode, ct); } return(m_database.BeginTransaction(mode, ct, context)); }
/// <summary>Create a new retry loop operation context</summary> /// <param name="db">Database that will be used by the retry loop</param> /// <param name="mode">Operation mode of the retry loop</param> /// <param name="ct">Optional cancellation token that will abort the retry loop if triggered.</param> public FdbOperationContext([NotNull] IFdbDatabase db, FdbTransactionMode mode, CancellationToken ct) { Contract.NotNull(db, nameof(db)); this.Database = db; this.Mode = mode; // note: we don't start the clock yet, only when the context starts executing... // by default, we hook ourselves to the database's CancellationToken, but we may need to also // hook with a different, caller-provided, token and respond to cancellation from both sites. var token = db.Cancellation; if (ct.CanBeCanceled && !ct.Equals(token)) { this.TokenSource = CancellationTokenSource.CreateLinkedTokenSource(token, ct); token = this.TokenSource.Token; } this.Cancellation = token; }
public FdbOperationContext([NotNull] IFdbDatabase db, FdbTransactionMode mode, CancellationToken cancellationToken) { if (db == null) { throw new ArgumentNullException("db"); } this.Database = db; this.Mode = mode; this.Duration = new Stopwatch(); // by default, we hook ourselves on the db's CancellationToken var token = db.Cancellation; if (cancellationToken.CanBeCanceled && cancellationToken != token) { this.TokenSource = CancellationTokenSource.CreateLinkedTokenSource(token, cancellationToken); token = this.TokenSource.Token; } this.Cancellation = token; }
/// <summary>Create a new retry loop operation context</summary> /// <param name="db">Database that will be used by the retry loop</param> /// <param name="mode">Operation mode of the retry loop</param> /// <param name="cancellationToken">Optional cancellation token that will abort the retry loop if triggered.</param> public FdbOperationContext([NotNull] IFdbDatabase db, FdbTransactionMode mode, CancellationToken cancellationToken) { if (db == null) { throw new ArgumentNullException("db"); } this.Database = db; this.Mode = mode; this.Clock = new Stopwatch(); // note: we don't start the clock yet, only when the context starts executing... // by default, we hook ourselves to the db's CancellationToken, but we may need to also // hook with a different, caller-provided, token and respond to cancellation from both sites. var token = db.Cancellation; if (cancellationToken.CanBeCanceled && !cancellationToken.Equals(token)) { this.TokenSource = CancellationTokenSource.CreateLinkedTokenSource(token, cancellationToken); token = this.TokenSource.Token; } this.Cancellation = token; }
private CancellationToken m_cancellation; //PERF: readonly struct #endregion #region Constructors... internal FdbTransaction(FdbDatabase db, FdbOperationContext context, int id, IFdbTransactionHandler handler, FdbTransactionMode mode) { Contract.Requires(db != null && context != null && handler != null); Contract.Requires(context.Database != null); m_context = context; m_database = db; m_id = id; //REVIEW: the operation context may already have created its own CTS, maybe we can merge them ? m_cts = CancellationTokenSource.CreateLinkedTokenSource(context.Cancellation); m_cancellation = m_cts.Token; m_readOnly = (mode & FdbTransactionMode.ReadOnly) != 0; m_handler = handler; }