Skip to content

Commit a0aefbc

Browse files
committed
Improved system collection $dump
1 parent 6520f09 commit a0aefbc

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

LiteDB/Engine/Structures/PageAddress.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,16 @@ public override string ToString()
6868
{
6969
return this.IsEmpty ? "(empty)" : this.PageID.ToString().PadLeft(4, '0') + ":" + this.Index.ToString().PadLeft(2, '0');
7070
}
71+
72+
public BsonValue ToBsonValue()
73+
{
74+
if (this.IsEmpty) return BsonValue.Null;
75+
76+
return new BsonDocument
77+
{
78+
["pageID"] = (int)this.PageID,
79+
["index"] = (int)this.Index
80+
};
81+
}
7182
}
7283
}

LiteDB/Engine/SystemCollections/SysDump.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ private IEnumerable<BsonDocument> DumpPages(uint? pageID)
4949
["_position"] = position,
5050
["_origin"] = origin.ToString(),
5151
["_version"] = walVersion,
52-
["nextPageID"] = (int)page.NextPageID,
5352
["prevPageID"] = (int)page.PrevPageID,
53+
["nextPageID"] = (int)page.NextPageID,
54+
["slot"] = (int)page.PageListSlot,
5455
["collection"] = collections.GetOrDefault(page.ColID, "-"),
5556
["itemsCount"] = (int)page.ItemsCount,
5657
["freeBytes"] = page.FreeBytes,
@@ -60,6 +61,25 @@ private IEnumerable<BsonDocument> DumpPages(uint? pageID)
6061
["highestIndex"] = (int)page.HighestIndex
6162
};
6263

64+
if (page.PageType == PageType.Collection)
65+
{
66+
var collectionPage = new CollectionPage(page.Buffer);
67+
doc["dataPageList"] = new BsonArray(collectionPage.FreeDataPageList.Select(x => new BsonValue((int)x)));
68+
doc["indexes"] = new BsonArray(collectionPage.GetCollectionIndexes().Select(x => new BsonDocument
69+
{
70+
["slot"] = (int)x.Slot,
71+
["empty"] = x.IsEmpty,
72+
["indexType"] = (int)x.IndexType,
73+
["name"] = x.Name,
74+
["expression"] = x.Expression,
75+
["unique"] = x.Unique,
76+
["head"] = x.Head.ToBsonValue(),
77+
["tail"] = x.Tail.ToBsonValue(),
78+
["maxLevel"] = (int)x.MaxLevel,
79+
["freeIndexPageList"] = (int)x.FreeIndexPageList,
80+
}));
81+
}
82+
6383
if (pageID.HasValue) doc["buffer"] = page.Buffer.ToArray();
6484

6585
yield return doc;

0 commit comments

Comments
 (0)