예제 #1
0
        public PageManager(uint defaultPageSize, IPersistedStream persistedStream, IBufferPool bufferPool, ILockManager lockManager, InstrumentationInterface logger)
        {
            this.pageSize        = defaultPageSize;
            this.persistedStream = persistedStream;
            this.lockManager     = lockManager;
            this.logger          = logger;
            this.bufferPool      = bufferPool;

            this.AllocatationMapPages = new List <BitTrackingPage>();

            if (!this.persistedStream.IsInitialized())
            {
                logger.LogInfo("Initializing the persisted stream.");
                using (ITransaction tran = new NotLoggedTransaction())
                {
                    MixedPage allocationMapFirstPage = new MixedPage(pageSize, (ulong)AllocationMapPageId, new [] { new ColumnInfo(ColumnType.Int) }, PageManagerConstants.NullPageId, PageManagerConstants.NullPageId, new byte[4096], 0, tran);
                    BitTrackingPage.NullifyMixedPage(allocationMapFirstPage, tran);

                    this.AllocatationMapPages.Add(new BitTrackingPage(allocationMapFirstPage));
                    this.persistedStream.MarkInitialized();
                }
            }
            else
            {
                // TODO: Read boot page.
                logger.LogInfo("Using already initialized stream.");
                ulong     position = AllocationMapPageId * this.pageSize;
                MixedPage allocationMapFirstPage = (MixedPage)this.persistedStream.SeekAndRead(position, PageType.MixedPage, this.bufferPool, new ColumnInfo[] { new ColumnInfo(ColumnType.Int) }).Result;
                this.AllocatationMapPages.Add(new BitTrackingPage(allocationMapFirstPage));

                using (ITransaction tran = new NotLoggedTransaction())
                {
                    // TODO: Here we only iterate the first page.
                    // These pages need to be linked...
                    foreach (int _ in this.AllocatationMapPages.First().FindAllSet(tran))
                    {
                        this.pageCount++;
                    }
                }
            }
        }
예제 #2
0
        private void AddToAllocationMap(IPage page)
        {
            // TODO: This needs to be revisited.
            // It is not ok to use Not logged transaction here.
            // it might be ok to use nested/inner transaction.
            // it is fine to leave the page even if user transaction is rolledbacked.
            BitTrackingPage AMPage            = this.AllocatationMapPages.Last();
            int             maxFit            = AMPage.MaxItemCount();
            uint            allocationMapPage = (uint)(page.PageId() / (uint)maxFit);

            if (allocationMapPage == this.AllocatationMapPages.Count)
            {
                using (ITransaction gamAllocTran = new NotLoggedTransaction())
                {
                    // TODO: Need to keep the list linked here.
                    (Memory <byte> memory, ulong token) = this.bufferPool.GetMemory();
                    MixedPage newAmPage = new MixedPage(
                        pageSize,
                        (ulong)AllocationMapPageId + (ulong)(maxFit * this.AllocatationMapPages.Count),
                        new ColumnInfo[] { new ColumnInfo(ColumnType.Int) },
                        PageManagerConstants.NullPageId,
                        PageManagerConstants.NullPageId,
                        memory,
                        token,
                        gamAllocTran);
                    BitTrackingPage.NullifyMixedPage(newAmPage, gamAllocTran);

                    this.AllocatationMapPages.Add(new BitTrackingPage(newAmPage));
                }
            }

            using (ITransaction gamUpdateTran = new NotLoggedTransaction())
            {
                BitTrackingPage gamPage        = this.AllocatationMapPages.ElementAt((int)allocationMapPage);
                int             positionInPage = (int)(page.PageId() % (uint)maxFit);

                gamPage.Set(positionInPage, gamUpdateTran);
            }
        }