public async Task StartShard(IAsyncProjectionShard shard, CancellationToken cancellationToken) { if (!_hasStarted) { StartNode(); } // Don't duplicate the shard if (_agents.ContainsKey(shard.Name.Identity)) { return; } await TryAction(null, async() => { try { var agent = new ProjectionAgent(_store, shard, _logger, cancellationToken); var position = await agent.Start(this); Tracker.Publish(new ShardState(shard.Name, position) { Action = ShardAction.Started }); _agents[shard.Name.Identity] = agent; } catch (Exception e) { _logger.LogError(e, "Error when trying to start projection shard '{ShardName}'", shard.Name.Identity); throw new ShardStartException(shard.Name, e); } }, cancellationToken); }
public ProjectionAgent(DocumentStore store, IAsyncProjectionShard projectionShard, ILogger logger, CancellationToken cancellation) { if (cancellation == CancellationToken.None) { _cancellationSource = new CancellationTokenSource(); _cancellation = _cancellationSource.Token; } _store = store; _projectionShard = projectionShard; _logger = logger; _cancellation = cancellation; _controller = new ProjectionController(projectionShard.Name, this, projectionShard.Options); }
public async Task StartShard(IAsyncProjectionShard shard) { if (!_hasStarted) { StartNode(); } // TODO -- log the start, or error if it fails var agent = new ProjectionAgent(_store, shard, _logger); var position = await agent.Start(Tracker); Tracker.Publish(new ShardState(shard.ProjectionOrShardName, position) { Action = ShardAction.Started }); _agents[shard.ProjectionOrShardName] = agent; }
// ReSharper disable once ContextualLoggerProblem public ProjectionAgent(DocumentStore store, IAsyncProjectionShard projectionShard, ILogger <IProjection> logger) { _store = store; _projectionShard = projectionShard; _logger = logger; var singleFile = new ExecutionDataflowBlockOptions { EnsureOrdered = true, MaxDegreeOfParallelism = 1, CancellationToken = _cancellationSource.Token }; _commandBlock = new ActionBlock <Command>(processCommand, singleFile); _controller = new ProjectionController(projectionShard.ProjectionOrShardName, this, projectionShard.Options); _loader = new TransformBlock <EventRange, EventRange>(loadEvents, singleFile); }
internal bool TryFindAsyncShard(string projectionOrShardName, out IAsyncProjectionShard shard) { return(_asyncShards.Value.TryGetValue(projectionOrShardName, out shard)); }
public ShardState(IAsyncProjectionShard shard, ShardAction action) : this(shard.ProjectionOrShardName, 0) { Action = action; }
public ShardState(IAsyncProjectionShard shard, long sequenceNumber) : this(shard.ProjectionOrShardName, sequenceNumber) { }