Example #1
0
        public PersistedStream(ulong startFileSize, string fileName, bool createNew, InstrumentationInterface logger)
        {
            this.logger = logger;

            string shadowFileName = fileName + ".shadow";

            if (File.Exists(fileName) && !createNew)
            {
                this.fileStream       = new FileStream(fileName, FileMode.Open, FileAccess.ReadWrite);
                this.fileStreamShadow = new FileStream(shadowFileName, FileMode.Open, FileAccess.ReadWrite);
                isInitialized         = true;
            }
            else
            {
                if (File.Exists(fileName))
                {
                    File.Delete(fileName);
                    File.Delete(shadowFileName);
                }

                this.fileStream = new FileStream(fileName, FileMode.CreateNew, FileAccess.ReadWrite);
                this.fileStream.SetLength((long)startFileSize);
                this.fileStreamShadow = new FileStream(shadowFileName, FileMode.CreateNew, FileAccess.ReadWrite);
                isInitialized         = false;
            }

            this.binaryWriter       = new BinaryWriter(this.fileStream);
            this.binaryReader       = new BinaryReader(this.fileStream);
            this.binaryReaderShadow = new BinaryReader(this.fileStreamShadow);
            this.binaryWriterShadow = new BinaryWriter(this.fileStreamShadow);

            this.fileName = fileName;
        }
Example #2
0
        public PageManager(uint defaultPageSize, IPersistedStream persistedStream, IBufferPool bufferPool, ILockManager lockManager, InstrumentationInterface logger)
        {
            this.pageSize        = defaultPageSize;
            this.persistedStream = persistedStream;
            this.lockManager     = lockManager;
            this.logger          = logger;
            this.bufferPool      = bufferPool;

            this.AllocatationMapPages = new List <BitTrackingPage>();

            if (!this.persistedStream.IsInitialized())
            {
                logger.LogInfo("Initializing the persisted stream.");
                using (ITransaction tran = new NotLoggedTransaction())
                {
                    MixedPage allocationMapFirstPage = new MixedPage(pageSize, (ulong)AllocationMapPageId, new [] { new ColumnInfo(ColumnType.Int) }, PageManagerConstants.NullPageId, PageManagerConstants.NullPageId, new byte[4096], 0, tran);
                    BitTrackingPage.NullifyMixedPage(allocationMapFirstPage, tran);

                    this.AllocatationMapPages.Add(new BitTrackingPage(allocationMapFirstPage));
                    this.persistedStream.MarkInitialized();
                }
            }
            else
            {
                // TODO: Read boot page.
                logger.LogInfo("Using already initialized stream.");
                ulong     position = AllocationMapPageId * this.pageSize;
                MixedPage allocationMapFirstPage = (MixedPage)this.persistedStream.SeekAndRead(position, PageType.MixedPage, this.bufferPool, new ColumnInfo[] { new ColumnInfo(ColumnType.Int) }).Result;
                this.AllocatationMapPages.Add(new BitTrackingPage(allocationMapFirstPage));

                using (ITransaction tran = new NotLoggedTransaction())
                {
                    // TODO: Here we only iterate the first page.
                    // These pages need to be linked...
                    foreach (int _ in this.AllocatationMapPages.First().FindAllSet(tran))
                    {
                        this.pageCount++;
                    }
                }
            }
        }