Example #1
0
        public void AddOrUpdateEntry(PageSummary summary)
        {
            if (!indices.Keys.Contains(summary.AddressSpaceId))
            {
                indices[summary.AddressSpaceId] = new List <PageSummary>();
            }

            if (!summary.PageFileIndex.HasValue)
            {
                stream.Position = stream.Length;
                indices[summary.AddressSpaceId].Add(summary);
                endOfIndex = Math.Max((summary.DataFileOffset + summary.Size), endOfIndex);
            }
            else
            {
                stream.Position = summary.PageFileIndex.Value;
                if (!indices[summary.AddressSpaceId].Contains(summary))
                {
                    //foreach (var space in indices.Values)
                    //{
                    //    if (space.Contains(summary)) space.Remove(summary);
                    //}
                    EmptyPages.Remove(summary);
                    indices[summary.AddressSpaceId].Add(summary);
                    summary.Allocated = true;
                }
            }

            summary.WriteToStream(writer);
        }
Example #2
0
        public PageIndex(Stream stream)
        {
            endOfIndex          = 0;
            this.stream         = stream;
            reader              = new BinaryReader(stream);
            writer              = new BinaryWriter(stream);
            indices             = new Dictionary <Guid, List <PageSummary> >();
            indices[Guid.Empty] = new List <PageSummary>();

            PageSummary summary = null;

            do
            {
                summary = PageSummary.ReadFromStream(reader);
                if (summary != null)
                {
                    if (!indices.Keys.Contains(summary.AddressSpaceId))
                    {
                        indices.Add(summary.AddressSpaceId, new List <PageSummary>());
                    }
                    indices[summary.AddressSpaceId].Add(summary);
                    endOfIndex = summary.DataFileOffset + summary.Size;
                }
            } while (summary != null);
        }
Example #3
0
        public void ExpandAddressSpace(Guid addressSpaceId, long localOffset)
        {
            if (!EmptyPages.Any())
            {
                IndexFileGrowth();
            }
            PageSummary summary = EmptyPages[0];

            summary.AddressSpaceId          = addressSpaceId;
            summary.LocalAddressSpaceOffset = localOffset;
            AddOrUpdateEntry(summary);
        }
Example #4
0
 public void IndexFileGrowth()
 {
     for (int i = 0; i < DbEngineConfigurationSection.ConfigSection.VfsConfig.PageIncreaseNum; i++)
     {
         PageSummary newSummary = new PageSummary();
         newSummary.AddressSpaceId = Guid.Empty;
         newSummary.Allocated      = false;
         newSummary.DataFileOffset = EndOfPageIndex;
         newSummary.Size           = DbEngineConfigurationSection.ConfigSection.VfsConfig.PageSizeInKb;
         newSummary.Used           = 0;
         AddOrUpdateEntry(newSummary);
     }
 }
Example #5
0
        public static PageSummary ReadFromStream(BinaryReader reader)
        {
            if (reader.BaseStream.Position == reader.BaseStream.Length)
            {
                return(null);
            }
            PageSummary summary = new PageSummary();

            summary.pageFileIndex  = reader.BaseStream.Position;
            summary.addressSpaceId = new Guid(reader.ReadBytes(16));
            summary.size           = reader.ReadInt32();
            summary.used           = reader.ReadInt32();
            summary.offset         = reader.ReadInt64();
            summary.localOffset    = reader.ReadInt64();
            summary.allocated      = reader.ReadBoolean();
            return(summary);
        }