/// <summary>
 /// Writes data to the specified page
 /// </summary>
 /// <param name="commitId">The transaction id for the update</param>
 /// <param name="pageId">The ID of the page to write to</param>
 /// <param name="buff">The data to be written</param>
 /// <param name="srcOffset">The offset into <paramref name="buff"/> from which to start copying bytes. Defaults to 0</param>
 /// <param name="pageOffset">The offset into the page data buffer to start writing to. Defaults to 0</param>
 /// <param name="len">The number of bytes to write. Defaults to all bytes in <paramref name="buff"/> from the specified <paramref name="srcOffset"/></param>
 /// <param name="profiler"></param>
 public void Write(ulong commitId, ulong pageId, byte[] buff, int srcOffset = 0, int pageOffset = 0, int len = -1, BrightstarProfiler profiler = null)
 {
     using (profiler.Step("Write Page"))
     {
         var page      = GetPage(pageId, profiler);
         var writeBuff = page.GetWriteBuffer(commitId);
         Array.Copy(buff, srcOffset, writeBuff, pageOffset, len < 0 ? buff.Length : len);
         _modifiedPages[pageId] = new Tuple <BinaryFilePage, ulong>(page, commitId);
     }
 }
        /// <summary>
        /// Returns a writeable copy of the specified page
        /// </summary>
        /// <param name="commitId">The transaction id for the write operation</param>
        /// <param name="page">The page to return a writeable version of</param>
        /// <returns></returns>
        public IPage GetWriteablePage(ulong commitId, IPage page)
        {
            Tuple <BinaryFilePage, ulong> bfpTuple;

            if (!_modifiedPages.TryGetValue(page.Id, out bfpTuple))
            {
#if DEBUG_BTREE
                Logging.LogDebug("Initialized Write Buffer for page@{0} in commit {1}", page.Id, commitId);
#endif
                var bfp = GetPage(page.Id, null);
                Array.ConstrainedCopy(bfp.GetReadBuffer(CurrentTransactionId), 0,
                                      bfp.GetWriteBuffer(commitId), 0,
                                      PageSize);
                bfpTuple = new Tuple <BinaryFilePage, ulong>(bfp, commitId);
                _modifiedPages[bfp.Id] = bfpTuple;
            }
            return(new BinaryPageAdapter(this, bfpTuple.Item1, commitId, true));
        }
Exemplo n.º 3
0
        private void Load(Stream inputStream)
        {
            var header = new byte[HeaderSize];

            inputStream.Read(header, 0, HeaderSize);
            uint magicNumber = BitConverter.ToUInt32(header, 0);

            if (magicNumber != MagicNumber)
            {
                throw new Exception("Invalid master file. Magic number does not match expected value");
            }
            StoreType          = (StoreType)header[4];
            PersistenceType    = (PersistenceType)header[5];
            StoreFormatVersion = BitConverter.ToInt32(header, 6);
            var guidBytes = new byte[16];

            Array.Copy(header, 10, guidBytes, 0, 16);
            StoreSetId = new Guid(guidBytes);
            Array.Copy(header, 26, guidBytes, 0, 16);
            StoreId = new Guid(guidBytes);
        }
Exemplo n.º 4
0
 // TODO: Modify the interface so that we don't have to implement this stub
 public void Write(ulong commitId, ulong pageId, byte[] buff, int srcOffset = 0, int pageOffset = 0, int len = -1,
                   BrightstarProfiler profiler = null)
 {
     // This method is only used by the ResourceTable, which is always an append-only store.
     throw new NotImplementedException();
 }