protected StateMachine(TransactionEnlistment enlistment) { this.enlistment = enlistment; this.state = enlistment.State; this.synchronization = new SynchronizationManager(this); if (DebugTrace.Warning || DiagnosticUtility.ShouldTraceWarning) { this.history = new StateMachineHistory(); } }
private void TryToAbortTransaction(SynchronizationEvent e, Microsoft.Transactions.Wsat.Protocol.TransactionEnlistment enlistment) { if (this is InactiveState) { enlistment.StateMachine.ChangeState(enlistment.StateMachine.AbortedState); } else if (this is ActiveState) { this.state.TransactionManagerSend.Rollback(enlistment); enlistment.StateMachine.ChangeState(enlistment.StateMachine.AbortedState); } }
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); }
private CompletionEnlistment CheckMessage(Message message, bool reply) { Guid guid; if (!Ports.TryGetEnlistment(message, out guid)) { DebugTrace.Trace(TraceLevel.Warning, "Could not read enlistment header from message"); if (reply) { 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.Warning, "Could not find enlistment {0}", guid); if (reply) { this.SendFault(message, this.state.Faults.InvalidState); } return(null); } CompletionEnlistment enlistment2 = enlistment as CompletionEnlistment; if (enlistment2 == null) { DebugTrace.Trace(TraceLevel.Warning, "Completion message received for non-completion enlistment {0}", guid); if (reply) { this.SendFault(message, this.state.Faults.InvalidParameters); } return(null); } if (this.state.Service.Security.CheckIdentity(enlistment2.ParticipantProxy, message)) { return(enlistment2); } if (EnlistmentIdentityCheckFailedRecord.ShouldTrace) { EnlistmentIdentityCheckFailedRecord.Trace(enlistment2.EnlistmentId); } return(null); }
private void InvalidFaultEvent(SynchronizationEvent e, Microsoft.Transactions.Wsat.Protocol.TransactionEnlistment enlistment, MessageFault fault) { this.TraceInvalidEvent(e, false); this.TryToAbortTransaction(e, enlistment); }
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); }
protected SynchronizationEvent(TransactionEnlistment enlistment) { this.enlistment = enlistment; this.state = enlistment.State; }
public TmRollbackResponseEvent(TransactionEnlistment enlistment, Microsoft.Transactions.Bridge.Status status) : base(enlistment) { this.status = status; }
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); }
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); }
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); }
public void AddEnlistment(TransactionEnlistment enlistment) { this.Add <Guid, TransactionEnlistment>(this.enlistments, this.enlistmentLock, enlistment.EnlistmentId, enlistment); }
public void RemoveEnlistment(TransactionEnlistment enlistment) { this.Remove <Guid, TransactionEnlistment>(this.enlistments, this.enlistmentLock, enlistment.EnlistmentId, enlistment); }