예제 #1
0
        public void SPT_TestReadWriteTable()
        {
            int entryCount = 40;
            int physicalPageDistance = 5;

            string dataFile = "SPT_TestData1.tpdb";
            if (File.Exists(dataFile))
            {
                File.Delete(dataFile);
            }

            List<int> freedPages = null;
            StoragePageManager spaceMgr = new StoragePageManager();
            StoragePageTable pageTable2 = new StoragePageTable();
            StoragePageTable pageTable = new StoragePageTable();
            for (int idx = 0; idx < entryCount; idx++)
            {
                pageTable.SetLogicalPage(idx + physicalPageDistance);
            }

            using (FileStreamWrapper dataFileStream = FileStreamWrapper.CreateObject(dataFile))
            {
                int root = pageTable.WritePageTableData(dataFileStream, spaceMgr, out freedPages);
                dataFileStream.Seek(0, SeekOrigin.Begin);
                pageTable2.ReadPageTableData(dataFileStream, root);
            }

            for (int idx = 0; idx < entryCount; idx++)
            {
                int physicalAddress = pageTable2.GetPhysicalPage(idx);
                Assert.AreEqual(idx + physicalPageDistance, physicalAddress);
            }
        }
예제 #2
0
        /// <summary>
        /// Default constructor.
        /// </summary>
        protected StorageManager()
        {
            this.activeContextMap   = new Dictionary <Transaction, StorageContext>();
            this.preparedContextMap = new StorageTransactionTable();
            this.pageManager        = new StoragePageManager();

            this.lockManager = new MyLM();

            this.disposed = false;
        }
예제 #3
0
        /// <summary>
        /// Writes the page table item to persitent storage as a list of items.
        /// </summary>
        /// <param name="stream">data file</param>
        /// <param name="manager">object that keeps track of free pages in the file</param>
        /// <param name="freedPages">list of pages to be freed when transaction commits</param>
        /// <returns>index of the first page storing the list</returns>
        public int WritePageTableData(FileStreamWrapper stream, StoragePageManager manager, out List <int> freedPages)
        {
            List <int> pageIdxList = null;

            // create the writer
            ListWriter <PageTableItem> writer = new ListWriter <PageTableItem>();

            writer.WriteList(stream, manager, this.pageTable, out pageIdxList);

            // update the list that stores the physical page idx
            freedPages = this.pageTableStoragePages;
            this.pageTableStoragePages = pageIdxList;

            // return the index of the first page
            return(this.pageTableStoragePages[0]);
        }
예제 #4
0
        /// <summary>
        /// Writes the index item to persitent storage as a list of items.
        /// We handle deletes by setting the "value" in the map to null and
        /// not writing any items whose value is null to persistent storage.
        /// </summary>
        /// <param name="stream">data file to write to</param>
        /// <param name="manager">object that keeps track of free pages in the file</param>
        /// <param name="freedPages">list of pages to be freed when transaction commits</param>
        /// <returns>index of the first page storing the list</returns>
        public int WriteIndexData(FileStreamWrapper stream, StoragePageManager manager, out List <int> freedPages)
        {
            List <int> pageIdxList = null;

            // create the writer
            ListWriter <IndexItem <T> > writer = new ListWriter <IndexItem <T> >();

            writer.WriteList(
                stream,
                manager,
                this.indexMap.Values.Where(c => c != null).ToList(),
                out pageIdxList);

            // update the list that stores the physical page idx
            freedPages             = this.indexStoragePages;
            this.indexStoragePages = pageIdxList;

            // return the index of the first page
            return(this.indexStoragePages[0]);
        }
예제 #5
0
        /// <summary>
        /// Writes the data item to persitent storage as a list of items.
        /// </summary>
        /// <param name="stream">data file to write to</param>
        /// <param name="manager">object that keeps track of free pages in the file</param>
        /// <param name="freedPages">list of pages to be freed when transaction commits</param>
        /// <returns>index of the first page storing the list</returns>
        public int WriteTransactionTableData(FileStreamWrapper stream, StoragePageManager manager, out List<int> freedPages)
        {
            List<int> pageIdxList = null;

            // create the writer
            ListWriter<TransItem> writer = new ListWriter<TransItem>();
            writer.WriteList(stream, manager, this.contextTable.Values.ToList() , out pageIdxList);

            // update the list that stores the physical page idx
            freedPages = this.contextTableStoragePages;
            this.contextTableStoragePages = pageIdxList;

            // return the index of the first page
            return this.contextTableStoragePages[0];
        }