Skip to content

Commit

Permalink
Added logging and interception for savepoints
Browse files Browse the repository at this point in the history
Part of #20176
  • Loading branch information
roji committed Jun 3, 2020
1 parent 5ae2e35 commit df60c0f
Show file tree
Hide file tree
Showing 11 changed files with 2,162 additions and 27 deletions.
87 changes: 87 additions & 0 deletions src/EFCore.Relational/Diagnostics/DbTransactionInterceptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,93 @@ public virtual Task TransactionRolledBackAsync(
CancellationToken cancellationToken = default)
=> Task.CompletedTask;

/// <inheritdoc />
public virtual InterceptionResult CreatingSavepoint(
DbTransaction transaction,
TransactionEventData eventData,
InterceptionResult result)
=> result;

/// <inheritdoc />
public virtual void CreatedSavepoint(
DbTransaction transaction,
TransactionEventData eventData)
{
}

/// <inheritdoc />
public virtual Task<InterceptionResult> CreatingSavepointAsync(
DbTransaction transaction,
TransactionEventData eventData,
InterceptionResult result,
CancellationToken cancellationToken = default)
=> Task.FromResult(result);

/// <inheritdoc />
public virtual Task CreatedSavepointAsync(
DbTransaction transaction,
TransactionEventData eventData,
CancellationToken cancellationToken = default)
=> Task.CompletedTask;

/// <inheritdoc />
public virtual InterceptionResult RollingBackToSavepoint(
DbTransaction transaction,
TransactionEventData eventData,
InterceptionResult result)
=> result;

/// <inheritdoc />
public virtual void RolledBackToSavepoint(
DbTransaction transaction,
TransactionEventData eventData)
{
}

/// <inheritdoc />
public virtual Task<InterceptionResult> RollingBackToSavepointAsync(
DbTransaction transaction,
TransactionEventData eventData,
InterceptionResult result,
CancellationToken cancellationToken = default)
=> Task.FromResult(result);

/// <inheritdoc />
public virtual Task RolledBackToSavepointAsync(
DbTransaction transaction,
TransactionEventData eventData,
CancellationToken cancellationToken = default)
=> Task.CompletedTask;

/// <inheritdoc />
public virtual InterceptionResult ReleasingSavepoint(
DbTransaction transaction,
TransactionEventData eventData,
InterceptionResult result)
=> result;

/// <inheritdoc />
public virtual void ReleasedSavepoint(
DbTransaction transaction,
TransactionEventData eventData)
{
}

/// <inheritdoc />
public virtual Task<InterceptionResult> ReleasingSavepointAsync(
DbTransaction transaction,
TransactionEventData eventData,
InterceptionResult result,
CancellationToken cancellationToken = default)
=> Task.FromResult(result);

/// <inheritdoc />
public virtual Task ReleasedSavepointAsync(
DbTransaction transaction,
TransactionEventData eventData,
CancellationToken cancellationToken = default)
=> Task.CompletedTask;

/// <summary>
/// Called when use of a <see cref="DbTransaction" /> has failed with an exception.
/// </summary>
Expand Down
207 changes: 207 additions & 0 deletions src/EFCore.Relational/Diagnostics/IDbTransactionInterceptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,213 @@ Task TransactionRolledBackAsync(
[NotNull] TransactionEndEventData eventData,
CancellationToken cancellationToken = default);

/// <summary>
/// Called just before EF intends to create a transaction savepoint.
/// </summary>
/// <param name="transaction"> The transaction. </param>
/// <param name="eventData"> Contextual information about connection and transaction. </param>
/// <param name="result">
/// Represents the current result if one exists.
/// This value will have <see cref="InterceptionResult.IsSuppressed" /> set to <see langword="true"/> if some previous
/// interceptor suppressed execution by calling <see cref="InterceptionResult.Suppress" />.
/// This value is typically used as the return value for the implementation of this method.
/// </param>
/// <returns>
/// If <see cref="InterceptionResult.IsSuppressed" /> is false, the EF will continue as normal.
/// If <see cref="InterceptionResult.IsSuppressed" /> is true, then EF will suppress the operation
/// it was about to perform.
/// A normal implementation of this method for any interceptor that is not attempting to suppress
/// the operation is to return the <paramref name="result" /> value passed in.
/// </returns>
InterceptionResult CreatingSavepoint(
[NotNull] DbTransaction transaction,
[NotNull] TransactionEventData eventData,
InterceptionResult result);

/// <summary>
/// Called immediately after EF creates a transaction savepoint.
/// </summary>
/// <param name="transaction"> The transaction. </param>
/// <param name="eventData"> Contextual information about connection and transaction. </param>
void CreatedSavepoint(
[NotNull] DbTransaction transaction,
[NotNull] TransactionEventData eventData);

/// <summary>
/// Called just before EF intends to create a transaction savepoint.
/// </summary>
/// <param name="transaction"> The transaction. </param>
/// <param name="eventData"> Contextual information about connection and transaction. </param>
/// <param name="result">
/// Represents the current result if one exists.
/// This value will have <see cref="InterceptionResult.IsSuppressed" /> set to <see langword="true"/> if some previous
/// interceptor suppressed execution by calling <see cref="InterceptionResult.Suppress" />.
/// This value is typically used as the return value for the implementation of this method.
/// </param>
/// <param name="cancellationToken"> The cancellation token. </param>
/// <returns>
/// If <see cref="InterceptionResult.IsSuppressed" /> is false, the EF will continue as normal.
/// If <see cref="InterceptionResult.IsSuppressed" /> is true, then EF will suppress the operation
/// it was about to perform.
/// A normal implementation of this method for any interceptor that is not attempting to suppress
/// the operation is to return the <paramref name="result" /> value passed in.
/// </returns>
Task<InterceptionResult> CreatingSavepointAsync(
[NotNull] DbTransaction transaction,
[NotNull] TransactionEventData eventData,
InterceptionResult result,
CancellationToken cancellationToken = default);

/// <summary>
/// Called immediately after EF calls <see cref="DbTransaction.CommitAsync" />.
/// </summary>
/// <param name="transaction"> The transaction. </param>
/// <param name="eventData"> Contextual information about connection and transaction. </param>
/// <param name="cancellationToken"> The cancellation token. </param>
/// <returns> A <see cref="Task" /> representing the asynchronous operation. </returns>
Task CreatedSavepointAsync(
[NotNull] DbTransaction transaction,
[NotNull] TransactionEventData eventData,
CancellationToken cancellationToken = default);

/// <summary>
/// Called just before EF intends to roll back to a transaction savepoint.
/// </summary>
/// <param name="transaction"> The transaction. </param>
/// <param name="eventData"> Contextual information about connection and transaction. </param>
/// <param name="result">
/// Represents the current result if one exists.
/// This value will have <see cref="InterceptionResult.IsSuppressed" /> set to <see langword="true"/> if some previous
/// interceptor suppressed execution by calling <see cref="InterceptionResult.Suppress" />.
/// This value is typically used as the return value for the implementation of this method.
/// </param>
/// <returns>
/// If <see cref="InterceptionResult.IsSuppressed" /> is false, the EF will continue as normal.
/// If <see cref="InterceptionResult.IsSuppressed" /> is true, then EF will suppress the operation
/// it was about to perform.
/// A normal implementation of this method for any interceptor that is not attempting to suppress
/// the operation is to return the <paramref name="result" /> value passed in.
/// </returns>
InterceptionResult RollingBackToSavepoint(
[NotNull] DbTransaction transaction,
[NotNull] TransactionEventData eventData,
InterceptionResult result);

/// <summary>
/// Called immediately after EF rolls back to a transaction savepoint.
/// </summary>
/// <param name="transaction"> The transaction. </param>
/// <param name="eventData"> Contextual information about connection and transaction. </param>
void RolledBackToSavepoint(
[NotNull] DbTransaction transaction,
[NotNull] TransactionEventData eventData);

/// <summary>
/// Called just before EF intends to roll back to a transaction savepoint.
/// </summary>
/// <param name="transaction"> The transaction. </param>
/// <param name="eventData"> Contextual information about connection and transaction. </param>
/// <param name="result">
/// Represents the current result if one exists.
/// This value will have <see cref="InterceptionResult.IsSuppressed" /> set to <see langword="true"/> if some previous
/// interceptor suppressed execution by calling <see cref="InterceptionResult.Suppress" />.
/// This value is typically used as the return value for the implementation of this method.
/// </param>
/// <param name="cancellationToken"> The cancellation token. </param>
/// <returns>
/// If <see cref="InterceptionResult.IsSuppressed" /> is false, the EF will continue as normal.
/// If <see cref="InterceptionResult.IsSuppressed" /> is true, then EF will suppress the operation
/// it was about to perform.
/// A normal implementation of this method for any interceptor that is not attempting to suppress
/// the operation is to return the <paramref name="result" /> value passed in.
/// </returns>
Task<InterceptionResult> RollingBackToSavepointAsync(
[NotNull] DbTransaction transaction,
[NotNull] TransactionEventData eventData,
InterceptionResult result,
CancellationToken cancellationToken = default);

/// <summary>
/// Called immediately after EF rolls back to a transaction savepoint.
/// </summary>
/// <param name="transaction"> The transaction. </param>
/// <param name="eventData"> Contextual information about connection and transaction. </param>
/// <param name="cancellationToken"> The cancellation token. </param>
/// <returns> A <see cref="Task" /> representing the asynchronous operation. </returns>
Task RolledBackToSavepointAsync(
[NotNull] DbTransaction transaction,
[NotNull] TransactionEventData eventData,
CancellationToken cancellationToken = default);

/// <summary>
/// Called just before EF intends to release a transaction savepoint.
/// </summary>
/// <param name="transaction"> The transaction. </param>
/// <param name="eventData"> Contextual information about connection and transaction. </param>
/// <param name="result">
/// Represents the current result if one exists.
/// This value will have <see cref="InterceptionResult.IsSuppressed" /> set to <see langword="true"/> if some previous
/// interceptor suppressed execution by calling <see cref="InterceptionResult.Suppress" />.
/// This value is typically used as the return value for the implementation of this method.
/// </param>
/// <returns>
/// If <see cref="InterceptionResult.IsSuppressed" /> is false, the EF will continue as normal.
/// If <see cref="InterceptionResult.IsSuppressed" /> is true, then EF will suppress the operation
/// it was about to perform.
/// A normal implementation of this method for any interceptor that is not attempting to suppress
/// the operation is to return the <paramref name="result" /> value passed in.
/// </returns>
InterceptionResult ReleasingSavepoint(
[NotNull] DbTransaction transaction,
[NotNull] TransactionEventData eventData,
InterceptionResult result);

/// <summary>
/// Called immediately after EF releases a transaction savepoint.
/// </summary>
/// <param name="transaction"> The transaction. </param>
/// <param name="eventData"> Contextual information about connection and transaction. </param>
void ReleasedSavepoint(
[NotNull] DbTransaction transaction,
[NotNull] TransactionEventData eventData);

/// <summary>
/// Called just before EF intends to release a transaction savepoint.
/// </summary>
/// <param name="transaction"> The transaction. </param>
/// <param name="eventData"> Contextual information about connection and transaction. </param>
/// <param name="result">
/// Represents the current result if one exists.
/// This value will have <see cref="InterceptionResult.IsSuppressed" /> set to <see langword="true"/> if some previous
/// interceptor suppressed execution by calling <see cref="InterceptionResult.Suppress" />.
/// This value is typically used as the return value for the implementation of this method.
/// </param>
/// <param name="cancellationToken"> The cancellation token. </param>
/// <returns>
/// If <see cref="InterceptionResult.IsSuppressed" /> is false, the EF will continue as normal.
/// If <see cref="InterceptionResult.IsSuppressed" /> is true, then EF will suppress the operation
/// it was about to perform.
/// A normal implementation of this method for any interceptor that is not attempting to suppress
/// the operation is to return the <paramref name="result" /> value passed in.
/// </returns>
Task<InterceptionResult> ReleasingSavepointAsync(
[NotNull] DbTransaction transaction,
[NotNull] TransactionEventData eventData,
InterceptionResult result,
CancellationToken cancellationToken = default);

/// <summary>
/// Called immediately after EF releases a transaction savepoint.
/// </summary>
/// <param name="transaction"> The transaction. </param>
/// <param name="eventData"> Contextual information about connection and transaction. </param>
/// <param name="cancellationToken"> The cancellation token. </param>
/// <returns> A <see cref="Task" /> representing the asynchronous operation. </returns>
Task ReleasedSavepointAsync(
[NotNull] DbTransaction transaction,
[NotNull] TransactionEventData eventData,
CancellationToken cancellationToken = default);

/// <summary>
/// Called when use of a <see cref="DbTransaction" /> has failed with an exception.
/// </summary>
Expand Down
Loading

0 comments on commit df60c0f

Please sign in to comment.