ForceRollback() public method

public ForceRollback ( ) : void
return void
 public void Prepare(PreparingEnlistment preparingEnlistment)
 {
   if (_transaction.IsValid(false) == false)
     preparingEnlistment.ForceRollback();
   else
     preparingEnlistment.Prepared();
 }
		/// <summary>
		/// Notifies an enlisted object that a transaction is being prepared for commitment.
		/// </summary>
		/// <param name="preparingEnlistment">A <see cref="T:System.Transactions.PreparingEnlistment"/> object used to send a response to the transaction manager.</param>
		public void Prepare(PreparingEnlistment preparingEnlistment)
		{
			try
			{

				onTxComplete();
				ctx.CreateFile(TransactionRecoveryInformationFileName, stream =>
				{
					var writer = new BinaryWriter(stream);
					writer.Write(session.ResourceManagerId.ToString());
					writer.Write(transaction.LocalIdentifier);
					writer.Write(session.DatabaseName ?? "");
					writer.Write(preparingEnlistment.RecoveryInformation());
				});

				session.PrepareTransaction(transaction.LocalIdentifier); 
			}
			catch (Exception e)
			{
				logger.ErrorException("Could not prepare distributed transaction", e);
			    try
			    {
                    session.Rollback(transaction.LocalIdentifier);
                    DeleteFile();
			    }
			    catch (Exception e2)
			    {
			        logger.ErrorException("Could not roll back transaction after prepare failed", e2);
			    }

				preparingEnlistment.ForceRollback(e);
				return;
			}
			preparingEnlistment.Prepared();
		}
		/// <summary>
		/// Notifies an enlisted object that a transaction is being prepared for commitment.
		/// </summary>
		/// <param name="preparingEnlistment">A <see cref="T:System.Transactions.PreparingEnlistment"/> object used to send a response to the transaction manager.</param>
		public void Prepare(PreparingEnlistment preparingEnlistment)
		{
			onTxComplete();
			try
			{
				using (var machineStoreForApplication = IsolatedStorageFile.GetMachineStoreForDomain())
				{
					var name = TransactionRecoveryInformationFileName;
					using (var file = machineStoreForApplication.CreateFile(name + ".temp"))
					using(var writer = new BinaryWriter(file))
					{
						writer.Write(session.ResourceManagerId.ToString());
						writer.Write(PromotableRavenClientEnlistment.GetLocalOrDistributedTransactionId(transaction).ToString());
						writer.Write(session.DatabaseName ?? "");
						writer.Write(preparingEnlistment.RecoveryInformation());
						file.Flush(true);
					}
					machineStoreForApplication.MoveFile(name + ".temp", name);
			}
			}
			catch (Exception e)
			{
				logger.ErrorException("Could not prepare distributed transaction", e);
				preparingEnlistment.ForceRollback(e);
				return;
			}
			preparingEnlistment.Prepared();
		}
 void IEnlistmentNotification.Prepare(PreparingEnlistment preparingEnlistment)
 {
     bool success = false;
     try
     {
         IAsyncResult result = new PrepareAsyncResult(this, TransactionContext.handleEndPrepare, preparingEnlistment);
         if (result.CompletedSynchronously)
         {
             PrepareAsyncResult.End(result);
             preparingEnlistment.Prepared();
         }
         success = true;
     }
     //we need to swollow the TransactionException as it could because another party aborting it
     catch (TransactionException) 
     {
     }
     finally
     {
         if (!success)
         {
             preparingEnlistment.ForceRollback();
         }
     }
 }
        public virtual void Prepare(PreparingEnlistment preparingEnlistment)
        {
            Trace.WriteIf(Tracing.Is.TraceVerbose, string.Empty);
            if (null == preparingEnlistment)
            {
                return;
            }

            try
            {
                Operation.Info = Convert.ToBase64String(preparingEnlistment.RecoveryInformation());
                if (ConfigureOperation() &&
                    Operation.Do())
                {
                    Trace.WriteIf(Tracing.Is.TraceVerbose, "preparingEnlistment.Prepared()");
                    preparingEnlistment.Prepared();
                    return;
                }

                Trace.WriteIf(Tracing.Is.TraceVerbose, "preparingEnlistment.ForceRollback()");
                preparingEnlistment.ForceRollback();
            }
            catch (Exception exception)
            {
                Trace.TraceError("{0}", exception);
                preparingEnlistment.ForceRollback(exception);
            }
        }
Beispiel #6
0
 public void Prepare(PreparingEnlistment preparingEnlistment)
 {
     DeveelDbException error;
     if (!transaction.IsOpen(out error)) {
         preparingEnlistment.ForceRollback(error);
     } else {
         preparingEnlistment.Prepared();
     }
 }
 public void Prepare(PreparingEnlistment preparingEnlistment)
 {
     try
     {
         transaction.Commit();
         preparingEnlistment.Prepared();
     }
     catch (Exception ex)
     {
         preparingEnlistment.ForceRollback(ex);
     }
 }
 public void Prepare(PreparingEnlistment preparingEnlistment)
 {
     try
       {
     _transaction.IsValid();
       }
       catch(Exception e)
       {
     preparingEnlistment.ForceRollback(e);
     return;
       }
       preparingEnlistment.Prepared();
 }
 public void Prepare(PreparingEnlistment preparingEnlistment)
 {
     if (commit)
     {
         preparingEnlistment.Prepared();
     }
     else
     {
         preparingEnlistment.ForceRollback();
         // Rollback is not called after 'Rollback' vote
         this.WasRollback = true;
         preparingEnlistment.Done();
     }
 }
Beispiel #10
0
		/// <summary>
		/// Notifies an enlisted object that a transaction is being prepared for commitment.
		/// </summary>
		/// <param name="preparingEnlistment">A <see cref="T:System.Transactions.PreparingEnlistment"/> object used to send a response to the transaction manager.</param>
		public void Prepare(PreparingEnlistment preparingEnlistment)
		{
			onTxComplete();
			try
			{
				session.StoreRecoveryInformation(session.ResourceManagerId, PromotableRavenClientEnlistment.GetLocalOrDistributedTransactionId(transaction), 
				                                 preparingEnlistment.RecoveryInformation());
			}
			catch (Exception e)
			{
				logger.ErrorException("Could not prepare distributed transaction", e);
				preparingEnlistment.ForceRollback(e);
				return;
			}
			preparingEnlistment.Prepared();
		}
Beispiel #11
0
        public void Prepare(PreparingEnlistment preparingEnlistment)
        {
            try
            {
                using (var ts = new TransactionScope(_transaction))
                {
                    _unitOfWork.Commit();

                    ts.Complete();
                }

                preparingEnlistment.Prepared();
            }
            catch (Exception ex)
            {
                preparingEnlistment.ForceRollback(ex);
            }
        }
Beispiel #12
0
        public void Prepare(PreparingEnlistment preparingEnlistment)
        {
            Log.Info("Prepare notification received");

            //Perform transactional work
            try
            {

                Log.InfoFormat("Trans: Status={0}, LocalId={1}, DistributedId={2}.",
                                Transaction.Current.TransactionInformation.Status,
                                Transaction.Current.TransactionInformation.LocalIdentifier,
                                Transaction.Current.TransactionInformation.DistributedIdentifier);
                //If work finished correctly, reply prepared
                preparingEnlistment.Prepared();
            }
            catch (Exception ex)
            {
                Log.Error(ex.Message);
                // otherwise, do a ForceRollback
                preparingEnlistment.ForceRollback();
                throw;
            }
        }
Beispiel #13
0
        public void Prepare(PreparingEnlistment preparingEnlistment)
        {
            Log.Info("Prepare notification received");

            //Perform transactional work
            using (var db = Dao.Default.Create())
            {
                using (var dbTransaction = db.Connection.BeginTransaction())
                {
                    using (var cmd = db.Connection.CreateCommand())
                    {
                        try
                        {
                            DbUtil.Execute(
                                "INSERT INTO GlobalSetting (SettingGroup, SettingKey, LastModified, SettingValue, System) VALUES ({0}, {1}, {2}, {3}, {4})",
                                db, cmd,
                                new[] { DbType.String, DbType.String, DbType.DateTime, DbType.String, DbType.Boolean },
                                new object[] { GlobalMutexScope.Group, _key, DateTime.UtcNow, "", true });
                            dbTransaction.Commit();
                            Log.InfoFormat("Trans: Status={0}, LocalId={1}, DistributedId={2}.",
                                           Transaction.Current.TransactionInformation.Status,
                                           Transaction.Current.TransactionInformation.LocalIdentifier,
                                           Transaction.Current.TransactionInformation.DistributedIdentifier);
                            //If work finished correctly, reply prepared
                            preparingEnlistment.Prepared();
                        }
                        catch (Exception ex)
                        {
                            Log.Error(ex.Message);
                            // otherwise, do a ForceRollback
                            preparingEnlistment.ForceRollback();
                            throw;
                        }
                    }
                }
            }
        }
 public void Prepare(PreparingEnlistment preparingEnlistment)
 {
     // Abort if this happens before the channel is closed...
     if (this.channel.State != CommunicationState.Closed)
     {
         channel.Fault();
         Exception e = DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.MsmqSessionChannelsMustBeClosed)));
         preparingEnlistment.ForceRollback(e);
     }
     else
         preparingEnlistment.Prepared();
 }
 public void Prepare(PreparingEnlistment preparingEnlistment)
 {
     if (_unitOfWork.KeepAlive())
     {
         preparingEnlistment.Prepared();
     }
     else
     {
         preparingEnlistment.ForceRollback();
     }
 }
Beispiel #16
0
        public void Prepare ( PreparingEnlistment preparingEnlistment )
        {
            resource.NumPrepare++;
            if ( resource.IgnorePrepare )
                return;

            if ( resource.FailPrepare ) {
                if (resource.FailWithException)
                    preparingEnlistment.ForceRollback ( new NotSupportedException () );
                else
                    preparingEnlistment.ForceRollback ();
            } else {
                preparingEnlistment.Prepared ();
            }
        }
 public void Prepare(PreparingEnlistment preparingEnlistment)
 {
     // Abort if this happens before all messges are consumed
     if (this.channel.State == CommunicationState.Opened && this.channel.InternalPendingItems > 0)
     {
         Exception e = DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.MsmqSessionChannelsMustBeClosed)));
         preparingEnlistment.ForceRollback(e);
         this.channel.Fault();
     }
     else
     {
         preparingEnlistment.Done();
     }
 }
 /// <summary>
 /// Notifies an enlisted object that a transaction is being prepared for
 /// commitment.
 /// </summary>
 /// <param name="preparingEnlistment">
 /// A <see cref="T:System.Transactions.PreparingEnlistment"></see> object
 /// used to send a response to the transaction manager.</param>
 void IEnlistmentNotification.Prepare(PreparingEnlistment preparingEnlistment)
 {
     if (m_dbTransaction.m_valid)
     {
         m_dbTransaction.Connection.Session.PrepareCommit();
         preparingEnlistment.Prepared();
     }
     else
     {
         preparingEnlistment.ForceRollback();
     }
 }
Beispiel #19
0
        public virtual void Prepare(PreparingEnlistment preparingEnlistment)
        {
            try
            {
                this.dataAccessObjectDataContext?.Commit(this, false);

                preparingEnlistment.Prepared();
            }
            catch (TransactionAbortedException)
            {
                throw;
            }
            catch (Exception e)
            {
                foreach (var persistenceTransactionContext in this.persistenceTransactionContextsBySqlDatabaseContexts.Values)
                {
                    persistenceTransactionContext.sqlDatabaseCommandsContext.Rollback();
                }

                preparingEnlistment.ForceRollback(e);

                this.Dispose();
            }
            finally
            {
                this.Dispose();
            }
        }
		public virtual void Prepare(PreparingEnlistment preparingEnlistment)
		{
			if (this.disposed)
			{
				return;
			}

			var dispose = true;

			try
			{
				if (this.dataAccessObjectDataContext != null)
				{
					this.commandsContext = this.GetSqlTransactionalCommandsContext();
					this.dataAccessObjectDataContext.Commit(this.commandsContext, false);

					if (this.commandsContext.SqlDatabaseContext.SupportsPreparedTransactions)
					{
						this.commandsContext.Prepare();
					}
				}

				preparingEnlistment.Prepared();

				dispose = false;
			}
			catch (TransactionAbortedException)
			{
				throw;
			}
			catch (Exception e)
			{
				ActionUtils.IgnoreExceptions(() => this.commandsContext?.Rollback());

				preparingEnlistment.ForceRollback(e);
			}
			finally
			{
				if (dispose)
				{
					this.Dispose();
				}
			}
		}
Beispiel #21
0
        public void Prepare(PreparingEnlistment preparingEnlistment)
        {
            lock (this.syncObject)
            {
                this.netTxState = TxState.Pending;

                try
                {
                    Tracer.Debug("Prepare notification received for TX id: " + this.transactionId);

                    BeforeEnd();

                    // Before sending the request to the broker, log the recovery bits, if
                    // this fails we can't prepare and the TX should be rolled back.
                    RecoveryLogger.LogRecoveryInfo(this.transactionId as XATransactionId,
                                                   preparingEnlistment.RecoveryInformation());

                    // Inform the broker that work on the XA'sh TX Branch is complete.
                    TransactionInfo info = new TransactionInfo();
                    info.ConnectionId = this.connection.ConnectionId;
                    info.TransactionId = this.transactionId;
                    info.Type = (int) TransactionType.End;

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

                    // Prepare the Transaction for commit.
                    info.Type = (int) TransactionType.Prepare;
                    IntegerResponse response = (IntegerResponse) this.connection.SyncRequest(info);
                    if (response.Result == XA_READONLY)
                    {
                        Tracer.Debug("Transaction Prepare done and doesn't need a commit, TX id: " + this.transactionId);

                        this.transactionId = null;
                        this.currentEnlistment = null;

                        // Read Only means there's nothing to recover because there was no
                        // change on the broker.
                        RecoveryLogger.LogRecovered(this.transactionId as XATransactionId);

                        // if server responds that nothing needs to be done, then reply prepared
                        // but clear the current state data so we appear done to the commit method.
                        preparingEnlistment.Prepared();

                        // Done so commit won't be called.
                        AfterCommit();

                        // A Read-Only TX is considered closed at this point, DTC won't call us again.
                        this.dtcControlEvent.Set();
                    }
                    else
                    {
                        Tracer.Debug("Transaction Prepare succeeded TX id: " + this.transactionId);

                        // If work finished correctly, reply prepared
                        preparingEnlistment.Prepared();
                    }
                }
                catch (Exception ex)
                {
                    Tracer.DebugFormat("Transaction[{0}] Prepare failed with error: {1}",
                                       this.transactionId, ex.Message);

                    AfterRollback();
                    preparingEnlistment.ForceRollback();
                    try
                    {
                        this.connection.OnException(ex);
                    }
                    catch (Exception error)
                    {
                        Tracer.Error(error.ToString());
                    }

                    this.currentEnlistment = null;
                    this.transactionId = null;
                    this.netTxState = TxState.None;
                    this.dtcControlEvent.Set();
                }
            }
        }
			void IEnlistmentNotification.Prepare(PreparingEnlistment preparingEnlistment)
			{
				using (new SessionIdLoggingContext(session.SessionId))
				{
					try
					{
						//using (var tx = new TransactionScope(AmbientTransation))
						{
							session.BeforeTransactionCompletion(null);
							if (session.FlushMode != FlushMode.Never && session.ConnectionManager.IsConnected)
							{
								using (session.ConnectionManager.FlushingFromDtcTransaction)
								{
									logger.Debug(string.Format("[session-id={0}] Flushing from Dtc Transaction", session.SessionId));
									session.Flush();
								}
							}
							//causes test failures because ambient transacaiton no longer has transaction information
							//logger.Debug("prepared for DTC transaction " + AmbientTransation.TransactionInformation.LocalIdentifier);

							//tx.Complete();
						}
						preparingEnlistment.Prepared();
					}
					catch (Exception exception)
					{
						logger.Error("DTC transaction prepre phase failed", exception);
						preparingEnlistment.ForceRollback(exception);
					}
				}
			}
Beispiel #23
0
			public void Prepare(PreparingEnlistment preparingEnlistment)
			{
				Assert.AreNotEqual(thread, Thread.CurrentThread.ManagedThreadId);
				if (shouldRollBack)
				{
					log.Debug(">>>>Force Rollback<<<<<");
					preparingEnlistment.ForceRollback();
				}
				else
				{
					preparingEnlistment.Prepared();
				}
			}
 public void Prepare(PreparingEnlistment preparingEnlistment)
 {
     try
     {
         log.Debug("Prepare {0}, Messages {1}. Sending the message batch.", TransactionId, Messages.Count);
         if (_onprepare != null) _onprepare(this);
         preparingEnlistment.Prepared();
     }
     catch (Exception ex)
     {
         log.Error("Error preparing transaction {0} ({1} messages): {2}", TransactionId, Messages.Count, ex);
         preparingEnlistment.ForceRollback(ex);
         TransactionOpen = false;
         if (_onrollback != null)
         {
             try
             {
                 _onrollback(this);
             }
             catch (Exception e2)
             {
                 log.Error("Error performing rollback after a failed prepare: {0}", e2);
             }
         }
     }
 }
Beispiel #25
0
		public virtual void Prepare(PreparingEnlistment preparingEnlistment)
		{
			if (this.disposed)
			{
				return;
			}

			var dispose = true;

			try
			{
				this.dataAccessObjectDataContext?.Commit(this, false);

				foreach (var commandsContext in this.commandsContextsBySqlDatabaseContexts.Values)
				{
					if (commandsContext.SqlDatabaseContext.SupportsPreparedTransactions)
					{
						commandsContext.Prepare();
					}
				}

				preparingEnlistment.Prepared();

				dispose = false;
			}
			catch (TransactionAbortedException)
			{
				throw;
			}
			catch (Exception e)
			{
				commandsContextsBySqlDatabaseContexts.Values.ForEach(c => ActionUtils.IgnoreExceptions(c.Rollback));

				preparingEnlistment.ForceRollback(e);
			}
			finally
			{
				if (dispose)
				{
					this.Dispose();
				}
			}
		}
			void IEnlistmentNotification.Prepare(PreparingEnlistment preparingEnlistment)
			{
				using (new SessionIdLoggingContext(sessionImplementor.SessionId))
				{
					try
					{
						using (var tx = new TransactionScope(AmbientTransation))
						{
							sessionImplementor.BeforeTransactionCompletion(null);
							if (sessionImplementor.FlushMode != FlushMode.Never && sessionImplementor.ConnectionManager.IsConnected)
							{
								using (sessionImplementor.ConnectionManager.FlushingFromDtcTransaction)
								{
									logger.Debug(string.Format("[session-id={0}] Flushing from Dtc Transaction", sessionImplementor.SessionId));
									sessionImplementor.Flush();
								}
							}
							logger.Debug("prepared for DTC transaction");

							tx.Complete();
						}
						preparingEnlistment.Prepared();
					}
					catch (Exception exception)
					{
						logger.Error("DTC transaction prepre phase failed", exception);
						preparingEnlistment.ForceRollback(exception);
					}
				}
			}
            public void Prepare(PreparingEnlistment preparingEnlistment)
            {
                // Abort if this happens before all messges are consumed
                // Note that we are not placing any restriction on the channel state
                if (this.channel.TotalPendingItems > 0 || this.channel.sessiongramDoomed)
                {
                    Exception e = DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.MsmqSessionChannelHasPendingItems)));
                    this.sessiongramReceiveContext.Abandon(TimeSpan.MaxValue);
                    preparingEnlistment.ForceRollback(e);
                    this.channel.Fault();
                }
                else
                {
                    Transaction savedTransaction = Transaction.Current;
                    // complete the sessiongram message within this transaction
                    try
                    {
                        Transaction.Current = this.transaction;

                        try
                        {
                            this.sessiongramReceiveContext.Complete(TimeSpan.MaxValue);
                            preparingEnlistment.Done();
                        }
                        catch (MsmqException msmqex)
                        {
                            preparingEnlistment.ForceRollback(msmqex);
                            this.channel.Fault();
                        }
                    }
                    finally
                    {
                        Transaction.Current = savedTransaction;
                    }
                }
            }
			public void Prepare(PreparingEnlistment preparingEnlistment)
			{
				if (_ThrowIt) preparingEnlistment.ForceRollback(new ApplicationException("this one went astray"));
				else preparingEnlistment.Prepared();
			}
		public void Prepare(PreparingEnlistment preparingEnlistment)
		{
			Console.WriteLine("PREPARE - VolatileResource");
			if (throwIt && ++errorCount < 2) throw new ApplicationException("simulating resource failure");

			preparingEnlistment.ForceRollback();
		}
 void IEnlistmentNotification.Prepare(PreparingEnlistment preparingEnlistment)
 {
     bool flag = false;
     try
     {
         IAsyncResult result = new PrepareAsyncResult(this, handleEndPrepare, preparingEnlistment);
         if (result.CompletedSynchronously)
         {
             PrepareAsyncResult.End(result);
             preparingEnlistment.Prepared();
         }
         flag = true;
     }
     catch (TransactionException)
     {
     }
     finally
     {
         if (!flag)
         {
             preparingEnlistment.ForceRollback();
         }
     }
 }