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);
            }
        }
Beispiel #2
0
        private void InitializeDataFile()
        {
            // helpers
            List <int> oldPages = null;

            DBHdr dbRoot = new DBHdr();

            WriteDBRoot(dbRoot);

            // create the page table
            StoragePageTable pageTable = new StoragePageTable();

            dbRoot.PageTable = pageTable.WritePageTableData(
                this.dataFile, this.pageManager, out oldPages);

            // create resource index
            StorageIndex <RID> resourceIndx = new StorageIndex <RID>();

            dbRoot.ResourceIndex = resourceIndx.WriteIndexData(
                this.dataFile, this.pageManager, out oldPages);

            // create reservation index
            StorageIndex <Customer> reservationIndex = new StorageIndex <Customer>();

            dbRoot.ReservationIndex = reservationIndex.WriteIndexData(
                this.dataFile, this.pageManager, out oldPages);

            // create preped transactions index
            StorageTransactionTable preparedTransactions = new StorageTransactionTable();

            dbRoot.PrepedTransactions = preparedTransactions.WriteTransactionTableData(
                this.dataFile, this.pageManager, out oldPages);

            // write the page manager
            dbRoot.PageManager = this.pageManager.WritePageManagerData(this.dataFile);

            // write the dbRoot one more time
            WriteDBRoot(dbRoot);
        }