private async Task<EventRangeGroup> groupEventRange(EventRange range) { if (_cancellation.IsCancellationRequested) return null; EventRangeGroup group = null; await TryAction(async () => { if (_logger.IsEnabled(LogLevel.Debug)) { _logger.LogDebug("Shard '{ShardName}':Starting to group {Range}", Name, range); } group = await _source.GroupEvents(_store, range, _cancellation); if (_logger.IsEnabled(LogLevel.Debug)) { _logger.LogDebug("Shard '{ShardName}': successfully grouped {Range}", Name, range); } }, _cancellation, (logger, e) => { logger.LogError(e, "Error while trying to group event range {EventRange} for projection shard {ShardName}", range, Name); }); return group; }
private async Task <ProjectionUpdateBatch> buildUpdateBatch(EventRangeGroup @group) { if (group.Cancellation.IsCancellationRequested) { return(null); // get out of here early instead of letting it linger } using var batch = StartNewBatch(group); await group.ConfigureUpdateBatch(this, batch, group); if (group.Cancellation.IsCancellationRequested) { if (group.Exception != null) { ExceptionDispatchInfo.Capture(group.Exception).Throw(); } return(batch); // get out of here early instead of letting it linger } batch.Queue.Complete(); await batch.Queue.Completion; if (group.Exception != null) { ExceptionDispatchInfo.Capture(group.Exception).Throw(); } return(batch); }
private async Task <EventRangeGroup> groupEventRange(EventRange range) { if (_cancellation.IsCancellationRequested) { return(null); } EventRangeGroup group = null; await TryAction(async() => { if (_logger.IsEnabled(LogLevel.Debug)) { _logger.LogDebug("Shard '{ProjectionShardIdentity}':Starting to group {Range}", ProjectionShardIdentity, range); } @group = await _source.GroupEvents(_store, _daemon.Database, range, _cancellation).ConfigureAwait(false); if (_logger.IsEnabled(LogLevel.Debug)) { _logger.LogDebug("Shard '{ProjectionShardIdentity}': successfully grouped {Range}", ProjectionShardIdentity, range); } }, _cancellation, (logger, e) => { logger.LogError(e, "Error while trying to group event range {EventRange} for projection shard {SProjectionShardIdentity}", range, ProjectionShardIdentity); }).ConfigureAwait(false); return(group); }
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)); }
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); }
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); }); }
private async Task <ProjectionUpdateBatch> buildUpdateBatch(EventRangeGroup @group) { if (group.Cancellation.IsCancellationRequested) { return(null); // get out of here early instead of letting it linger } var batch = StartNewBatch(group); try { await @group.ConfigureUpdateBatch(this, batch, @group).ConfigureAwait(false); if (group.Cancellation.IsCancellationRequested) { if (group.Exception != null) { ExceptionDispatchInfo.Capture(group.Exception).Throw(); } return(batch); // get out of here early instead of letting it linger } batch.Queue.Complete(); await batch.Queue.Completion.ConfigureAwait(false); if (group.Exception != null) { ExceptionDispatchInfo.Capture(group.Exception).Throw(); } } finally { if (batch != null) { await batch.CloseSession().ConfigureAwait(false); } } return(batch); }
public ProjectionUpdateBatch StartNewBatch(EventRangeGroup group) { var session = _store.LightweightSession(); return new ProjectionUpdateBatch(_store.Events, (DocumentSessionBase) session, group.Range, group.Cancellation); }
public Task TryAction(Func<Task> action, CancellationToken token, Action<ILogger, Exception> logException = null, EventRangeGroup group = null, GroupActionMode actionMode = GroupActionMode.Parent) { var parameters = new ActionParameters(this, action, token == default ? _cancellation : token) { GroupActionMode = actionMode }; parameters.LogAction = logException ?? parameters.LogAction; parameters.Group = group; return _daemon.TryAction(parameters); }
public abstract Task ConfigureUpdateBatch(IShardAgent shardAgent, ProjectionUpdateBatch batch, EventRangeGroup eventRangeGroup);
public ProjectionUpdateBatch StartNewBatch(EventRangeGroup group) { var session = _store.OpenSession(_sessionOptions); return(new ProjectionUpdateBatch(_store.Events, (DocumentSessionBase)session, group.Range, group.Cancellation)); }