Esempio n. 1
0
 public void GetPfsPointerForPage()
 {
     Assert.AreEqual(new PagePointer(1, 1), PfsPage.GetPfsPointerForPage(new PagePointer(1, 27)));
     Assert.AreEqual(new PagePointer(1, 1), PfsPage.GetPfsPointerForPage(new PagePointer(1, 0)));
     Assert.AreEqual(new PagePointer(1, 1), PfsPage.GetPfsPointerForPage(new PagePointer(1, 8087)));
     Assert.AreEqual(new PagePointer(1, 8088), PfsPage.GetPfsPointerForPage(new PagePointer(1, 8088)));
     Assert.AreEqual(new PagePointer(1, 8088), PfsPage.GetPfsPointerForPage(new PagePointer(1, 8089)));
 }
Esempio n. 2
0
        /// <summary>
        /// Scans a heap beginning from the provided IAM page and onwards.
        /// </summary>
        private IEnumerable <Row> scanHeap(PagePointer loc, Row schema, CompressionContext compression)
        {
            // Traverse the linked list of IAM pages untill the tail pointer is zero
            while (loc != PagePointer.Zero)
            {
                // Before scanning, check that the IAM page itself is allocated
                var pfsPage = Database.GetPfsPage(PfsPage.GetPfsPointerForPage(loc));

                // If IAM page isn't allocated, there's nothing to return
                if (!pfsPage.GetPageDescription(loc.PageID).IsAllocated)
                {
                    yield break;
                }

                var iamPage = Database.GetIamPage(loc);

                // Create an array with all of the header slot pointers
                var iamPageSlots = new[]
                {
                    iamPage.Slot0,
                    iamPage.Slot1,
                    iamPage.Slot2,
                    iamPage.Slot3,
                    iamPage.Slot4,
                    iamPage.Slot5,
                    iamPage.Slot6,
                    iamPage.Slot7
                };

                // Loop each header slot and yield the results, provided the header slot is allocated
                foreach (var slot in iamPageSlots.Where(x => x != PagePointer.Zero))
                {
                    var recordParser = RecordEntityParser.CreateEntityParserForPage(slot, compression, Database);

                    foreach (var dr in recordParser.GetEntities(schema))
                    {
                        yield return(dr);
                    }
                }

                // Then loop through allocated extents and yield results
                foreach (var extent in iamPage.GetAllocatedExtents())
                {
                    // Get PFS page that tracks this extent
                    var pfs = Database.GetPfsPage(PfsPage.GetPfsPointerForPage(extent.StartPage));

                    foreach (var pageLoc in extent.GetPagePointers())
                    {
                        // Check if page is allocated according to PFS page
                        var pfsDescription = pfs.GetPageDescription(pageLoc.PageID);

                        if (!pfsDescription.IsAllocated)
                        {
                            continue;
                        }

                        var recordParser = RecordEntityParser.CreateEntityParserForPage(pageLoc, compression, Database);

                        foreach (var dr in recordParser.GetEntities(schema))
                        {
                            yield return(dr);
                        }
                    }
                }

                // Update current IAM chain location to the tail pointer
                loc = iamPage.Header.NextPage;
            }
        }