예제 #1
0
        public async Task <long> Start(ProjectionDaemon daemon)
        {
            if (daemon.Database.Identifier != "Marten")
            {
                ProjectionShardIdentity = $"{ProjectionShardIdentity}@{daemon.Database.Identifier}";
            }

            _logger.LogInformation("Starting projection agent for '{ProjectionShardIdentity}'", ProjectionShardIdentity);

            _sessionOptions = SessionOptions.ForDatabase(daemon.Database);

            initializeDataflowBlocks(daemon);

            var lastCommitted = await daemon.Database.ProjectionProgressFor(_projectionShard.Name, _cancellation).ConfigureAwait(false);

            foreach (var storageType in _source.Options.StorageTypes)
            {
                await daemon.Database.EnsureStorageExistsAsync(storageType, _cancellation).ConfigureAwait(false);
            }

            foreach (var publishedType in _source.PublishedTypes())
            {
                await daemon.Database.EnsureStorageExistsAsync(publishedType, _cancellation).ConfigureAwait(false);
            }

            _subscription = _tracker.Subscribe(this);
            _commandBlock.Post(Command.Started(_tracker.HighWaterMark, lastCommitted));

            _logger.LogInformation("Projection agent for '{ProjectionShardIdentity}' has started from sequence {LastCommitted} and a high water mark of {HighWaterMark}", ProjectionShardIdentity, lastCommitted, _tracker.HighWaterMark);

            Status = AgentStatus.Running;

            Position = lastCommitted;
            return(lastCommitted);
        }
예제 #2
0
        private void initializeDataflowBlocks(ProjectionDaemon daemon)
        {
            var singleFileOptions = new ExecutionDataflowBlockOptions
            {
                EnsureOrdered          = true,
                MaxDegreeOfParallelism = 1,
                CancellationToken      = _cancellation,
            };

            _commandBlock = new ActionBlock <Command>(command => command.Apply(_controller), singleFileOptions);
            _loader       = new TransformBlock <EventRange, EventRange>(loadEvents, singleFileOptions);

            _tracker = daemon.Tracker;
            _daemon  = daemon;

            _fetcher  = new EventFetcher(_store, _daemon.Database, _projectionShard.EventFilters);
            _grouping = new TransformBlock <EventRange, EventRangeGroup>(groupEventRange, singleFileOptions);

            _building = new ActionBlock <EventRangeGroup>(processRange, singleFileOptions);

            _grouping.LinkTo(_building);

            // The filter is important. You may need to allow an empty page to go through
            // just to keep tracking correct
            _loader.LinkTo(_grouping, e => e.Events != null);
        }
예제 #3
0
        public async Task <long> Start(ProjectionDaemon daemon)
        {
            _logger.LogInformation("Starting projection agent for '{ShardName}'", _projectionShard.Name);

            var singleFile = new ExecutionDataflowBlockOptions
            {
                EnsureOrdered          = true,
                MaxDegreeOfParallelism = 1,
                CancellationToken      = _cancellation,
            };

            _commandBlock = new ActionBlock <Command>(processCommand, singleFile);
            _loader       = new TransformBlock <EventRange, EventRange>(loadEvents, singleFile);

            _tracker = daemon.Tracker;
            _daemon  = daemon;


            _fetcher = new EventFetcher(_store, _projectionShard.EventFilters);
            _hopper  = _projectionShard.Start(this, _logger, _cancellation);
            _loader.LinkTo(_hopper, e => e.Events.Any());

            var lastCommitted = await _store.Advanced.ProjectionProgressFor(_projectionShard.Name, _cancellation);

            _commandBlock.Post(Command.Started(_tracker.HighWaterMark, lastCommitted));

            _subscription = _tracker.Subscribe(this);

            _logger.LogInformation("Projection agent for '{ShardName}' has started from sequence {LastCommitted} and a high water mark of {HighWaterMark}", _projectionShard.Name, lastCommitted, _tracker.HighWaterMark);

            Status = AgentStatus.Running;

            Position = lastCommitted;
            return(lastCommitted);
        }
예제 #4
0
        public async Task<long> Start(ProjectionDaemon daemon)
        {
            _logger.LogInformation("Starting projection agent for '{ShardName}'", _projectionShard.Name);

            var singleFileOptions = new ExecutionDataflowBlockOptions
            {
                EnsureOrdered = true,
                MaxDegreeOfParallelism = 1,
                CancellationToken = _cancellation,
            };

            _commandBlock = new ActionBlock<Command>(processCommand, singleFileOptions);
            _loader = new TransformBlock<EventRange, EventRange>(loadEvents, singleFileOptions);

            _tracker = daemon.Tracker;
            _daemon = daemon;


            _fetcher = new EventFetcher(_store, _projectionShard.EventFilters);
            _grouping = new TransformBlock<EventRange, EventRangeGroup>(groupEventRange, singleFileOptions);


            _building = new ActionBlock<EventRangeGroup>(processRange, singleFileOptions);

            _grouping.LinkTo(_building);

            // The filter is important. You may need to allow an empty page to go through
            // just to keep tracking correct
            _loader.LinkTo(_grouping, e => e.Events != null);

            var lastCommitted = await _store.Advanced.ProjectionProgressFor(_projectionShard.Name, _cancellation);

            foreach (var storageType in _source.Options.StorageTypes)
            {
                await _store.Tenancy.Default.EnsureStorageExistsAsync(storageType, _cancellation);
            }

            _commandBlock.Post(Command.Started(_tracker.HighWaterMark, lastCommitted));

            _subscription = _tracker.Subscribe(this);

            _logger.LogInformation("Projection agent for '{ShardName}' has started from sequence {LastCommitted} and a high water mark of {HighWaterMark}", _projectionShard.Name, lastCommitted, _tracker.HighWaterMark);

            Status = AgentStatus.Running;

            Position = lastCommitted;
            return lastCommitted;
        }
예제 #5
0
        public async Task <long> Start(ProjectionDaemon daemon)
        {
            _logger.LogInformation("Starting projection agent for '{ShardName}'", _projectionShard.Name);

            var singleFileOptions = new ExecutionDataflowBlockOptions
            {
                EnsureOrdered          = true,
                MaxDegreeOfParallelism = 1,
                CancellationToken      = _cancellation,
            };

            _commandBlock = new ActionBlock <Command>(processCommand, singleFileOptions);
            _loader       = new TransformBlock <EventRange, EventRange>(loadEvents, singleFileOptions);

            _tracker = daemon.Tracker;
            _daemon  = daemon;


            _fetcher  = new EventFetcher(_store, _projectionShard.EventFilters);
            _grouping = new TransformBlock <EventRange, EventRangeGroup>(groupEventRange, singleFileOptions);


            _building = new ActionBlock <EventRangeGroup>(processRange, singleFileOptions);

            _grouping.LinkTo(_building);
            _loader.LinkTo(_grouping, e => e.Events.Any());

            var lastCommitted = await _store.Advanced.ProjectionProgressFor(_projectionShard.Name, _cancellation);

            foreach (var storageType in _source.Options.StorageTypes)
            {
                // TODO -- this will have to get fancier when we do multi-tenancy by database
                _store.Tenancy.Default.EnsureStorageExists(storageType);
            }

            _commandBlock.Post(Command.Started(_tracker.HighWaterMark, lastCommitted));

            _subscription = _tracker.Subscribe(this);

            _logger.LogInformation("Projection agent for '{ShardName}' has started from sequence {LastCommitted} and a high water mark of {HighWaterMark}", _projectionShard.Name, lastCommitted, _tracker.HighWaterMark);

            Status = AgentStatus.Running;

            Position = lastCommitted;
            return(lastCommitted);
        }