protected override void CompleteSuccessRequest(long firstEventNumber, long lastEventNumber, long preparePosition, long commitPosition)
        {
            base.CompleteSuccessRequest(firstEventNumber, lastEventNumber, preparePosition, commitPosition);
            var responseMsg = new ClientMessage.DeleteStreamCompleted(ClientCorrId, OperationResult.Success, null, preparePosition, commitPosition);

            ResponseEnvelope.ReplyWith(responseMsg);
        }
        protected override void CompleteFailedRequest(OperationResult result, string error, long currentVersion = -1)
        {
            base.CompleteFailedRequest(result, error, currentVersion);
            var responseMsg = new ClientMessage.DeleteStreamCompleted(ClientCorrId, result, error);

            ResponseEnvelope.ReplyWith(responseMsg);
        }
Beispiel #3
0
        protected override void CompleteSuccessRequest(int firstEventNumber, int lastEventNumber)
        {
            base.CompleteSuccessRequest(firstEventNumber, lastEventNumber);
            var responseMsg = new ClientMessage.DeleteStreamCompleted(ClientCorrId, OperationResult.Success, null);

            ResponseEnvelope.ReplyWith(responseMsg);
        }
Beispiel #4
0
 private void DeleteStreamCompleted(ClientMessage.DeleteStreamCompleted deleteStreamCompleted, Action onEmittedStreamsDeleted, string streamId, long eventNumber)
 {
     if (deleteStreamCompleted.Result == OperationResult.Success || deleteStreamCompleted.Result == OperationResult.StreamDeleted)
     {
         _retryCount = RetryLimit;
         _numberOfEventsProcessed++;
         if (_numberOfEventsProcessed >= _checkPointThreshold)
         {
             _numberOfEventsProcessed = 0;
             TryMarkCheckpoint(eventNumber);
         }
         DeleteEmittedStreamsFrom(eventNumber + 1, onEmittedStreamsDeleted);
     }
     else
     {
         if (_retryCount == 0)
         {
             Log.Error("PROJECTIONS: Retry limit reached, could not delete stream: {0}. Manual intervention is required and you may need to delete this stream manually", streamId);
             _retryCount = RetryLimit;
             DeleteEmittedStreamsFrom(eventNumber + 1, onEmittedStreamsDeleted);
             return;
         }
         Log.Error("PROJECTIONS: Failed to delete emitted stream {0}, Retrying ({1}/{2}). Reason: {3}", streamId, (RetryLimit - _retryCount) + 1, RetryLimit, deleteStreamCompleted.Result);
         _retryCount--;
         DeleteEmittedStreamsFrom(eventNumber, onEmittedStreamsDeleted);
     }
 }
        protected override void CompleteFailedRequest(Guid correlationId, string eventStreamId, OperationErrorCode errorCode, string error)
        {
            base.CompleteFailedRequest(correlationId, eventStreamId, errorCode, error);
            var responseMsg = new ClientMessage.DeleteStreamCompleted(
                correlationId, eventStreamId, errorCode, error);

            _responseEnvelope.ReplyWith(responseMsg);
        }
        protected override void CompleteSuccessRequest(Guid correlationId, string eventStreamId, int startEventNumber)
        {
            base.CompleteSuccessRequest(correlationId, eventStreamId, startEventNumber);
            var responseMsg = new ClientMessage.DeleteStreamCompleted(
                correlationId, eventStreamId, OperationErrorCode.Success, null);

            _responseEnvelope.ReplyWith(responseMsg);
        }
Beispiel #7
0
        private static TcpPackage WrapDeleteStreamCompleted(ClientMessage.DeleteStreamCompleted msg)
        {
            var dto = new TcpClientMessageDto.DeleteStreamCompleted((TcpClientMessageDto.OperationResult)msg.Result,
                                                                    msg.Message,
                                                                    msg.PreparePosition,
                                                                    msg.CommitPosition);

            return(new TcpPackage(TcpCommand.DeleteStreamCompleted, 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.DeleteStreamCompleted)
                {
                    return(new InspectionResult(InspectionDecision.NotifyError,
                                                new CommandNotExpectedException(TcpCommand.DeleteStreamCompleted.ToString(),
                                                                                package.Command.ToString())));
                }

                var data = package.Data;
                var dto  = data.Deserialize <ClientMessage.DeleteStreamCompleted>();
                _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("Delete stream 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.DeleteStream message)
        {
            if (message.RequireMaster)
            {
                DenyRequestBecauseNotMaster(message.CorrelationId, message.Envelope);
                return;
            }
            var timeoutMessage = new ClientMessage.DeleteStreamCompleted(
                message.CorrelationId, OperationResult.ForwardTimeout, "Forwarding timeout", -1, -1);

            ForwardRequest(message, timeoutMessage);
        }
Beispiel #10
0
        private void CompleteFailedRequest(Guid correlationId, string eventStreamId, OperationErrorCode errorCode, string error)
        {
            Debug.Assert(errorCode != OperationErrorCode.Success);

            _completed = true;

            _bus.Publish(new ReplicationMessage.RequestCompleted(correlationId, false));

            switch (_requestType)
            {
            case RequestType.CreateStream:
            {
                var responseMsg = new ClientMessage.CreateStreamCompleted(correlationId, eventStreamId, errorCode, error);
                _responseEnvelope.ReplyWith(responseMsg);
                break;
            }

            case RequestType.Write:
            {
                var responseMsg = new ClientMessage.WriteEventsCompleted(
                    correlationId, eventStreamId, errorCode, error);
                _responseEnvelope.ReplyWith(responseMsg);
                break;
            }

            case RequestType.DeleteStream:
            {
                var responseMsg = new ClientMessage.DeleteStreamCompleted(
                    correlationId, eventStreamId, errorCode, error);
                _responseEnvelope.ReplyWith(responseMsg);
                break;
            }

            case RequestType.TransactionCommit:
            {
                var responseMsg = new ClientMessage.TransactionCommitCompleted(
                    correlationId, _preparePos, errorCode, error);
                _responseEnvelope.ReplyWith(responseMsg);
                break;
            }

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Beispiel #11
0
 private void StreamDeleted(ClientMessage.DeleteStreamCompleted message, string eventStreamId)
 {
     if (message.Result == OperationResult.Success)
     {
         _logger.Info("projection stream '{0}' deleted", eventStreamId);
         return;
     }
     _logger.Info(
         "Projection stream '{0}' could not be deleted. Error: {1}",
         eventStreamId,
         Enum.GetName(typeof(OperationResult), message.Result));
     if (message.Result == OperationResult.CommitTimeout ||
         message.Result == OperationResult.ForwardTimeout)
     {
         DeleteCheckpointStream();
     }
     else
     {
         throw new NotSupportedException("Unsupported error code received");
     }
 }
        private static TcpPackage WrapDeleteStreamCompleted(ClientMessage.DeleteStreamCompleted msg)
        {
            var dto = new ClientMessageDto.DeleteStreamCompleted(msg.CorrelationId, msg.EventStreamId, msg.ErrorCode, msg.Error);

            return(new TcpPackage(TcpCommand.DeleteStreamCompleted, msg.CorrelationId, dto.Serialize()));
        }
Beispiel #13
0
 public void Handle(ClientMessage.DeleteStreamCompleted message)
 {
     _streamDispatcher.Handle(message);
 }
 public void Handle(ClientMessage.DeleteStreamCompleted message)
 {
     _forwardingProxy.TryForwardReply(message.CorrelationId, message,
                                      (clientCorrId, m) => m.WithCorrelationId(clientCorrId));
 }