protected override IProjectionProcessingPhase[] CreateProjectionProcessingPhases(
            IPublisher publisher, Guid projectionCorrelationId, ProjectionNamesBuilder namingBuilder,
            PartitionStateCache partitionStateCache, CoreProjection coreProjection, IODispatcher ioDispatcher,
            IProjectionProcessingPhase firstPhase)
        {

            var coreProjectionCheckpointWriter =
                new CoreProjectionCheckpointWriter(
                    namingBuilder.MakeCheckpointStreamName(), ioDispatcher, _projectionVersion, _name);
            var checkpointManager2 = new DefaultCheckpointManager(
                publisher, projectionCorrelationId, _projectionVersion, _projectionConfig.RunAs, ioDispatcher,
                _projectionConfig, _name, new PhasePositionTagger(1), namingBuilder, GetUseCheckpoints(), false,
                _sourceDefinition.DefinesFold, coreProjectionCheckpointWriter);

            IProjectionProcessingPhase writeResultsPhase;
            if (GetProducesRunningResults()
                || !string.IsNullOrEmpty(_sourceDefinition.CatalogStream) && _sourceDefinition.ByStreams)
                writeResultsPhase = new WriteQueryEofProjectionProcessingPhase(
                    1, namingBuilder.GetResultStreamName(), coreProjection, partitionStateCache, checkpointManager2,
                    checkpointManager2);
            else
                writeResultsPhase = new WriteQueryResultProjectionProcessingPhase(
                    1, namingBuilder.GetResultStreamName(), coreProjection, partitionStateCache, checkpointManager2,
                    checkpointManager2);

            return new[] {firstPhase, writeResultsPhase};
        }
        public ProjectionProcessingStrategy CreateProjectionProcessingStrategy(
            string name, ProjectionVersion projectionVersion, ProjectionNamesBuilder namesBuilder,
            IQueryDefinition sourceDefinition, ProjectionConfig projectionConfig,
            Func<IProjectionStateHandler> handlerFactory, IProjectionStateHandler stateHandler)
        {

            if (!sourceDefinition.DisableParallelismOption && projectionConfig.StopOnEof && sourceDefinition.ByStreams
                && sourceDefinition.DefinesFold && !string.IsNullOrEmpty(sourceDefinition.CatalogStream))
            {
                return new ParallelQueryProcessingStrategy(
                    name, projectionVersion, stateHandler, handlerFactory, projectionConfig, sourceDefinition,
                    namesBuilder, _logger, _spoolProcessingResponseDispatcher, _subscriptionDispatcher);
            }

            if (!sourceDefinition.DisableParallelismOption && projectionConfig.StopOnEof && sourceDefinition.ByStreams
                && sourceDefinition.DefinesFold && sourceDefinition.HasCategories())
            {
                return new ParallelQueryProcessingStrategy(
                    name, projectionVersion, stateHandler, handlerFactory, projectionConfig, sourceDefinition,
                    namesBuilder, _logger, _spoolProcessingResponseDispatcher, _subscriptionDispatcher);
            }

            return projectionConfig.StopOnEof
                ? (ProjectionProcessingStrategy)
                    new QueryProcessingStrategy(
                        name, projectionVersion, stateHandler, projectionConfig, sourceDefinition, _logger,
                        _subscriptionDispatcher)
                : new ContinuousProjectionProcessingStrategy(
                    name, projectionVersion, stateHandler, projectionConfig, sourceDefinition, _logger,
                    _subscriptionDispatcher);
        }
 protected override IProjectionProcessingPhase[] CreateProjectionProcessingPhases(
     IPublisher publisher, Guid projectionCorrelationId, ProjectionNamesBuilder namingBuilder,
     PartitionStateCache partitionStateCache, CoreProjection coreProjection, IODispatcher ioDispatcher,
     IProjectionProcessingPhase firstPhase)
 {
     return new[] {firstPhase};
 }
        protected CoreProjectionCheckpointManager(
            IPublisher publisher, Guid projectionCorrelationId, ProjectionConfig projectionConfig, string name,
            PositionTagger positionTagger, ProjectionNamesBuilder namingBuilder, bool usePersistentCheckpoints,
            bool producesRunningResults)
        {
            if (publisher == null) throw new ArgumentNullException("publisher");
            if (projectionConfig == null) throw new ArgumentNullException("projectionConfig");
            if (name == null) throw new ArgumentNullException("name");
            if (positionTagger == null) throw new ArgumentNullException("positionTagger");
            if (namingBuilder == null) throw new ArgumentNullException("namingBuilder");
            if (name == "") throw new ArgumentException("name");

            _lastProcessedEventPosition = new PositionTracker(positionTagger);
            _zeroTag = positionTagger.MakeZeroCheckpointTag();

            _publisher = publisher;
            _projectionCorrelationId = projectionCorrelationId;
            _projectionConfig = projectionConfig;
            _logger = LogManager.GetLoggerFor<CoreProjectionCheckpointManager>();
            _namingBuilder = namingBuilder;
            _usePersistentCheckpoints = usePersistentCheckpoints;
            _producesRunningResults = producesRunningResults;
            _requestedCheckpointState = new PartitionState("", null, _zeroTag);
            _currentProjectionState = new PartitionState("", null, _zeroTag);
        }
        public override sealed IProjectionProcessingPhase[] CreateProcessingPhases(
            IPublisher publisher, Guid projectionCorrelationId, PartitionStateCache partitionStateCache,
            Action updateStatistics, CoreProjection coreProjection, ProjectionNamesBuilder namingBuilder,
            ITimeProvider timeProvider, IODispatcher ioDispatcher,
            CoreProjectionCheckpointWriter coreProjectionCheckpointWriter)
        {
            var definesFold = _sourceDefinition.DefinesFold;

            var readerStrategy = CreateReaderStrategy(timeProvider);

            var zeroCheckpointTag = readerStrategy.PositionTagger.MakeZeroCheckpointTag();

            var checkpointManager = CreateCheckpointManager(
                projectionCorrelationId, publisher, ioDispatcher, namingBuilder, coreProjectionCheckpointWriter,
                definesFold, readerStrategy);


            var resultWriter = CreateFirstPhaseResultWriter(
                checkpointManager as IEmittedEventWriter, zeroCheckpointTag, namingBuilder);

            var firstPhase = CreateFirstProcessingPhase(
                publisher, projectionCorrelationId, partitionStateCache, updateStatistics, coreProjection,
                _subscriptionDispatcher, zeroCheckpointTag, checkpointManager, readerStrategy, resultWriter);

            return CreateProjectionProcessingPhases(
                publisher, projectionCorrelationId, namingBuilder, partitionStateCache, coreProjection, ioDispatcher,
                firstPhase);
        }
 public ParallelQueryProcessingStrategy(
     string name, ProjectionVersion projectionVersion, IProjectionStateHandler stateHandler,
     Func<IProjectionStateHandler> handlerFactory, ProjectionConfig projectionConfig,
     IQueryDefinition sourceDefinition, ProjectionNamesBuilder namesBuilder, ILogger logger,
     SpooledStreamReadingDispatcher spoolProcessingResponseDispatcher,
     ReaderSubscriptionDispatcher subscriptionDispatcher)
     : base(name, projectionVersion, projectionConfig, sourceDefinition, logger, subscriptionDispatcher)
 {
     _stateHandler = stateHandler;
     _projectionConfig = projectionConfig;
     _sourceDefinition = sourceDefinition;
     _namesBuilder = namesBuilder;
     _spoolProcessingResponseDispatcher = spoolProcessingResponseDispatcher;
     if (_sourceDefinition.CatalogStream == SystemStreams.AllStream)
     {
         _catalogStreamName = SystemStreams.AllStream;
     }
     else if (_sourceDefinition.HasCategories())
     {
         _catalogStreamName = _namesBuilder.GetCategoryCatalogStreamName(_sourceDefinition.Categories[0]);
     }
     else
     {
         _catalogStreamName = _sourceDefinition.CatalogStream;
     }
 }
 public override IProjectionProcessingPhase[] CreateProcessingPhases(
     IPublisher publisher, Guid projectionCorrelationId, PartitionStateCache partitionStateCache,
     Action updateStatistics, CoreProjection coreProjection, ProjectionNamesBuilder namingBuilder,
     ITimeProvider timeProvider, IODispatcher ioDispatcher,
     CoreProjectionCheckpointWriter coreProjectionCheckpointWriter)
 {
     return new IProjectionProcessingPhase[] {_phase1, _phase2};
 }
예제 #8
0
 private void Given()
 {
     _projection = "projection";
     _partitionAt = CheckpointTag.FromPosition(100, 50);
     _partition = "partition";
     _namesBuilder = ProjectionNamesBuilder.CreateForTest(_projection);
     _re = new ResultEmitter(_namesBuilder);
 }
 protected override ICoreProjectionCheckpointManager CreateCheckpointManager(
     Guid projectionCorrelationId, IPublisher publisher, IODispatcher ioDispatcher, ProjectionNamesBuilder namingBuilder,
     CoreProjectionCheckpointWriter coreProjectionCheckpointWriter, bool definesFold, IReaderStrategy readerStrategy)
 {
     return new NoopCheckpointManager(
         publisher, projectionCorrelationId, _projectionConfig, _name, readerStrategy.PositionTagger,
         namingBuilder);
 }
 public void setup()
 {
     Given();
     _namingBuilder = ProjectionNamesBuilder.CreateForTest("projection");
     _config = new ProjectionConfig(null, _checkpointHandledThreshold, _checkpointUnhandledBytesThreshold,
         _pendingEventsThreshold, _maxWriteBatchLength, _emitEventEnabled,
         _checkpointsEnabled, _createTempStreams, _stopOnEof, isSlaveProjection: false);
     When();
 }
 public abstract IProjectionProcessingPhase[] CreateProcessingPhases(
     IPublisher publisher,
     IPublisher inputQueue,
     Guid projectionCorrelationId,
     PartitionStateCache partitionStateCache,
     Action updateStatistics,
     CoreProjection coreProjection,
     ProjectionNamesBuilder namingBuilder,
     ITimeProvider timeProvider,
     IODispatcher ioDispatcher,
     CoreProjectionCheckpointWriter coreProjectionCheckpointWriter);
예제 #12
0
 public MultiStreamMultiOutputCheckpointManager(
     IPublisher publisher, Guid projectionCorrelationId, ProjectionVersion projectionVersion, IPrincipal runAs,
     IODispatcher ioDispatcher, ProjectionConfig projectionConfig, string name, PositionTagger positionTagger,
     ProjectionNamesBuilder namingBuilder, bool usePersistentCheckpoints, bool producesRunningResults, bool definesFold,
     CoreProjectionCheckpointWriter coreProjectionCheckpointWriter)
     : base(
         publisher, projectionCorrelationId, projectionVersion, runAs, ioDispatcher, projectionConfig, name,
         positionTagger, namingBuilder, usePersistentCheckpoints, producesRunningResults, definesFold,
         coreProjectionCheckpointWriter)
 {
     _positionTagger = positionTagger;
 }
 public MultiStreamMultiOutputCheckpointManager(
     IPublisher publisher, Guid projectionCorrelationId, ProjectionVersion projectionVersion, IPrincipal runAs,
     IODispatcher ioDispatcher, ProjectionConfig projectionConfig, string name, PositionTagger positionTagger,
     ProjectionNamesBuilder namingBuilder, bool useCheckpoints, bool producesRunningResults, bool definesFold,
     CoreProjectionCheckpointWriter coreProjectionCheckpointWriter)
     : base(
         publisher, projectionCorrelationId, projectionVersion, runAs, ioDispatcher, projectionConfig, name,
         positionTagger, namingBuilder, useCheckpoints, producesRunningResults, definesFold,
         coreProjectionCheckpointWriter)
 {
     _positionTagger = positionTagger;
 }
 public ParallelQueryProcessingStrategy(
     string name, ProjectionVersion projectionVersion, Func<IProjectionStateHandler> handlerFactory,
     ProjectionConfig projectionConfig, IQueryDefinition sourceDefinition, ProjectionNamesBuilder namesBuilder,
     ILogger logger, SpooledStreamReadingDispatcher spoolProcessingResponseDispatcher,
     ReaderSubscriptionDispatcher subscriptionDispatcher)
     : base(name, projectionVersion, projectionConfig, sourceDefinition, logger, subscriptionDispatcher)
 {
     _projectionConfig = projectionConfig;
     _sourceDefinition = sourceDefinition;
     _namesBuilder = namesBuilder;
     _spoolProcessingResponseDispatcher = spoolProcessingResponseDispatcher;
 }
 protected override IProjectionProcessingPhase[] CreateProjectionProcessingPhases(
     IPublisher publisher,
     IPublisher inputQueue,
     Guid projectionCorrelationId,
     ProjectionNamesBuilder namingBuilder,
     PartitionStateCache partitionStateCache,
     CoreProjection coreProjection,
     IODispatcher ioDispatcher,
     IProjectionProcessingPhase firstPhase)
 {
     return(new IProjectionProcessingPhase[] { firstPhase });
 }
예제 #16
0
        public CoreProjection(
            string name, Guid projectionCorrelationId, IPublisher publisher,
            IProjectionStateHandler projectionStateHandler, ProjectionConfig projectionConfig,
            RequestResponseDispatcher
            <ClientMessage.ReadStreamEventsBackward, ClientMessage.ReadStreamEventsBackwardCompleted> readDispatcher,
            RequestResponseDispatcher <ClientMessage.WriteEvents, ClientMessage.WriteEventsCompleted> writeDispatcher,
            ILogger logger = null)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (name == "")
            {
                throw new ArgumentException("name");
            }
            if (publisher == null)
            {
                throw new ArgumentNullException("publisher");
            }
            if (projectionStateHandler == null)
            {
                throw new ArgumentNullException("projectionStateHandler");
            }
            _projectionStateHandler  = projectionStateHandler;
            _projectionCorrelationId = projectionCorrelationId;

            var namingBuilder = new ProjectionNamesBuilder();

            _projectionStateHandler.ConfigureSourceProcessingStrategy(namingBuilder);

            _name = namingBuilder.ForceProjectionName ?? name;
            //TODO: move into name builder
            _stateStreamNamePattern = namingBuilder.StateStreamName ?? ProjectionsStreamPrefix + _name + "-{0}" + ProjectionsStateStreamSuffix;
            _stateStreamName        = namingBuilder.StateStreamName ?? ProjectionsStreamPrefix + _name + ProjectionsStateStreamSuffix;
            _projectionConfig       = projectionConfig;
            _logger          = logger;
            _publisher       = publisher;
            _readDispatcher  = readDispatcher;
            _writeDispatcher = writeDispatcher;
            var builder = new CheckpointStrategy.Builder();

            _projectionStateHandler.ConfigureSourceProcessingStrategy(builder);
            _checkpointStrategy  = builder.Build(_projectionConfig.Mode);
            _partitionStateCache = new PartitionStateCache();
            _processingQueue     = new CoreProjectionQueue(
                projectionCorrelationId, publisher, projectionConfig.PendingEventsThreshold, UpdateStatistics);
            _checkpointManager = this._checkpointStrategy.CreateCheckpointManager(
                this, projectionCorrelationId, this._publisher, this._readDispatcher,
                this._writeDispatcher, this._projectionConfig, this._name, _stateStreamName);
            GoToState(State.Initial);
        }
 protected override void Given()
 {
     _ioDispatcher = new IODispatcher(_node.Node.MainQueue, new PublishEnvelope(_node.Node.MainQueue));
     _node.Node.MainBus.Subscribe(_ioDispatcher.BackwardReader);
     _node.Node.MainBus.Subscribe(_ioDispatcher.ForwardReader);
     _node.Node.MainBus.Subscribe(_ioDispatcher.Writer);
     _node.Node.MainBus.Subscribe(_ioDispatcher.StreamDeleter);
     _node.Node.MainBus.Subscribe(_ioDispatcher.Awaker);
     _node.Node.MainBus.Subscribe(_ioDispatcher);
     _projectionNamesBuilder = ProjectionNamesBuilder.CreateForTest(_projectionName);
     _emittedStreamsTracker = new EmittedStreamsTracker(_ioDispatcher, new ProjectionConfig(null, 1000, 1000 * 1000, 100, 500, true, true, false, false, false, _trackEmittedStreams), _projectionNamesBuilder);
     _emittedStreamsDeleter = new EmittedStreamsDeleter(_ioDispatcher, _projectionNamesBuilder.GetEmittedStreamsName(), _projectionNamesBuilder.GetEmittedStreamsCheckpointName());
 }
예제 #18
0
 public ParallelQueryProcessingStrategy(
     string name, ProjectionVersion projectionVersion, Func <IProjectionStateHandler> handlerFactory,
     ProjectionConfig projectionConfig, IQueryDefinition sourceDefinition, ProjectionNamesBuilder namesBuilder,
     ILogger logger, SpooledStreamReadingDispatcher spoolProcessingResponseDispatcher,
     ReaderSubscriptionDispatcher subscriptionDispatcher)
     : base(name, projectionVersion, projectionConfig, sourceDefinition, logger, subscriptionDispatcher)
 {
     _handlerFactory   = handlerFactory;
     _projectionConfig = projectionConfig;
     _sourceDefinition = sourceDefinition;
     _namesBuilder     = namesBuilder;
     _spoolProcessingResponseDispatcher = spoolProcessingResponseDispatcher;
 }
 public DefaultCheckpointManager(
     ICoreProjection coreProjection, IPublisher publisher, Guid projectionCorrelationId,
     RequestResponseDispatcher
         <ClientMessage.ReadStreamEventsBackward, ClientMessage.ReadStreamEventsBackwardCompleted> readDispatcher,
     RequestResponseDispatcher<ClientMessage.WriteEvents, ClientMessage.WriteEventsCompleted> writeDispatcher,
     ProjectionConfig projectionConfig, string name,
     PositionTagger positionTagger, ProjectionNamesBuilder namingBuilder, bool useCheckpoints,
     bool emitStateUpdated, bool emitPartitionCheckpoints = false)
     : base(
         coreProjection, publisher, projectionCorrelationId, readDispatcher, writeDispatcher, projectionConfig,
         name, positionTagger, namingBuilder, useCheckpoints, emitStateUpdated, emitPartitionCheckpoints)
 {
     _projectionCheckpointStreamId = namingBuilder.MakeCheckpointStreamName();
 }
        protected CoreProjectionCheckpointManager(
            IPublisher publisher, Guid projectionCorrelationId, ProjectionConfig projectionConfig, string name,
            PositionTagger positionTagger, ProjectionNamesBuilder namingBuilder, IResultEmitter resultEmitter,
            bool useCheckpoints, bool emitPartitionCheckpoints)
        {
            if (publisher == null)
            {
                throw new ArgumentNullException("publisher");
            }
            if (projectionConfig == null)
            {
                throw new ArgumentNullException("projectionConfig");
            }
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (positionTagger == null)
            {
                throw new ArgumentNullException("positionTagger");
            }
            if (namingBuilder == null)
            {
                throw new ArgumentNullException("namingBuilder");
            }
            if (resultEmitter == null)
            {
                throw new ArgumentNullException("resultEmitter");
            }
            if (name == "")
            {
                throw new ArgumentException("name");
            }

            _lastProcessedEventPosition = new PositionTracker(positionTagger);
            _zeroTag = positionTagger.MakeZeroCheckpointTag();

            _publisher = publisher;
            _projectionCorrelationId = projectionCorrelationId;
            _projectionConfig        = projectionConfig;
            _logger                   = LogManager.GetLoggerFor <CoreProjectionCheckpointManager>();
            _name                     = name;
            _namingBuilder            = namingBuilder;
            _resultEmitter            = resultEmitter;
            _useCheckpoints           = useCheckpoints;
            _emitPartitionCheckpoints = emitPartitionCheckpoints;
            _requestedCheckpointState = new PartitionState("", null, _zeroTag);
            _currentProjectionState   = new PartitionState("", null, _zeroTag);
        }
 public MultiStreamMultiOutputCheckpointManager(
     IPublisher publisher, Guid projectionCorrelationId, ProjectionVersion projectionVersion, IPrincipal runAs,
     RequestResponseDispatcher
         <ClientMessage.ReadStreamEventsBackward, ClientMessage.ReadStreamEventsBackwardCompleted> readDispatcher,
     RequestResponseDispatcher<ClientMessage.WriteEvents, ClientMessage.WriteEventsCompleted> writeDispatcher,
     ProjectionConfig projectionConfig, string name, PositionTagger positionTagger,
     ProjectionNamesBuilder namingBuilder, IResultEmitter resultEmitter, bool useCheckpoints,
     bool emitPartitionCheckpoints = false)
     : base(
         publisher, projectionCorrelationId, projectionVersion, runAs, readDispatcher, writeDispatcher,
         projectionConfig, name, positionTagger, namingBuilder, resultEmitter, useCheckpoints,
         emitPartitionCheckpoints)
 {
     _positionTagger = positionTagger;
 }
 public MultiStreamMultiOutputCheckpointManager(
     IPublisher publisher, Guid projectionCorrelationId, ProjectionVersion projectionVersion, IPrincipal runAs,
     RequestResponseDispatcher
     <ClientMessage.ReadStreamEventsBackward, ClientMessage.ReadStreamEventsBackwardCompleted> readDispatcher,
     RequestResponseDispatcher <ClientMessage.WriteEvents, ClientMessage.WriteEventsCompleted> writeDispatcher,
     ProjectionConfig projectionConfig, string name, PositionTagger positionTagger,
     ProjectionNamesBuilder namingBuilder, IResultEmitter resultEmitter, bool useCheckpoints,
     bool emitPartitionCheckpoints = false)
     : base(
         publisher, projectionCorrelationId, projectionVersion, runAs, readDispatcher, writeDispatcher,
         projectionConfig, name, positionTagger, namingBuilder, resultEmitter, useCheckpoints,
         emitPartitionCheckpoints)
 {
     _positionTagger = positionTagger;
 }
        public NoopCheckpointManager(
            IPublisher publisher, Guid projectionCorrelationId, ProjectionConfig projectionConfig, string name,
            PositionTagger positionTagger, ProjectionNamesBuilder namingBuilder)
        {
            if (publisher == null) throw new ArgumentNullException("publisher");
            if (projectionConfig == null) throw new ArgumentNullException("projectionConfig");
            if (name == null) throw new ArgumentNullException("name");
            if (positionTagger == null) throw new ArgumentNullException("positionTagger");
            if (namingBuilder == null) throw new ArgumentNullException("namingBuilder");
            if (name == "") throw new ArgumentException("name");

            _lastProcessedEventPosition = new PositionTracker(positionTagger);

            _publisher = publisher;
            _projectionCorrelationId = projectionCorrelationId;
        }
예제 #24
0
        //NOTE: this is only for slave projections (TBD)


        public CoreProjection(
            ProjectionProcessingStrategy projectionProcessingStrategy, ProjectionVersion version,
            Guid projectionCorrelationId, IPublisher inputQueue, IPrincipal runAs, IPublisher publisher, IODispatcher ioDispatcher,
            ReaderSubscriptionDispatcher subscriptionDispatcher, ILogger logger, ProjectionNamesBuilder namingBuilder, CoreProjectionCheckpointWriter coreProjectionCheckpointWriter,
            PartitionStateCache partitionStateCache, string effectiveProjectionName, ITimeProvider timeProvider, bool isSlaveProjection)
        {
            if (publisher == null)
            {
                throw new ArgumentNullException("publisher");
            }
            if (ioDispatcher == null)
            {
                throw new ArgumentNullException("ioDispatcher");
            }
            if (subscriptionDispatcher == null)
            {
                throw new ArgumentNullException("subscriptionDispatcher");
            }

            _projectionProcessingStrategy = projectionProcessingStrategy;
            _projectionCorrelationId      = projectionCorrelationId;
            _inputQueue            = inputQueue;
            _runAs                 = runAs;
            _name                  = effectiveProjectionName;
            _version               = version;
            _stopOnEof             = projectionProcessingStrategy.GetStopOnEof();
            _logger                = logger;
            _publisher             = publisher;
            _partitionStateCache   = partitionStateCache;
            _requiresRootPartition = projectionProcessingStrategy.GetRequiresRootPartition();
            _isSlaveProjection     = isSlaveProjection;
            var useCheckpoints = projectionProcessingStrategy.GetUseCheckpoints();

            _coreProjectionCheckpointWriter = coreProjectionCheckpointWriter;

            _projectionProcessingPhases = projectionProcessingStrategy.CreateProcessingPhases(
                publisher, projectionCorrelationId, partitionStateCache, UpdateStatistics, this, namingBuilder,
                timeProvider, ioDispatcher, coreProjectionCheckpointWriter);


            //NOTE: currently assuming the first checkpoint manager to be able to load any state
            _checkpointReader = new CoreProjectionCheckpointReader(
                publisher, _projectionCorrelationId, ioDispatcher, namingBuilder.MakeCheckpointStreamName(), _version,
                useCheckpoints);
            _enrichStatistics = projectionProcessingStrategy.EnrichStatistics;
            GoToState(State.Initial);
        }
예제 #25
0
        protected override IProjectionProcessingPhase[] CreateProjectionProcessingPhases(
            IPublisher publisher, IPublisher inputQueue, Guid projectionCorrelationId,
            ProjectionNamesBuilder namingBuilder,
            PartitionStateCache partitionStateCache, CoreProjection coreProjection, IODispatcher ioDispatcher,
            IProjectionProcessingPhase firstPhase)
        {
            var coreProjectionCheckpointWriter =
                new CoreProjectionCheckpointWriter(
                    namingBuilder.MakeCheckpointStreamName(), ioDispatcher, _projectionVersion, _name);
            var checkpointManager2 = new DefaultCheckpointManager(
                publisher, projectionCorrelationId, _projectionVersion, SystemAccount.Principal, ioDispatcher,
                _projectionConfig, _name, new PhasePositionTagger(1), namingBuilder, GetUseCheckpoints(), false,
                _sourceDefinition.DefinesFold, coreProjectionCheckpointWriter);

            IProjectionProcessingPhase writeResultsPhase;

            if (GetProducesRunningResults() ||
                !string.IsNullOrEmpty(_sourceDefinition.CatalogStream) && _sourceDefinition.ByStreams)
            {
                writeResultsPhase = new WriteQueryEofProjectionProcessingPhase(
                    publisher,
                    1,
                    namingBuilder.GetResultStreamName(),
                    coreProjection,
                    partitionStateCache,
                    checkpointManager2,
                    checkpointManager2,
                    firstPhase.EmittedStreamsTracker);
            }
            else
            {
                writeResultsPhase = new WriteQueryResultProjectionProcessingPhase(
                    publisher,
                    1,
                    namingBuilder.GetResultStreamName(),
                    coreProjection,
                    partitionStateCache,
                    checkpointManager2,
                    checkpointManager2,
                    firstPhase.EmittedStreamsTracker);
            }

            return(new[] { firstPhase, writeResultsPhase });
        }
        public CoreProjection Create(
            Guid projectionCorrelationId,
            IPublisher inputQueue,
            Guid workerId,
            IPrincipal runAs,
            IPublisher publisher,
            IODispatcher ioDispatcher,
            ReaderSubscriptionDispatcher subscriptionDispatcher,
            ITimeProvider timeProvider)
        {
            if (inputQueue == null) throw new ArgumentNullException("inputQueue");
            //if (runAs == null) throw new ArgumentNullException("runAs");
            if (publisher == null) throw new ArgumentNullException("publisher");
            if (ioDispatcher == null) throw new ArgumentNullException("ioDispatcher");
            if (timeProvider == null) throw new ArgumentNullException("timeProvider");

            var namingBuilder = new ProjectionNamesBuilder(_name, GetSourceDefinition());

            var coreProjectionCheckpointWriter =
                new CoreProjectionCheckpointWriter(
                    namingBuilder.MakeCheckpointStreamName(),
                    ioDispatcher,
                    _projectionVersion,
                    namingBuilder.EffectiveProjectionName);

            var partitionStateCache = new PartitionStateCache();

            return new CoreProjection(
                this,
                _projectionVersion,
                projectionCorrelationId,
                inputQueue,
                workerId,
                runAs,
                publisher,
                ioDispatcher,
                subscriptionDispatcher,
                _logger,
                namingBuilder,
                coreProjectionCheckpointWriter,
                partitionStateCache,
                namingBuilder.EffectiveProjectionName,
                timeProvider);
        }
        protected override IProjectionProcessingPhase[] CreateProjectionProcessingPhases(
            IPublisher publisher,
            IPublisher inputQueue,
            Guid projectionCorrelationId,
            ProjectionNamesBuilder namingBuilder,
            PartitionStateCache partitionStateCache,
            CoreProjection coreProjection,
            IODispatcher ioDispatcher,
            IProjectionProcessingPhase firstPhase)
        {
            var coreProjectionCheckpointWriter =
                new CoreProjectionCheckpointWriter(
                    namingBuilder.MakeCheckpointStreamName(),
                    ioDispatcher,
                    _projectionVersion,
                    _name);
            var checkpointManager2 = new DefaultCheckpointManager(
                publisher,
                projectionCorrelationId,
                _projectionVersion,
                _projectionConfig.RunAs,
                ioDispatcher,
                _projectionConfig,
                _name,
                new PhasePositionTagger(1),
                namingBuilder,
                GetUseCheckpoints(),
                false,
                _sourceDefinition.DefinesFold,
                coreProjectionCheckpointWriter);

            var writeResultsPhase = new WriteQueryEofProjectionProcessingPhase(
                publisher,
                1,
                namingBuilder.GetResultStreamName(),
                coreProjection,
                partitionStateCache,
                checkpointManager2,
                checkpointManager2,
                firstPhase.EmittedStreamsTracker);

            return new[] {firstPhase, writeResultsPhase};
        }
예제 #28
0
 public ProjectionSourceDefinition Build(ProjectionNamesBuilder namingBuilder)
 {
     return(new ProjectionSourceDefinition
     {
         AllEvents = _allEvents,
         AllStreams = _allStreams,
         ByStream = _byStream,
         ByCustomPartitions = _byCustomPartitions,
         Categories = (_categories ?? new List <string>()).ToArray(),
         Events = (_events ?? new List <string>()).ToArray(),
         Streams = (_streams ?? new List <string>()).ToArray(),
         DefinesStateTransform = _definesStateTransform,
         Options = _options,
         ResultStreamName = namingBuilder.GetResultStreamName(),
         PartitionResultStreamNamePattern = namingBuilder.GetPartitionResultStreamNamePattern(),
         PartitionResultCatalogStream = namingBuilder.GetPartitionResultCatalogStreamName(),
         PartitionCatalogStream = namingBuilder.GetPartitionCatalogStreamName(),
     });
 }
		public CoreProjection Create(
			Guid projectionCorrelationId,
			IPublisher inputQueue,
			Guid workerId,
			IPrincipal runAs,
			IPublisher publisher,
			IODispatcher ioDispatcher,
			ReaderSubscriptionDispatcher subscriptionDispatcher,
			ITimeProvider timeProvider) {
			if (inputQueue == null) throw new ArgumentNullException("inputQueue");
			//if (runAs == null) throw new ArgumentNullException("runAs");
			if (publisher == null) throw new ArgumentNullException("publisher");
			if (ioDispatcher == null) throw new ArgumentNullException("ioDispatcher");
			if (timeProvider == null) throw new ArgumentNullException("timeProvider");

			var namingBuilder = new ProjectionNamesBuilder(_name, GetSourceDefinition());

			var coreProjectionCheckpointWriter =
				new CoreProjectionCheckpointWriter(
					namingBuilder.MakeCheckpointStreamName(),
					ioDispatcher,
					_projectionVersion,
					namingBuilder.EffectiveProjectionName);

			var partitionStateCache = new PartitionStateCache();

			return new CoreProjection(
				this,
				_projectionVersion,
				projectionCorrelationId,
				inputQueue,
				workerId,
				runAs,
				publisher,
				ioDispatcher,
				subscriptionDispatcher,
				_logger,
				namingBuilder,
				coreProjectionCheckpointWriter,
				partitionStateCache,
				namingBuilder.EffectiveProjectionName,
				timeProvider);
		}
 public ProjectionSourceDefinition Build(ProjectionNamesBuilder namingBuilder)
 {
     return new ProjectionSourceDefinition
         {
             AllEvents = _allEvents,
             AllStreams = _allStreams,
             ByStream = _byStream,
             ByCustomPartitions = _byCustomPartitions,
             Categories = (_categories ?? new List<string>()).ToArray(),
             Events = (_events ?? new List<string>()).ToArray(),
             Streams = (_streams ?? new List<string>()).ToArray(),
             DefinesStateTransform = _definesStateTransform,
             Options = _options,
             ResultStreamName = namingBuilder.GetResultStreamName(),
             PartitionResultStreamNamePattern = namingBuilder.GetPartitionResultStreamNamePattern(),
             PartitionResultCatalogStream = namingBuilder.GetPartitionResultCatalogStreamName(),
             PartitionCatalogStream = namingBuilder.GetPartitionCatalogStreamName(),
         };
 }
        protected override IProjectionProcessingPhase[] CreateProjectionProcessingPhases(
            IPublisher publisher, Guid projectionCorrelationId, ProjectionNamesBuilder namingBuilder,
            PartitionStateCache partitionStateCache, CoreProjection coreProjection, IODispatcher ioDispatcher,
            IProjectionProcessingPhase firstPhase)
        {
            var coreProjectionCheckpointWriter =
                new CoreProjectionCheckpointWriter(
                    namingBuilder.MakeCheckpointStreamName(), ioDispatcher, _projectionVersion, _name);
            var checkpointManager2 = new DefaultCheckpointManager(
                publisher, projectionCorrelationId, _projectionVersion, _projectionConfig.RunAs, ioDispatcher,
                _projectionConfig, _name, new PhasePositionTagger(1), namingBuilder,
                GetUseCheckpoints(), false, _sourceDefinition.DefinesFold, coreProjectionCheckpointWriter);

            var writeResultsPhase = new WriteQueryEofProjectionProcessingPhase(
                1, namingBuilder.GetResultStreamName(), coreProjection, partitionStateCache, checkpointManager2,
                checkpointManager2);

            return(new[] { firstPhase, writeResultsPhase });
        }
예제 #32
0
        public ParallelQueryProcessingStrategy(
            string name,
            ProjectionVersion projectionVersion,
            IProjectionStateHandler stateHandler,
            ProjectionConfig projectionConfig,
            IQuerySources sourceDefinition,
            string handlerType,
            string query,
            ProjectionNamesBuilder namesBuilder,
            ILogger logger,
            SpooledStreamReadingDispatcher spoolProcessingResponseDispatcher,
            ReaderSubscriptionDispatcher subscriptionDispatcher)
            : base(name, projectionVersion, projectionConfig, sourceDefinition, logger, subscriptionDispatcher)
        {
            if (string.IsNullOrEmpty(handlerType))
            {
                throw new ArgumentNullException("handlerType");
            }
            if (string.IsNullOrEmpty(query))
            {
                throw new ArgumentNullException("query");
            }

            _stateHandler     = stateHandler;
            _projectionConfig = projectionConfig;
            _sourceDefinition = sourceDefinition;
            _handlerType      = handlerType;
            _query            = query;
            _namesBuilder     = namesBuilder;
            _spoolProcessingResponseDispatcher = spoolProcessingResponseDispatcher;
            if (_sourceDefinition.CatalogStream == SystemStreams.AllStream)
            {
                _catalogStreamName = SystemStreams.AllStream;
            }
            else if (_sourceDefinition.HasCategories())
            {
                _catalogStreamName = _namesBuilder.GetCategoryCatalogStreamName(_sourceDefinition.Categories[0]);
            }
            else
            {
                _catalogStreamName = _sourceDefinition.CatalogStream;
            }
        }
 public DefaultCheckpointManager(
     IPublisher publisher, Guid projectionCorrelationId, ProjectionVersion projectionVersion, IPrincipal runAs,
     IODispatcher ioDispatcher, ProjectionConfig projectionConfig, string name, PositionTagger positionTagger,
     ProjectionNamesBuilder namingBuilder, bool usePersistentCheckpoints, bool producesRunningResults, bool definesFold,
     CoreProjectionCheckpointWriter coreProjectionCheckpointWriter)
     : base(
         publisher, projectionCorrelationId, projectionConfig, name, positionTagger, namingBuilder,
         usePersistentCheckpoints)
 {
     if (ioDispatcher == null)
     {
         throw new ArgumentNullException("ioDispatcher");
     }
     _projectionVersion = projectionVersion;
     _runAs             = runAs;
     _ioDispatcher      = ioDispatcher;
     _positionTagger    = positionTagger;
     _coreProjectionCheckpointWriter = coreProjectionCheckpointWriter;
     _zeroTag = positionTagger.MakeZeroCheckpointTag();
 }
예제 #34
0
        public static ProjectionSourceDefinition From(
            string name, IQuerySources sources, string handlerType, string query)
        {
            var namingBuilder = new ProjectionNamesBuilder(name, sources);

            return(new ProjectionSourceDefinition
            {
                AllEvents = sources.AllEvents,
                AllStreams = sources.AllStreams,
                ByStream = sources.ByStreams,
                ByCustomPartitions = sources.ByCustomPartitions,
                Categories = (sources.Categories ?? new string[0]).ToArray(),
                Events = (sources.Events ?? new string[0]).ToArray(),
                Streams = (sources.Streams ?? new string[0]).ToArray(),
                CatalogStream = sources.CatalogStream,
                LimitingCommitPosition = sources.LimitingCommitPosition,
                Options =
                    new QuerySourceOptions
                {
                    DefinesStateTransform = sources.DefinesStateTransform,
                    DefinesCatalogTransform = sources.DefinesCatalogTransform,
                    ProducesResults = sources.ProducesResults,
                    DefinesFold = sources.DefinesFold,
                    HandlesDeletedNotifications = sources.HandlesDeletedNotifications,
                    ForceProjectionName = sources.ForceProjectionNameOption,
                    IncludeLinks = sources.IncludeLinksOption,
                    DisableParallelism = sources.DisableParallelismOption,
                    PartitionResultStreamNamePattern = sources.PartitionResultStreamNamePatternOption,
                    ProcessingLag = sources.ProcessingLagOption.GetValueOrDefault(),
                    IsBiState = sources.IsBiState,
                    ReorderEvents = sources.ReorderEventsOption,
                    ResultStreamName = sources.ResultStreamNameOption,
                },
                ResultStreamName = namingBuilder.GetResultStreamName(),
                PartitionResultStreamNamePattern = namingBuilder.GetPartitionResultStreamNamePattern(),
                PartitionResultCatalogStream = namingBuilder.GetPartitionResultCatalogStreamName(),
                PartitionCatalogStream = namingBuilder.GetPartitionCatalogStreamName(),
                HandlerType = handlerType,
                Query = query
            });
        }
예제 #35
0
        public void Handle(CoreProjectionManagementMessage.CreateAndPrepare message)
        {
            try
            {
                //TODO: factory method can throw
                var stateHandler = CreateStateHandler(
                    _timeoutScheduler,
                    _logger,
                    message.HandlerType,
                    message.Query);

                string name             = message.Name;
                var    sourceDefinition = ProjectionSourceDefinition.From(stateHandler.GetSourceDefinition());

                var projectionVersion = message.Version;
                var projectionConfig  = message.Config;
                var namesBuilder      = new ProjectionNamesBuilder(name, sourceDefinition);

                var projectionProcessingStrategy = _processingStrategySelector.CreateProjectionProcessingStrategy(
                    name,
                    projectionVersion,
                    namesBuilder,
                    sourceDefinition,
                    projectionConfig,
                    stateHandler,
                    message.HandlerType,
                    message.Query);

                CreateCoreProjection(message.ProjectionId, projectionConfig.RunAs, projectionProcessingStrategy);
                _publisher.Publish(
                    new CoreProjectionStatusMessage.Prepared(
                        message.ProjectionId, sourceDefinition));
            }
            catch (Exception ex)
            {
                _publisher.Publish(
                    new CoreProjectionStatusMessage.Faulted(message.ProjectionId, ex.Message));
            }
        }
 public DefaultCheckpointManager(
     IPublisher publisher, Guid projectionCorrelationId, ProjectionVersion projectionVersion, IPrincipal runAs,
     RequestResponseDispatcher
         <ClientMessage.ReadStreamEventsBackward, ClientMessage.ReadStreamEventsBackwardCompleted> readDispatcher,
     RequestResponseDispatcher<ClientMessage.WriteEvents, ClientMessage.WriteEventsCompleted> writeDispatcher,
     ProjectionConfig projectionConfig, string name, PositionTagger positionTagger,
     ProjectionNamesBuilder namingBuilder, IResultEmitter resultEmitter, bool useCheckpoints,
     bool emitPartitionCheckpoints = false)
     : base(
         publisher, projectionCorrelationId, projectionConfig, name, positionTagger, namingBuilder, resultEmitter,
         useCheckpoints, emitPartitionCheckpoints)
 {
     if (readDispatcher == null) throw new ArgumentNullException("readDispatcher");
     if (writeDispatcher == null) throw new ArgumentNullException("writeDispatcher");
     _projectionVersion = projectionVersion;
     _runAs = runAs;
     _readDispatcher = readDispatcher;
     _writeDispatcher = writeDispatcher;
     _positionTagger = positionTagger;
     _projectionCheckpointStreamId = namingBuilder.MakeCheckpointStreamName();
     _zeroTag = positionTagger.MakeZeroCheckpointTag();
 }
        public ParallelQueryProcessingStrategy(
            string name,
            ProjectionVersion projectionVersion,
            IProjectionStateHandler stateHandler,
            ProjectionConfig projectionConfig,
            IQuerySources sourceDefinition,
            string handlerType,
            string query,
            ProjectionNamesBuilder namesBuilder,
            ILogger logger,
            SpooledStreamReadingDispatcher spoolProcessingResponseDispatcher,
            ReaderSubscriptionDispatcher subscriptionDispatcher)
            : base(name, projectionVersion, projectionConfig, sourceDefinition, logger, subscriptionDispatcher)
        {
            if (string.IsNullOrEmpty(handlerType)) throw new ArgumentNullException("handlerType");
            if (string.IsNullOrEmpty(query)) throw new ArgumentNullException("query");

            _stateHandler = stateHandler;
            _projectionConfig = projectionConfig;
            _sourceDefinition = sourceDefinition;
            _handlerType = handlerType;
            _query = query;
            _namesBuilder = namesBuilder;
            _spoolProcessingResponseDispatcher = spoolProcessingResponseDispatcher;
            if (_sourceDefinition.CatalogStream == SystemStreams.AllStream)
            {
                _catalogStreamName = SystemStreams.AllStream;
            }
            else if (_sourceDefinition.HasCategories())
            {
                _catalogStreamName = _namesBuilder.GetCategoryCatalogStreamName(_sourceDefinition.Categories[0]);
            }
            else
            {
                _catalogStreamName = _sourceDefinition.CatalogStream;
            }
        }
예제 #38
0
 protected abstract IProjectionProcessingPhase[] CreateProjectionProcessingPhases(
     IPublisher publisher, Guid projectionCorrelationId, ProjectionNamesBuilder namingBuilder,
     PartitionStateCache partitionStateCache, CoreProjection coreProjection, IODispatcher ioDispatcher,
     IProjectionProcessingPhase firstPhase);
 protected override IResultWriter CreateFirstPhaseResultWriter(
     IEmittedEventWriter emittedEventWriter, CheckpointTag zeroCheckpointTag,
     ProjectionNamesBuilder namingBuilder)
 {
     return new SlaveResultWriter(_resultsPublisher, _masterCoreProjectionId);
 }
 protected override IResultEventEmitter CreateFirstPhaseResultEmitter(ProjectionNamesBuilder namingBuilder)
 {
     throw new NotImplementedException();
 }
예제 #41
0
 protected override IResultWriter CreateFirstPhaseResultWriter(
     IEmittedEventWriter emittedEventWriter, CheckpointTag zeroCheckpointTag,
     ProjectionNamesBuilder namingBuilder)
 {
     return new SlaveResultWriter(_resultsPublisher, _masterCoreProjectionId);
 }
예제 #42
0
 protected override IResultEventEmitter CreateFirstPhaseResultEmitter(ProjectionNamesBuilder namingBuilder)
 {
     return(_sourceDefinition.ProducesResults
         ? new ResultEventEmitter(namingBuilder)
         : (IResultEventEmitter) new NoopResultEventEmitter());
 }
예제 #43
0
 protected override ICoreProjectionCheckpointManager CreateCheckpointManager(
     Guid projectionCorrelationId, IPublisher publisher, IODispatcher ioDispatcher, ProjectionNamesBuilder namingBuilder,
     CoreProjectionCheckpointWriter coreProjectionCheckpointWriter, bool definesFold, IReaderStrategy readerStrategy)
 {
     return new NoopCheckpointManager(
         publisher, projectionCorrelationId, _projectionConfig, _name, readerStrategy.PositionTagger,
         namingBuilder);
 }
예제 #44
0
 public EmittedStreamsTracker(IODispatcher ioDispatcher, ProjectionConfig projectionConfig, ProjectionNamesBuilder projectionNamesBuilder)
 {
     _ioDispatcher           = ioDispatcher;
     _projectionConfig       = projectionConfig;
     _projectionNamesBuilder = projectionNamesBuilder;
 }
예제 #45
0
        public ProjectionProcessingStrategy CreateProjectionProcessingStrategy(
            string name,
            ProjectionVersion projectionVersion,
            ProjectionNamesBuilder namesBuilder,
            IQuerySources sourceDefinition,
            ProjectionConfig projectionConfig,
            IProjectionStateHandler stateHandler, string handlerType, string query)
        {
            if (!sourceDefinition.DisableParallelismOption && projectionConfig.StopOnEof && sourceDefinition.ByStreams &&
                sourceDefinition.DefinesFold && !string.IsNullOrEmpty(sourceDefinition.CatalogStream))
            {
                return(new ParallelQueryProcessingStrategy(
                           name,
                           projectionVersion,
                           stateHandler,
                           projectionConfig,
                           sourceDefinition,
                           handlerType,
                           query,
                           namesBuilder,
                           _logger,
                           _spoolProcessingResponseDispatcher,
                           _subscriptionDispatcher));
            }

            if (!sourceDefinition.DisableParallelismOption && projectionConfig.StopOnEof && sourceDefinition.ByStreams &&
                sourceDefinition.DefinesFold && sourceDefinition.HasCategories())
            {
                return(new ParallelQueryProcessingStrategy(
                           name,
                           projectionVersion,
                           stateHandler,
                           projectionConfig,
                           sourceDefinition,
                           handlerType,
                           query,
                           namesBuilder,
                           _logger,
                           _spoolProcessingResponseDispatcher,
                           _subscriptionDispatcher));
            }

            return(projectionConfig.StopOnEof
                                ? (ProjectionProcessingStrategy)
                   new QueryProcessingStrategy(
                       name,
                       projectionVersion,
                       stateHandler,
                       projectionConfig,
                       sourceDefinition,
                       _logger,
                       _subscriptionDispatcher)
                                : new ContinuousProjectionProcessingStrategy(
                       name,
                       projectionVersion,
                       stateHandler,
                       projectionConfig,
                       sourceDefinition,
                       _logger,
                       _subscriptionDispatcher));
        }
예제 #46
0
 protected abstract IResultEventEmitter CreateFirstPhaseResultEmitter(ProjectionNamesBuilder namingBuilder);
예제 #47
0
 protected override IResultEventEmitter CreateFirstPhaseResultEmitter(ProjectionNamesBuilder namingBuilder)
 {
     return new ResultEventEmitter(namingBuilder);
 }
        private IEnumerable <IODispatcherAsync.Step> ControlSteps(Guid instanceCorrelationId)
        {
            long fromEventNumber = 0;

            Log.Debug("PROJECTIONS: Starting read {stream}", ProjectionNamesBuilder.BuildControlStreamName(instanceCorrelationId));

            long subscribeFrom = 0;

            while (!_stopped)
            {
                ClientMessage.ReadStreamEventsForwardCompleted readResultForward = null;
                var success = false;
                while (!success)
                {
                    yield return
                        (_ioDispatcher.BeginReadForward(
                             _cancellationScope,
                             ProjectionNamesBuilder.BuildControlStreamName(instanceCorrelationId),
                             fromEventNumber,
                             1,
                             false,
                             SystemAccount.Principal,
                             completed => {
                        readResultForward = completed;
                        success = true;
                    },
                             () => Log.Warn("Read forward of stream {stream} timed out. Retrying",
                                            ProjectionNamesBuilder.BuildControlStreamName(instanceCorrelationId))));
                }

                if (readResultForward.Result != ReadStreamResult.Success &&
                    readResultForward.Result != ReadStreamResult.NoStream)
                {
                    throw new Exception("Control reader failed. Read result: " + readResultForward.Result);
                }
                if (readResultForward.Events != null && readResultForward.Events.Length > 0)
                {
                    var doWriteRegistration =
                        readResultForward.Events.Any(v => v.Event.EventType == "$response-reader-started");
                    fromEventNumber = readResultForward.NextEventNumber;
                    subscribeFrom   = readResultForward.TfLastCommitPosition;
                    if (doWriteRegistration)
                    {
                        var events = new[] {
                            new Event(
                                Guid.NewGuid(), "$projection-worker-started", true,
                                "{\"id\":\"" + _coreServiceId + "\"}", null)
                        };
                        yield return
                            (_ioDispatcher.BeginWriteEvents(
                                 _cancellationScope,
                                 ProjectionNamesBuilder._projectionsMasterStream,
                                 ExpectedVersion.Any,
                                 SystemAccount.Principal,
                                 events,
                                 r => { }));
                    }

                    break;
                }

                if (readResultForward.Result == ReadStreamResult.Success)
                {
                    subscribeFrom = readResultForward.TfLastCommitPosition;
                }

                yield return
                    (_ioDispatcher.BeginSubscribeAwake(
                         _cancellationScope,
                         ProjectionNamesBuilder.BuildControlStreamName(instanceCorrelationId),
                         new TFPos(subscribeFrom, subscribeFrom),
                         message => { }));
            }
        }
예제 #49
0
        public ICoreProjectionCheckpointManager CreateCheckpointManager(
            Guid projectionCorrelationId, ProjectionVersion projectionVersion, IPublisher publisher,
            RequestResponseDispatcher
                <ClientMessage.ReadStreamEventsBackward, ClientMessage.ReadStreamEventsBackwardCompleted> readDispatcher,
            RequestResponseDispatcher<ClientMessage.WriteEvents, ClientMessage.WriteEventsCompleted> writeDispatcher,
            ProjectionConfig projectionConfig, string name, ProjectionNamesBuilder namingBuilder)
        {
            var emitAny = projectionConfig.EmitEventEnabled;
            var emitPartitionCheckpoints = UseCheckpoints && (_byCustomPartitions || _byStream);
            var resultEmitter = _definesStateTransform
                                    ? new ResultEmitter(namingBuilder)
                                    : (IResultEmitter) new NoopResultEmitter();

            //NOTE: not emitting one-time/transient projections are always handled by default checkpoint manager
            // as they don't depend on stable event order
            if (emitAny && !ReaderStrategy.IsReadingOrderRepeatable)
            {
                return new MultiStreamMultiOutputCheckpointManager(
                    publisher, projectionCorrelationId, projectionVersion, _runAs, readDispatcher, writeDispatcher,
                    projectionConfig, name, ReaderStrategy.PositionTagger, namingBuilder, resultEmitter, UseCheckpoints,
                    emitPartitionCheckpoints);
            }
            else
            {
                return new DefaultCheckpointManager(
                    publisher, projectionCorrelationId, projectionVersion, _runAs, readDispatcher, writeDispatcher,
                    projectionConfig, name, ReaderStrategy.PositionTagger, namingBuilder, resultEmitter, UseCheckpoints,
                    emitPartitionCheckpoints);
            }
        }
예제 #50
0
 public ResultEventEmitter(ProjectionNamesBuilder namesBuilder)
 {
     if (namesBuilder == null) throw new ArgumentNullException("namesBuilder");
     _namesBuilder = namesBuilder;
 }
 protected abstract IProjectionProcessingPhase[] CreateProjectionProcessingPhases(
     IPublisher publisher,
     IPublisher inputQueue,
     Guid projectionCorrelationId,
     ProjectionNamesBuilder namingBuilder,
     PartitionStateCache partitionStateCache,
     CoreProjection coreProjection,
     IODispatcher ioDispatcher,
     IProjectionProcessingPhase firstPhase);
예제 #52
0
 protected override IResultEventEmitter CreateFirstPhaseResultEmitter(ProjectionNamesBuilder namingBuilder)
 {
     throw new NotImplementedException();
 }
예제 #53
0
 protected override IResultEventEmitter CreateFirstPhaseResultEmitter(ProjectionNamesBuilder namingBuilder)
 {
     return(new ResultEventEmitter(namingBuilder));
 }
        protected virtual ICoreProjectionCheckpointManager CreateCheckpointManager(
            Guid projectionCorrelationId, IPublisher publisher, IODispatcher ioDispatcher,
            ProjectionNamesBuilder namingBuilder, CoreProjectionCheckpointWriter coreProjectionCheckpointWriter,
            bool definesFold, IReaderStrategy readerStrategy)
        {
            var emitAny = _projectionConfig.EmitEventEnabled;

            //NOTE: not emitting one-time/transient projections are always handled by default checkpoint manager
            // as they don't depend on stable event order
            if (emitAny && !readerStrategy.IsReadingOrderRepeatable)
            {
                return new MultiStreamMultiOutputCheckpointManager(
                    publisher, projectionCorrelationId, _projectionVersion, _projectionConfig.RunAs, ioDispatcher,
                    _projectionConfig, _name, readerStrategy.PositionTagger, namingBuilder,
                    _projectionConfig.CheckpointsEnabled, GetProducesRunningResults(), definesFold,
                    coreProjectionCheckpointWriter);
            }
            else
            {
                return new DefaultCheckpointManager(
                    publisher, projectionCorrelationId, _projectionVersion, _projectionConfig.RunAs, ioDispatcher,
                    _projectionConfig, _name, readerStrategy.PositionTagger, namingBuilder,
                    _projectionConfig.CheckpointsEnabled, GetProducesRunningResults(), definesFold,
                    coreProjectionCheckpointWriter);
            }
        }
 public abstract IProjectionProcessingPhase[] CreateProcessingPhases(
     IPublisher publisher, Guid projectionCorrelationId, PartitionStateCache partitionStateCache,
     Action updateStatistics, CoreProjection coreProjection, ProjectionNamesBuilder namingBuilder,
     ITimeProvider timeProvider, IODispatcher ioDispatcher,
     CoreProjectionCheckpointWriter coreProjectionCheckpointWriter);
 protected virtual IResultWriter CreateFirstPhaseResultWriter(
     IEmittedEventWriter emittedEventWriter, CheckpointTag zeroCheckpointTag,
     ProjectionNamesBuilder namingBuilder)
 {
     return new ResultWriter(
         CreateFirstPhaseResultEmitter(namingBuilder), emittedEventWriter, GetProducesRunningResults(),
         zeroCheckpointTag, namingBuilder.GetPartitionCatalogStreamName());
 }