Example #1
0
        // public methods
        /// <inheritdoc />
        public void AbortTransaction(CancellationToken cancellationToken = default(CancellationToken))
        {
            EnsureAbortTransactionCanBeCalled(nameof(AbortTransaction));

            try
            {
                if (_currentTransaction.IsEmpty)
                {
                    return;
                }

                try
                {
                    var firstAttempt = CreateAbortTransactionOperation();
                    ExecuteEndTransactionOnPrimary(firstAttempt, cancellationToken);
                    return;
                }
                catch (Exception exception) when(ShouldRetryEndTransactionException(exception))
                {
                    // unpin if retryable error
                    _currentTransaction.UnpinAll();

                    // ignore exception and retry
                }
                catch
                {
                    return; // ignore exception and return
                }

                try
                {
                    var secondAttempt = CreateAbortTransactionOperation();
                    ExecuteEndTransactionOnPrimary(secondAttempt, cancellationToken);
                }
                catch
                {
                    return; // ignore exception and return
                }
            }
            finally
            {
                _currentTransaction.SetState(CoreTransactionState.Aborted);
                // The transaction is aborted.The session MUST be unpinned regardless
                // of whether the abortTransaction command succeeds or fails
                _currentTransaction.UnpinAll();
            }
        }
Example #2
0
        // public methods
        /// <inheritdoc />
        public void AbortTransaction(CancellationToken cancellationToken = default(CancellationToken))
        {
            EnsureAbortTransactionCanBeCalled(nameof(AbortTransaction));

            try
            {
                if (_currentTransaction.IsEmpty)
                {
                    return;
                }

                try
                {
                    var firstAttempt = CreateAbortTransactionOperation();
                    ExecuteEndTransactionOnPrimary(firstAttempt, cancellationToken);
                    return;
                }
                catch (Exception exception) when(ShouldIgnoreAbortTransactionException(exception))
                {
                    return; // ignore exception and return
                }
                catch (Exception exception) when(ShouldRetryEndTransactionException(exception))
                {
                    // ignore exception and retry
                }
                catch
                {
                    return; // ignore exception and return
                }

                try
                {
                    var secondAttempt = CreateAbortTransactionOperation();
                    ExecuteEndTransactionOnPrimary(secondAttempt, cancellationToken);
                }
                catch
                {
                    return; // ignore exception and return
                }
            }
            finally
            {
                _currentTransaction.SetState(CoreTransactionState.Aborted);
            }
        }