Esempio n. 1
0
        private void EnqueueTasks(ConcurrentDictionary <Task, Task> tasks, BulkImport <TIndexed> bulk, bool uncompletePartitions, TaskScheduler scheduler)
        {
            this.logger.LogTrace("()");

            if (!uncompletePartitions && !bulk.HasFullPartition)
            {
                this.logger.LogTrace("(-):PARTITIONS {0}:{1},{2}:{3}", nameof(uncompletePartitions), uncompletePartitions, nameof(bulk.HasFullPartition), bulk.HasFullPartition);
                return;
            }

            if (uncompletePartitions)
            {
                bulk.FlushUncompletePartitions();
            }

            while (bulk._ReadyPartitions.Count != 0)
            {
                var item = bulk._ReadyPartitions.Dequeue();
                var task = retry.Do(() => IndexCore(item.Item1, item.Item2), scheduler);
                tasks.TryAdd(task, task);
                task.ContinueWith(prev =>
                {
                    _Exception = prev.Exception ?? _Exception;
                    tasks.TryRemove(prev, out prev);
                });

                if (tasks.Count > MaxQueued)
                {
                    WaitFinished(tasks, MaxQueued / 2);
                }
            }

            this.logger.LogTrace("(-)");
        }
Esempio n. 2
0
 protected override void ProcessBlock(BlockInfo block, BulkImport <TransactionEntry.Entity> bulk)
 {
     foreach (var transaction in block.Block.Transactions)
     {
         var indexed = new TransactionEntry.Entity(null, transaction, block.BlockId);
         bulk.Add(indexed.PartitionKey, indexed);
     }
 }
Esempio n. 3
0
        protected override void ProcessBlock(BlockInfo block, BulkImport <TransactionEntry.Entity> bulk, Network network)
        {
            this.logger.LogTrace("()");

            foreach (var transaction in block.Block.Transactions)
            {
                var indexed = new TransactionEntry.Entity(null, transaction, block.BlockId);
                bulk.Add(indexed.PartitionKey, indexed);
            }

            this.logger.LogTrace("(-)");
        }
Esempio n. 4
0
        protected override void ProcessBlock(BlockInfo block, BulkImport <OrderedBalanceChange> bulk)
        {
            foreach (var tx in block.Block.Transactions)
            {
                var txId = tx.GetHash();

                var entries = extract(txId, tx, block.BlockId, block.Block.Header, block.Height);
                foreach (var entry in entries)
                {
                    bulk.Add(entry.PartitionKey, entry);
                }
            }
        }
Esempio n. 5
0
        protected override void ProcessBlock(BlockInfo block, BulkImport <OrderedBalanceChange> bulk, Network network)
        {
            this.logger.LogTrace("()");

            foreach (var tx in block.Block.Transactions)
            {
                var txId = tx.GetHash();

                var entries = extract(txId, tx, block.BlockId, block.Block.Header, block.Height, network);
                foreach (var entry in entries)
                {
                    bulk.Add(entry.PartitionKey, entry);
                }
            }

            this.logger.LogTrace("(-)");
        }
Esempio n. 6
0
 protected override void ProcessBlock(BlockInfo block, BulkImport <ITableEntity> bulk)
 {
     throw new NotSupportedException();
 }
 protected override void ProcessBlock(BlockInfo block, BulkImport <BlockInfo> bulk)
 {
     bulk.Add("o", block);
 }
Esempio n. 8
0
        public void Index(BlockFetcher blockFetcher, TaskScheduler scheduler, Network network)
        {
            this.logger.LogTrace("()");

            ConcurrentDictionary <Task, Task> tasks = new ConcurrentDictionary <Task, Task>();

            try
            {
                SetThrottling();
                if (EnsureIsSetup)
                {
                    EnsureSetup().Wait();
                }

                BulkImport <TIndexed> bulk = new BulkImport <TIndexed>(PartitionSize);
                if (!SkipToEnd)
                {
                    try
                    {
                        foreach (var block in blockFetcher)
                        {
                            ThrowIfException();
                            if (blockFetcher.NeedSave)
                            {
                                if (SaveProgression)
                                {
                                    EnqueueTasks(tasks, bulk, true, scheduler);
                                    Save(tasks, blockFetcher, bulk);
                                }
                            }
                            ProcessBlock(block, bulk, network);
                            if (bulk.HasFullPartition)
                            {
                                EnqueueTasks(tasks, bulk, false, scheduler);
                            }
                        }
                        EnqueueTasks(tasks, bulk, true, scheduler);
                    }
                    catch (OperationCanceledException ex)
                    {
                        if (ex.CancellationToken != blockFetcher.CancellationToken)
                        {
                            throw;
                        }
                    }
                }
                else
                {
                    this.logger.LogTrace("Skipping to end");
                    blockFetcher.SkipToEnd();
                }

                if (SaveProgression)
                {
                    Save(tasks, blockFetcher, bulk);
                }
                WaitFinished(tasks);
                ThrowIfException();
            }
            catch (AggregateException aex)
            {
                ExceptionDispatchInfo.Capture(aex.InnerException).Throw();
                throw;
            }

            this.logger.LogTrace("(-)");
        }
Esempio n. 9
0
 protected abstract void ProcessBlock(BlockInfo block, BulkImport <TIndexed> bulk, Network network);
Esempio n. 10
0
        private void Save(ConcurrentDictionary <Task, Task> tasks, BlockFetcher fetcher, BulkImport <TIndexed> bulk)
        {
            this.logger.LogTrace("()");

            WaitFinished(tasks);
            ThrowIfException();
            fetcher.SaveCheckpoint();

            this.logger.LogTrace("(-)");
        }
Esempio n. 11
0
 private void Save(ConcurrentDictionary <Task, Task> tasks, BlockFetcher fetcher, BulkImport <TIndexed> bulk)
 {
     WaitFinished(tasks);
     ThrowIfException();
     fetcher.SaveCheckpoint();
 }