public DebugDocumentStats GetDocumentStatsVerySlowly()
        {
            var sp   = Stopwatch.StartNew();
            var stat = new DebugDocumentStats {
                Total = GetDocumentsCount()
            };

            var documentsByEtag = tableStorage.Documents.GetIndex(Tables.Documents.Indices.KeyByEtag);

            using (var iterator = documentsByEtag.Iterate(Snapshot, writeBatch.Value))
            {
                if (!iterator.Seek(Slice.BeforeAllKeys))
                {
                    stat.TimeToGenerate = sp.Elapsed;
                    return(stat);
                }

                do
                {
                    var key  = GetKeyFromCurrent(iterator);
                    var doc  = DocumentByKey(key);
                    var size = doc.SerializedSizeOnDisk;
                    stat.TotalSize += size;
                    if (key.StartsWith("Raven/", StringComparison.OrdinalIgnoreCase))
                    {
                        stat.System++;
                        stat.SystemSize += size;
                    }


                    var metadata = ReadDocumentMetadata(key);

                    var entityName = metadata.Metadata.Value <string>(Constants.RavenEntityName);
                    if (string.IsNullOrEmpty(entityName))
                    {
                        stat.NoCollection++;
                        stat.NoCollectionSize += size;
                    }

                    else
                    {
                        stat.IncrementCollection(entityName, size);
                    }


                    if (metadata.Metadata.ContainsKey(Constants.RavenDeleteMarker))
                    {
                        stat.Tombstones++;
                    }
                }while (iterator.MoveNext());
                var sortedStat = stat.Collections.OrderByDescending(x => x.Value.Size).ToDictionary(x => x.Key, x => x.Value);
                stat.TimeToGenerate = sp.Elapsed;
                stat.Collections    = sortedStat;
                return(stat);
            }
        }
Example #2
0
        public HttpResponseMessage SlowDocCounts()
        {
            DebugDocumentStats stat = null;

            Database.TransactionalStorage.Batch(accessor =>
            {
                stat = accessor.Documents.GetDocumentStatsVerySlowly();
            });

            return(GetMessageWithObject(stat));
        }
Example #3
0
        public override void Respond(IHttpContext context)
        {
            DebugDocumentStats stat = null;

            Database.TransactionalStorage.Batch(accessor =>
            {
                stat = accessor.Documents.GetDocumentStatsVerySlowly();
            });

            context.WriteJson(stat);
        }
Example #4
0
        public DebugDocumentStats GetDocumentStatsVerySlowly(Action <string> progress, CancellationToken token)
        {
            var sp   = Stopwatch.StartNew();
            var stat = new DebugDocumentStats {
                Total = GetDocumentsCount()
            };

            var processedDocuments = 0;

            Api.JetSetCurrentIndex(session, Documents, "by_etag");
            Api.MoveBeforeFirst(Session, Documents);
            while (Api.TryMoveNext(Session, Documents))
            {
                if (processedDocuments % 64 == 0)
                {
                    token.ThrowIfCancellationRequested();
                    progress($"Scanned {$"{processedDocuments:#,#;;0}"} documents");
                }

                var key = Api.RetrieveColumnAsString(Session, Documents, tableColumnsCache.DocumentsColumns["key"],
                                                     Encoding.Unicode);

                RavenJObject metadata;
                var          metadateSize = GetMetadataFromStorage(Documents, out metadata);
                var          docSize      = Api.RetrieveColumnSize(session, Documents, tableColumnsCache.DocumentsColumns["data"]) ?? -1;
                var          totalSize    = docSize + metadateSize;
                stat.TotalSize += totalSize;

                if (key.StartsWith("Raven/", StringComparison.OrdinalIgnoreCase))
                {
                    stat.System.Update(totalSize, key);
                }

                var entityName = metadata.Value <string>(Constants.RavenEntityName);
                if (string.IsNullOrEmpty(entityName))
                {
                    stat.NoCollection.Update(totalSize, key);
                }
                else
                {
                    stat.IncrementCollection(entityName, totalSize, key);
                }

                if (metadata.ContainsKey(Constants.RavenDeleteMarker))
                {
                    stat.Tombstones++;
                }

                processedDocuments++;
            }
            stat.TimeToGenerate = sp.Elapsed;

            return(stat);
        }
Example #5
0
        public DebugDocumentStats GetDocumentStatsVerySlowly()
        {
            var sp   = Stopwatch.StartNew();
            var stat = new DebugDocumentStats {
                Total = GetDocumentsCount()
            };

            Api.JetSetCurrentIndex(session, Documents, "by_etag");
            Api.MoveBeforeFirst(Session, Documents);
            while (Api.TryMoveNext(Session, Documents))
            {
                var key = Api.RetrieveColumnAsString(Session, Documents, tableColumnsCache.DocumentsColumns["key"],
                                                     Encoding.Unicode);

                var doc  = DocumentByKey(key, null);
                var size = doc.SerializedSizeOnDisk;
                stat.TotalSize += size;
                if (key.StartsWith("Raven/", StringComparison.OrdinalIgnoreCase))
                {
                    stat.System++;
                    stat.SystemSize += size;
                }


                var metadata =
                    Api.RetrieveColumn(session, Documents, tableColumnsCache.DocumentsColumns["metadata"]).ToJObject();

                var entityName = metadata.Value <string>(Constants.RavenEntityName);
                if (string.IsNullOrEmpty(entityName))
                {
                    stat.NoCollection++;
                    stat.NoCollectionSize += size;
                }

                else
                {
                    stat.IncrementCollection(entityName, size);
                }


                if (metadata.ContainsKey("Raven-Delete-Marker"))
                {
                    stat.Tombstones++;
                }
            }
            var sortedStat = stat.Collections.OrderByDescending(x => x.Value.Size).ToDictionary(x => x.Key, x => x.Value);

            stat.TimeToGenerate = sp.Elapsed;
            stat.Collections    = sortedStat;

            return(stat);
        }
Example #6
0
        public DebugDocumentStats GetDocumentStatsVerySlowly()
        {
            var sp   = Stopwatch.StartNew();
            var stat = new DebugDocumentStats {
                Total = GetDocumentsCount()
            };

            Api.JetSetCurrentIndex(session, Documents, "by_etag");
            Api.MoveBeforeFirst(Session, Documents);
            while (Api.TryMoveNext(Session, Documents))
            {
                var key = Api.RetrieveColumnAsString(Session, Documents, tableColumnsCache.DocumentsColumns["key"],
                                                     Encoding.Unicode);

                var metadata = Api.RetrieveColumn(session, Documents, tableColumnsCache.DocumentsColumns["metadata"]).ToJObject();
                var size     = Api.RetrieveColumnSize(session, Documents, tableColumnsCache.DocumentsColumns["data"]) ?? -1;
                stat.TotalSize += size;
                if (key.StartsWith("Raven/", StringComparison.OrdinalIgnoreCase))
                {
                    stat.System.Update(size, key);
                }


                var entityName = metadata.Value <string>(Constants.RavenEntityName);
                if (string.IsNullOrEmpty(entityName))
                {
                    stat.NoCollection.Update(size, key);
                }
                else
                {
                    stat.IncrementCollection(entityName, size, key);
                }

                if (metadata.ContainsKey("Raven-Delete-Marker"))
                {
                    stat.Tombstones++;
                }
            }
            stat.TimeToGenerate = sp.Elapsed;

            return(stat);
        }
Example #7
0
        public DebugDocumentStats GetDocumentStatsVerySlowly()
        {
            var sp   = Stopwatch.StartNew();
            var stat = new DebugDocumentStats {
                Total = GetDocumentsCount()
            };

            foreach (var readResult in storage.Documents)
            {
                var key = readResult.Key.Value <string>("key");
                if (key.StartsWith("Raven/", StringComparison.OrdinalIgnoreCase))
                {
                    stat.System++;
                }

                var metadata = readResult.Data().ToJObject();

                var entityName = metadata.Value <string>(Constants.RavenEntityName);
                if (string.IsNullOrEmpty(entityName))
                {
                    stat.NoCollection++;
                }
                else
                {
                    stat.IncrementCollection(entityName);
                }

                if (metadata.ContainsKey("Raven-Delete-Marker"))
                {
                    stat.Tombstones++;
                }
            }

            stat.TimeToGenerate = sp.Elapsed;
            return(stat);
        }
        public DebugDocumentStats GetDocumentStatsVerySlowly()
        {
            var sp = Stopwatch.StartNew();
            var stat = new DebugDocumentStats { Total = GetDocumentsCount() };

            var documentsByEtag = tableStorage.Documents.GetIndex(Tables.Documents.Indices.KeyByEtag);
            using (var iterator = documentsByEtag.Iterate(Snapshot, writeBatch.Value))
            {
                if (!iterator.Seek(Slice.BeforeAllKeys))
                {
                    stat.TimeToGenerate = sp.Elapsed;
                    return stat;
                }

                do
                {
                    var key = GetKeyFromCurrent(iterator);
                    var doc = DocumentByKey(key);
                    if (key.StartsWith("Raven/", StringComparison.OrdinalIgnoreCase))
                    {
                        stat.System.Update(doc.SerializedSizeOnDisk, doc.Key);
                    }

                    var entityName = doc.Metadata.Value<string>(Constants.RavenEntityName);
                    if (string.IsNullOrEmpty(entityName))
                    {
                        stat.NoCollection.Update(doc.SerializedSizeOnDisk, doc.Key);
                    }
                    else
                    {
                        stat.IncrementCollection(entityName, doc.SerializedSizeOnDisk, doc.Key);
                    }

                    if (doc.Metadata.ContainsKey(Constants.RavenDeleteMarker))
                        stat.Tombstones++;

                }
                while (iterator.MoveNext());
                stat.TimeToGenerate = sp.Elapsed;
                return stat;
            }
        }
        public DebugDocumentStats GetDocumentStatsVerySlowly(Action <string> progress, CancellationToken token)
        {
            var sp   = Stopwatch.StartNew();
            var stat = new DebugDocumentStats {
                Total = GetDocumentsCount()
            };

            var processedDocuments = 0;

            var documentsByEtag = tableStorage.Documents.GetIndex(Tables.Documents.Indices.KeyByEtag);

            using (var iterator = documentsByEtag.Iterate(Snapshot, writeBatch.Value))
            {
                if (iterator.Seek(Slice.BeforeAllKeys) == false)
                {
                    stat.TimeToGenerate = sp.Elapsed;
                    return(stat);
                }

                do
                {
                    if (processedDocuments % 64 == 0)
                    {
                        token.ThrowIfCancellationRequested();
                        progress($"Scanned {$"{processedDocuments:#,#;;0}"} documents");
                    }

                    var key           = GetKeyFromCurrent(iterator);
                    var normalizedKey = CreateKey(key);
                    var sliceKey      = (Slice)normalizedKey;

                    var documentReadResult = tableStorage.Documents.Read(Snapshot, sliceKey, writeBatch.Value);
                    var docSize            = documentReadResult.Reader.Length;
                    int metadataSize;
                    var metadata  = ReadDocumentMetadata(normalizedKey, sliceKey, out metadataSize);
                    var totalSize = docSize + metadataSize;

                    if (key.StartsWith("Raven/", StringComparison.OrdinalIgnoreCase))
                    {
                        stat.System.Update(totalSize, key);
                    }

                    var entityName = metadata.Metadata.Value <string>(Constants.RavenEntityName);
                    if (string.IsNullOrEmpty(entityName))
                    {
                        stat.NoCollection.Update(totalSize, key);
                    }
                    else
                    {
                        stat.IncrementCollection(entityName, totalSize, key);
                    }

                    if (metadata.Metadata.ContainsKey(Constants.RavenDeleteMarker))
                    {
                        stat.Tombstones++;
                    }

                    processedDocuments++;
                }while (iterator.MoveNext());

                stat.TimeToGenerate = sp.Elapsed;
                return(stat);
            }
        }
        public DebugDocumentStats GetDocumentStatsVerySlowly()
        {
            var sp = Stopwatch.StartNew();
            var stat = new DebugDocumentStats { Total = GetDocumentsCount() };

            var documentsByEtag = tableStorage.Documents.GetIndex(Tables.Documents.Indices.KeyByEtag);
            using (var iterator = documentsByEtag.Iterate(Snapshot, writeBatch.Value))
            {
                if (!iterator.Seek(Slice.BeforeAllKeys))
                {
                    stat.TimeToGenerate = sp.Elapsed;
                    return stat;
                }

                do
                {
                    var key = GetKeyFromCurrent(iterator);
                    var normalizedKey = CreateKey(key);
                    var sliceKey = (Slice)normalizedKey;

                    var documentReadResult = tableStorage.Documents.Read(Snapshot, sliceKey, writeBatch.Value);
                    var docSize = documentReadResult.Reader.Length;
                    int metadataSize;
                    var metadata = ReadDocumentMetadata(normalizedKey, sliceKey, out metadataSize);
                    var totalSize = docSize + metadataSize;

                    if (key.StartsWith("Raven/", StringComparison.OrdinalIgnoreCase))
                    {
                        stat.System.Update(totalSize, key);
                    }

                    var entityName = metadata.Metadata.Value<string>(Constants.RavenEntityName);
                    if (string.IsNullOrEmpty(entityName))
                    {
                        stat.NoCollection.Update(totalSize, key);
                    }
                    else
                    {
                        stat.IncrementCollection(entityName, totalSize, key);
                    }

                    if (metadata.Metadata.ContainsKey(Constants.RavenDeleteMarker))
                        stat.Tombstones++;

                }
                while (iterator.MoveNext());
                stat.TimeToGenerate = sp.Elapsed;
                return stat;
            }
        }