public byte[] Retrieve(ulong pageId, BrightstarProfiler profiler)
 {
     using (profiler.Step("PageStore.Retrieve"))
     {
         if (!_readonly && pageId >= _newPageOffset)
         {
             var newPage = _newPages[(int) (pageId - _newPageOffset)];
             return newPage.Data;
         }
         var page = PageCache.Instance.Lookup(_path, pageId) as FilePage;
         if (page != null)
         {
             profiler.Incr("PageCache Hit");
             return page.Data;
         }
         using (profiler.Step("Load Page"))
         {
             profiler.Incr("PageCache Miss");
             using (profiler.Step("Create FilePage"))
             {
                 // Lock on stream to prevent attempts to concurrently load a page
                 lock (_stream)
                 {
                     page = new FilePage(_stream, pageId, _pageSize);
                 }
             }
             using (profiler.Step("Add FilePage To Cache"))
             {
                 PageCache.Instance.InsertOrUpdate(_path, page);
             }
             return page.Data;
         }
     }
 }
Пример #2
0
 public byte[] Retrieve(ulong pageId, BrightstarProfiler profiler)
 {
     using (profiler.Step("PageStore.Retrieve"))
     {
         if (!_readonly && pageId >= _newPageOffset)
         {
             var newPage = _newPages[(int)(pageId - _newPageOffset)];
             return(newPage.Data);
         }
         var page = PageCache.Instance.Lookup(_path, pageId) as FilePage;
         if (page != null)
         {
             profiler.Incr("PageCache Hit");
             return(page.Data);
         }
         using (profiler.Step("Load Page"))
         {
             profiler.Incr("PageCache Miss");
             using (profiler.Step("Create FilePage"))
             {
                 // Lock on stream to prevent attempts to concurrently load a page
                 lock (_stream)
                 {
                     page = new FilePage(_stream, pageId, _pageSize);
                 }
             }
             using (profiler.Step("Add FilePage To Cache"))
             {
                 PageCache.Instance.InsertOrUpdate(_path, page);
             }
             return(page.Data);
         }
     }
 }
Пример #3
0
        public ulong Create()
        {
            if (_readonly)
            {
                throw new InvalidOperationException("Cannot create new pages in readonly page store");
            }
            var dataPage = new FilePage(_nextPageId, _pageSize);

            _newPages.Add(dataPage);
            _nextPageId++;
            return(dataPage.Id);
        }
        public IPage Retrieve(ulong pageId, BrightstarProfiler profiler)
        {
            using (profiler.Step("PageStore.Retrieve"))
            {
                if (!_readonly && pageId >= _newPageOffset)
                {
                    var newPageRef = _newPages[(int)(pageId - _newPageOffset)];
                    if (newPageRef.IsAlive)
                    {
                        var newPage = newPageRef.Target as IPage;
                        if (newPage != null)
                        {
                            return(newPage);
                        }
                    }
                }
                var page = PageCache.Instance.Lookup(_path, pageId) as IPage;
                if (page != null)
                {
                    profiler.Incr("PageCache Hit");
                    return(page);
                }
                if (_backgroundPageWriter != null)
                {
                    // See if the page is currently queued for background write
                    if (_backgroundPageWriter.TryGetPage(pageId, out page))
                    {
                        profiler.Incr("BackgroundWriter Queue Hit");
                        return(page);
                    }
                }
                using (profiler.Step("Load Page"))
                {
                    profiler.Incr("PageCache Miss");
                    using (profiler.Step("Create FilePage"))
                    {
                        page = new FilePage(_stream, pageId, _pageSize);
                        if (_backgroundPageWriter != null)
                        {
                            _backgroundPageWriter.ResetTimestamp(pageId);
                        }
#if DEBUG_PAGESTORE
                        Logging.LogDebug("Load {0} {1}", pageId, BitConverter.ToInt32(page.Data, 0));
#endif
                    }
                    using (profiler.Step("Add FilePage To Cache"))
                    {
                        PageCache.Instance.InsertOrUpdate(_path, page);
                    }
                    return(page);
                }
            }
        }
        public IPage Create(ulong commitId)
        {
            if (_readonly)
            {
                throw new InvalidOperationException("Cannot create new pages in readonly page store");
            }
            var dataPage = new FilePage(_nextPageId, _pageSize);

            _newPages.Add(new WeakReference(dataPage));
            _nextPageId++;
            PageCache.Instance.InsertOrUpdate(_path, dataPage);
            return(dataPage);
        }
Пример #6
0
        public IPage Retrieve(ulong pageId, BrightstarProfiler profiler)
        {
            using (profiler.Step("PageStore.Retrieve"))
            {
                if (!_readonly && pageId >= _newPageOffset)
                {
                    var newPageRef = _newPages[(int)(pageId - _newPageOffset)];
                    if (newPageRef.IsAlive)
                    {
                        var newPage = newPageRef.Target as IPage;
                        if (newPage != null)
                        {
                            return(newPage);
                        }
                    }
                }
                var page = PageCache.Instance.Lookup(_path, pageId) as IPage;
                if (page != null)
                {
                    profiler.Incr("PageCache Hit");
                    return(page);
                }
                using (profiler.Step("Load Page"))
                {
                    profiler.Incr("PageCache Miss");
                    using (profiler.Step("Create FilePage"))
                    {
                        page = new FilePage(_stream, pageId, _pageSize);
#if DEBUG_PAGESTORE
                        Logging.LogDebug("Load {0} {1}", pageId, BitConverter.ToInt32(page.Data, 0));
#endif
                    }
                    using (profiler.Step("Add FilePage To Cache"))
                    {
                        PageCache.Instance.InsertOrUpdate(_path, page);
                    }
                    return(page);
                }
            }
        }
 public IPage Create(ulong commitId)
 {
     if (_readonly) throw new InvalidOperationException("Cannot create new pages in readonly page store");
     var dataPage = new FilePage(_nextPageId, _pageSize);
     _newPages.Add(new WeakReference(dataPage));
     _nextPageId++;
     PageCache.Instance.InsertOrUpdate(_path, dataPage);
     return dataPage;
 }
        public IPage Retrieve(ulong pageId, BrightstarProfiler profiler)
        {
            using (profiler.Step("PageStore.Retrieve"))
            {
                if (!_readonly && pageId >= _newPageOffset)
                {
                    var newPageRef = _newPages[(int) (pageId - _newPageOffset)];
                    if (newPageRef.IsAlive)
                    {
                        var newPage = newPageRef.Target as IPage;
                        if (newPage != null) return newPage;
                    }
                }
                var page = PageCache.Instance.Lookup(_path, pageId) as IPage;
                if (page != null)
                {
                    profiler.Incr("PageCache Hit");
                    return page;
                }
                using (profiler.Step("Load Page"))
                {
                    profiler.Incr("PageCache Miss");
                    using (profiler.Step("Create FilePage"))
                    {
                        page = new FilePage(_stream, pageId, _pageSize);
#if DEBUG_PAGESTORE
                        Logging.LogDebug("Load {0} {1}", pageId, BitConverter.ToInt32(page.Data, 0));
#endif
                    }
                    using (profiler.Step("Add FilePage To Cache"))
                    {
                        PageCache.Instance.InsertOrUpdate(_path, page);
                    }
                    return page;
                }
            }
        }
        public IPage Retrieve(ulong pageId, BrightstarProfiler profiler)
        {
            using (profiler.Step("PageStore.Retrieve"))
            {
                if (!_readonly && pageId >= _newPageOffset)
                {
                    var newPageRef = _newPages[(int) (pageId - _newPageOffset)];
                    if (newPageRef.IsAlive)
                    {
                        var newPage = newPageRef.Target as IPage;
                        if (newPage != null) return newPage;
                    }
                }
                var page = PageCache.Instance.Lookup(_path, pageId) as IPage;
                if (page != null)
                {
                    profiler.Incr("PageCache Hit");
                    return page;
                }
                if (_backgroundPageWriter != null)
                {
                    // See if the page is currently queued for background write
                    if (_backgroundPageWriter.TryGetPage(pageId, out page))
                    {
                        profiler.Incr("BackgroundWriter Queue Hit");
                        return page;
                    }
                }
                using (profiler.Step("Load Page"))
                {
                    profiler.Incr("PageCache Miss");
                    using (profiler.Step("Create FilePage"))
                    {
                        page = new FilePage(_stream, pageId, _pageSize);
                        if (_backgroundPageWriter != null)
                        {
                            _backgroundPageWriter.ResetTimestamp(pageId);
                        }
#if DEBUG_PAGESTORE
                        Logging.LogDebug("Load {0} {1}", pageId, BitConverter.ToInt32(page.Data, 0));
#endif
                    }
                    using (profiler.Step("Add FilePage To Cache"))
                    {
                        PageCache.Instance.InsertOrUpdate(_path, page);
                    }
                    return page;
                }
            }
        }
 public ulong Create()
 {
     if (_readonly) throw new InvalidOperationException("Cannot create new pages in readonly page store");
     var dataPage = new FilePage(_nextPageId, _pageSize);
     _newPages.Add(dataPage);
     _nextPageId++;
     return dataPage.Id;
 }