protected void VerifyAndTraceEnlistmentOptions()
 {
     Microsoft.Transactions.Bridge.EnlistmentOptions enlistmentOptions = this.enlistment.EnlistmentOptions;
     if (enlistmentOptions == null)
     {
         DiagnosticUtility.FailFast("Need EnlistmentOptions for context");
     }
     if (enlistmentOptions.IsoLevel == IsolationLevel.Unspecified)
     {
         DiagnosticUtility.FailFast("Need IsolationLevel for context");
     }
     if (this.enlistment.LocalTransactionId == Guid.Empty)
     {
         DiagnosticUtility.FailFast("Need LocalTransactionId for context");
     }
     if (string.IsNullOrEmpty(this.enlistment.RemoteTransactionId))
     {
         DiagnosticUtility.FailFast("Need RemoteTransactionId for context");
     }
     if (DebugTrace.Info)
     {
         DebugTrace.TxTrace(TraceLevel.Info, this.enlistmentId, "Local transactionId is {0}", this.enlistment.LocalTransactionId);
         DebugTrace.TxTrace(TraceLevel.Info, this.enlistmentId, "Remote transactionId is {0}", this.enlistment.RemoteTransactionId);
         DebugTrace.TxTrace(TraceLevel.Info, this.enlistmentId, "Transaction timeout is {0} seconds", enlistmentOptions.Expires.TotalSeconds);
         DebugTrace.TxTrace(TraceLevel.Info, this.enlistmentId, "Transaction isolation level is {0}", enlistmentOptions.IsoLevel);
     }
 }
Example #2
0
 public void Rejoined(ParticipantEnlistment participant)
 {
     if (DebugTrace.Info)
     {
         DebugTrace.TxTrace(TraceLevel.Info, participant.EnlistmentId, "Replying Success to transaction manager's Rejoin");
     }
     participant.DeliverCallback(Status.Success);
 }
Example #3
0
 public void PrePrepare(VolatileCoordinatorEnlistment volatileCoordinator)
 {
     if (DebugTrace.Info)
     {
         DebugTrace.TxTrace(TraceLevel.Info, volatileCoordinator.EnlistmentId, "Sending PrePrepare to transaction manager");
     }
     this.coordination.PrePrepare(volatileCoordinator.Enlistment, this.prePrepareResponseCallback, volatileCoordinator);
 }
Example #4
0
 public void ForgetResponse(TransactionEnlistment enlistment, Status status)
 {
     if (DebugTrace.Info)
     {
         DebugTrace.TxTrace(TraceLevel.Info, enlistment.EnlistmentId, "Replying {0} to transaction manager's Forget", status);
     }
     enlistment.DeliverCallback(status);
 }
Example #5
0
 public void Replayed(CoordinatorEnlistment coordinator)
 {
     if (DebugTrace.Info)
     {
         DebugTrace.TxTrace(TraceLevel.Info, coordinator.EnlistmentId, "Replying Success to transaction manager's Replay");
     }
     coordinator.DeliverCallback(Status.Success);
 }
Example #6
0
 public void Rollback(CompletionEnlistment completion)
 {
     if (DebugTrace.Info)
     {
         DebugTrace.TxTrace(TraceLevel.Info, completion.EnlistmentId, "Sending completion Rollback to transaction manager");
     }
     this.coordination.Rollback(completion.Enlistment, this.completionRollbackResponseCallback, completion);
 }
Example #7
0
 public void Rollback(TransactionEnlistment enlistment)
 {
     if (DebugTrace.Info)
     {
         DebugTrace.TxTrace(TraceLevel.Info, enlistment.EnlistmentId, "Sending Rollback to transaction manager");
     }
     this.coordination.Rollback(enlistment.Enlistment, this.rollbackResponseCallback, enlistment);
 }
Example #8
0
 public void Aborted(CoordinatorEnlistment coordinator)
 {
     if (DebugTrace.Info)
     {
         DebugTrace.TxTrace(TraceLevel.Info, coordinator.EnlistmentId, "Replying Aborted to transaction manager");
     }
     coordinator.DeliverCallback(Status.Aborted);
 }
Example #9
0
 public void Commit(CoordinatorEnlistment coordinator)
 {
     if (DebugTrace.Info)
     {
         DebugTrace.TxTrace(TraceLevel.Info, coordinator.EnlistmentId, "Sending Commit to transaction manager");
     }
     this.coordination.Commit(coordinator.Enlistment, this.commitResponseCallback, coordinator);
 }
Example #10
0
 public void Committed(ParticipantEnlistment participant)
 {
     if (DebugTrace.Info)
     {
         DebugTrace.TxTrace(TraceLevel.Info, participant.EnlistmentId, "Replying Committed to transaction manager");
     }
     participant.DeliverCallback(Status.Committed);
 }
Example #11
0
 public void EnlistPrePrepareResponse(CoordinatorEnlistment coordinator, Status status)
 {
     if (DebugTrace.Info)
     {
         DebugTrace.TxTrace(TraceLevel.Info, coordinator.EnlistmentId, "Replying {0} to transaction manager's EnlistPrePrepare", status);
     }
     coordinator.DeliverCallback(status);
 }
Example #12
0
 public void Register(ParticipantEnlistment participant, MsgRegisterEvent e)
 {
     if (DebugTrace.Info)
     {
         DebugTrace.TxTrace(TraceLevel.Info, participant.EnlistmentId, "Sending Register for {0} to transaction manager", participant.Enlistment.NotificationMask);
     }
     this.propagation.CreateSubordinateEnlistment(participant.Enlistment, this.registerResponseCallback, e);
 }
Example #13
0
 public void ReadOnly(ParticipantEnlistment participant)
 {
     if (DebugTrace.Info)
     {
         DebugTrace.TxTrace(TraceLevel.Info, participant.EnlistmentId, "Replying Readonly to transaction manager");
     }
     participant.DeliverCallback(Status.Readonly);
 }
Example #14
0
 private void Execute()
 {
     if (DebugTrace.Verbose)
     {
         DebugTrace.TxTrace(TraceLevel.Verbose, this.stateMachine.Enlistment.EnlistmentId, "Now processing events on {0}", this.stateMachine.GetType().Name);
     }
     while (true)
     {
         SynchronizationEvent e = this.queue.Peek();
         if (e == null)
         {
             DiagnosticUtility.FailFast("Peek returned null synchronization event");
         }
         try
         {
             if (DebugTrace.Verbose)
             {
                 DebugTrace.TxTrace(TraceLevel.Verbose, this.stateMachine.Enlistment.EnlistmentId, "Dispatching {0} event to {1} in {2}", e.GetType().Name, this.stateMachine.GetType().Name, this.stateMachine.State.GetType().Name);
             }
             using (Activity.CreateActivity(this.stateMachine.Enlistment.EnlistmentId))
             {
                 this.stateMachine.Dispatch(e);
             }
             if (DebugTrace.Verbose)
             {
                 DebugTrace.TxTrace(TraceLevel.Verbose, this.stateMachine.Enlistment.EnlistmentId, "Dispatched {0} event to {1} in {2}", e.GetType().Name, this.stateMachine.GetType().Name, this.stateMachine.State.GetType().Name);
             }
         }
         catch (Exception exception)
         {
             DebugTrace.TxTrace(TraceLevel.Error, this.stateMachine.Enlistment.EnlistmentId, "REALLY BAD ERROR: Unhandled exception caught by synchronization manager: {0}", exception);
             UnhandledStateMachineExceptionRecord.TraceAndLog(this.stateMachine.Enlistment.EnlistmentId, (this.stateMachine.Enlistment.Enlistment != null) ? this.stateMachine.Enlistment.Enlistment.RemoteTransactionId : string.Empty, this.stateMachine.ToString(), this.stateMachine.State.ToString(), this.stateMachine.History, exception);
             DiagnosticUtility.FailFast(string.Format(CultureInfo.InvariantCulture, "Failfasting due to unhandled exception: {0}\r\n\r\n{1}", new object[] { exception.Message, exception }));
         }
         lock (this.mutex)
         {
             this.queue.Dequeue();
             if (this.queue.Count == 0)
             {
                 break;
             }
         }
         if (DebugTrace.Verbose)
         {
             DebugTrace.TxTrace(TraceLevel.Verbose, this.stateMachine.Enlistment.EnlistmentId, "Continuing to process events on {0}", this.stateMachine.GetType().Name);
         }
     }
     if (DebugTrace.Verbose)
     {
         DebugTrace.TxTrace(TraceLevel.Verbose, this.stateMachine.Enlistment.EnlistmentId, "Stopped processing events on {0}", this.stateMachine.GetType().Name);
     }
 }
        public void SendRollback(ParticipantEnlistment participant)
        {
            if (DebugTrace.Info)
            {
                DebugTrace.TxTrace(TraceLevel.Info, participant.EnlistmentId, "Sending Rollback to {0} participant at {1}", participant.ControlProtocol, Ports.TryGetAddress(participant.ParticipantProxy));
            }
            IAsyncResult ar = participant.ParticipantProxy.BeginSendRollback(this.sendComplete, participant);

            if (ar.CompletedSynchronously)
            {
                this.OnSendComplete(ar, participant);
            }
        }
Example #16
0
 public void EnqueueRecoveryReplay(TmReplayEvent e)
 {
     if (!this.recovering)
     {
         Microsoft.Transactions.Bridge.DiagnosticUtility.FailFast("Cannot enqueue recovery event outside of recovery");
     }
     if (DebugTrace.Info)
     {
         CoordinatorEnlistment coordinator = e.Coordinator;
         DebugTrace.TxTrace(TraceLevel.Info, coordinator.EnlistmentId, "Enqueuing recovery replay for coordinator at {0}", Ports.TryGetAddress(coordinator.CoordinatorProxy));
     }
     this.recoveryQueue.Enqueue(e);
 }
        public void SendCommitted(CompletionEnlistment completion)
        {
            if (DebugTrace.Info)
            {
                DebugTrace.TxTrace(TraceLevel.Info, completion.EnlistmentId, "Sending Committed to completion participant at {0}", Ports.TryGetAddress(completion.ParticipantProxy));
            }
            IAsyncResult ar = completion.ParticipantProxy.BeginSendCommitted(this.sendComplete, completion);

            if (ar.CompletedSynchronously)
            {
                this.OnSendComplete(ar, completion, completion.ParticipantProxy);
            }
        }
Example #18
0
        public void SendVolatileReadOnly(VolatileCoordinatorEnlistment coordinator)
        {
            if (DebugTrace.Info)
            {
                DebugTrace.TxTrace(TraceLevel.Info, coordinator.EnlistmentId, "Sending ReadOnly to volatile coordinator at {0}", Ports.TryGetAddress(coordinator.CoordinatorProxy));
            }
            IAsyncResult ar = coordinator.CoordinatorProxy.BeginSendReadOnly(this.volatileSendComplete, coordinator);

            if (ar.CompletedSynchronously)
            {
                this.OnVolatileSendComplete(ar, coordinator);
            }
        }
        public void SendRegisterResponse(Microsoft.Transactions.Wsat.Protocol.TransactionEnlistment enlistment, Microsoft.Transactions.Wsat.Messaging.RequestAsyncResult result, ControlProtocol protocol, EndpointAddress coordinatorService)
        {
            RegisterResponse response = new RegisterResponse(this.state.ProtocolVersion)
            {
                CoordinatorProtocolService = coordinatorService
            };

            if (DebugTrace.Info)
            {
                DebugTrace.TxTrace(TraceLevel.Info, enlistment.EnlistmentId, "Sending RegisterResponse for {0}", protocol);
            }
            RegistrationProxy.SendRegisterResponse(result, ref response);
        }
Example #20
0
        public void SendRecoverMessage(CoordinatorEnlistment coordinator)
        {
            if (DebugTrace.Info)
            {
                DebugTrace.TxTrace(TraceLevel.Info, coordinator.EnlistmentId, "Sending Replay to durable coordinator at {0}", Ports.TryGetAddress(coordinator.CoordinatorProxy));
            }
            IAsyncResult ar = coordinator.CoordinatorProxy.BeginSendRecoverMessage(this.durableSendComplete, coordinator);

            if (ar.CompletedSynchronously)
            {
                this.OnDurableSendComplete(ar, coordinator);
            }
        }
Example #21
0
 public void CancelTimer()
 {
     lock (this.timerLock)
     {
         if (this.timer.Active)
         {
             if (DebugTrace.Verbose)
             {
                 DebugTrace.TxTrace(TraceLevel.Verbose, this.enlistment.EnlistmentId, "Removing active timer");
             }
             this.state.TimerManager.Remove(this);
             this.timer.Instance = null;
             this.timer.Active   = false;
         }
     }
 }
Example #22
0
 public bool TryEnqueueRecoveryOutcome(ParticipantCallbackEvent e)
 {
     lock (this.recoveryLock)
     {
         if (!this.recovering)
         {
             return(false);
         }
         if (DebugTrace.Info)
         {
             ParticipantEnlistment participant = e.Participant;
             DebugTrace.TxTrace(TraceLevel.Info, participant.EnlistmentId, "Queuing recovery outcome {0} for participant at {1}", e, Ports.TryGetAddress(participant.ParticipantProxy));
         }
         this.recoveryQueue.Enqueue(e);
     }
     return(true);
 }
Example #23
0
        private void SendRegister(CoordinatorEnlistment coordinator, ControlProtocol protocol, EndpointAddress protocolService, AsyncCallback callback, object callbackState)
        {
            Register register = new Register(this.state.ProtocolVersion)
            {
                Protocol = protocol,
                Loopback = this.state.ProcessId,
                ParticipantProtocolService = protocolService,
                SupportingToken            = coordinator.SuperiorIssuedToken
            };

            if (DebugTrace.Info)
            {
                DebugTrace.TxTrace(TraceLevel.Info, coordinator.EnlistmentId, "Sending Register for {0} to {1}", protocol, Ports.TryGetAddress(coordinator.RegistrationProxy));
            }
            IAsyncResult ar = coordinator.RegistrationProxy.BeginSendRegister(ref register, callback, callbackState);

            if (ar.CompletedSynchronously)
            {
                this.OnSendRegisterComplete(coordinator, protocol, ar);
            }
        }
Example #24
0
 public void ChangeState(Microsoft.Transactions.Wsat.StateMachines.State newState)
 {
     if (this.history != null)
     {
         this.history.AddState(newState.ToString());
     }
     if (this.current != null)
     {
         if (DebugTrace.Info)
         {
             DebugTrace.TxTrace(TraceLevel.Info, this.enlistment.EnlistmentId, "Leaving [{0}]", this.current);
         }
         this.current.Leave(this);
     }
     if (DebugTrace.Info)
     {
         DebugTrace.TxTrace(TraceLevel.Info, this.enlistment.EnlistmentId, "Entering [{0}]", newState);
     }
     this.current = newState;
     this.current.Enter(this);
 }
Example #25
0
 public void TraceInvalidEvent(SynchronizationEvent e, bool fatal)
 {
     if (DebugTrace.Error)
     {
         if (this.history != null)
         {
             DebugTrace.TxTrace(TraceLevel.Error, e.Enlistment.EnlistmentId, "The {0} was not expected by the {1} state. The state machine history history follows:\n\n{2}", e, this.current, this.history.ToString());
         }
         else
         {
             DebugTrace.TxTrace(TraceLevel.Error, e.Enlistment.EnlistmentId, "The {0} was not expected by the {1} state", e, this.current);
         }
     }
     if (fatal)
     {
         FatalUnexpectedStateMachineEventRecord.TraceAndLog(this.enlistment.EnlistmentId, this.enlistment.Enlistment.RemoteTransactionId, this.ToString(), this.current.ToString(), this.history, e.ToString(), null);
     }
     else
     {
         NonFatalUnexpectedStateMachineEventRecord.TraceAndLog(this.enlistment.EnlistmentId, this.enlistment.Enlistment.RemoteTransactionId, this.ToString(), this.current.ToString(), this.history, e.ToString(), null);
     }
 }
Example #26
0
        private bool CheckMessage(Message message, bool fault, out CoordinatorEnlistment durableCoordinator, out VolatileCoordinatorEnlistment volatileCoordinator)
        {
            Guid guid;
            TwoPhaseCommitCoordinatorProxy coordinatorProxy;

            durableCoordinator  = null;
            volatileCoordinator = null;
            if (!Ports.TryGetEnlistment(message, out guid))
            {
                DebugTrace.Trace(TraceLevel.Warning, "Could not read enlistment header from message");
                if (fault)
                {
                    this.SendFault(message, this.state.Faults.InvalidParameters);
                }
                return(false);
            }
            Microsoft.Transactions.Wsat.Protocol.TransactionEnlistment enlistment = this.state.Lookup.FindEnlistment(guid);
            if (enlistment == null)
            {
                DebugTrace.Trace(TraceLevel.Warning, "Could not find enlistment {0}", guid);
                return(true);
            }
            durableCoordinator = enlistment as CoordinatorEnlistment;
            if (durableCoordinator == null)
            {
                volatileCoordinator = enlistment as VolatileCoordinatorEnlistment;
                if (volatileCoordinator == null)
                {
                    DebugTrace.Trace(TraceLevel.Warning, "2PC message received for non-2PC enlistment {0}", guid);
                    if (fault)
                    {
                        this.SendFault(message, this.state.Faults.InvalidParameters);
                    }
                    return(false);
                }
                coordinatorProxy = volatileCoordinator.CoordinatorProxy;
            }
            else
            {
                coordinatorProxy = durableCoordinator.CoordinatorProxy;
            }
            if (coordinatorProxy == null)
            {
                if ((durableCoordinator != null) && object.ReferenceEquals(durableCoordinator.StateMachine.State, this.state.States.CoordinatorFailedRecovery))
                {
                    DebugTrace.TxTrace(TraceLevel.Warning, enlistment.EnlistmentId, "Coordinator enlistment was not correctly recovered");
                    if (fault)
                    {
                        this.SendFault(message, this.state.Faults.InvalidPolicy);
                    }
                    return(false);
                }
                if (DebugTrace.Warning)
                {
                    DebugTrace.TxTrace(TraceLevel.Warning, enlistment.EnlistmentId, "Received premature message with action {0}", message.Headers.Action);
                }
                if (fault)
                {
                    this.SendFault(message, this.state.Faults.InvalidState);
                }
                return(false);
            }
            if (this.state.Service.Security.CheckIdentity(coordinatorProxy, message))
            {
                return(true);
            }
            if (EnlistmentIdentityCheckFailedRecord.ShouldTrace)
            {
                EnlistmentIdentityCheckFailedRecord.Trace(enlistment.EnlistmentId);
            }
            return(false);
        }
Example #27
0
 private void TraceTmResponse(SynchronizationEvent e, Status status)
 {
     DebugTrace.TxTrace(TraceLevel.Info, e.Enlistment.EnlistmentId, "{0} {1}", e, status);
 }
Example #28
0
 public void OnEvent(MsgCreateTransactionEvent e)
 {
     DebugTrace.TxTrace(TraceLevel.Info, e.Enlistment.EnlistmentId, "{0}", e);
 }
Example #29
0
 public void OnEvent(MsgEnlistTransactionEvent e)
 {
     DebugTrace.TxTrace(TraceLevel.Info, e.Enlistment.EnlistmentId, "{0}{1}", e, (e.Body.IssuedToken != null) ? " with issued token" : string.Empty);
 }
        private ParticipantEnlistment CheckMessage(Message message, bool fault, bool preparedOrReplay)
        {
            Guid            guid;
            ControlProtocol protocol;

            if (!Ports.TryGetEnlistment(message, out guid, out protocol))
            {
                DebugTrace.Trace(TraceLevel.Warning, "Could not read enlistment header from message");
                if (fault)
                {
                    this.SendFault(message, this.state.Faults.InvalidParameters);
                }
                return(null);
            }
            Microsoft.Transactions.Wsat.Protocol.TransactionEnlistment enlistment = this.state.Lookup.FindEnlistment(guid);
            if (enlistment == null)
            {
                DebugTrace.Trace(TraceLevel.Verbose, "Enlistment {0} could not be found", guid);
                if (preparedOrReplay)
                {
                    if (protocol == ControlProtocol.Volatile2PC)
                    {
                        if (DebugTrace.Warning)
                        {
                            DebugTrace.Trace(TraceLevel.Warning, "Received Prepared or Replay from unrecognized volatile participant at {0}", Ports.TryGetFromAddress(message));
                        }
                        if (VolatileParticipantInDoubtRecord.ShouldTrace)
                        {
                            VolatileParticipantInDoubtRecord.Trace(guid, Library.GetReplyToHeader(message.Headers), this.state.ProtocolVersion);
                        }
                        this.SendFault(message, this.state.Faults.UnknownTransaction);
                    }
                    else if (protocol == ControlProtocol.Durable2PC)
                    {
                        this.SendRollback(message);
                    }
                    else
                    {
                        this.SendFault(message, this.state.Faults.InvalidParameters);
                    }
                }
                else if (DebugTrace.Info)
                {
                    DebugTrace.Trace(TraceLevel.Info, "Ignoring message from unrecognized participant at {0}", Ports.TryGetFromAddress(message));
                }
                return(null);
            }
            ParticipantEnlistment enlistment2 = enlistment as ParticipantEnlistment;

            if ((enlistment2 == null) || (protocol != enlistment2.ControlProtocol))
            {
                DebugTrace.Trace(TraceLevel.Warning, "Enlistment state does not match message for {0}", guid);
                if (fault)
                {
                    this.SendFault(message, this.state.Faults.InvalidParameters);
                }
                return(null);
            }
            if (enlistment2.ParticipantProxy == null)
            {
                DebugTrace.TxTrace(TraceLevel.Warning, enlistment2.EnlistmentId, "Participant enlistment was not correctly recovered");
                if (fault)
                {
                    this.SendFault(message, this.state.Faults.InvalidPolicy);
                }
                return(null);
            }
            if (this.state.Service.Security.CheckIdentity(enlistment2.ParticipantProxy, message))
            {
                return(enlistment2);
            }
            if (EnlistmentIdentityCheckFailedRecord.ShouldTrace)
            {
                EnlistmentIdentityCheckFailedRecord.Trace(enlistment2.EnlistmentId);
            }
            return(null);
        }