SetLastCheckPoint() public method

public SetLastCheckPoint ( int lastEventNumber ) : void
lastEventNumber int
return void
        public void TryMarkCheckpoint(bool isTimeCheck)
        {
            lock (_lock) {
                var lowest = _outstandingMessages.GetLowestPosition() - 1;
                // Subtract 1 from retry and outstanding as those messages have not been processed yet.
                var lowestBufferedRetry = StreamBuffer.GetLowestRetry() - 1;
                lowest = Math.Min(lowest, lowestBufferedRetry);
                if (lowest == long.MaxValue - 1)
                {
                    lowest = _lastKnownMessage;
                }
                if (lowest == -1)
                {
                    return;
                }

                //no outstanding messages. in this case we can say that the last known
                //event would be our checkpoint place (we have already completed it)
                var difference     = lowest - _lastCheckPoint;
                var now            = DateTime.UtcNow;
                var timedifference = now - _lastCheckPointTime;
                if (timedifference < _settings.CheckPointAfter && difference < _settings.MaxCheckPointCount)
                {
                    return;
                }
                if ((difference >= _settings.MinCheckPointCount && isTimeCheck) ||
                    difference >= _settings.MaxCheckPointCount)
                {
                    _lastCheckPointTime = now;
                    _lastCheckPoint     = lowest;
                    _settings.CheckpointWriter.BeginWriteState(lowest);
                    _statistics.SetLastCheckPoint(lowest);
                }
            }
        }
Example #2
0
 public void TryMarkCheckpoint(bool isTimeCheck)
 {
     lock (_lock)
     {
         var lowest = _outstandingMessages.GetLowestPosition();
         //TODO? COMPETING better to make -1? as of now we are inclusive of checkpoint.
         var lowestBufferedRetry = _streamBuffer.GetLowestRetry();
         lowest = Math.Min(lowest, lowestBufferedRetry);
         if (lowest == int.MinValue)
         {
             lowest = _lastKnownMessage;
         }
         //no outstanding messages. in this case we can say that the last known
         //event would be our checkpoint place (we have already completed it)
         var difference     = lowest - _lastCheckPoint;
         var now            = DateTime.Now;
         var timedifference = now - _lastCheckPointTime;
         if (timedifference < _settings.CheckPointAfter && difference < _settings.MaxCheckPointCount)
         {
             return;
         }
         if ((difference >= _settings.MinCheckPointCount && isTimeCheck) ||
             difference >= _settings.MaxCheckPointCount)
         {
             _lastCheckPointTime = now;
             _lastCheckPoint     = lowest;
             _settings.CheckpointWriter.BeginWriteState(lowest);
             _statistics.SetLastCheckPoint(lowest);
         }
     }
 }
Example #3
0
        private void OnCheckpointLoaded(string checkpoint)
        {
            lock (_lock) {
                _state = PersistentSubscriptionState.Behind;
                if (checkpoint == null)
                {
                    Log.Debug("Subscription {subscriptionId}: no checkpoint found", _settings.SubscriptionId);

                    Log.Debug("Start from = " + _settings.StartFrom);

                    _nextEventToPullFrom = _settings.StartFrom.IsLivePosition ? _settings.EventSource.StreamStartPosition : _settings.StartFrom;
                    _streamBufferSource.SetResult(new StreamBuffer(_settings.BufferSize, _settings.LiveBufferSize, null,
                                                                   !_settings.StartFrom.IsLivePosition));
                    TryReadingNewBatch();
                }
                else
                {
                    _nextEventToPullFrom = _settings.EventSource.GetStreamPositionFor(checkpoint);
                    _skipFirstEvent      = true;                //skip the checkpointed event

                    //initialize values based on the loaded checkpoint
                    _nextSequenceNumber             = 1L;
                    _lastCheckpointedSequenceNumber = 0L;
                    _lastKnownSequenceNumber        = 0L;
                    _lastKnownMessage = _settings.EventSource.GetStreamPositionFor(checkpoint);
                    _statistics.SetLastCheckPoint(_lastKnownMessage);

                    Log.Debug("Subscription {subscriptionId}: read checkpoint {checkpoint}", _settings.SubscriptionId,
                              checkpoint);
                    _streamBufferSource.SetResult(new StreamBuffer(_settings.BufferSize, _settings.LiveBufferSize, _nextEventToPullFrom, true));
                    _settings.MessageParker.BeginLoadStats(TryReadingNewBatch);
                }
            }
        }