private TransItem WriteStorageContext(StorageContext storageContext) { // write the context to disk List <int> usedPages = null; TransItem contextData = new TransItem(); // write the page table if (null != storageContext.PageTable) { contextData.PageTableStartPage = storageContext.PageTable.WritePageTableData( this.dataFile, this.pageManager, out usedPages); usedPages = storageContext.PageTable.GetStoragePages(); contextData.StoragePageList.AddRange(usedPages); } // write the resource index if (null != storageContext.ResourceIndex) { contextData.ResourceIndexStartPage = storageContext.ResourceIndex.WriteIndexData( this.dataFile, this.pageManager, out usedPages); usedPages = storageContext.ResourceIndex.GetStoragePages(); contextData.StoragePageList.AddRange(usedPages); } // write the reservation index if (null != storageContext.ReservationIndex) { contextData.ReservationIndexStartPage = storageContext.ReservationIndex.WriteIndexData( this.dataFile, this.pageManager, out usedPages); usedPages = storageContext.ReservationIndex.GetStoragePages(); contextData.StoragePageList.AddRange(usedPages); } // write allocated page list if (null != storageContext.AllocatedPageList) { ListWriter <int> writer = new ListWriter <int>(); writer.WriteList( this.dataFile, this.pageManager, storageContext.AllocatedPageList, out usedPages); contextData.AllocatedPageListStartPage = usedPages[0]; contextData.StoragePageList.AddRange(usedPages); } // write freed page list if (null != storageContext.FreedPageList) { ListWriter <int> writer = new ListWriter <int>(); writer.WriteList( this.dataFile, this.pageManager, storageContext.FreedPageList, out usedPages); contextData.FreedPageListStartPage = usedPages[0]; contextData.StoragePageList.AddRange(usedPages); } return(contextData); }
/// <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]); }
/// <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 WritePageManagerData(FileStreamWrapper stream) { lock (this.freePages) { this.writingSelf = true; // make the list of pages to write this.freePages.Insert(0, SelfWriteBarrier); this.freePages.InsertRange(0, this.managerStoragePages); // create writer ListWriter <int> writer = new ListWriter <int>(); writer.WriteList(stream, this, this.freePages, out this.managerStoragePages); this.writingSelf = false; } return(this.managerStoragePages[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]); }
/// <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 WritePageManagerData(FileStreamWrapper stream) { lock (this.freePages) { this.writingSelf = true; // make the list of pages to write this.freePages.Insert(0, SelfWriteBarrier); this.freePages.InsertRange(0, this.managerStoragePages); // create writer ListWriter<int> writer = new ListWriter<int>(); writer.WriteList(stream, this, this.freePages, out this.managerStoragePages); this.writingSelf = false; } return this.managerStoragePages[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]; }