Beispiel #1
0
        private ClientMessage.FilteredReadAllEventsForwardCompleted FilteredReadAllEventsForward(
            ClientMessage.FilteredReadAllEventsForward 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(NoDataForFilteredCommand(msg, FilteredReadAllResult.Error, pos, lastCommitPosition,
                                                        "Invalid position."));
                    }
                    if (msg.ValidationTfLastCommitPosition == lastCommitPosition)
                    {
                        return(NoDataForFilteredCommand(msg, FilteredReadAllResult.NotModified, pos,
                                                        lastCommitPosition));
                    }
                    var access = _readIndex.CheckStreamAccess(SystemStreams.AllStream, StreamAccessType.Read, msg.User);
                    if (!access.Granted)
                    {
                        return(NoDataForFilteredCommand(msg, FilteredReadAllResult.AccessDenied, pos,
                                                        lastCommitPosition));
                    }

                    var res = _readIndex.ReadAllEventsForwardFiltered(pos, msg.MaxCount, msg.MaxSearchWindow,
                                                                      msg.EventFilter);
                    var resolved = ResolveReadAllResult(res.Records, msg.ResolveLinkTos, msg.User);
                    if (resolved == null)
                    {
                        return(NoDataForFilteredCommand(msg, FilteredReadAllResult.AccessDenied, pos,
                                                        lastCommitPosition));
                    }

                    var metadata = _readIndex.GetStreamMetadata(SystemStreams.AllStream);
                    return(new ClientMessage.FilteredReadAllEventsForwardCompleted(
                               msg.CorrelationId, FilteredReadAllResult.Success, null, resolved, metadata, access.Public,
                               msg.MaxCount,
                               res.CurrentPos, res.NextPos, res.PrevPos, lastCommitPosition, res.IsEndOfStream));
                } catch (Exception exc) {
                    Log.ErrorException(exc, "Error during processing ReadAllEventsForwardFiltered request.");
                    return(NoDataForFilteredCommand(msg, FilteredReadAllResult.Error, pos, lastCommitPosition,
                                                    exc.Message));
                }
            }
        }
Beispiel #2
0
 public IndexReadAllResult ReadAllEventsForwardFiltered(TFPos pos, int maxCount, int maxSearchWindow, IEventFilter eventFilter) =>
 _readIndex.ReadAllEventsForwardFiltered(pos, maxCount, maxSearchWindow, eventFilter);