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)); }
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)); }
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)); }
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)); }
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)); }
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); }
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)); }
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); }); }
protected abstract Task configureUpdateBatch(ProjectionUpdateBatch batch, T group, CancellationToken token);
public abstract Task ConfigureUpdateBatch(IShardAgent shardAgent, ProjectionUpdateBatch batch);
public abstract Task ConfigureUpdateBatch(IShardAgent shardAgent, ProjectionUpdateBatch batch, EventRangeGroup eventRangeGroup);
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); }