예제 #1
0
        /// <summary>
        /// Get a single page from database based on newsest version of page (use only PageID)
        /// </summary>
        private IEnumerable <BsonDocument> DumpPages(uint pageID)
        {
            var collections = _header.GetCollections().ToDictionary(x => x.Value, x => x.Key);

            // get any transaction from current thread ID
            var transaction = _monitor.GetThreadTransaction();

            var snapshot = transaction.CreateSnapshot(LockMode.Read, "$", false);

            var page = pageID == 0 ? _header : snapshot.GetPage <BasePage>(pageID);

            var doc = new BsonDocument
            {
                ["pageID"]           = (int)page.PageID,
                ["pageType"]         = page.PageType.ToString(),
                ["nextPageID"]       = (int)page.NextPageID,
                ["prevPageID"]       = (int)page.PrevPageID,
                ["collection"]       = collections.GetOrDefault(page.ColID, "-"),
                ["itemsCount"]       = (int)page.ItemsCount,
                ["freeBytes"]        = page.FreeBytes,
                ["usedBytes"]        = (int)page.UsedBytes,
                ["fragmentedBytes"]  = (int)page.FragmentedBytes,
                ["nextFreePosition"] = (int)page.NextFreePosition,
                ["highestIndex"]     = (int)page.HighestIndex,
                ["buffer"]           = page.Buffer.ToArray()
            };

            yield return(doc);
        }
예제 #2
0
        public override IEnumerable <BsonDocument> Input(BsonValue options)
        {
            var pageID = GetOption(options, "pageID");

            // get any transaction from current thread ID
            var transaction = _monitor.GetThreadTransaction();
            var snapshot    = transaction.CreateSnapshot(LockMode.Read, "$", false);

            _collections = _header.GetCollections().ToDictionary(x => x.Value, x => x.Key);

            try
            {
                var result = pageID != null?
                             this.GetList((uint)pageID.AsInt32, null, transaction, snapshot) :
                                 this.GetAllList(transaction, snapshot);

                foreach (var page in result)
                {
                    yield return(page);
                }
            }
            finally
            {
                transaction.Commit();
            }
        }
예제 #3
0
파일: SysDump.cs 프로젝트: zipfried/Cytoid
        private IEnumerable <BsonDocument> DumpPages(uint?pageID)
        {
            var collections = _header.GetCollections().ToDictionary(x => x.Value, x => x.Key);

            // get any transaction from current thread ID
            var transaction = _monitor.GetThreadTransaction();

            var snapshot = transaction.CreateSnapshot(LockMode.Read, "$", false);

            var start = pageID.HasValue ? pageID.Value : 0;
            var end   = pageID.HasValue ? pageID.Value : _header.LastPageID;

            for (uint i = start; i <= Math.Min(end, _header.LastPageID); i++)
            {
                var page = snapshot.GetPage <BasePage>(i, out var origin, out var position, out var walVersion);

                var doc = new BsonDocument
                {
                    ["pageID"]           = (int)page.PageID,
                    ["pageType"]         = page.PageType.ToString(),
                    ["_position"]        = position,
                    ["_origin"]          = origin.ToString(),
                    ["_version"]         = walVersion,
                    ["nextPageID"]       = (int)page.NextPageID,
                    ["prevPageID"]       = (int)page.PrevPageID,
                    ["collection"]       = collections.GetOrDefault(page.ColID, "-"),
                    ["itemsCount"]       = (int)page.ItemsCount,
                    ["freeBytes"]        = page.FreeBytes,
                    ["usedBytes"]        = (int)page.UsedBytes,
                    ["fragmentedBytes"]  = (int)page.FragmentedBytes,
                    ["nextFreePosition"] = (int)page.NextFreePosition,
                    ["highestIndex"]     = (int)page.HighestIndex
                };

                if (pageID.HasValue)
                {
                    doc["buffer"] = page.Buffer.ToArray();
                }

                yield return(doc);

                transaction.Safepoint();
            }
        }
예제 #4
0
        private IEnumerable <BsonDocument> DumpPages(uint?pageID)
        {
            var collections = _header.GetCollections().ToDictionary(x => x.Value, x => x.Key);

            // get any transaction from current thread ID
            var transaction = _monitor.GetThreadTransaction();

            var snapshot = transaction.CreateSnapshot(LockMode.Read, "$", false);

            var start = pageID.HasValue ? pageID.Value : 0;
            var end   = pageID.HasValue ? pageID.Value : _header.LastPageID;

            for (uint i = start; i <= Math.Min(end, _header.LastPageID); i++)
            {
                var page = snapshot.GetPage <BasePage>(i, out var origin, out var position, out var walVersion);

                var doc = new BsonDocument
                {
                    ["pageID"]           = (int)page.PageID,
                    ["pageType"]         = page.PageType.ToString(),
                    ["_position"]        = position,
                    ["_origin"]          = origin.ToString(),
                    ["_version"]         = walVersion,
                    ["prevPageID"]       = (int)page.PrevPageID,
                    ["nextPageID"]       = (int)page.NextPageID,
                    ["slot"]             = (int)page.PageListSlot,
                    ["collection"]       = collections.GetOrDefault(page.ColID, "-"),
                    ["itemsCount"]       = (int)page.ItemsCount,
                    ["freeBytes"]        = page.FreeBytes,
                    ["usedBytes"]        = (int)page.UsedBytes,
                    ["fragmentedBytes"]  = (int)page.FragmentedBytes,
                    ["nextFreePosition"] = (int)page.NextFreePosition,
                    ["highestIndex"]     = (int)page.HighestIndex
                };

                if (page.PageType == PageType.Collection)
                {
                    var collectionPage = new CollectionPage(page.Buffer);
                    doc["dataPageList"] = new BsonArray(collectionPage.FreeDataPageList.Select(x => new BsonValue((int)x)));
                    doc["indexes"]      = new BsonArray(collectionPage.GetCollectionIndexes().Select(x => new BsonDocument
                    {
                        ["slot"]              = (int)x.Slot,
                        ["empty"]             = x.IsEmpty,
                        ["indexType"]         = (int)x.IndexType,
                        ["name"]              = x.Name,
                        ["expression"]        = x.Expression,
                        ["unique"]            = x.Unique,
                        ["head"]              = x.Head.ToBsonValue(),
                        ["tail"]              = x.Tail.ToBsonValue(),
                        ["maxLevel"]          = (int)x.MaxLevel,
                        ["freeIndexPageList"] = (int)x.FreeIndexPageList,
                    }));
                }

                if (pageID.HasValue)
                {
                    doc["buffer"] = page.Buffer.ToArray();
                }

                yield return(doc);

                transaction.Safepoint();
            }
        }