Esempio n. 1
0
 public void SinglePhaseCommit(SinglePhaseEnlistment singlePhaseEnlistment)
 {
     switch (_singlePhaseVote)
     {
         case SinglePhaseVote.Committed:
             {
                 singlePhaseEnlistment.Committed();
                 break;
             }
         case SinglePhaseVote.Aborted:
             {
                 singlePhaseEnlistment.Aborted();
                 break;
             }
         case SinglePhaseVote.InDoubt:
             {
                 singlePhaseEnlistment.InDoubt();
                 break;
             }
     }
 }
 public void Rollback(SinglePhaseEnlistment singlePhaseEnlistment)
 {
     singlePhaseEnlistment.Aborted();
 }
 void IPromotableSinglePhaseNotification.Rollback(SinglePhaseEnlistment singlePhaseEnlistment)
 {
     _transactionManager.RemoveEnlistment(_transactionId);
     _ = RollbackAsync(singlePhaseEnlistment);
 }
Esempio n. 4
0
        public void SinglePhaseCommit(SinglePhaseEnlistment enlistment)
        {
            resource.NumSingle++;
            if (resource.IgnoreSPC)
                return;

            if (resource.FailSPC)
            {
                if (resource.FailWithException)
                    enlistment.Aborted(resource.ThrowThisException ?? new NotSupportedException());
                else
                    enlistment.Aborted();
            }
            else
            {
                resource.Commit();
                enlistment.Committed();
            }
        }
Esempio n. 5
0
            public void SinglePhaseCommit(SinglePhaseEnlistment singlePhaseEnlistment)
            {
                Trace("NonMSDTCPromoterEnlistment.SinglePhaseCommit");
                _completionEvent.Set();

                if (_failSPC)
                {
                    Trace("NonMSDTCPromoterEnlistment.SinglePhaseCommit - Failing based on configuration");
                    throw new Exception("Failing SinglePhaseCommit based on configuration");
                }

                switch (_spcResponse)
                {
                    case TransactionStatus.Committed:
                        {
                            singlePhaseEnlistment.Committed();
                            break;
                        }

                    case TransactionStatus.Aborted:
                        {
                            singlePhaseEnlistment.Aborted(new Exception("Aborted by NonMSDTCPromoterEnlistment.SinglePhaseCommit"));
                            break;
                        }

                    case TransactionStatus.InDoubt:
                        {
                            singlePhaseEnlistment.InDoubt(new Exception("InDoubt by NonMSDTCPromoterEnlistment.SinglePhaseCommit"));
                            break;
                        }
                    default:
                        {
                            throw new Exception("InDoubt by NonMSDTCPromoterEnlistment.SinglePhaseCommit because of invalid TransactionStatus outcome value.");
                        }
                }
            }
        // Called by the transaction to initiate commit sequence
        public void SinglePhaseCommit(SinglePhaseEnlistment enlistment)
        {
            Debug.Assert(null != enlistment, "null enlistment?");
            SqlInternalConnection connection = GetValidConnection();

            if (null != connection)
            {
                SqlConnection usersConnection = connection.Connection;
                SqlClientEventSource.Log.TraceEvent("<sc.SqlDelegatedTransaction.SinglePhaseCommit|RES|CPOOL> {0}, Connection {1}, committing transaction.", ObjectID, connection.ObjectID);
                RuntimeHelpers.PrepareConstrainedRegions();
                try
                {
                    // If the connection is doomed, we can be certain that the
                    // transaction will eventually be rolled back, and we shouldn't
                    // attempt to commit it.
                    if (connection.IsConnectionDoomed)
                    {
                        lock (connection)
                        {
                            _active     = false; // set to inactive first, doesn't matter how the rest completes, this transaction is done.
                            _connection = null;
                        }

                        enlistment.Aborted(SQL.ConnectionDoomed());
                    }
                    else
                    {
                        Exception commitException;
                        lock (connection)
                        {
                            try
                            {
                                // Now that we've acquired the lock, make sure we still have valid state for this operation.
                                ValidateActiveOnConnection(connection);

                                _active     = false; // set to inactive first, doesn't matter how the rest completes, this transaction is done.
                                _connection = null;  // Set prior to ExecuteTransaction call in case this initiates a TransactionEnd event

                                connection.ExecuteTransaction(SqlInternalConnection.TransactionRequest.Commit, null, System.Data.IsolationLevel.Unspecified, _internalTransaction, true);
                                commitException = null;
                            }
                            catch (SqlException e)
                            {
                                commitException = e;

                                // Doom the connection, to make sure that the transaction is
                                // eventually rolled back.
                                // VSTS 144562: doom the connection while having the lock on it to prevent race condition with "Transaction Ended" Event
                                connection.DoomThisConnection();
                            }
                            catch (InvalidOperationException e)
                            {
                                commitException = e;
                                connection.DoomThisConnection();
                            }
                        }
                        if (commitException != null)
                        {
                            // connection.ExecuteTransaction failed with exception
                            if (_internalTransaction.IsCommitted)
                            {
                                // Even though we got an exception, the transaction
                                // was committed by the server.
                                enlistment.Committed();
                            }
                            else if (_internalTransaction.IsAborted)
                            {
                                // The transaction was aborted, report that to
                                // SysTx.
                                enlistment.Aborted(commitException);
                            }
                            else
                            {
                                // The transaction is still active, we cannot
                                // know the state of the transaction.
                                enlistment.InDoubt(commitException);
                            }

                            // We eat the exception.  This is called on the SysTx
                            // thread, not the applications thread.  If we don't
                            // eat the exception an UnhandledException will occur,
                            // causing the process to FailFast.
                        }

                        connection.CleanupConnectionOnTransactionCompletion(_atomicTransaction);
                        if (commitException == null)
                        {
                            // connection.ExecuteTransaction succeeded
                            enlistment.Committed();
                        }
                    }
                }
                catch (System.OutOfMemoryException e)
                {
                    usersConnection.Abort(e);
                    throw;
                }
                catch (System.StackOverflowException e)
                {
                    usersConnection.Abort(e);
                    throw;
                }
                catch (System.Threading.ThreadAbortException e)
                {
                    usersConnection.Abort(e);
                    throw;
                }
            }
            else
            {
                // The transaction was aborted before we could commit, report that to SysTx and log the same.
                enlistment.Aborted();
                SqlClientEventSource.Log.TraceEvent("<sc.SqlDelegatedTransaction.SinglePhaseCommit|RES|CPOOL> {0}, Connection null, aborted before commit.", ObjectID);
            }
        }
Esempio n. 7
0
 public void Rollback(SinglePhaseEnlistment singlePhaseEnlistment)
 {
 }
Esempio n. 8
0
 public void SinglePhaseCommit(SinglePhaseEnlistment singlePhaseEnlistment)
 {
     Tracer.Info("Performing invalid single phase commit.");
     singlePhaseCommit = true;
     singlePhaseEnlistment.Committed();
 }
Esempio n. 9
0
 /// <summary>
 /// Notifies this object that the transaction is being committed.
 /// </summary>
 /// <param name="singlePhaseEnlistment">
 /// Interface used to send a response to the transaction manager.
 /// </param>
 void IPromotableSinglePhaseNotification.SinglePhaseCommit(SinglePhaseEnlistment singlePhaseEnlistment)
 {
     this.SinglePhaseCommit(singlePhaseEnlistment);
 } 
 public void Rollback(SinglePhaseEnlistment singlePhaseEnlistment)
 {
     singlePhaseEnlistment.Done();
 }
Esempio n. 11
0
 public void SinglePhaseCommit(SinglePhaseEnlistment singlePhaseEnlistment)
 {
     Console.WriteLine("Tx SinglePhaseCommit");
     singlePhaseEnlistment.Committed();
     //singlePhaseEnlistment.Aborted();
 }
 public void SinglePhaseCommit(SinglePhaseEnlistment singlePhaseEnlistment)
 {
     singlePhaseEnlistment.Committed();
 }
Esempio n. 13
0
 public void Rollback(SinglePhaseEnlistment enlistment)
 {
     resource.NumRollback++;
     resource.Rollback();
 }
 void IPromotableSinglePhaseNotification.SinglePhaseCommit(SinglePhaseEnlistment singlePhaseEnlistment)
 {
     _transactionManager.RemoveEnlistment(_transactionId);
     _ = SinglePhaseCommitAsync(singlePhaseEnlistment);
 }
 public void SinglePhaseCommit(SinglePhaseEnlistment singlePhaseEnlistment)
 {
     _callbacks.CommitTransaction();
     singlePhaseEnlistment.Committed();
     _callbacks.Dispose();
 }
 void ISinglePhaseNotification.SinglePhaseCommit(SinglePhaseEnlistment singlePhaseEnlistment)
 {
 }
        // Called by transaction to initiate abort sequence
        public void Rollback(SinglePhaseEnlistment enlistment)
        {
            Debug.Assert(null != enlistment, "null enlistment?");
            SqlInternalConnection connection = GetValidConnection();

            if (null != connection)
            {
                SqlConnection usersConnection = connection.Connection;
                SqlClientEventSource.Log.TraceEvent("<sc.SqlDelegatedTransaction.Rollback|RES|CPOOL> {0}, Connection {1}, rolling back transaction.", ObjectID, connection.ObjectID);
                RuntimeHelpers.PrepareConstrainedRegions();
                try
                {
                    lock (connection)
                    {
                        try
                        {
                            // Now that we've acquired the lock, make sure we still have valid state for this operation.
                            ValidateActiveOnConnection(connection);
                            _active     = false; // set to inactive first, doesn't matter how the execute completes, this transaction is done.
                            _connection = null;  // Set prior to ExecuteTransaction call in case this initiates a TransactionEnd event

                            // If we haven't already rolled back (or aborted) then tell the SQL Server to roll back
                            if (!_internalTransaction.IsAborted)
                            {
                                connection.ExecuteTransaction(SqlInternalConnection.TransactionRequest.Rollback, null, System.Data.IsolationLevel.Unspecified, _internalTransaction, true);
                            }
                        }
                        catch (SqlException)
                        {
                            // Doom the connection, to make sure that the transaction is
                            // eventually rolled back.
                            // VSTS 144562: doom the connection while having the lock on it to prevent race condition with "Transaction Ended" Event
                            connection.DoomThisConnection();

                            // Unlike SinglePhaseCommit, a rollback is a rollback, regardless
                            // of how it happens, so SysTx won't throw an exception, and we
                            // don't want to throw an exception either, because SysTx isn't
                            // handling it and it may create a fail fast scenario. In the end,
                            // there is no way for us to communicate to the consumer that this
                            // failed for more serious reasons than usual.
                            //
                            // This is a bit like "should you throw if Close fails", however,
                            // it only matters when you really need to know.  In that case,
                            // we have the tracing that we're doing to fallback on for the
                            // investigation.
                        }
                        catch (InvalidOperationException)
                        {
                            connection.DoomThisConnection();
                        }
                    }

                    // it doesn't matter whether the rollback succeeded or not, we presume
                    // that the transaction is aborted, because it will be eventually.
                    connection.CleanupConnectionOnTransactionCompletion(_atomicTransaction);
                    enlistment.Aborted();
                }
                catch (System.OutOfMemoryException e)
                {
                    usersConnection.Abort(e);
                    throw;
                }
                catch (System.StackOverflowException e)
                {
                    usersConnection.Abort(e);
                    throw;
                }
                catch (System.Threading.ThreadAbortException e)
                {
                    usersConnection.Abort(e);
                    throw;
                }
            }
            else
            {
                // The transaction was aborted, report that to SysTx and log the same.
                enlistment.Aborted();
                SqlClientEventSource.Log.TraceEvent("<sc.SqlDelegatedTransaction.Rollback|RES|CPOOL> {0}, Connection null, aborted before rollback.", ObjectID);
            }
        }
Esempio n. 18
0
 void ISinglePhaseNotification.SinglePhaseCommit(SinglePhaseEnlistment singlePhaseEnlistment)
 {
     Commit();
     singlePhaseEnlistment.Committed();
 }
Esempio n. 19
0
 public void SinglePhaseCommit(SinglePhaseEnlistment singlePhaseEnlistment)
 {
 }
Esempio n. 20
0
 void IPromotableSinglePhaseNotification.Rollback(SinglePhaseEnlistment singlePhaseEnlistment)
 {
     simpleTransaction.Rollback();
     singlePhaseEnlistment.Aborted();
     connection.CurrentTransaction = null;
 }
 void IPromotableSinglePhaseNotification.Rollback(SinglePhaseEnlistment singlePhaseEnlistment)
 {
     _transactionManager.RemoveEnlistment(_transactionId);
     TaskExtensionHelper.Schedule(() => RollbackAsync(singlePhaseEnlistment));
 }
Esempio n. 22
0
 void IPromotableSinglePhaseNotification.SinglePhaseCommit(SinglePhaseEnlistment singlePhaseEnlistment)
 {
     simpleTransaction.Commit();
     singlePhaseEnlistment.Committed();
     connection.CurrentTransaction = null;
 }
Esempio n. 23
0
 public void Rollback(SinglePhaseEnlistment singlePhaseEnlistment)
 {
     Trace("NonMSDTCPromoterEnlistment.Aborted");
     this.Aborted = true;
     _completionEvent.Set();
     singlePhaseEnlistment.Done();
 }
 void IPromotableSinglePhaseNotification.SinglePhaseCommit(SinglePhaseEnlistment singlePhaseEnlistment)
 {
     scopeStack.Pop().SinglePhaseCommit(singlePhaseEnlistment);
 }
Esempio n. 25
0
 public void SinglePhaseCommit(SinglePhaseEnlistment singlePhaseEnlistment)
 {
     throw new NotImplementedException();
 }
Esempio n. 26
0
 void IPromotableSinglePhaseNotification.SinglePhaseCommit(SinglePhaseEnlistment singlePhaseEnlistment)
 {
     this.transactionManager.RemoveEnlistment(this.transactionId);
     TaskExtensionHelper.Schedule(() => this.SinglePhaseCommitAsync(singlePhaseEnlistment));
 }
Esempio n. 27
0
 public void Rollback(SinglePhaseEnlistment enlistment)
 {
     resource.NumRollback++;
     resource.Rollback();
 }
Esempio n. 28
0
        public void SinglePhaseCommit(SinglePhaseEnlistment enlistment)
        {
            try
            {
                dtcControlEvent.Reset();

                Tracer.Debug("Single Phase Commit notification received for TX id: " + this.transactionId);

                if (this.transactionId != null)
                {
                    BeforeEnd();

                    // Now notify the broker that a new XA'ish transaction has completed.
                    TransactionInfo info = new TransactionInfo();
                    info.ConnectionId = this.connection.ConnectionId;
                    info.TransactionId = this.transactionId;
                    info.Type = (int) TransactionType.CommitOnePhase;

                    this.connection.CheckConnected();
                    this.connection.SyncRequest(info);

                    Tracer.Debug("Transaction Single Phase Commit Done TX id: " + this.transactionId);

                    // if server responds that nothing needs to be done, then reply done.
                    enlistment.Done();

                    AfterCommit();
                }
            }
            catch(Exception ex)
            {
                Tracer.DebugFormat("Transaction[{0}] Single Phase Commit failed with error: {1}",
                                   this.transactionId, ex.Message);
                AfterRollback();
                enlistment.Done();
                try
                {
                    this.connection.OnException(ex);
                }
                catch (Exception error)
                {
                    Tracer.Error(error.ToString());
                }
            }
            finally
            {
                this.currentEnlistment = null;
                this.transactionId = null;

                this.dtcControlEvent.Set();
            }
        }