public void Commit(ulong commitId, BrightstarProfiler profiler)
 {
     if (CanWrite)
     {
         foreach (var pageId in _modifiedPages.Keys)
         {
             var page = PageCache.Instance.Lookup(_partitionId, pageId) as BinaryFilePage;
             if (page != null && page.IsDirty)
             {
                 _backgroundPageWriter.QueueWrite(page, commitId);
             }
         }
         _backgroundPageWriter.Flush();
         lock (_restartLock)
         {
             _backgroundPageWriter.Shutdown();
             _backgroundPageWriter.Dispose();
             PageCache.Instance.Clear(_partitionId);
             UpdatePartitionId();
             _readTxnId = _writeTxnId;
             _writeTxnId++;
             _backgroundPageWriter =
                 new BackgroundPageWriter(_persistenceManager.GetOutputStream(_filePath, FileMode.Open));
         }
     }
     else
     {
         throw new InvalidOperationException("Attempt to Commit on a read-only store instance");
     }
 }
Beispiel #2
0
        public AppendOnlyFilePageStore(IPersistenceManager persistenceManager, string filePath, int pageSize, bool readOnly, bool disableBackgroundWrites)
        {
            _peristenceManager = persistenceManager;
            _path = filePath;

            if ((_pageSize % 4096) != 0)
            {
                throw new ArgumentException("Page size must be a multiple of 4096 bytes");
            }
            _pageSize = pageSize;
            _bitShift = (int)Math.Log(_pageSize, 2.0);

            if (!_peristenceManager.FileExists(filePath) && !readOnly)
            {
                // Create an empty file that we can write to later
                _peristenceManager.CreateFile(filePath);
            }
            _stream     = _peristenceManager.GetInputStream(_path);
            _nextPageId = ((ulong)_stream.Length >> _bitShift) + 1;
            if (!readOnly)
            {
                _newPages      = new List <IPage>(512);
                _newPageOffset = _nextPageId;
            }
            _pageSize = pageSize;
            _readonly = readOnly;

            if (!readOnly && !disableBackgroundWrites)
            {
                _backgroundPageWriter =
                    new BackgroundPageWriter(persistenceManager.GetOutputStream(filePath, FileMode.Open));
            }
        }
        public AppendOnlyFilePageStore(IPersistenceManager persistenceManager, string filePath, int pageSize, bool readOnly, bool disableBackgroundWrites)
        {
            _peristenceManager = persistenceManager;
            _path = filePath;

            if ((_pageSize % 4096) != 0)
            {
                throw new ArgumentException("Page size must be a multiple of 4096 bytes");
            }
            _pageSize = pageSize;
            _bitShift = (int)Math.Log(_pageSize, 2.0);

            if (!_peristenceManager.FileExists(filePath) && !readOnly)
            {
                // Create an empty file that we can write to later
                _peristenceManager.CreateFile(filePath);
            }
            _stream = _peristenceManager.GetInputStream(_path);
            _nextPageId = ((ulong)_stream.Length >> _bitShift) + 1;
            if (!readOnly)
            {
                _newPages = new List<IPage>(512);
                _newPageOffset = _nextPageId;
            }
            _pageSize = pageSize;
            _readonly = readOnly;

            if (!readOnly && !disableBackgroundWrites)
            {
                _backgroundPageWriter =
                    new BackgroundPageWriter(persistenceManager.GetOutputStream(filePath, FileMode.Open));
            }

        }
Beispiel #4
0
 private void RestartBackgroundWriter()
 {
     lock (this)
     {
         _backgroundPageWriter.Shutdown();
         _backgroundPageWriter.Dispose();
         _backgroundPageWriter =
             new BackgroundPageWriter(_peristenceManager.GetOutputStream(_path, FileMode.Open));
     }
 }
Beispiel #5
0
 private void RestartBackgroundWriter()
 {
     if (_backgroundPageWriter != null)
     {
         lock (this)
         {
             _backgroundPageWriter.Dispose();
             _backgroundPageWriter =
                 new BackgroundPageWriter(_peristenceManager.GetOutputStream(_path, FileMode.Open), 1024);
         }
     }
 }
Beispiel #6
0
 /// <summary>
 /// Close the store, releasing any resources (such as file handles) it may be using
 /// </summary>
 public void Close()
 {
     if (_stream != null)
     {
         _stream.Close();
     }
     if (_backgroundPageWriter != null)
     {
         _backgroundPageWriter.Shutdown();
         _backgroundPageWriter.Dispose();
         _backgroundPageWriter = null;
     }
 }
Beispiel #7
0
        public void Close()
        {
            if (_inputStream != null)
            {
                _inputStream.Close();
                _inputStream.Dispose();
                _inputStream = null;
            }

            if (_backgroundPageWriter != null)
            {
                _backgroundPageWriter.Dispose();
                _backgroundPageWriter = null;
            }
        }
Beispiel #8
0
 private void Dispose(bool disposing)
 {
     if (!_disposed)
     {
         if (disposing)
         {
             Close();
             if (_backgroundPageWriter != null)
             {
                 _backgroundPageWriter.Dispose();
                 _backgroundPageWriter = null;
             }
         }
         _disposed = true;
     }
 }
Beispiel #9
0
 /// <summary>
 /// Close the store, releasing any resources (such as file handles) it may be using
 /// </summary>
 public void Close()
 {
     lock (this)
     {
         if (_stream != null)
         {
             _stream.Close();
             _stream = null;
         }
         if (_backgroundPageWriter != null)
         {
             _backgroundPageWriter.Dispose();
             _backgroundPageWriter = null;
         }
     }
 }
 public BinaryFilePageStore(IPersistenceManager persistenceManager, string filePath, int pageSize, bool readOnly,
                            ulong transactionId, ulong nextTransactionId)
 {
     _persistenceManager = persistenceManager;
     _nominalPageSize    = pageSize;
     _filePath           = filePath;
     _readTxnId          = transactionId;
     _writeTxnId         = nextTransactionId;
     PageSize            = _nominalPageSize - 8;
     CanWrite            = !readOnly;
     OpenInputStream();
     _nextPageId = (ulong)_inputStream.Length / ((uint)_nominalPageSize * 2) + 1;
     if (CanWrite)
     {
         _backgroundPageWriter =
             new BackgroundPageWriter(_persistenceManager.GetOutputStream(_filePath, FileMode.Open));
         PageCache.Instance.BeforeEvict += BeforePageCacheEvict;
     }
     _modifiedPages = new ConcurrentDictionary <ulong, bool>();
     UpdatePartitionId();
 }
 private void RestartBackgroundWriter()
 {
     lock (this)
     {
         _backgroundPageWriter.Shutdown();
         _backgroundPageWriter.Dispose();
         _backgroundPageWriter =
             new BackgroundPageWriter(_peristenceManager.GetOutputStream(_path, FileMode.Open));
     }
 }
 public void Commit(ulong commitId, BrightstarProfiler profiler)
 {
     if (CanWrite)
     {
         foreach (var pageId in _modifiedPages.Keys)
         {
             var page = PageCache.Instance.Lookup(_partitionId, pageId) as BinaryFilePage;
             if (page != null && page.IsDirty)
             {
                 _backgroundPageWriter.QueueWrite(page, commitId);
             }
         }
         _backgroundPageWriter.Flush();
         lock (_restartLock)
         {
             _backgroundPageWriter.Shutdown();
             _backgroundPageWriter.Dispose();
             PageCache.Instance.Clear(_partitionId);
             UpdatePartitionId();
             _readTxnId = _writeTxnId;
             _writeTxnId++;
             _backgroundPageWriter =
                 new BackgroundPageWriter(_persistenceManager.GetOutputStream(_filePath, FileMode.Open));
         }
     }
     else
     {
         throw new InvalidOperationException("Attempt to Commit on a read-only store instance");
     }
 }
 private void RestartBackgroundWriter()
 {
     if (_backgroundPageWriter != null)
     {
         lock (this)
         {
             _backgroundPageWriter.Dispose();
             _backgroundPageWriter =
                 new BackgroundPageWriter(_peristenceManager.GetOutputStream(_path, FileMode.Open), 1024);
         }
     }
 }
 private void Dispose(bool disposing)
 {
     if (!_disposed)
     {
         if (disposing)
         {
             Close();
             if (_backgroundPageWriter != null)
             {
                 _backgroundPageWriter.Dispose();
                 _backgroundPageWriter = null;
             }
         }
         _disposed = true;
     }
 }
 /// <summary>
 /// Close the store, releasing any resources (such as file handles) it may be using
 /// </summary>
 public void Close()
 {
     lock (this)
     {
         if (_stream != null)
         {
             _stream.Close();
             _stream = null;
         }
         if (_backgroundPageWriter != null)
         {
             _backgroundPageWriter.Dispose();
             _backgroundPageWriter = null;
         }
     }
 }
 public BinaryFilePageStore(IPersistenceManager persistenceManager, string filePath, int pageSize, bool readOnly,
     ulong transactionId, ulong nextTransactionId)
 {
     _persistenceManager = persistenceManager;
     _nominalPageSize = pageSize;
     _filePath = filePath;
     _readTxnId = transactionId;
     _writeTxnId = nextTransactionId;
     PageSize = _nominalPageSize - 8;
     CanWrite = !readOnly;
     OpenInputStream();
     _nextPageId = (ulong) _inputStream.Length/((uint) _nominalPageSize*2) + 1;
     if (CanWrite)
     {
         _backgroundPageWriter =
             new BackgroundPageWriter(_persistenceManager.GetOutputStream(_filePath, FileMode.Open));
         PageCache.Instance.BeforeEvict += BeforePageCacheEvict;
     }
     _modifiedPages = new ConcurrentDictionary<ulong, bool>();
     UpdatePartitionId();
 }
        public void Close()
        {
            if (_inputStream != null)
            {
                _inputStream.Close();
                _inputStream.Dispose();
                _inputStream = null;
            }

            if (_backgroundPageWriter != null)
            {
                _backgroundPageWriter.Dispose();
                _backgroundPageWriter = null;
            }

        }
 /// <summary>
 /// Close the store, releasing any resources (such as file handles) it may be using
 /// </summary>
 public void Close()
 {
     if (_stream != null)
     {
         _stream.Close();
     }
     if (_backgroundPageWriter != null)
     {
         _backgroundPageWriter.Shutdown();
         _backgroundPageWriter.Dispose();
         _backgroundPageWriter = null;
     }
 }