Beispiel #1
0
        void IHandle <ClientMessage.ReadAllEventsForward> .Handle(ClientMessage.ReadAllEventsForward message)
        {
            var pos    = new TFPos(message.CommitPosition, message.PreparePosition);
            var result = _readIndex.ReadAllEventsForward(pos, message.MaxCount, message.ResolveLinks);

            message.Envelope.ReplyWith(new ClientMessage.ReadAllEventsForwardCompleted(message.CorrelationId, result));
        }
        private ClientMessage.ReadAllEventsForwardCompleted ReadAllEventsForward(ClientMessage.ReadAllEventsForward msg)
        {
            using (HistogramService.Measure(_readerAllRangeHistogram))
            {
                var pos = new TFPos(msg.CommitPosition, msg.PreparePosition);
                var lastCommitPosition = _readIndex.LastReplicatedPosition;
                try
                {
                    if (msg.MaxCount > MaxPageSize)
                    {
                        throw new ArgumentException(string.Format("Read size too big, should be less than {0} items",
                                                                  MaxPageSize));
                    }
                    if (pos == TFPos.HeadOfTf)
                    {
                        var checkpoint = _writerCheckpoint.Read();
                        pos = new TFPos(checkpoint, checkpoint);
                    }
                    if (pos.CommitPosition < 0 || pos.PreparePosition < 0)
                    {
                        return(NoData(msg, ReadAllResult.Error, pos, lastCommitPosition, "Invalid position."));
                    }
                    if (msg.ValidationTfLastCommitPosition == lastCommitPosition)
                    {
                        return(NoData(msg, ReadAllResult.NotModified, pos, lastCommitPosition));
                    }
                    var access = _readIndex.CheckStreamAccess(SystemStreams.AllStream, StreamAccessType.Read, msg.User);
                    if (!access.Granted)
                    {
                        return(NoData(msg, ReadAllResult.AccessDenied, pos, lastCommitPosition));
                    }


                    var res      = _readIndex.ReadAllEventsForward(pos, msg.MaxCount);
                    var resolved = ResolveReadAllResult(res.Records, msg.ResolveLinkTos, msg.User);
                    if (resolved == null)
                    {
                        return(NoData(msg, ReadAllResult.AccessDenied, pos, lastCommitPosition));
                    }

                    var metadata = _readIndex.GetStreamMetadata(SystemStreams.AllStream);
                    return(new ClientMessage.ReadAllEventsForwardCompleted(
                               msg.CorrelationId, ReadAllResult.Success, null, resolved, metadata, access.Public, msg.MaxCount,
                               res.CurrentPos, res.NextPos, res.PrevPos, lastCommitPosition));
                }
                catch (Exception exc)
                {
                    Log.ErrorException(exc, "Error during processing ReadAllEventsForward request.");
                    return(NoData(msg, ReadAllResult.Error, pos, lastCommitPosition, exc.Message));
                }
            }
        }
 private void Subscribe(Position?startPosition)
 {
     if (startPosition == Position.End)
     {
         GoLive(Position.End);
     }
     else if (startPosition == null)
     {
         CatchUp(Position.Start);
     }
     else
     {
         var(commitPosition, preparePosition) = startPosition.Value.ToInt64();
         var indexResult =
             _readIndex.ReadAllEventsForward(new TFPos(commitPosition, preparePosition), 1);
         CatchUp(Position.FromInt64(indexResult.NextPos.CommitPosition,
                                    indexResult.NextPos.PreparePosition));
     }
 }
Beispiel #4
0
        private ClientMessage.ReadAllEventsForwardCompleted ReadAllEventsForward(ClientMessage.ReadAllEventsForward msg)
        {
            var pos = new TFPos(msg.CommitPosition, msg.PreparePosition);

            try
            {
                if (pos == TFPos.HeadOfTf)
                {
                    var checkpoint = _writerCheckpoint.Read();
                    pos = new TFPos(checkpoint, checkpoint);
                }
                if (pos.CommitPosition < 0 || pos.PreparePosition < 0)
                {
                    return(NoData(msg, ReadAllResult.Error, pos, "Invalid position."));
                }
                if (msg.ValidationTfEofPosition.HasValue && _readIndex.LastCommitPosition == msg.ValidationTfEofPosition.Value)
                {
                    return(NoData(msg, ReadAllResult.NotModified, pos));
                }
                var access = _readIndex.CheckStreamAccess(SystemStreams.AllStream, StreamAccessType.Read, msg.User);
                if (!access.Granted)
                {
                    return(NoData(msg, ReadAllResult.AccessDenied, pos));
                }

                var res      = _readIndex.ReadAllEventsForward(pos, msg.MaxCount);
                var resolved = ResolveReadAllResult(res.Records, msg.ResolveLinkTos, msg.User);
                if (resolved == null)
                {
                    return(NoData(msg, ReadAllResult.AccessDenied, pos));
                }

                return(new ClientMessage.ReadAllEventsForwardCompleted(
                           msg.CorrelationId, ReadAllResult.Success, null, resolved, res.Metadata, access.Public, msg.MaxCount,
                           res.CurrentPos, res.NextPos, res.PrevPos, res.TfEofPosition));
            }
            catch (Exception exc)
            {
                Log.ErrorException(exc, "Error during processing ReadAllEventsForward request.");
                return(NoData(msg, ReadAllResult.Error, pos, exc.Message));
            }
        }
Beispiel #5
0
 public IndexReadAllResult ReadAllEventsForward(TFPos pos, int maxCount) => _readIndex.ReadAllEventsForward(pos, maxCount);