Inheritance: IDisposable, IEmittedStreamContainer, IEventWriter
 public void setup()
 {
     _readyHandler = new TestCheckpointManagerMessageHandler();
     _checkpoint = new ProjectionCheckpoint(
         _ioDispatcher, new ProjectionVersion(1, 0, 0), null, _readyHandler,
         CheckpointTag.FromPosition(0, 100, 50), new TransactionFilePositionTagger(0), 250);
 }
Ejemplo n.º 2
0
        public virtual void Initialize()
        {
            if (_currentCheckpoint != null)
            {
                _currentCheckpoint.Dispose();
            }
            if (_closingCheckpoint != null)
            {
                _closingCheckpoint.Dispose();
            }
            _currentCheckpoint           = null;
            _closingCheckpoint           = null;
            _requestedCheckpointPosition = null;
            _inCheckpoint                    = false;
            _requestedCheckpointState        = new PartitionState("", null, _zeroTag);
            _lastCompletedCheckpointPosition = null;
            _lastProcessedEventPosition.Initialize();
            _lastProcessedEventProgress = -1;

            _eventsProcessedAfterRestart = 0;
            _started  = false;
            _stopping = false;
            _stopped  = false;
            _currentProjectionState = new PartitionState("", null, _zeroTag);
        }
 public void setup()
 {
     _readyHandler = new TestCheckpointManagerMessageHandler();
     _checkpoint = new ProjectionCheckpoint(
         _ioDispatcher, new ProjectionVersion(1, 0, 0), null, _readyHandler,
         CheckpointTag.FromPosition(0, 100, 50), new TransactionFilePositionTagger(0),
         CheckpointTag.FromPosition(0, 0, -1), 250);
     _checkpoint.Start();
     _checkpoint.ValidateOrderAndEmitEvents(
         new[]
         {
             new EmittedEventEnvelope(
                 new EmittedDataEvent(
                     "stream2", Guid.NewGuid(), "type", true, "data2", null, CheckpointTag.FromPosition(0, 120, 110), null)),
             new EmittedEventEnvelope(
                 new EmittedDataEvent(
                     "stream2", Guid.NewGuid(), "type", true, "data4", null, CheckpointTag.FromPosition(0, 120, 110), null)),
         });
     _checkpoint.ValidateOrderAndEmitEvents(
         new[]
         {
             new EmittedEventEnvelope(
                 new EmittedDataEvent(
                     "stream1", Guid.NewGuid(), "type", true, "data", null, CheckpointTag.FromPosition(0, 140, 130), null))
         });
     var writes = _consumer.HandledMessages.OfType<ClientMessage.WriteEvents>().ToArray();
     writes[0].Envelope.ReplyWith(new ClientMessage.WriteEventsCompleted(writes[0].CorrelationId, 0, 0));
     writes[1].Envelope.ReplyWith(new ClientMessage.WriteEventsCompleted(writes[1].CorrelationId, 0, 0));
     _checkpoint.Prepare(CheckpointTag.FromPosition(0, 200, 150));
     //TODO: test whether checkpoint does not allow positions before last emitted event caused by position
 }
 public void setup()
 {
     _readyHandler = new TestCheckpointManagerMessageHandler();;
     _checkpoint = new ProjectionCheckpoint(
         new FakePublisher(), _readyHandler, CheckpointTag.FromPosition(0, -1), CheckpointTag.FromPosition(0, -1), 250);
     _checkpoint.Start();
 }
 public void setup()
 {
     _readyHandler = new TestMessageHandler<ProjectionMessage.Projections.ReadyForCheckpoint>();
     _checkpoint = new ProjectionCheckpoint(
         new FakePublisher(), _readyHandler, false, CheckpointTag.FromPosition(0, -1), 250);
     _checkpoint.Start();
 }
 public void setup()
 {
     _readyHandler = new TestCheckpointManagerMessageHandler();
     _checkpoint = new ProjectionCheckpoint(
         _ioDispatcher, new ProjectionVersion(1, 0, 0), null, _readyHandler,
         CheckpointTag.FromPosition(0, 100, 50), new TransactionFilePositionTagger(0), 250);
     _checkpoint.ValidateOrderAndEmitEvents(
         new[]
         {
             new EmittedEventEnvelope(
                 new EmittedDataEvent(
                     "stream2", Guid.NewGuid(), "type", true, "data2", null, CheckpointTag.FromPosition(0, 120, 110), null)),
             new EmittedEventEnvelope(
                 new EmittedDataEvent(
                     "stream3", Guid.NewGuid(), "type", true, "data3", null, CheckpointTag.FromPosition(0, 120, 110), null)),
             new EmittedEventEnvelope(
                 new EmittedDataEvent(
                     "stream2", Guid.NewGuid(), "type", true, "data4", null, CheckpointTag.FromPosition(0, 120, 110), null)),
         });
     _checkpoint.ValidateOrderAndEmitEvents(
         new[]
         {
             new EmittedEventEnvelope(
                 new EmittedDataEvent(
                     "stream1", Guid.NewGuid(), "type", true, "data", null, CheckpointTag.FromPosition(0, 140, 130), null))
         });
 }
Ejemplo n.º 7
0
        /// <returns>true - if checkpoint has been completed in-sync</returns>
        private bool StartCheckpoint(PositionTracker lastProcessedEventPosition, PartitionState projectionState)
        {
            Contract.Requires(_closingCheckpoint == null);
            if (projectionState == null)
            {
                throw new ArgumentNullException("projectionState");
            }

            CheckpointTag requestedCheckpointPosition = lastProcessedEventPosition.LastTag;

            if (requestedCheckpointPosition == _lastCompletedCheckpointPosition)
            {
                return(true);                // either suggested or requested to stop
            }
            if (_usePersistentCheckpoints)   // do not emit any events if we do not use persistent checkpoints
            {
                EmitPartitionCheckpoints();
            }

            _inCheckpoint = true;
            _requestedCheckpointPosition = requestedCheckpointPosition;
            _requestedCheckpointState    = projectionState;
            _closingCheckpoint           = _currentCheckpoint;
            _currentCheckpoint           = CreateProjectionCheckpoint(requestedCheckpointPosition);
            // checkpoint only after assigning new current checkpoint, as it may call back immediately
            _closingCheckpoint.Prepare(requestedCheckpointPosition);
            return(false);            // even if prepare completes in sync it notifies the world by a message
        }
 public void setup()
 {
     _readyHandler = new TestCheckpointManagerMessageHandler();;
     _checkpoint = new ProjectionCheckpoint(
         _readDispatcher, _writeDispatcher, new ProjectionVersion(1, 0, 0), null, _readyHandler,
         CheckpointTag.FromPosition(100, 50), new TransactionFilePositionTagger(),
         CheckpointTag.FromPosition(0, -1), 250);
     _checkpoint.Start();
     _checkpoint.ValidateOrderAndEmitEvents(
         new[]
             {
                 new EmittedDataEvent(
             "stream2", Guid.NewGuid(), "type", "data2", null, CheckpointTag.FromPosition(120, 110), null),
                 new EmittedDataEvent(
             "stream2", Guid.NewGuid(), "type", "data4", null, CheckpointTag.FromPosition(120, 110), null),
             });
     _checkpoint.ValidateOrderAndEmitEvents(
         new[]
             {
                 new EmittedDataEvent(
             "stream1", Guid.NewGuid(), "type", "data", null, CheckpointTag.FromPosition(140, 130), null)
             });
     _checkpoint.ValidateOrderAndEmitEvents(
         new[]
             {
                 new EmittedDataEvent(
             "stream1", Guid.NewGuid(), "type", "data", null, CheckpointTag.FromPosition(160, 150), null)
             });
 }
        public void setup()
        {
            _readyHandler = new TestCheckpointManagerMessageHandler();
            _checkpoint = new ProjectionCheckpoint(
                _ioDispatcher, new ProjectionVersion(1, 0, 0), null, _readyHandler,
                CheckpointTag.FromPosition(0, 100, 50), new TransactionFilePositionTagger(0), 250);

            _fakeEnvelope = new FakeEnvelope();
            _checkpoint.Handle(new CoreProjectionProcessingMessage.EmittedStreamAwaiting("awaiting_stream", _fakeEnvelope));
        }
Ejemplo n.º 10
0
 public virtual void Start(CheckpointTag checkpointTag)
 {
     Contract.Requires(_currentCheckpoint == null);
     if (_started)
     {
         throw new InvalidOperationException("Already started");
     }
     _started = true;
     _lastProcessedEventPosition.UpdateByCheckpointTagInitial(checkpointTag);
     _lastProcessedEventProgress      = -1;
     _lastCompletedCheckpointPosition = checkpointTag;
     _requestedCheckpointPosition     = null;
     _currentCheckpoint = CreateProjectionCheckpoint(_lastProcessedEventPosition.LastTag);
     _currentCheckpoint.Start();
 }
Ejemplo n.º 11
0
 private void EnterSubscribed()
 {
     _lastEnqueuedEventTag        = _checkpointStrategy.PositionTagger.MakeZeroCheckpointTag();
     _requestedCheckpointPosition = null;
     _currentCheckpoint           = new ProjectionCheckpoint(
         _publisher, this, _recoveryMode, _lastProcessedEventPosition.LastTag,
         _projectionConfig.MaxWriteBatchLength, _logger);
     _currentCheckpoint.Start();
     _publisher.Publish(
         new ProjectionMessage.Projections.SubscribeProjection(
             _projectionCorrelationId, this, _lastProcessedEventPosition.LastTag, _checkpointStrategy,
             _projectionConfig.CheckpointUnhandledBytesThreshold));
     _publisher.Publish(new ProjectionMessage.Projections.Started(_projectionCorrelationId));
     GoToState(State.Running);
 }
 public void setup()
 {
     _readyHandler = new TestCheckpointManagerMessageHandler();;
     _checkpoint = new ProjectionCheckpoint(_bus, _readyHandler, CheckpointTag.FromPosition(100, 50), CheckpointTag.FromPosition(0, -1), 250);
     try
     {
         _checkpoint.ValidateOrderAndEmitEvents(
             new[] {new EmittedEvent("stream1", Guid.NewGuid(), "type", "data",
             CheckpointTag.FromPosition(40, 30), null)});
     }
     catch (Exception ex)
     {
         _lastException = ex;
     }
 }
 public void setup()
 {
     _readyHandler = new TestMessageHandler<ProjectionMessage.Projections.ReadyForCheckpoint>();
     _checkpoint = new ProjectionCheckpoint(_bus, _readyHandler, false, CheckpointTag.FromPosition(100, 50), 250);
     try
     {
         _checkpoint.EmitEvents(
             new[] {new EmittedEvent("stream1", Guid.NewGuid(), "type", "data")},
             CheckpointTag.FromPosition(40, 30));
     }
     catch (Exception ex)
     {
         _lastException = ex;
     }
 }
Ejemplo n.º 14
0
        protected void CheckpointWritten()
        {
            _lastCompletedCheckpointPosition = _requestedCheckpointPosition;
            _closingCheckpoint = null;
            if (!_stopping)
            {
                // ignore any writes pending in the current checkpoint (this is not the best, but they will never hit the storage, so it is safe)
                _currentCheckpoint.Start();
            }
            _inCheckpoint = false;

            ProcessCheckpoints();
            _coreProjection.Handle(
                new CoreProjectionProcessingMessage.CheckpointCompleted(_lastCompletedCheckpointPosition));
        }
 public void setup()
 {
     _readyHandler = new TestCheckpointManagerMessageHandler();;
     _checkpoint = new ProjectionCheckpoint(_bus, _readyHandler, CheckpointTag.FromPosition(100, 50), CheckpointTag.FromPosition(0, -1), 250);
     _checkpoint.ValidateOrderAndEmitEvents(
         new[]
             {
                 new EmittedEvent("stream2", Guid.NewGuid(), "type", "data2", CheckpointTag.FromPosition(120, 110), null),
                 new EmittedEvent("stream3", Guid.NewGuid(), "type", "data3", CheckpointTag.FromPosition(120, 110), null),
                 new EmittedEvent("stream2", Guid.NewGuid(), "type", "data4", CheckpointTag.FromPosition(120, 110), null),
             }
         );
     _checkpoint.ValidateOrderAndEmitEvents(
         new[] {new EmittedEvent("stream1", Guid.NewGuid(), "type", "data",
         CheckpointTag.FromPosition(140, 130), null)});
 }
 public void setup()
 {
     _readyHandler = new TestMessageHandler<ProjectionMessage.Projections.ReadyForCheckpoint>();
     _checkpoint = new ProjectionCheckpoint(_bus, _readyHandler, CheckpointTag.FromPosition(100, 50), 250);
     _checkpoint.EmitEvents(
         new[]
             {
                 new EmittedEvent("stream2", Guid.NewGuid(), "type", "data2"),
                 new EmittedEvent("stream3", Guid.NewGuid(), "type", "data3"),
                 new EmittedEvent("stream2", Guid.NewGuid(), "type", "data4"),
             },
         CheckpointTag.FromPosition(120, 110));
     _checkpoint.EmitEvents(
         new[] {new EmittedEvent("stream1", Guid.NewGuid(), "type", "data")},
         CheckpointTag.FromPosition(140, 130));
 }
 public void Start(CheckpointTag checkpointTag)
 {
     if (!_stateLoaded)
     {
         throw new InvalidOperationException("State is not loaded");
     }
     if (_started)
     {
         throw new InvalidOperationException("Already started");
     }
     _started = true;
     _lastProcessedEventPosition.UpdateByCheckpointTagInitial(checkpointTag);
     _lastCompletedCheckpointPosition = checkpointTag;
     _requestedCheckpointPosition     = null;
     _currentCheckpoint = new ProjectionCheckpoint(
         _publisher, this, _lastProcessedEventPosition.LastTag, _projectionConfig.MaxWriteBatchLength, _logger);
     _currentCheckpoint.Start();
 }
Ejemplo n.º 18
0
        protected void CheckpointWritten(CheckpointTag lastCompletedCheckpointPosition)
        {
            Contract.Requires(_closingCheckpoint != null);
            _lastCompletedCheckpointPosition = lastCompletedCheckpointPosition;
            _closingCheckpoint.Dispose();
            _closingCheckpoint = null;
            if (!_stopping)
            {
                // ignore any writes pending in the current checkpoint (this is not the best, but they will never hit the storage, so it is safe)
                _currentCheckpoint.Start();
            }
            _inCheckpoint = false;

            //NOTE: the next checkpoint will start by completing checkpoint work item
            _publisher.Publish(
                new CoreProjectionProcessingMessage.CheckpointCompleted(
                    _projectionCorrelationId, _lastCompletedCheckpointPosition));
        }
Ejemplo n.º 19
0
        public void Stopped()
        {
            EnsureStarted();
            _started = false;
            _stopped = true;

            if (_currentCheckpoint != null)
            {
                _currentCheckpoint.Dispose();
            }
            _currentCheckpoint = null;

            if (_closingCheckpoint != null)
            {
                _closingCheckpoint.Dispose();
            }
            _closingCheckpoint = null;
        }
Ejemplo n.º 20
0
        public virtual void Initialize()
        {
            _currentCheckpoint            = null;
            _closingCheckpoint            = null;
            _handledEventsAfterCheckpoint = 0;
            _requestedCheckpointPosition  = null;
            _inCheckpoint                    = false;
            _requestedCheckpointState        = null;
            _lastCompletedCheckpointPosition = null;
            _lastProcessedEventPosition.Initialize();
            _lastProcessedEventProgress = -1;

            _eventsProcessedAfterRestart = 0;
            _stateLoaded            = false;
            _started                = false;
            _stopping               = false;
            _stateRequested         = false;
            _currentProjectionState = null;
        }
Ejemplo n.º 21
0
        private void CompleteCheckpoint(PositionTracker lastProcessedEventPosition, string projectionState)
        {
            CheckpointTag requestedCheckpointPosition = lastProcessedEventPosition.LastTag;

            if (requestedCheckpointPosition == _lastCompletedCheckpointPosition)
            {
                return; // either suggested or requested to stop
            }
            _inCheckpoint = true;
            _requestedCheckpointPosition  = requestedCheckpointPosition;
            _requestedCheckpointState     = projectionState;
            _handledEventsAfterCheckpoint = 0;

            _closingCheckpoint = _currentCheckpoint;
            _currentCheckpoint = new ProjectionCheckpoint(
                _publisher, this, requestedCheckpointPosition, _positionTagger.MakeZeroCheckpointTag(), _projectionConfig.MaxWriteBatchLength, _logger);
            // checkpoint only after assigning new current checkpoint, as it may call back immediately
            _closingCheckpoint.Prepare(requestedCheckpointPosition);
        }
        public virtual void Initialize()
        {
            if (_currentCheckpoint != null) _currentCheckpoint.Dispose();
            if (_closingCheckpoint != null) _closingCheckpoint.Dispose();
            _currentCheckpoint = null;
            _closingCheckpoint = null;
            _requestedCheckpointPosition = null;
            _inCheckpoint = false;
            _requestedCheckpointState = new PartitionState("", null, _zeroTag);
            _lastCompletedCheckpointPosition = null;
            _lastProcessedEventPosition.Initialize();
            _lastProcessedEventProgress = -1;

            _eventsProcessedAfterRestart = 0;
            _started = false;
            _stopping = false;
            _stopped = false;
            _currentProjectionState = new PartitionState("", null, _zeroTag);

        }
Ejemplo n.º 23
0
        private void CompleteCheckpoint()
        {
            CheckpointTag requestedCheckpointPosition = _lastProcessedEventPosition.LastTag;

            if (requestedCheckpointPosition == _lastCompletedCheckpointPosition)
            {
                return; // either suggested or requested to stop
            }
            _inCheckpoint = true;
            _requestedCheckpointPosition  = requestedCheckpointPosition;
            _requestedCheckpointStateJson = GetProjectionState();
            _handledEventsAfterCheckpoint = 0;

            _closingCheckpoint = _currentCheckpoint;
            _recoveryMode      = false;
            _currentCheckpoint = new ProjectionCheckpoint(
                _publisher, this, false, requestedCheckpointPosition, _projectionConfig.MaxWriteBatchLength, _logger);
            // checkpoint only after assigning new current checkpoint, as it may call back immediately
            _closingCheckpoint.Prepare(requestedCheckpointPosition);
        }
 public void setup()
 {
     _readyHandler = new TestCheckpointManagerMessageHandler();
     _checkpoint = new ProjectionCheckpoint(
         _readDispatcher, _writeDispatcher, new ProjectionVersion(1, 0, 0), null, _readyHandler,
         CheckpointTag.FromPosition(100, 50), new TransactionFilePositionTagger(),
         CheckpointTag.FromPosition(0, -1), 250);
     try
     {
         _checkpoint.ValidateOrderAndEmitEvents(
             new[]
                 {
                     new EmittedDataEvent(
                 "stream1", Guid.NewGuid(), "type", "data", null, CheckpointTag.FromPosition(40, 30), null)
                 });
     }
     catch (Exception ex)
     {
         _lastException = ex;
     }
 }
 public void setup()
 {
     _readyHandler = new TestCheckpointManagerMessageHandler();;
     _checkpoint = new ProjectionCheckpoint(_bus, _readyHandler, CheckpointTag.FromPosition(100, 50), CheckpointTag.FromPosition(0, -1), 250);
     _checkpoint.Start();
     _checkpoint.EmitEvents(
         new[]
             {
                 new EmittedEvent("stream2", Guid.NewGuid(), "type", "data2", CheckpointTag.FromPosition(120, 110), null),
                 new EmittedEvent("stream2", Guid.NewGuid(), "type", "data4", CheckpointTag.FromPosition(120, 110), null),
             }
         );
     _checkpoint.EmitEvents(
         new[] {new EmittedEvent("stream1", Guid.NewGuid(), "type", "data",
         CheckpointTag.FromPosition(140, 130), null)});
     var writes = _consumer.HandledMessages.OfType<ClientMessage.WriteEvents>().ToArray();
     writes[0].Envelope.ReplyWith(
         new ClientMessage.WriteEventsCompleted(writes[0].CorrelationId, writes[0].EventStreamId, 0));
     writes[1].Envelope.ReplyWith(
         new ClientMessage.WriteEventsCompleted(writes[1].CorrelationId, writes[1].EventStreamId, 0));
     _checkpoint.Prepare(CheckpointTag.FromPosition(200, 150));
     //TODO: test whether checkpoint does not allow positions before last emitted event caused by position
 }
        public virtual void Initialize()
        {
            _currentCheckpoint = null;
            _closingCheckpoint = null;
            _handledEventsAfterCheckpoint = 0;
            _requestedCheckpointPosition = null;
            _inCheckpoint = false;
            _requestedCheckpointState = null;
            _lastCompletedCheckpointPosition = null;
            _lastProcessedEventPosition.Initialize();
            _lastProcessedEventProgress = -1;

            _eventsProcessedAfterRestart = 0;
            _stateLoaded = false;
            _started = false;
            _stopping = false;
            _stateRequested = false;
            _currentProjectionState = null;
        }
 public void Start(CheckpointTag checkpointTag)
 {
     if (!_stateLoaded)
         throw new InvalidOperationException("State is not loaded");
     if (_started)
         throw new InvalidOperationException("Already started");
     _started = true;
     _lastProcessedEventPosition.UpdateByCheckpointTagInitial(checkpointTag);
     _lastProcessedEventProgress = -1;
     _lastCompletedCheckpointPosition = checkpointTag;
     _requestedCheckpointPosition = null;
     _currentCheckpoint = new ProjectionCheckpoint(
         _publisher, this, _lastProcessedEventPosition.LastTag, _positionTagger.MakeZeroCheckpointTag(), _projectionConfig.MaxWriteBatchLength, _logger);
     _currentCheckpoint.Start();
 }
 public void commit_position_less_than_or_equal_to_prepare_position_throws_argument_exception()
 {
     var c = new ProjectionCheckpoint(
         new FakePublisher(), _readyHandler, CheckpointTag.FromPosition(100, 101), CheckpointTag.FromPosition(0, -1), 250);
 }
 public void setup()
 {
     _readyHandler = new TestCheckpointManagerMessageHandler();;
     _checkpoint = new ProjectionCheckpoint(_bus, _readyHandler, CheckpointTag.FromPosition(100, 50), CheckpointTag.FromPosition(0, -1), 250);
 }
 public void null_ready_handler_throws_argument_null_exception()
 {
     var c = new ProjectionCheckpoint(new FakePublisher(), null, CheckpointTag.FromPosition(100, 50), CheckpointTag.FromPosition(0, -1), 250);
 }
 public void it_can_be_created()
 {
     var c = new ProjectionCheckpoint(
         new FakePublisher(), _readyHandler, CheckpointTag.FromPosition(100, 50), CheckpointTag.FromPosition(0, -1), 250);
 }
        protected void CheckpointWritten()
        {
            _lastCompletedCheckpointPosition = _requestedCheckpointPosition;
            _closingCheckpoint = null;
            if (!_stopping)
                // ignore any writes pending in the current checkpoint (this is not the best, but they will never hit the storage, so it is safe)
                _currentCheckpoint.Start();
            _inCheckpoint = false;

            ProcessCheckpoints();
            _coreProjection.Handle(
                new CoreProjectionProcessingMessage.CheckpointCompleted(_lastCompletedCheckpointPosition));
        }
Ejemplo n.º 33
0
        public void Handle(ClientMessage.WriteEventsCompleted message)
        {
            EnsureState(State.Running | State.Paused | State.Stopping | State.FaultedStopping);
            if (!_inCheckpoint || _inCheckpointWriteAttempt == 0)
            {
                throw new InvalidOperationException();
            }
            if (message.ErrorCode == OperationErrorCode.Success)
            {
                if (_logger != null)
                {
                    _logger.Trace(
                        "Checkpoint has be written for projection {0} at sequence number {1} (current)", _name,
                        message.EventNumber);
                }
                _lastCompletedCheckpointPosition  = _requestedCheckpointPosition;
                _lastWrittenCheckpointEventNumber = message.EventNumber
                                                    +
                                                    (_lastWrittenCheckpointEventNumber == ExpectedVersion.NoStream // account for StreamCreated
                                                         ? 1
                                                         : 0);

                _closingCheckpoint = null;
                if (_state != State.Stopping && _state != State.FaultedStopping)
                {
                    // ignore any writes pending in the current checkpoint (this is not the best, but they will never hit the storage, so it is safe)
                    _currentCheckpoint.Start();
                }
                _inCheckpoint             = false;
                _inCheckpointWriteAttempt = 0;

                if (_state != State.Running)
                {
                    ProcessCheckpoints();
                    if (_state == State.Paused)
                    {
                        TryResume();
                    }
                    else if (_state == State.Stopping)
                    {
                        GoToState(State.Stopped);
                    }
                    else if (_state == State.FaultedStopping)
                    {
                        GoToState(State.Faulted);
                    }
                }
            }
            else
            {
                if (_logger != null)
                {
                    _logger.Info(
                        "Failed to write projection checkpoint to stream {0}. Error: {1}", message.EventStreamId,
                        Enum.GetName(typeof(OperationErrorCode), message.ErrorCode));
                }
                if (message.ErrorCode == OperationErrorCode.CommitTimeout ||
                    message.ErrorCode == OperationErrorCode.ForwardTimeout ||
                    message.ErrorCode == OperationErrorCode.PrepareTimeout ||
                    message.ErrorCode == OperationErrorCode.WrongExpectedVersion)
                {
                    if (_logger != null)
                    {
                        _logger.Info("Retrying write checkpoint to {0}", message.EventStreamId);
                    }
                    _inCheckpointWriteAttempt++;
                    PublishWriteCheckpointEvent();
                }
                else
                {
                    throw new NotSupportedException("Unsupported error code received");
                }
            }
        }
        protected void CheckpointWritten(CheckpointTag lastCompletedCheckpointPosition)
        {
            Contract.Requires(_closingCheckpoint != null);
            _lastCompletedCheckpointPosition = lastCompletedCheckpointPosition;
            _closingCheckpoint.Dispose();
            _closingCheckpoint = null;
            if (!_stopping)
                // ignore any writes pending in the current checkpoint (this is not the best, but they will never hit the storage, so it is safe)
                _currentCheckpoint.Start();
            _inCheckpoint = false;

            //NOTE: the next checkpoint will start by completing checkpoint work item
            _publisher.Publish(
                new CoreProjectionProcessingMessage.CheckpointCompleted(
                    _projectionCorrelationId, _lastCompletedCheckpointPosition));
        }
        /// <returns>true - if checkpoint has been completed in-sync</returns>
        private bool StartCheckpoint(PositionTracker lastProcessedEventPosition, PartitionState projectionState)
        {
            Contract.Requires(_closingCheckpoint == null);
            if (projectionState == null) throw new ArgumentNullException("projectionState");

            CheckpointTag requestedCheckpointPosition = lastProcessedEventPosition.LastTag;
            if (requestedCheckpointPosition == _lastCompletedCheckpointPosition)
                return true; // either suggested or requested to stop

            if (_usePersistentCheckpoints) // do not emit any events if we do not use persistent checkpoints
                EmitPartitionCheckpoints();

            _inCheckpoint = true;
            _requestedCheckpointPosition = requestedCheckpointPosition;
            _requestedCheckpointState = projectionState;
            _closingCheckpoint = _currentCheckpoint;
            _currentCheckpoint = CreateProjectionCheckpoint(requestedCheckpointPosition);
            // checkpoint only after assigning new current checkpoint, as it may call back immediately
            _closingCheckpoint.Prepare(requestedCheckpointPosition);
            return false; // even if prepare completes in sync it notifies the world by a message
        }
 public virtual void Start(CheckpointTag checkpointTag)
 {
     Contract.Requires(_currentCheckpoint == null);
     if (_started)
         throw new InvalidOperationException("Already started");
     _started = true;
     _lastProcessedEventPosition.UpdateByCheckpointTagInitial(checkpointTag);
     _lastProcessedEventProgress = -1;
     _lastCompletedCheckpointPosition = checkpointTag;
     _requestedCheckpointPosition = null;
     _currentCheckpoint = CreateProjectionCheckpoint(_lastProcessedEventPosition.LastTag);
     _currentCheckpoint.Start();
 }
        public virtual void Initialize()
        {
            _currentCheckpoint = null;
            _closingCheckpoint = null;
            _handledEventsAfterCheckpoint = 0;
            _requestedCheckpointPosition = null;
            _inCheckpoint = false;
            _requestedCheckpointState = null;
            _lastCompletedCheckpointPosition = null;
            _lastProcessedEventPosition.Initialize();
            _lastProcessedEventProgress = -1;

            _eventsProcessedAfterRestart = 0;
            _stateLoaded = false;
            _started = false;
            _stopping = false;
            _stateRequested = false;
            _currentProjectionState = null;

            foreach (var requestId in _loadStateRequests)
                _readDispatcher.Cancel(requestId);
            _loadStateRequests.Clear();
        }
 public void setup()
 {
     _readyHandler = new TestMessageHandler<ProjectionMessage.Projections.ReadyForCheckpoint>();
     _checkpoint = new ProjectionCheckpoint(_bus, _readyHandler, false, CheckpointTag.FromPosition(100, 50), 250);
 }
        private void CompleteCheckpoint(PositionTracker lastProcessedEventPosition, string projectionState)
        {
            CheckpointTag requestedCheckpointPosition = lastProcessedEventPosition.LastTag;
            if (requestedCheckpointPosition == _lastCompletedCheckpointPosition)
                return; // either suggested or requested to stop
            _inCheckpoint = true;
            _requestedCheckpointPosition = requestedCheckpointPosition;
            _requestedCheckpointState = projectionState;
            _handledEventsAfterCheckpoint = 0;

            _closingCheckpoint = _currentCheckpoint;
            _currentCheckpoint = new ProjectionCheckpoint(
                _publisher, this, requestedCheckpointPosition, _positionTagger.MakeZeroCheckpointTag(), _projectionConfig.MaxWriteBatchLength, _logger);
            // checkpoint only after assigning new current checkpoint, as it may call back immediately
            _closingCheckpoint.Prepare(requestedCheckpointPosition);
        }
 public void null_publisher_throws_argument_null_exception()
 {
     var c = new ProjectionCheckpoint(null, _readyHandler, false, CheckpointTag.FromPosition(100, 50), 250);
 }