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);
        }
示例#2
0
 private void TrySendFault(DatagramProxy proxy, UniqueId messageID, Fault fault)
 {
     if (proxy == null)
     {
         if (DebugTrace.Warning)
         {
             DebugTrace.Trace(TraceLevel.Warning, "Could not create a proxy to send {0} fault", fault.Code.Name);
         }
     }
     else
     {
         this.state.Perf.FaultsSentCountPerInterval.Increment();
         if (DebugTrace.Info)
         {
             DebugTrace.Trace(TraceLevel.Info, "Sending {0} fault to {1}", fault.Code.Name, Ports.TryGetAddress(proxy));
         }
         IAsyncResult ar = proxy.BeginSendFault(messageID, fault, this.sendFaultComplete, proxy);
         if (ar.CompletedSynchronously)
         {
             this.OnSendFaultComplete(ar, proxy);
         }
     }
 }
 public void Fault(Message message, MessageFault fault)
 {
     if (this.CheckMessage(message, false) != null)
     {
         this.state.Perf.FaultsReceivedCountPerInterval.Increment();
     }
     if (DebugTrace.Info)
     {
         DebugTrace.Trace(TraceLevel.Info, "Ignoring {0} fault from completion participant at {1}: {2}", Library.GetFaultCodeName(fault), Ports.TryGetFromAddress(message), Library.GetFaultCodeReason(fault));
     }
 }
        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);
            }
        }
 public void SendCommitted(EndpointAddress sendTo)
 {
     if (sendTo != null)
     {
         CompletionParticipantProxy proxy = this.state.TryCreateCompletionParticipantProxy(sendTo);
         if (proxy != null)
         {
             try
             {
                 if (DebugTrace.Info)
                 {
                     DebugTrace.Trace(TraceLevel.Info, "Sending Committed to unrecognized completion participant at {0}", Ports.TryGetAddress(proxy));
                 }
                 IAsyncResult ar = proxy.BeginSendCommitted(this.politeSendComplete, proxy);
                 if (ar.CompletedSynchronously)
                 {
                     this.OnSendComplete(ar, null, proxy);
                 }
             }
             finally
             {
                 proxy.Release();
             }
         }
     }
 }
示例#6
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);
            }
        }
示例#7
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);
            }
        }
示例#8
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);
        }
示例#9
0
 public void SendReadOnly(EndpointAddress sendTo)
 {
     if (sendTo != null)
     {
         TwoPhaseCommitCoordinatorProxy proxy = this.state.TryCreateTwoPhaseCommitCoordinatorProxy(sendTo);
         if (proxy != null)
         {
             try
             {
                 if (DebugTrace.Info)
                 {
                     DebugTrace.Trace(TraceLevel.Info, "Sending ReadOnly to unrecognized participant at {0}", Ports.TryGetAddress(proxy));
                 }
                 IAsyncResult ar = proxy.BeginSendReadOnly(this.politeSendComplete, proxy);
                 if (ar.CompletedSynchronously)
                 {
                     this.OnPoliteSendComplete(ar, proxy);
                 }
             }
             finally
             {
                 proxy.Release();
             }
         }
     }
 }
示例#10
0
        public void Fault(Message message, MessageFault fault)
        {
            CoordinatorEnlistment         enlistment;
            VolatileCoordinatorEnlistment enlistment2;

            if (this.CheckMessage(message, false, out enlistment, out enlistment2))
            {
                if (enlistment != null)
                {
                    enlistment.StateMachine.Enqueue(new MsgDurableCoordinatorFaultEvent(enlistment, fault));
                }
                else if (enlistment2 != null)
                {
                    enlistment2.StateMachine.Enqueue(new MsgVolatileCoordinatorFaultEvent(enlistment2, fault));
                }
                else if (DebugTrace.Info)
                {
                    DebugTrace.Trace(TraceLevel.Info, "Ignoring {0} fault from unrecognized coordinator at {1}: {2}", Library.GetFaultCodeName(fault), Ports.TryGetFromAddress(message), Library.GetFaultCodeReason(fault));
                }
                this.state.Perf.FaultsReceivedCountPerInterval.Increment();
            }
        }
        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 SendRollback(EndpointAddress sendTo)
 {
     if (sendTo != null)
     {
         TwoPhaseCommitParticipantProxy proxy = this.state.TryCreateTwoPhaseCommitParticipantProxy(sendTo);
         if (proxy != null)
         {
             try
             {
                 if (DebugTrace.Info)
                 {
                     DebugTrace.Trace(TraceLevel.Info, "Sending Rollback to unrecognized participant at {0}", Ports.TryGetAddress(proxy));
                 }
                 proxy.From = this.CreateForgottenSource();
                 IAsyncResult ar = proxy.BeginSendRollback(this.politeSendComplete, proxy);
                 if (ar.CompletedSynchronously)
                 {
                     this.OnPoliteSendComplete(ar, proxy);
                 }
             }
             finally
             {
                 proxy.Release();
             }
         }
     }
 }
        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);
            }
        }
示例#14
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);
            }
        }