コード例 #1
0
        protected override Task configureUpdateBatch(ProjectionUpdateBatch batch, TenantedEventRange group,
                                                     CancellationToken token)
        {
            var tasks = group.Groups.Select(x => x.ApplyEvents(batch, _projection, Store, token)).ToArray();

            return(Task.WhenAll(tasks));
        }
コード例 #2
0
        public async Task ExecuteBatch(ProjectionUpdateBatch batch)
        {
            await batch.Queue.Completion;

            using (var session = (DocumentSessionBase)_store.LightweightSession())
            {
                try
                {
                    await session.ExecuteBatchAsync(batch, _cancellationSource.Token);

                    _logger.LogInformation($"Shard '{ProjectionOrShardName}': Executed updates for {batch.Range}");
                }
                catch (Exception e)
                {
                    _logger.LogError(e, $"Failure in shard '{ProjectionOrShardName}' trying to execute an update batch for {batch.Range}");
                    // TODO -- error handling

                    throw;
                }
            }

            batch.Dispose();


            Position = batch.Range.SequenceCeiling;


            _tracker.Publish(new ShardState(ProjectionOrShardName, batch.Range.SequenceCeiling));

            _commandBlock.Post(Command.Completed(batch.Range));
        }
コード例 #3
0
        public override Task ConfigureUpdateBatch(IShardAgent shardAgent, ProjectionUpdateBatch batch,
                                                  EventRangeGroup eventRangeGroup)
        {
            var tasks = Groups
                        .Select(tenantGroup => tenantGroup.ApplyEvents(batch, _projection, _store, Cancellation)).ToArray();

            return(Task.WhenAll(tasks));
        }
コード例 #4
0
ファイル: ShardAgent.cs プロジェクト: cocowalla/marten
        public async Task ExecuteBatch(ProjectionUpdateBatch batch)
        {
            if (_cancellation.IsCancellationRequested || batch == null)
            {
                return;
            }

            await batch.Queue.Completion.ConfigureAwait(false);

            if (_cancellation.IsCancellationRequested)
            {
                return;
            }

            var session = (DocumentSessionBase)_store.OpenSession(_sessionOptions);

            await using (session.ConfigureAwait(false))
            {
                try
                {
                    await session.ExecuteBatchAsync(batch, _cancellation).ConfigureAwait(false);

                    _logger.LogInformation("Shard '{ProjectionShardIdentity}': Executed updates for {Range}", ProjectionShardIdentity, batch.Range);
                }
                catch (Exception e)
                {
                    if (!_cancellation.IsCancellationRequested)
                    {
                        _logger.LogError(e,
                                         "Failure in shard '{ProjectionShardIdentity}' trying to execute an update batch for {Range}", ProjectionShardIdentity,
                                         batch.Range);
                        throw;
                    }
                }
                finally
                {
                    batch.Dispose();
                }
            }

            batch.Dispose();

            if (_cancellation.IsCancellationRequested)
            {
                return;
            }

            Position = batch.Range.SequenceCeiling;

            _tracker.Publish(new ShardState(ShardName, batch.Range.SequenceCeiling)
            {
                Action = ShardAction.Updated
            });

            _commandBlock.Post(Command.Completed(batch.Range));
        }
コード例 #5
0
        public Task ApplyEvents(ProjectionUpdateBatch batch, IProjection projection, DocumentStore store,
                                CancellationToken cancellationToken)
        {
            return(Task.Run(async() =>
            {
                await using var operations = new ProjectionDocumentSession(store, _tenant, batch);

                await projection.ApplyAsync(operations, _actions, cancellationToken);
            }, cancellationToken));
        }
コード例 #6
0
ファイル: ShardAgent.cs プロジェクト: cocowalla/marten
        private async Task processRange(EventRangeGroup group)
        {
            if (_cancellation.IsCancellationRequested)
            {
                return;
            }

            if (_logger.IsEnabled(LogLevel.Debug))
            {
                _logger.LogDebug("Shard '{ProjectionShardIdentity}': Starting to process events for {Group}", ProjectionShardIdentity, group);
            }

            // This should be done *once* here before going to the TryAction()
            group.Reset();

            ProjectionUpdateBatch batch = null;

            // Building the ProjectionUpdateBatch
            await TryAction(async() =>
            {
                batch = await buildUpdateBatch(@group).ConfigureAwait(false);

                @group.Dispose();
            }, _cancellation, (logger, e) =>
            {
                logger.LogError(e, "Failure while trying to process updates for event range {EventRange} for projection shard '{ProjectionShardIdentity}'", @group, ProjectionShardIdentity);
            }, @group : @group).ConfigureAwait(false);

            // This has failed, so get out of here.
            if (batch == null)
            {
                return;
            }

            // Executing the SQL commands for the ProjectionUpdateBatch
            await TryAction(async() =>
            {
                await ExecuteBatch(batch).ConfigureAwait(false);

                if (_logger.IsEnabled(LogLevel.Debug))
                {
                    _logger.LogDebug("Shard '{ProjectionShardIdentity}': Successfully processed batch {Group}", ProjectionShardIdentity, @group);
                }
            }, _cancellation, (logger, e) =>
            {
                logger.LogError(e, "Failure while trying to process updates for event range {EventRange} for projection shard '{ProjectionShardIdentity}'", @group, ProjectionShardIdentity);
            }).ConfigureAwait(false);
        }
コード例 #7
0
        public async Task ExecuteBatch(ProjectionUpdateBatch batch)
        {
            if (_cancellation.IsCancellationRequested)
            {
                return;
            }

            await batch.Queue.Completion;

            if (_cancellation.IsCancellationRequested)
            {
                return;
            }

            await using (var session = (DocumentSessionBase)_store.LightweightSession())
            {
                try
                {
                    await session.ExecuteBatchAsync(batch, _cancellation);

                    _logger.LogInformation("Shard '{ShardName}': Executed updates for {Range}", ShardName, batch.Range);
                }
                catch (Exception e)
                {
                    if (!_cancellation.IsCancellationRequested)
                    {
                        _logger.LogError(e, "Failure in shard '{ShardName}' trying to execute an update batch for {Range}", ShardName, batch.Range);
                        throw;
                    }
                }
            }

            batch.Dispose();

            if (_cancellation.IsCancellationRequested)
            {
                return;
            }

            Position = batch.Range.SequenceCeiling;

            _tracker.Publish(new ShardState(ShardName, batch.Range.SequenceCeiling));

            _commandBlock.Post(Command.Completed(batch.Range));
        }
コード例 #8
0
        private async Task processRange(EventRangeGroup group)
        {
            if (_cancellation.IsCancellationRequested)
            {
                return;
            }

            if (_logger.IsEnabled(LogLevel.Debug))
            {
                _logger.LogDebug("Shard '{ShardName}': Starting to process events for {Group}", Name, group);
            }

            // This should be done *once* here before going to the TryAction()
            group.Reset();

            ProjectionUpdateBatch batch = null;

            // Building the ProjectionUpdateBatch
            await TryAction(async() =>
            {
                batch = await buildUpdateBatch(@group);



                group.Dispose();
            }, _cancellation, (logger, e) =>
            {
                logger.LogError(e, "Failure while trying to process updates for event range {EventRange} for projection shard '{ShardName}'", group, Name);
            }, group : group);

            // Executing the SQL commands for the ProjectionUpdateBatch
            await TryAction(async() =>
            {
                await ExecuteBatch(batch);

                if (_logger.IsEnabled(LogLevel.Debug))
                {
                    _logger.LogDebug("Shard '{ShardName}': Configured batch {Group}", Name, group);
                }
            }, _cancellation, (logger, e) =>
            {
                logger.LogError(e, "Failure while trying to process updates for event range {EventRange} for projection shard '{ShardName}'", group, Name);
            });
        }
コード例 #9
0
 protected abstract Task configureUpdateBatch(ProjectionUpdateBatch batch, T group, CancellationToken token);
コード例 #10
0
 public abstract Task ConfigureUpdateBatch(IShardAgent shardAgent, ProjectionUpdateBatch batch);
コード例 #11
0
 public abstract Task ConfigureUpdateBatch(IShardAgent shardAgent, ProjectionUpdateBatch batch,
                                           EventRangeGroup eventRangeGroup);
コード例 #12
0
 public async Task ApplyEvents(ProjectionUpdateBatch batch, IProjection projection, DocumentStore store,
                               CancellationToken cancellationToken)
 {
     await using var operations = new ProjectionDocumentSession(store, batch, new SessionOptions { Tracking = DocumentTracking.None, Tenant = _tenant });
     await projection.ApplyAsync(operations, _actions, cancellationToken).ConfigureAwait(false);
 }