コード例 #1
0
ファイル: ResourceTable.cs プロジェクト: illinar/BrightstarDB
 /// <summary>
 /// Retrieve the resource at the specified page and segment offset
 /// </summary>
 /// <param name="pageId">The ID of the page that holds the resource to be retrieved</param>
 /// <param name="segment">The index of the segment within the page that holds the start of the resource</param>
 /// <param name="profiler"></param>
 /// <returns>The resource</returns>
 public string GetResource(ulong pageId, byte segment, BrightstarProfiler profiler)
 {
     using (profiler.Step("ResourceTable.GetResource"))
     {
         var currentPage    = _pageStore.Retrieve(pageId, profiler);
         int resourceLength = BitConverter.ToInt32(currentPage, segment * _segmentSize);
         int totalLength    = resourceLength + 4;
         int segmentsToLoad = totalLength / _segmentSize;
         if (totalLength % _segmentSize > 0)
         {
             segmentsToLoad++;
         }
         var  buffer       = new byte[segmentsToLoad * _segmentSize];
         byte segmentIndex = segment;
         for (int i = 0; i < segmentsToLoad; i++)
         {
             if (segmentIndex == _pointerSegment)
             {
                 ulong nextPageId = BitConverter.ToUInt64(currentPage, _pageStore.PageSize - 8);
                 currentPage  = _pageStore.Retrieve(nextPageId, profiler);
                 segmentIndex = 0;
             }
             Array.Copy(currentPage, segmentIndex * _segmentSize, buffer, i * _segmentSize, _segmentSize);
             segmentIndex++;
         }
         return(Encoding.UTF8.GetString(buffer, 4, resourceLength));
     }
 }
コード例 #2
0
        public INode GetNode(ulong nodeId, BrightstarProfiler profiler)
        {
            using (profiler.Step("BPlusTree.GetNode"))
            {
                INode ret;
                if (_modifiedNodes.TryGetValue(nodeId, out ret))
                {
                    profiler.Incr("NodeCache Hit");
                    return(ret);
                }
                if (_nodeCache.TryGetValue(nodeId, out ret))
                {
                    profiler.Incr("NodeCache Hit");
                    return(ret);
                }

                profiler.Incr("NodeCache Miss");
                using (profiler.Step("Load Node"))
                {
                    var nodePage = _pageStore.Retrieve(nodeId, profiler);
                    var header   = BitConverter.ToInt32(nodePage, 0);
                    if (header < 0)
                    {
                        ret = new InternalNode(nodeId, nodePage, ~header, _config);
                    }
                    else
                    {
                        ret = new LeafNode(nodeId, nodePage, header, _config);
                    }
                    _nodeCache.Add(ret);
                    return(ret);
                }
            }
        }
コード例 #3
0
        public INode GetNode(ulong nodeId, BrightstarProfiler profiler)
        {
            using (profiler.Step("BPlusTree.GetNode"))
            {
                INode ret;
                if (_nodeCache.TryGetValue(nodeId, out ret))
                {
                    profiler.Incr("NodeCache Hit");
                    return(ret);
                }

                profiler.Incr("NodeCache Miss");
                using (profiler.Step("Load Node"))
                {
                    var nodePage = _pageStore.Retrieve(nodeId, profiler);
                    var header   = BitConverter.ToInt32(nodePage.Data, 0);
                    if (header < 0)
                    {
                        ret = MakeInternalNode(nodePage, ~header);
#if DEBUG_BTREE
                        _config.BTreeDebug("{0}: Loaded INTERNAL node from page {1}. {2}", _config.DebugId, nodePage.Id, ret.ToString());
#endif
                    }
                    else
                    {
                        ret = MakeLeafNode(nodePage, header);
#if DEBUG_BTREE
                        _config.BTreeDebug("{0}: Loaded LEAF node from page {1}. {2}", _config.DebugId, nodePage.Id, ret.ToString());
#endif
                    }
                    _nodeCache.Add(ret);
                    return(ret);
                }
            }
        }
コード例 #4
0
        public PrefixManager(IPageStore pageStore, ulong startPageId, BrightstarProfiler profiler)
        {
            _pageStore = pageStore;
            var startPage = _pageStore.Retrieve(startPageId, profiler);

            Load(startPage, profiler);
        }
コード例 #5
0
 /// <summary>
 /// Performs the actual load of prefixes from a page.
 /// </summary>
 /// <param name="page"></param>
 /// <param name="profiler"></param>
 /// <remarks>Calls to this method should be made inside a critical section of code protected with a mutex or reader/writer lock</remarks>
 private void InterlockedLoad(IPage page, BrightstarProfiler profiler)
 {
     using (profiler.Step("PrefixManager.InterlockedLoad"))
     {
         int offset = 0;
         while (offset < _pageStore.PageSize)
         {
             ushort prefixLength = BitConverter.ToUInt16(page.Data, offset);
             offset += 2;
             if (prefixLength == ushort.MaxValue)
             {
                 ulong nextPageId = BitConverter.ToUInt64(page.Data, offset);
                 if (nextPageId == 0)
                 {
                     // End of data
                     return;
                 }
                 page   = _pageStore.Retrieve(nextPageId, profiler);
                 offset = 0;
             }
             else
             {
                 var prefix = Encoding.UTF8.GetString(page.Data, offset, prefixLength);
                 offset += prefixLength;
                 var uriLen = BitConverter.ToUInt16(page.Data, offset);
                 offset += 2;
                 var uri = Encoding.UTF8.GetString(page.Data, offset, uriLen);
                 offset += uriLen;
                 _prefixMappings[uri]        = prefix;
                 _shortValueMappings[prefix] = uri;
             }
         }
     }
 }
コード例 #6
0
ファイル: Store.cs プロジェクト: rexwhitten/BrightstarDB
 public Store(string storeLocation, IPageStore dataPageStore, IResourceTable resourceTable, ulong storePageId, BrightstarProfiler profiler)
 {
     using (profiler.Step("Load Store"))
     {
         DirectoryPath = storeLocation;
         _pageStore = dataPageStore;
         _resourceTable = resourceTable;
         var storePage = _pageStore.Retrieve(storePageId, profiler);
         Load(storePage, profiler);
     }
 }
コード例 #7
0
ファイル: Store.cs プロジェクト: rexwhitten/BrightstarDB
 public Store(string storeLocation, IPageStore dataPageStore, IResourceTable resourceTable, ulong storePageId, BrightstarProfiler profiler)
 {
     using (profiler.Step("Load Store"))
     {
         DirectoryPath  = storeLocation;
         _pageStore     = dataPageStore;
         _resourceTable = resourceTable;
         var storePage = _pageStore.Retrieve(storePageId, profiler);
         Load(storePage, profiler);
     }
 }
コード例 #8
0
        void Read(ulong rootPageId, BrightstarProfiler profiler)
        {
            IPage currentPage = _pageStore.Retrieve(rootPageId, profiler);
            int   offset      = 0;
            int   entryIndex  = 0;

            while (true)
            {
                var marker = currentPage.Data[offset++];
                if (marker == 0xff)
                {
                    ulong nextPageId = BitConverter.ToUInt64(currentPage.Data, _pageStore.PageSize - 8);
                    if (nextPageId == 0)
                    {
                        return;
                    }
                    currentPage = _pageStore.Retrieve(nextPageId, profiler);
                    offset      = 0;
                }
                else if (marker == 2)
                {
                    _allEntries.Add(new GraphIndexEntry(entryIndex++, null, true));
                }
                else
                {
                    int uriByteLength = BitConverter.ToInt32(currentPage.Data, offset);
                    offset += 4;
                    var uri = Encoding.UTF8.GetString(currentPage.Data, offset, uriByteLength);
                    offset += uriByteLength;
                    var newEntry = new GraphIndexEntry(entryIndex++, uri, marker == 1);
                    _allEntries.Add(newEntry);
                    if (!newEntry.IsDeleted)
                    {
                        _graphUriIndex[newEntry.Uri] = newEntry.Id;
                    }
                }
            }
        }
コード例 #9
0
 public PrefixManager(IPageStore pageStore, ulong startPageId, BrightstarProfiler profiler)
 {
     _pageStore = pageStore;
     var startPage = _pageStore.Retrieve(startPageId, profiler);
     Load(startPage, profiler);
 }