public void QueueWrite(IPage pageToWrite, ulong transactionId) { #if DEBUG_PAGESTORE Logging.LogDebug("Queue {0}", pageToWrite.Id); #endif var writeTask = new WriteTask {PageToWrite = pageToWrite, TransactionId = transactionId}; _writeTasks.AddOrUpdate(pageToWrite.Id, writeTask, (pageId, task) => writeTask); _writeQueue.Enqueue(pageToWrite.Id); }
public void QueueWrite(IPage pageToWrite, ulong transactionId) { #if DEBUG_PAGESTORE Logging.LogDebug("Queue {0}", pageToWrite.Id); #endif var writeTask = new WriteTask { PageToWrite = pageToWrite, TransactionId = transactionId }; _writeTasks.AddOrUpdate(pageToWrite.Id, writeTask, (pageId, task) => writeTask); _writeQueue.Enqueue(pageToWrite.Id); }
private void Run(object state) { while (!_shutdownRequested) { ulong writePageId; if (_writeQueue.TryDequeue(out writePageId)) { #if DEBUG_PAGESTORE Logging.LogDebug("BackgroundWriter: Next page id in queue: {0}", writePageId); #endif // Retrieve the page write information from the _writeTasks dictionary WriteTask writeTask; if (_writeTasks.TryRemove(writePageId, out writeTask)) { lock (this) { _writing = writeTask; } #if DEBUG_PAGESTORE Logging.LogDebug("BackgroundWriter: Page {0} found in task dictionary.", writePageId); #endif try { _writing.PageToWrite.Write(_outputStream, _writing.TransactionId); } catch (Exception ex) { Logging.LogError(BrightstarEventId.StoreBackgroundWriteError, "Error in BackgroundPageWriter: {0}", ex); } finally { lock (this) { _writing = null; } } } else { #if DEBUG_PAGESTORE Logging.LogDebug("BackgroundWriter: Page {0} no longer in task dictionary. Skipping.", writePageId); #endif } } else { // Instead of waiting on a event, just spin wait _shutdownCompleted.WaitOne(1); } } _shutdownCompleted.Set(); }