/// <summary> /// Performs "Chain" indexing into Azure storage. /// </summary> /// <param name="cancellationToken">The token used for cancellation.</param> /// <returns>A task for asynchronous completion.</returns> private async Task IndexChainAsync(CancellationToken cancellationToken) { this.logger.LogTrace("()"); while (!cancellationToken.IsCancellationRequested) { try { this.AzureIndexer.IndexChain(this.Chain, cancellationToken); await Task.Delay(TimeSpan.FromMinutes(1), cancellationToken).ContinueWith(t => { }).ConfigureAwait(false); } catch (OperationCanceledException) { break; } catch (Exception ex) { // If something goes wrong then try again 1 minute later IndexerTrace.ErrorWhileImportingBlockToAzure(this.StoreTip.HashBlock, ex); await Task.Delay(TimeSpan.FromMinutes(1), cancellationToken).ContinueWith(t => { }).ConfigureAwait(false); } } this.logger.LogTrace("(-)"); }
/// <summary> /// Performs indexing into Azure storage. /// </summary> /// <param name="cancellationToken">The token used for cancellation.</param> /// <returns>A task for asynchronous completion.</returns> private async Task IndexAsync(CancellationToken cancellationToken) { this.logger.LogTrace("()"); while (this.StoreTip.Height < indexerSettings.To && !cancellationToken.IsCancellationRequested) { try { // All indexes will progress more or less in step int fromHeight = this.StoreTip.Height + 1; int toHeight = Math.Min(this.StoreTip.Height + IndexBatchSize, this.indexerSettings.To); this.logger.LogTrace("Starting indexing from {0}, to {1}", fromHeight, toHeight); // Index a batch of blocks PerformIndexing(IndexerCheckpoints.Blocks, fromHeight, toHeight); // Index a batch of transactions PerformIndexing(IndexerCheckpoints.Transactions, fromHeight, toHeight); // Index a batch of balances PerformIndexing(IndexerCheckpoints.Balances, fromHeight, toHeight); // Index a batch of wallets PerformIndexing(IndexerCheckpoints.Wallets, fromHeight, toHeight); // Update the StoreTip UpdateStoreTip(); this.logger.LogTrace("Indexing iteration finished"); } catch (OperationCanceledException) { break; } catch (Exception ex) { // If something goes wrong then try again 1 minute later this.logger.LogError("Exception occurred: {0}", ex.ToString()); IndexerTrace.ErrorWhileImportingBlockToAzure(this.StoreTip.HashBlock, ex); await Task.Delay(TimeSpan.FromSeconds(10), cancellationToken).ContinueWith(t => { }).ConfigureAwait(false); } } this.logger.LogTrace("(-)"); }
/// <summary> /// Performs indexing into Azure storage. /// </summary> /// <param name="cancellationToken">The token used for cancellation.</param> /// <returns>A task for asynchronous completion.</returns> private async Task IndexAsync(CancellationToken cancellationToken) { this.logger.LogTrace("()"); while (this.StoreTip.Height < indexerSettings.To && !cancellationToken.IsCancellationRequested) { try { // All indexes will progress more or less in step // Use 'minHeight' to track the current indexed height int minHeight = int.MaxValue; // Index a batch of blocks if (!cancellationToken.IsCancellationRequested) { var task = new IndexBlocksTask(this.IndexerConfig); task.SaveProgression = !this.indexerSettings.IgnoreCheckpoints; var fetcher = this.GetBlockFetcher(IndexerCheckpoints.Blocks, cancellationToken); task.Index(fetcher, this.AzureIndexer.TaskScheduler); minHeight = Math.Min(minHeight, fetcher._LastProcessed.Height); } // Index a batch of transactions if (!cancellationToken.IsCancellationRequested) { var task = new IndexTransactionsTask(this.IndexerConfig); task.SaveProgression = !this.indexerSettings.IgnoreCheckpoints; var fetcher = this.GetBlockFetcher(IndexerCheckpoints.Transactions, cancellationToken); task.Index(fetcher, this.AzureIndexer.TaskScheduler); minHeight = Math.Min(minHeight, fetcher._LastProcessed.Height); } // Index a batch of balances if (!cancellationToken.IsCancellationRequested) { var task = new IndexBalanceTask(this.IndexerConfig, null); task.SaveProgression = !this.indexerSettings.IgnoreCheckpoints; var fetcher = this.GetBlockFetcher(IndexerCheckpoints.Balances, cancellationToken); task.Index(fetcher, this.AzureIndexer.TaskScheduler); minHeight = Math.Min(minHeight, fetcher._LastProcessed.Height); } // Index a batch of wallets if (!cancellationToken.IsCancellationRequested) { var task = new IndexBalanceTask(this.IndexerConfig, this.IndexerConfig.CreateIndexerClient().GetAllWalletRules()); task.SaveProgression = !this.indexerSettings.IgnoreCheckpoints; var fetcher = this.GetBlockFetcher(IndexerCheckpoints.Wallets, cancellationToken); task.Index(fetcher, this.AzureIndexer.TaskScheduler); minHeight = Math.Min(minHeight, fetcher._LastProcessed.Height); } // Update the StoreTip value from the minHeight this.SetStoreTip(this.Chain.GetBlock(Math.Min(minHeight, this.indexerSettings.To))); } catch (OperationCanceledException) { break; } catch (Exception ex) { // If something goes wrong then try again 1 minute later IndexerTrace.ErrorWhileImportingBlockToAzure(this.StoreTip.HashBlock, ex); await Task.Delay(TimeSpan.FromMinutes(1), cancellationToken).ContinueWith(t => { }).ConfigureAwait(false); } } this.logger.LogTrace("(-)"); }
/// <summary> /// Performs indexing into Azure storage. /// </summary> /// <param name="cancellationToken">The token used for cancellation.</param> /// <returns>A task for asynchronous completion.</returns> private async Task IndexAsync(CancellationToken cancellationToken) { this.logger.LogTrace("()"); while (this.StoreTip.Height < indexerSettings.To && !cancellationToken.IsCancellationRequested) { try { // All indexes will progress more or less in step int fromHeight = this.StoreTip.Height + 1; int toHeight = Math.Min(this.StoreTip.Height + IndexBatchSize, this.indexerSettings.To); // Index a batch of blocks if (!cancellationToken.IsCancellationRequested && toHeight > this.BlocksFetcher._LastProcessed.Height) { this.BlocksFetcher.FromHeight = Math.Max(this.BlocksFetcher._LastProcessed.Height + 1, fromHeight); this.BlocksFetcher.ToHeight = toHeight; var task = new IndexBlocksTask(this.IndexerConfig); task.SaveProgression = !this.indexerSettings.IgnoreCheckpoints; task.Index(this.BlocksFetcher, this.AzureIndexer.TaskScheduler); } // Index a batch of transactions if (!cancellationToken.IsCancellationRequested && toHeight > this.TransactionsFetcher._LastProcessed.Height) { this.TransactionsFetcher.FromHeight = Math.Max(this.TransactionsFetcher._LastProcessed.Height + 1, fromHeight); this.TransactionsFetcher.ToHeight = toHeight; var task = new IndexTransactionsTask(this.IndexerConfig); task.SaveProgression = !this.indexerSettings.IgnoreCheckpoints; task.Index(this.TransactionsFetcher, this.AzureIndexer.TaskScheduler); } // Index a batch of balances if (!cancellationToken.IsCancellationRequested && toHeight > this.BalancesFetcher._LastProcessed.Height) { this.BalancesFetcher.FromHeight = Math.Max(this.BalancesFetcher._LastProcessed.Height + 1, fromHeight); this.BalancesFetcher.ToHeight = toHeight; var task = new IndexBalanceTask(this.IndexerConfig, null); task.SaveProgression = !this.indexerSettings.IgnoreCheckpoints; task.Index(this.BalancesFetcher, this.AzureIndexer.TaskScheduler); } // Index a batch of wallets if (!cancellationToken.IsCancellationRequested && toHeight > this.WalletsFetcher._LastProcessed.Height) { this.WalletsFetcher.FromHeight = Math.Max(this.WalletsFetcher._LastProcessed.Height + 1, fromHeight); this.WalletsFetcher.ToHeight = toHeight; var task = new IndexBalanceTask(this.IndexerConfig, this.IndexerConfig.CreateIndexerClient().GetAllWalletRules()); task.SaveProgression = !this.indexerSettings.IgnoreCheckpoints; task.Index(this.WalletsFetcher, this.AzureIndexer.TaskScheduler); } // Update the StoreTip value from the minHeight int minHeight = this.BlocksFetcher._LastProcessed.Height; minHeight = Math.Min(minHeight, this.BalancesFetcher._LastProcessed.Height); minHeight = Math.Min(minHeight, this.TransactionsFetcher._LastProcessed.Height); minHeight = Math.Min(minHeight, this.WalletsFetcher._LastProcessed.Height); this.SetStoreTip(this.Chain.GetBlock(minHeight)); } catch (OperationCanceledException) { break; } catch (Exception ex) { // If something goes wrong then try again 1 minute later this.logger.LogError(ex.Message); IndexerTrace.ErrorWhileImportingBlockToAzure(this.StoreTip.HashBlock, ex); await Task.Delay(TimeSpan.FromSeconds(10), cancellationToken).ContinueWith(t => { }).ConfigureAwait(false); } } this.logger.LogTrace("(-)"); }