コード例 #1
0
        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);
        }
コード例 #2
0
        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};
        }
コード例 #3
0
        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));
        }
コード例 #4
0
        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 });
        }
コード例 #5
0
        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));
            }
        }
コード例 #6
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);
 }
 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
 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);
 }
 protected override void When()
 {
     // do not create
     _coreProjectionCheckpointWriter =
         new CoreProjectionCheckpointWriter(
             _namingBuilder.MakeCheckpointStreamName(), _ioDispatcher, _projectionVersion, _projectionName);
     _namingBuilder = ProjectionNamesBuilder.CreateForTest("projection");
 }
コード例 #10
0
        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));
        }
コード例 #11
0
 public abstract IProjectionProcessingPhase[] CreateProcessingPhases(
     IPublisher publisher,
     IPublisher inputQueue,
     Guid projectionCorrelationId,
     PartitionStateCache partitionStateCache,
     Action updateStatistics,
     CoreProjection coreProjection,
     ProjectionNamesBuilder namingBuilder,
     ITimeProvider timeProvider,
     IODispatcher ioDispatcher,
     CoreProjectionCheckpointWriter coreProjectionCheckpointWriter);
 protected new virtual void When()
 {
     _projectionVersion = new ProjectionVersion(1, 0, 0);
     _projectionName = "projection";
     _checkpointWriter = new CoreProjectionCheckpointWriter(
         _namingBuilder.MakeCheckpointStreamName(), _ioDispatcher, _projectionVersion, _projectionName);
     _checkpointReader = new CoreProjectionCheckpointReader(
         GetInputQueue(), _projectionCorrelationId, _ioDispatcher, _projectionCheckpointStreamId,
         _projectionVersion, _checkpointsEnabled);
     _manager = GivenCheckpointManager();
 }
コード例 #13
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;
 }
コード例 #15
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);
        }
コード例 #16
0
        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);
        }
コード例 #17
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())
            {
                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 });
        }
コード例 #18
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,
                _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};
        }
コード例 #19
0
 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();
 }
コード例 #20
0
 public abstract IProjectionProcessingPhase[] CreateProcessingPhases(
     IPublisher publisher, Guid projectionCorrelationId, PartitionStateCache partitionStateCache,
     Action updateStatistics, CoreProjection coreProjection, ProjectionNamesBuilder namingBuilder,
     ITimeProvider timeProvider, IODispatcher ioDispatcher,
     CoreProjectionCheckpointWriter coreProjectionCheckpointWriter);
コード例 #21
0
        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);
            }
        }