Esempio n. 1
0
        private static IDisposable ReadStats(DocumentsOperationContext context, Table table, TimeSeriesSliceHolder slicer, out long count, out DateTime start, out DateTime end, out Slice name)
        {
            count = 0;
            start = DateTime.MaxValue;
            end   = DateTime.MinValue;
            name  = slicer.NameSlice;

            if (table.ReadByKey(slicer.StatsKey, out var tvr) == false)
            {
                return(null);
            }

            count = DocumentsStorage.TableValueToLong((int)StatsColumns.Count, ref tvr);
            start = new DateTime(Bits.SwapBytes(DocumentsStorage.TableValueToLong((int)StatsColumns.Start, ref tvr)));
            end   = DocumentsStorage.TableValueToDateTime((int)StatsColumns.End, ref tvr);

            if (count == 0 && start == default && end == default)
            {
                // this is delete a stats, that we re-create, so we need to treat is as a new one.
                start = DateTime.MaxValue;
                end   = DateTime.MinValue;
                return(null);
            }

            return(DocumentsStorage.TableValueToSlice(context, (int)StatsColumns.Name, ref tvr, out name));
        }
Esempio n. 2
0
        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--;
                }
            }
        }