internal async Task<long> RunRollups(bool propagateException = true, List<string> explanations = null) { var now = _database.Time.GetUtcNow(); var total = 0L; try { var states = new List<TimeSeriesRollups.RollupState>(); var start = 0L; using (_database.DocumentsStorage.ContextPool.AllocateOperationContext(out DocumentsOperationContext context)) { while (true) { states.Clear(); context.Reset(); context.Renew(); Stopwatch duration; using (context.OpenReadTransaction()) { explanations?.Add($"Preparing rollups at '{now.GetDefaultRavenFormat()}' with '{0}' start."); _database.DocumentsStorage.TimeSeriesStorage.Rollups.PrepareRollups(context, now, 1024, start, states, out duration); if (states.Count == 0) { explanations?.Add($"Cannot run rollups at '{now.GetDefaultRavenFormat()}' because there are no rollup states."); return total; } } Cts.Token.ThrowIfCancellationRequested(); var topology = _database.ServerStore.LoadDatabaseTopology(_database.Name); var isFirstInTopology = string.Equals(topology.Members.FirstOrDefault(), _database.ServerStore.NodeTag, StringComparison.OrdinalIgnoreCase); explanations?.Add($"RollupTimeSeriesCommand({now.GetDefaultRavenFormat()}, {isFirstInTopology})"); var command = new TimeSeriesRollups.RollupTimeSeriesCommand(Configuration, now, states, isFirstInTopology); await _database.TxMerger.Enqueue(command); if (command.RolledUp > 0) { explanations?.Add($"RollupTimeSeriesCommand({now.GetDefaultRavenFormat()}, {isFirstInTopology}) = {command.RolledUp}"); total += command.RolledUp; if (Logger.IsInfoEnabled) Logger.Info($"Successfully aggregated {command.RolledUp:#,#;;0} time-series within {duration.ElapsedMilliseconds:#,#;;0} ms."); } start = states.Last().NextRollup.Ticks + 1; } } } catch (OperationCanceledException) { // this will stop processing throw; } catch (Exception e) { if (Logger.IsOperationsEnabled) Logger.Operations($"Failed to roll-up time series for '{_database.Name}' which are older than {now}", e); if (propagateException) throw; return total; } }
internal async Task <long> RunRollups(bool propagateException = true) { var now = _database.Time.GetUtcNow(); var total = 0L; try { var states = new List <TimeSeriesRollups.RollupState>(); using (_database.DocumentsStorage.ContextPool.AllocateOperationContext(out DocumentsOperationContext context)) { while (true) { states.Clear(); context.Reset(); context.Renew(); Stopwatch duration; using (context.OpenReadTransaction()) { _database.DocumentsStorage.TimeSeriesStorage.Rollups.PrepareRollups(context, now, 1024, states, out duration); if (states.Count == 0) { return(total); } } Cts.Token.ThrowIfCancellationRequested(); var topology = _database.ServerStore.LoadDatabaseTopology(_database.Name); var isFirstInTopology = string.Equals(topology.Members.FirstOrDefault(), _database.ServerStore.NodeTag, StringComparison.OrdinalIgnoreCase); var command = new TimeSeriesRollups.RollupTimeSeriesCommand(Configuration, now, states, isFirstInTopology); await _database.TxMerger.Enqueue(command); if (command.RolledUp == 0) { break; } total += command.RolledUp; if (Logger.IsInfoEnabled) { Logger.Info($"Successfully aggregated {command.RolledUp:#,#;;0} time-series within {duration.ElapsedMilliseconds:#,#;;0} ms."); } } } return(total); } catch (OperationCanceledException) { // this will stop processing throw; } catch (Exception e) { if (Logger.IsOperationsEnabled) { Logger.Operations($"Failed to roll-up time series for '{_database.Name}' which are older than {now}", e); } if (propagateException) { throw; } return(total); } }