internal void PrepareRollups(DocumentsOperationContext context, DateTime currentTime, long take, long start, List <RollupState> states, out Stopwatch duration) { duration = Stopwatch.StartNew(); var table = context.Transaction.InnerTransaction.OpenTable(RollupSchema, TimeSeriesRollupTable); if (table == null) { return; } var currentTicks = currentTime.Ticks; using (DocumentsStorage.GetEtagAsSlice(context, start, out var startSlice)) { foreach (var item in table.SeekForwardFrom(RollupSchema.Indexes[NextRollupIndex], startSlice, 0)) { if (take <= 0) { return; } var rollUpTime = DocumentsStorage.TableValueToEtag((int)RollupColumns.NextRollup, ref item.Result.Reader); if (rollUpTime > currentTicks) { return; } DocumentsStorage.TableValueToSlice(context, (int)RollupColumns.Key, ref item.Result.Reader, out var key); SplitKey(key, out var docId, out var name); name = context.DocumentDatabase.DocumentsStorage.TimeSeriesStorage.GetOriginalName(context, docId, name); var state = new RollupState { Key = key, DocId = docId, Name = name, Collection = DocumentsStorage.TableValueToId(context, (int)RollupColumns.Collection, ref item.Result.Reader), NextRollup = new DateTime(rollUpTime), RollupPolicy = DocumentsStorage.TableValueToString(context, (int)RollupColumns.PolicyToApply, ref item.Result.Reader), Etag = DocumentsStorage.TableValueToLong((int)RollupColumns.Etag, ref item.Result.Reader), ChangeVector = DocumentsStorage.TableValueToChangeVector(context, (int)RollupColumns.ChangeVector, ref item.Result.Reader) }; if (_logger.IsInfoEnabled) { _logger.Info($"{state} is prepared."); } states.Add(state); take--; } } }
private static void UpdateSchemaForDocumentsAndRevisions(UpdateStep step) { using var _ = step.DocumentsStorage.ContextPool.AllocateOperationContext(out DocumentsOperationContext context); var collections = step.WriteTx.OpenTable(DocumentsStorage.CollectionsSchema, DocumentsStorage.CollectionsSlice); foreach (var tvr in collections.SeekByPrimaryKey(Slices.BeforeAllKeys, 0)) { var collection = DocumentsStorage.TableValueToId(context, (int)DocumentsStorage.CollectionsTable.Name, ref tvr.Reader); var collectionName = new CollectionName(collection); var tableTree = step.WriteTx.CreateTree(collectionName.GetTableName(CollectionTableType.Documents), RootObjectType.Table); DocumentsStorage.DocsSchema.SerializeSchemaIntoTableTree(tableTree); var revisionsTree = step.WriteTx.ReadTree(collectionName.GetTableName(CollectionTableType.Revisions), RootObjectType.Table); if (revisionsTree != null) { RevisionsStorage.RevisionsSchema.SerializeSchemaIntoTableTree(revisionsTree); } } }