private void CompleteFailedRequest(OperationResult result, string error) { Debug.Assert(result != OperationResult.Success); _completed = true; Message responseMsg; switch (_requestType) { case RequestType.TransactionStart: responseMsg = new ClientMessage.TransactionStartCompleted(_clientCorrId, _transactionId, result, error); break; case RequestType.TransactionWrite: // Should never happen, only possibly under very heavy load... responseMsg = new ClientMessage.TransactionWriteCompleted(_clientCorrId, _transactionId, result, error); break; default: throw new ArgumentOutOfRangeException(); } _responseEnvelope.ReplyWith(responseMsg); _bus.Publish(new StorageMessage.RequestCompleted(_internalCorrId, false)); }
private static TcpPackage WrapTransactionStartCompleted(ClientMessage.TransactionStartCompleted msg) { var dto = new TcpClientMessageDto.TransactionStartCompleted(msg.TransactionId, (TcpClientMessageDto.OperationResult)msg.Result, msg.Message); return(new TcpPackage(TcpCommand.TransactionStartCompleted, msg.CorrelationId, dto.Serialize())); }
public InspectionResult InspectPackage(TcpPackage package) { try { if (package.Command == TcpCommand.DeniedToRoute) { var route = package.Data.Deserialize <ClientMessage.DeniedToRoute>(); return(new InspectionResult(InspectionDecision.Reconnect, data: new EndpointsPair(route.ExternalTcpEndPoint, route.ExternalHttpEndPoint))); } if (package.Command != TcpCommand.TransactionStartCompleted) { return(new InspectionResult(InspectionDecision.NotifyError, new CommandNotExpectedException(TcpCommand.TransactionStartCompleted.ToString(), package.Command.ToString()))); } var data = package.Data; var dto = data.Deserialize <ClientMessage.TransactionStartCompleted>(); _result = dto; switch ((OperationErrorCode)dto.ErrorCode) { case OperationErrorCode.Success: return(new InspectionResult(InspectionDecision.Succeed)); case OperationErrorCode.PrepareTimeout: case OperationErrorCode.CommitTimeout: case OperationErrorCode.ForwardTimeout: return(new InspectionResult(InspectionDecision.Retry)); case OperationErrorCode.WrongExpectedVersion: var err = string.Format("Start transaction failed due to WrongExpectedVersion. Stream: {0}, Expected version: {1}, CorrID: {2}.", _stream, _expectedVersion, CorrelationId); return(new InspectionResult(InspectionDecision.NotifyError, new WrongExpectedVersionException(err))); case OperationErrorCode.StreamDeleted: return(new InspectionResult(InspectionDecision.NotifyError, new StreamDeletedException(_stream))); case OperationErrorCode.InvalidTransaction: return(new InspectionResult(InspectionDecision.NotifyError, new InvalidTransactionException())); default: throw new ArgumentOutOfRangeException(); } } catch (Exception e) { return(new InspectionResult(InspectionDecision.NotifyError, e)); } }
private void HandleAsNonMaster(ClientMessage.TransactionStart message) { if (message.RequireMaster) { DenyRequestBecauseNotMaster(message.CorrelationId, message.Envelope); return; } var timeoutMessage = new ClientMessage.TransactionStartCompleted( message.CorrelationId, -1, OperationResult.ForwardTimeout, "Forwarding timeout"); ForwardRequest(message, timeoutMessage); }
private void CompleteSuccessRequest() { _completed = true; Message responseMsg; switch (_requestType) { case RequestType.TransactionStart: responseMsg = new ClientMessage.TransactionStartCompleted(_clientCorrId, _transactionId, OperationResult.Success, null); break; case RequestType.TransactionWrite: responseMsg = new ClientMessage.TransactionWriteCompleted(_clientCorrId, _transactionId, OperationResult.Success, null); break; default: throw new ArgumentOutOfRangeException(); } _responseEnvelope.ReplyWith(responseMsg); _bus.Publish(new StorageMessage.RequestCompleted(_internalCorrId, true)); }
private void CompleteSuccessRequest(Guid correlationId, long transactionId, string eventStreamId) { _completed = true; Message responseMsg; switch (_requestType) { case RequestType.TransactionStart: responseMsg = new ClientMessage.TransactionStartCompleted(correlationId, transactionId, eventStreamId, OperationErrorCode.Success, null); break; case RequestType.TransactionWrite: responseMsg = new ClientMessage.TransactionWriteCompleted(correlationId, transactionId, eventStreamId, OperationErrorCode.Success, null); break; default: throw new ArgumentOutOfRangeException(); } _responseEnvelope.ReplyWith(responseMsg); _bus.Publish(new ReplicationMessage.RequestCompleted(correlationId, true)); }
private void CompleteFailedRequest(Guid correlationId, long transactionId, string eventStreamId, OperationErrorCode errorCode, string error) { Debug.Assert(errorCode != OperationErrorCode.Success); _completed = true; Message responseMsg; switch (_requestType) { case RequestType.TransactionStart: responseMsg = new ClientMessage.TransactionStartCompleted(correlationId, transactionId, eventStreamId, errorCode, error); break; case RequestType.TransactionWrite: // Should never happen, only possibly under very heavy load... responseMsg = new ClientMessage.TransactionWriteCompleted(correlationId, transactionId, eventStreamId, errorCode, error); break; default: throw new ArgumentOutOfRangeException(); } _responseEnvelope.ReplyWith(responseMsg); _bus.Publish(new ReplicationMessage.RequestCompleted(correlationId, false)); }
private static TcpPackage WrapTransactionStartCompleted(ClientMessage.TransactionStartCompleted msg) { var dto = new ClientMessageDto.TransactionStartCompleted(msg.CorrelationId, msg.TransactionId, msg.EventStreamId, msg.ErrorCode, msg.Error); return(new TcpPackage(TcpCommand.TransactionStartCompleted, msg.CorrelationId, dto.Serialize())); }
public void Handle(ClientMessage.TransactionStartCompleted message) { _forwardingProxy.TryForwardReply(message.CorrelationId, message, (clientCorrId, m) => m.WithCorrelationId(clientCorrId)); }