public void TestPageReadFromStreamIsNotWriteable()
 {
     byte[] pageData = MakeTestPage(1, 1, 0, 0);
     var ms = new MemoryStream(pageData);
     var p = new BinaryFilePage(ms, 1ul, 16, 2ul, false);
     Assert.That(p.IsWriteable, Is.False);
 }
 private BinaryFilePage GetPage(ulong pageId, BrightstarProfiler profiler)
 {
     using (profiler.Step("PageStore.GetPage"))
     {
         lock (_pageCacheLock)
         {
             BinaryFilePage page;
             Tuple <BinaryFilePage, ulong> modifiedPage;
             if (_modifiedPages.TryGetValue(pageId, out modifiedPage))
             {
                 profiler.Incr("PageCache Hit");
                 return(modifiedPage.Item1);
             }
             page = PageCache.Instance.Lookup(_filePath, pageId) as BinaryFilePage;
             if (page != null)
             {
                 profiler.Incr("PageCache Hit");
                 return(page);
             }
             using (profiler.Step("Load Page"))
             {
                 profiler.Incr("PageCache Miss");
                 page = new BinaryFilePage(_inputStream, pageId, _nominalPageSize);
                 PageCache.Instance.InsertOrUpdate(_filePath, page);
             }
             return(page);
         }
     }
 }
Esempio n. 3
0
 internal void OnPageModified(BinaryFilePage page)
 {
     _modifiedPages.AddOrUpdate(page.Id, true, (k, v) => true);
     if (_backgroundPageWriter != null)
     {
         _backgroundPageWriter.QueueWrite(page, _writeTxnId);
     }
 }
 public void TestCreateFromStream()
 {
     byte[] pageData = MakeTestPage(1, 1, 0, 0);
     var ms = new MemoryStream(pageData);
     var p = new BinaryFilePage(ms, 1ul, 16, 2ul, false);
     Assert.That(p.FirstTransactionId, Is.EqualTo(1ul));
     Assert.That(BitConverter.ToUInt64(p.FirstBuffer, 0), Is.EqualTo(1ul));
     Assert.That(p.SecondTransactionId, Is.EqualTo(0ul));
     Assert.That(BitConverter.ToUInt64(p.SecondBuffer, 0), Is.EqualTo(0ul));
 }
 public void TestWriteToPage()
 {
     byte[] pageData = MakeTestPage(1, 1, 0, 0);
     var ms = new MemoryStream(pageData);
     var p = new BinaryFilePage(ms, 1ul, 16, 2ul, false);
     p.MakeWriteable(2ul);
     p.SetData(BitConverter.GetBytes(2ul));
     // Data should get written into the second buffer
     Assert.That(BitConverter.ToUInt64(p.SecondBuffer, 0), Is.EqualTo(2ul));
 }
 public BinaryPageAdapter(BinaryFilePageStore store, BinaryFilePage page, ulong currentTransactionId, bool isModified)
 {
     _store = store;
     _page = page;
     _isModified = isModified;
     if (_page.FirstTransactionId > currentTransactionId && _page.SecondTransactionId > currentTransactionId)
     {
         // This is an error condition that would happen if a store is kept open while two successive writes are committed
         throw new ReadWriteStoreModifiedException();
     }
     _data = isModified ? _page.GetWriteBuffer(currentTransactionId) : _page.GetReadBuffer(currentTransactionId);
 }
        public IPage Create(ulong commitId)
        {
            if (!CanWrite)
            {
                throw new InvalidOperationException("Cannot create new pages in a read-only store.");
            }
            var page = new BinaryFilePage(_nextPageId++, _nominalPageSize, _writeTxnId);

            _modifiedPages.AddOrUpdate(page.Id, true, (k, v) => true);
            PageCache.Instance.InsertOrUpdate(_partitionId, page);
            return(page);
        }
 public BinaryPageAdapter(BinaryFilePageStore store, BinaryFilePage page, ulong currentTransactionId, bool isModified)
 {
     _store      = store;
     _page       = page;
     _isModified = isModified;
     if (_page.FirstTransactionId > currentTransactionId && _page.SecondTransactionId > currentTransactionId)
     {
         // This is an error condition that would happen if a store is kept open while two successive writes are committed
         throw new ReadWriteStoreModifiedException();
     }
     _data = isModified ? _page.GetWriteBuffer(currentTransactionId) : _page.GetReadBuffer(currentTransactionId);
 }
 public void TestMakePageWriteable()
 {
     byte[] pageData = MakeTestPage(1, 1, 0, 0);
     var ms = new MemoryStream(pageData);
     var p = new BinaryFilePage(ms, 1ul, 16, 2ul, false);
     p.MakeWriteable(2ul);
     // Data in first buffer should be copied to second buffer
     Assert.That(p.FirstTransactionId, Is.EqualTo(1ul));
     Assert.That(BitConverter.ToUInt64(p.FirstBuffer, 0), Is.EqualTo(1ul));
     Assert.That(p.SecondTransactionId, Is.EqualTo(2ul));
     Assert.That(BitConverter.ToUInt64(p.SecondBuffer, 0), Is.EqualTo(1ul));
 }
 /// <summary>
 /// Creates a new empty page in the page store
 /// </summary>
 /// <param name="commitId"></param>
 /// <returns>The new page</returns>
 public IPage Create(ulong commitId)
 {
     if (_isReadOnly)
     {
         throw new InvalidOperationException("Cannot create new pages in a read-only store.");
     }
     lock (_pageCacheLock)
     {
         var page = new BinaryFilePage(_nextPageId++, _nominalPageSize, CurrentTransactionId);
         _modifiedPages.Add(page.Id, new Tuple <BinaryFilePage, ulong>(page, commitId));
         return(new BinaryPageAdapter(this, page, commitId, true));
     }
 }
Esempio n. 11
0
 /// <summary>
 /// Creates a new empty page in the page store
 /// </summary>
 /// <returns>The ID of the new page</returns>
 public ulong Create()
 {
     if (_isReadOnly)
     {
         throw new InvalidOperationException("Cannot create new pages in a read-only store.");
     }
     lock (_pageCacheLock)
     {
         var page = new BinaryFilePage(_nextPageId++, _nominalPageSize, CurrentTransactionId);
         _modifiedPages.Add(page.Id, page);
         return(page.Id);
     }
 }
 /// <summary>
 /// Creates a new empty page in the page store
 /// </summary>
 /// <param name="commitId"></param>
 /// <returns>The new page</returns>
 public IPage Create(ulong commitId)
 {
     if (_isReadOnly)
     {
         throw new InvalidOperationException("Cannot create new pages in a read-only store.");
     }
     lock (_pageCacheLock)
     {
         var page = new BinaryFilePage(_nextPageId++, _nominalPageSize, CurrentTransactionId);
             _modifiedPages.Add(page.Id, new Tuple<BinaryFilePage, ulong>(page, commitId));
             return new BinaryPageAdapter(this, page, commitId, true);
     }
 }
Esempio n. 13
0
 internal void OnPageModified(BinaryFilePage page)
 {
     _modifiedPages.AddOrUpdate(page.Id, true, (k, v) => true);
 }
Esempio n. 14
0
 public IPage Create(ulong commitId)
 {
     if (!CanWrite)
     {
         throw new InvalidOperationException("Cannot create new pages in a read-only store.");
     }
     var page = new BinaryFilePage(_nextPageId++, _nominalPageSize, _writeTxnId);
     _modifiedPages.AddOrUpdate(page.Id, true, (k, v) => true);
     PageCache.Instance.InsertOrUpdate(_partitionId, page);
     return page;
 }
Esempio n. 15
0
 public void TestNewPageIsWriteable()
 {
     var p = new BinaryFilePage(1ul, 16, 1ul);
     Assert.That(p.IsWriteable);
 }
 private BinaryFilePage GetPage(ulong pageId, BrightstarProfiler profiler)
 {
     using (profiler.Step("PageStore.GetPage"))
     {
         lock (_pageCacheLock)
         {
             BinaryFilePage page;
             Tuple<BinaryFilePage, ulong> modifiedPage;
             if (_modifiedPages.TryGetValue(pageId, out modifiedPage))
             {
                 profiler.Incr("PageCache Hit");
                 return modifiedPage.Item1;
             }
             page = PageCache.Instance.Lookup(_filePath, pageId) as BinaryFilePage;
             if (page != null)
             {
                 profiler.Incr("PageCache Hit");
                 return page;
             }
             using (profiler.Step("Load Page"))
             {
                 profiler.Incr("PageCache Miss");
                 page = new BinaryFilePage(_inputStream, pageId, _nominalPageSize);
                 PageCache.Instance.InsertOrUpdate(_filePath, page);
             }
             return page;
         }
     }
 }
Esempio n. 17
0
 internal void OnPageModified(BinaryFilePage page)
 {
     _modifiedPages.AddOrUpdate(page.Id, true, (k, v) => true);
 }
Esempio n. 18
0
 /// <summary>
 /// Creates a new empty page in the page store
 /// </summary>
 /// <returns>The ID of the new page</returns>
 public ulong Create()
 {
     if (_isReadOnly)
     {
         throw new InvalidOperationException("Cannot create new pages in a read-only store.");
     }
     lock (_pageCacheLock)
     {
         var page = new BinaryFilePage(_nextPageId++, _nominalPageSize, CurrentTransactionId);
         _modifiedPages.Add(page.Id, page);
         return page.Id;
     }
 }
Esempio n. 19
0
 internal void OnPageModified(BinaryFilePage page)
 {
     _modifiedPages.AddOrUpdate(page.Id, true, (k, v) => true);
     _backgroundPageWriter.QueueWrite(page, _writeTxnId);
 }