Example #1
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();
     session.StoreRecoveryInformation(session.ResourceManagerId, PromotableRavenClientEnlistment.GetLocalOrDistributedTransactionId(transaction),
                                      preparingEnlistment.RecoveryInformation());
     preparingEnlistment.Prepared();
 }
Example #2
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
     {
         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();
 }
Example #3
0
        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);
            }
        }
Example #4
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)
        {
            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();
        }
        public void Prepare(PreparingEnlistment preparingEnlistment)
        {
            uint method = 0x4fe;

            this.TrEntry(method, new object[] { preparingEnlistment });
            Exception e    = null;
            bool      flag = false;

            try
            {
                if (base.asyncFailureNotify != null)
                {
                    base.TrText(method, "Rollback the tx as we have an async failure");
                    preparingEnlistment.ForceRollback(base.asyncFailureNotify);
                    flag = true;
                }
                else
                {
                    base.TrText(method, "Hconn =" + base.hconn.Value + " has been asked to Prepare by the Transaction Co-ordinator");
                    base.MQRMIXAEnd();
                    if (base.MQRMIXAPrepare(preparingEnlistment.RecoveryInformation()) == 3)
                    {
                        flag = true;
                        preparingEnlistment.Done();
                    }
                    else
                    {
                        base.TrText(method, "WMQ .NET is now prepared..");
                        preparingEnlistment.Prepared();
                    }
                }
            }
            catch (MQException exception2)
            {
                base.TrException(method, exception2, 1);
                e = exception2;
                preparingEnlistment.ForceRollback(e);
                flag = true;
            }
            catch (Exception exception3)
            {
                base.TrException(method, exception3, 2);
                e = exception3;
                preparingEnlistment.ForceRollback(e);
                flag = true;
            }
            finally
            {
                if (flag)
                {
                    this.rmiTxComplete = true;
                    if (base.hconn != null)
                    {
                        base.hconn.PulseCommitWait();
                    }
                }
                base.TrExit(method);
            }
        }
            public void Prepare(PreparingEnlistment preparingEnlistment)
            {
                byte[] recoveryInformation = preparingEnlistment.RecoveryInformation();
                var    ravenJObject        = new RavenJObject
                {
                    { Constants.NotForReplication, true }
                };

                database.PutStatic("transactions/recoveryInformation/" + txId, null, new MemoryStream(recoveryInformation), ravenJObject);
                preparingEnlistment.Prepared();
            }
		public void Prepare(PreparingEnlistment preparingEnlistment)
		{
			_assertNotDisposed();
			_logger.Debug("Preparing enlistment with id: {0}", Id);
			var information = preparingEnlistment.RecoveryInformation();
			_queueStorage.Global(actions =>
			{
				actions.RegisterRecoveryInformation(Id, information);
			});
			preparingEnlistment.Prepared();
			_logger.Debug("Prepared enlistment with id: {0}", Id);
		}
Example #8
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();
 }
        public async Task PrepareAsync(PreparingEnlistment preparingEnlistment)
        {
            using (await this.syncObject.LockAsync().Await())
            {
                this.netTxState = TxState.Pending;

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

                    await BeforeEndAsync().Await();

                    // 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;

                    await this.connection.CheckConnectedAsync().Await();

                    await this.connection.SyncRequestAsync((TransactionInfo)info.Clone()).Await();

                    // Prepare the Transaction for commit.
                    info.Type = (int)TransactionType.Prepare;
                    IntegerResponse response = (IntegerResponse)await this.connection.SyncRequestAsync(info).Await();

                    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 done.
                        // otherwise the DTC will call Commit or Rollback but another transaction
                        // can already be in progress and this one would be commited or rolled back
                        // immediately.
                        preparingEnlistment.Done();

                        // 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.OnAsyncException(ex);
                    }
                    catch (Exception error)
                    {
                        Tracer.Error(error.ToString());
                    }

                    this.currentEnlistment = null;
                    this.TransactionId     = null;
                    this.netTxState        = TxState.None;
                    this.dtcControlEvent.Set();
                }
            }
        }
Example #10
0
 public void Prepare(PreparingEnlistment preparingEnlistment)
 {
     database.PutStatic("transactions/recoveryInformation/" + txId, null, preparingEnlistment.RecoveryInformation(), new RavenJObject());
     preparingEnlistment.Prepared();
 }
 public void Prepare(PreparingEnlistment preparingEnlistment)
 {
     session.StoreRecoveryInformation(PromotableRavenClientEnlistment.GetLocalOrDistributedTransactionId(transaction), preparingEnlistment.RecoveryInformation());
     preparingEnlistment.Prepared();
 }
 public byte[] GetRecoveryInformation(PreparingEnlistment preparingEnlistment)
 {
     return(preparingEnlistment.RecoveryInformation());
 }
 public void Prepare(PreparingEnlistment preparingEnlistment)
 {
     byte[] recoveryInformation = preparingEnlistment.RecoveryInformation();
     database.PutStatic("transactions/recoveryInformation/" + txId, null, new MemoryStream(recoveryInformation), new RavenJObject());
     preparingEnlistment.Prepared();
 }
        public void Prepare(PreparingEnlistment preparingEnlistment)
        {
            try
            {
                dtcControlEvent.Reset();

                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();
                }
                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;
            }
            finally
            {
                this.dtcControlEvent.Set();
            }
        }
Example #15
0
        public void Prepare(PreparingEnlistment preparingEnlistment)
        {
            try
            {
                dtcControlEvent.Reset();

                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();
                }
                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;
            }
            finally
            {
                this.dtcControlEvent.Set();
            }
        }