Storage Engine API
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
mongo::dur::JournalWriter Class Reference

Manages the thread and queues used for writing the journal to disk and notify parties with are waiting on the write concern. More...

#include <dur_journal_writer.h>

Detailed Description

Manages the thread and queues used for writing the journal to disk and notify parties with are waiting on the write concern.

NOTE: Not thread-safe and must not be used from more than one thread.

Classes

class  Buffer
 Stores the memory and the header for a complete journal buffer which is pending to be written by the journal writer thread. More...
 

Public Member Functions

 JournalWriter (CommitNotifier *commitNotify, CommitNotifier *applyToDataFilesNotify, size_t numBuffers)
 Initializes the journal writer. More...
 
 ~JournalWriter ()
 
void start ()
 Allocates buffer memory and starts the journal writer thread. More...
 
void shutdown ()
 Terminates the journal writer thread and frees memory for the buffers. More...
 
void assertIdle ()
 Asserts that there are no pending journal writes. More...
 
BuffernewBuffer ()
 Obtains a new empty buffer into which a journal entry should be written. More...
 
void writeBuffer (Buffer *buffer, CommitNotifier::When commitNumber)
 Requests that the specified buffer be written asynchronously. More...
 
void flush ()
 Ensures that all previously submitted write requests complete. More...
 

Private Types

enum  { InitialBufferSizeBytes = 4 * 1024 * 1024 }
 
typedef BlockingQueue< Buffer * > BufferQueue
 

Private Member Functions

 MONGO_DISALLOW_COPYING (JournalWriter)
 
void _journalWriterThread ()
 

Private Attributes

CommitNotifier *const _commitNotify
 
CommitNotifier *const _applyToDataFilesNotify
 
stdx::thread _journalWriterThreadHandle
 
bool _shutdownRequested
 
BufferQueue _journalQueue
 
CommitNotifier::When _lastCommitNumber
 
BufferQueue _readyQueue
 

Friends

class BufferGuard
 

Member Typedef Documentation

◆ BufferQueue

typedef BlockingQueue<Buffer*> mongo::dur::JournalWriter::BufferQueue
private

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
private
Enumerator
InitialBufferSizeBytes 

Constructor & Destructor Documentation

◆ JournalWriter()

mongo::dur::JournalWriter::JournalWriter ( CommitNotifier commitNotify,
CommitNotifier applyToDataFilesNotify,
size_t  numBuffers 
)

Initializes the journal writer.

Parameters
commitNotifyNotification object to be called after journal entries have been written to disk. The caller retains ownership and the notify object must outlive the journal writer object.
applyToDataFilesNotifyNotification object to be called after journal entries have been applied to the shared view. This means that if the shared view were to be flushed at this point, the journal files before this point are not necessary. The caller retains ownership and the notify object must outlive the journal writer object.
numBuffersHow many buffers to create to hold outstanding writes. If there are more than this number of journal writes that have not completed, the write calls will block.

◆ ~JournalWriter()

mongo::dur::JournalWriter::~JournalWriter ( )

Member Function Documentation

◆ _journalWriterThread()

void mongo::dur::JournalWriter::_journalWriterThread ( )
private

◆ assertIdle()

void mongo::dur::JournalWriter::assertIdle ( )

Asserts that there are no pending journal writes.

◆ flush()

void mongo::dur::JournalWriter::flush ( )

Ensures that all previously submitted write requests complete.

This call is blocking.

◆ MONGO_DISALLOW_COPYING()

mongo::dur::JournalWriter::MONGO_DISALLOW_COPYING ( JournalWriter  )
private

◆ newBuffer()

JournalWriter::Buffer * mongo::dur::JournalWriter::newBuffer ( )

Obtains a new empty buffer into which a journal entry should be written.

This method may block if there are no free buffers.

The caller does not own the buffer and needs to "return" it to the writer by calling writeBuffer. Buffers with data on them should never be discarded until they are written.

◆ shutdown()

void mongo::dur::JournalWriter::shutdown ( )

Terminates the journal writer thread and frees memory for the buffers.

Must not be called if there are any pending journal writes.

◆ start()

void mongo::dur::JournalWriter::start ( )

Allocates buffer memory and starts the journal writer thread.

◆ writeBuffer()

void mongo::dur::JournalWriter::writeBuffer ( Buffer buffer,
CommitNotifier::When  commitNumber 
)

Requests that the specified buffer be written asynchronously.

This method may block if there are too many outstanding unwritten buffers.

Parameters
bufferBuffer entry to be written. The buffer object must not be used anymore after it has been given to this function.
commitNumberWhat commit number to be notified once the buffer has been written to disk.

Friends And Related Function Documentation

◆ BufferGuard

friend class BufferGuard
friend

Member Data Documentation

◆ _applyToDataFilesNotify

CommitNotifier* const mongo::dur::JournalWriter::_applyToDataFilesNotify
private

◆ _commitNotify

CommitNotifier* const mongo::dur::JournalWriter::_commitNotify
private

◆ _journalQueue

BufferQueue mongo::dur::JournalWriter::_journalQueue
private

◆ _journalWriterThreadHandle

stdx::thread mongo::dur::JournalWriter::_journalWriterThreadHandle
private

◆ _lastCommitNumber

CommitNotifier::When mongo::dur::JournalWriter::_lastCommitNumber
private

◆ _readyQueue

BufferQueue mongo::dur::JournalWriter::_readyQueue
private

◆ _shutdownRequested

bool mongo::dur::JournalWriter::_shutdownRequested
private

The documentation for this class was generated from the following files: