示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
        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;
        }
示例#4
0
        // 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));
 }
示例#6
0
 public ShardState(IAsyncProjectionShard shard, ShardAction action) : this(shard.ProjectionOrShardName, 0)
 {
     Action = action;
 }
示例#7
0
 public ShardState(IAsyncProjectionShard shard, long sequenceNumber) : this(shard.ProjectionOrShardName, sequenceNumber)
 {
 }