Example #1
0
        /// <summary>
        /// Reads the list of page table items whose head is stored at the page index provided.
        /// The data read from persistent storage is merges with the data already in memory
        /// using the following protocol:
        ///     if the in memory data has the "IsDirty" flag set then we keep the in memory data
        ///     else we over-write the in-memory data with the data from disk
        /// </summary>
        /// <param name="stream">data file to read from</param>
        /// <param name="pageIdx">index of the first physical page storing the list</param>
        /// <returns>returns the index of the first physical page we read data from</returns>
        public int ReadPageTableData(FileStreamWrapper stream, int pageIdx)
        {
            List <PageTableItem> itemList    = null;
            List <int>           pageIdxList = null;

            // create reader
            ListReader <PageTableItem> reader = new ListReader <PageTableItem>();

            reader.ReadList(stream, pageIdx, out itemList, out pageIdxList);

            // merge with current data
            for (int idx = 0; idx < this.pageTable.Count && idx < itemList.Count; idx++)
            {
                if (!this.pageTable[idx].IsDirty)
                {
                    this.pageTable[idx] = itemList[idx];
                }
            }

            // add the missing ones
            if (this.pageTable.Count < itemList.Count)
            {
                this.pageTable.AddRange(
                    itemList.GetRange(
                        this.pageTable.Count,
                        (itemList.Count - this.pageTable.Count)));
            }

            // update page index
            this.pageTableStoragePages = pageIdxList;

            // return index of the first page
            return(this.pageTableStoragePages[0]);
        }
Example #2
0
        /// <summary>
        /// Reads the list of index items whose head is stored at the page index provided.
        /// The data read from persistent storage is merges with the data already in memory
        /// using the following protocol:
        ///     if the in memory data has the "IsDirty" flag set then we keep the in memory data
        ///     else we over-write the in-memory data with the data from disk
        /// </summary>
        /// <param name="stream">data file to read from</param>
        /// <param name="pageIdx">index of the first physical page storing the list</param>
        /// <returns>returns the index of the first physical page we read data from</returns>
        public int ReadIndexData(FileStreamWrapper stream, int pageIdx)
        {
            List <IndexItem <T> > itemList    = null;
            List <int>            pageIdxList = null;

            // create reader
            ListReader <IndexItem <T> > reader = new ListReader <IndexItem <T> >();

            reader.ReadList(stream, pageIdx, out itemList, out pageIdxList);

            // merge with current data
            for (int idx = 0; idx < itemList.Count; idx++)
            {
                var item = itemList[idx];

                IndexItem <T> indexEntry = null;
                if (this.indexMap.TryGetValue(item.ResourceId, out indexEntry))
                {
                    if (null == indexEntry ||
                        indexEntry.IsDirty)
                    {
                        continue;
                    }
                }

                this.indexMap[item.ResourceId] = item;
            }

            // update page index
            this.indexStoragePages = pageIdxList;

            // return index of the first page
            return(this.indexStoragePages[0]);
        }
Example #3
0
        /// <summary>
        /// Reads the list of data items whose head is stored at the page index provided.
        /// </summary>
        /// <param name="stream">data file to read from</param>
        /// <param name="pageIdx">index of the first physical page storing the list</param>
        /// <returns>returns the index of the first physical page we read data from</returns>
        public int ReadPageManagerData(FileStreamWrapper stream, int pageIdx)
        {
            List <int> itemList    = null;
            List <int> pageIdxList = null;

            // create reader
            ListReader <int> reader = new ListReader <int>();

            reader.ReadList(stream, pageIdx, out itemList, out pageIdxList);

            // merge with current data
            this.SetFreePages(itemList);

            // update page index
            this.managerStoragePages = pageIdxList;

            return(this.managerStoragePages[0]);
        }
        /// <summary>
        /// Reads the list of data items whose head is stored at the page index provided.
        /// </summary>
        /// <param name="stream">data file to read from</param>
        /// <param name="pageIdx">index of the first physical page storing the list</param>
        /// <returns>returns the index of the first physical page we read data from</returns>
        public int ReadTransactionTableData(FileStreamWrapper stream, int pageIdx)
        {
            List<TransItem> itemList = null;
            List<int> pageIdxList = null;

            // create reader
            ListReader<TransItem> reader = new ListReader<TransItem>();
            reader.ReadList(stream, pageIdx, out itemList, out pageIdxList);

            // clear the current data
            this.contextTable.Clear();

            foreach (TransItem item in itemList)
            {
                this.contextTable.Add(item.Transaction, item);
            }

            // update page index
            this.contextTableStoragePages = pageIdxList;

            // return index of the first page
            return this.contextTableStoragePages[0];
        }
        /// <summary>
        /// Reads the list of data items whose head is stored at the page index provided.
        /// </summary>
        /// <param name="stream">data file to read from</param>
        /// <param name="pageIdx">index of the first physical page storing the list</param>
        /// <returns>returns the index of the first physical page we read data from</returns>
        public int ReadTransactionTableData(FileStreamWrapper stream, int pageIdx)
        {
            List <TransItem> itemList    = null;
            List <int>       pageIdxList = null;

            // create reader
            ListReader <TransItem> reader = new ListReader <TransItem>();

            reader.ReadList(stream, pageIdx, out itemList, out pageIdxList);

            // clear the current data
            this.contextTable.Clear();

            foreach (TransItem item in itemList)
            {
                this.contextTable.Add(item.Transaction, item);
            }

            // update page index
            this.contextTableStoragePages = pageIdxList;

            // return index of the first page
            return(this.contextTableStoragePages[0]);
        }
Example #6
0
        /// <summary>
        /// Reads the list of data items whose head is stored at the page index provided.
        /// </summary>
        /// <param name="stream">data file to read from</param>
        /// <param name="pageIdx">index of the first physical page storing the list</param>
        /// <returns>returns the index of the first physical page we read data from</returns>
        public int ReadPageManagerData(FileStreamWrapper stream, int pageIdx)
        {
            List<int> itemList = null;
            List<int> pageIdxList = null;

            // create reader
            ListReader<int> reader = new ListReader<int>();
            reader.ReadList(stream, pageIdx, out itemList, out pageIdxList);

            // merge with current data
            this.SetFreePages(itemList);

            // update page index
            this.managerStoragePages = pageIdxList;

            return this.managerStoragePages[0];
        }
Example #7
0
        /// <summary>
        /// Reads the list of page table items whose head is stored at the page index provided.
        /// The data read from persistent storage is merges with the data already in memory
        /// using the following protocol:
        ///     if the in memory data has the "IsDirty" flag set then we keep the in memory data
        ///     else we over-write the in-memory data with the data from disk
        /// </summary>
        /// <param name="stream">data file to read from</param>
        /// <param name="pageIdx">index of the first physical page storing the list</param>
        /// <returns>returns the index of the first physical page we read data from</returns>
        public int ReadPageTableData(FileStreamWrapper stream, int pageIdx)
        {
            List<PageTableItem> itemList = null;
            List<int> pageIdxList = null;

            // create reader
            ListReader<PageTableItem> reader = new ListReader<PageTableItem>();
            reader.ReadList(stream, pageIdx, out itemList, out pageIdxList);

            // merge with current data
            for (int idx = 0; idx < this.pageTable.Count && idx < itemList.Count; idx++)
            {
                if (!this.pageTable[idx].IsDirty)
                {
                    this.pageTable[idx] = itemList[idx];
                }
            }

            // add the missing ones
            if (this.pageTable.Count < itemList.Count)
            {
                this.pageTable.AddRange(
                    itemList.GetRange(
                        this.pageTable.Count,
                        (itemList.Count - this.pageTable.Count)));
            }

            // update page index
            this.pageTableStoragePages = pageIdxList;

            // return index of the first page
            return this.pageTableStoragePages[0];
        }
Example #8
0
        private StorageContext ReadStorageContext(TransItem contextData, out List <int> oldStorageContextPages)
        {
            // allocate the storage page list
            oldStorageContextPages = new List <int>();

            // look for the context in the map
            StorageContext storageContext = new StorageContext();

            // read in the page table
            if (TransItem.NotStored != contextData.PageTableStartPage)
            {
                storageContext.PageTable.ReadPageTableData(
                    this.dataFile, contextData.PageTableStartPage);
                oldStorageContextPages.AddRange(
                    storageContext.PageTable.GetStoragePages());
            }

            // read in the resource index
            if (TransItem.NotStored != contextData.ResourceIndexStartPage)
            {
                storageContext.ResourceIndex.ReadIndexData(
                    this.dataFile, contextData.ResourceIndexStartPage);
                oldStorageContextPages.AddRange(
                    storageContext.ResourceIndex.GetStoragePages());
            }

            // read in the reservation index
            if (TransItem.NotStored != contextData.ReservationIndexStartPage)
            {
                storageContext.ReservationIndex.ReadIndexData(
                    this.dataFile, contextData.ReservationIndexStartPage);
                oldStorageContextPages.AddRange(
                    storageContext.ReservationIndex.GetStoragePages());
            }

            // read in the allocated page list
            if (TransItem.NotStored != contextData.AllocatedPageListStartPage)
            {
                List <int> usedPages = null;
                List <int> data      = null;

                ListReader <int> reader = new ListReader <int>();
                reader.ReadList(this.dataFile, contextData.AllocatedPageListStartPage, out data, out usedPages);

                storageContext.AllocatedPageList = data;
                oldStorageContextPages.AddRange(usedPages);
            }

            // read in the freed page list
            if (TransItem.NotStored != contextData.FreedPageListStartPage)
            {
                List <int> usedPages = null;
                List <int> data      = null;

                ListReader <int> reader = new ListReader <int>();
                reader.ReadList(this.dataFile, contextData.FreedPageListStartPage, out data, out usedPages);

                storageContext.FreedPageList = data;
                oldStorageContextPages.AddRange(usedPages);
            }

            return(storageContext);
        }