![]() |
Storage Engine API
|
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>
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... | |
Buffer * | newBuffer () |
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 |
|
private |
mongo::dur::JournalWriter::JournalWriter | ( | CommitNotifier * | commitNotify, |
CommitNotifier * | applyToDataFilesNotify, | ||
size_t | numBuffers | ||
) |
Initializes the journal writer.
commitNotify | Notification 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. |
applyToDataFilesNotify | Notification 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. |
numBuffers | How 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. |
mongo::dur::JournalWriter::~JournalWriter | ( | ) |
|
private |
void mongo::dur::JournalWriter::assertIdle | ( | ) |
Asserts that there are no pending journal writes.
void mongo::dur::JournalWriter::flush | ( | ) |
Ensures that all previously submitted write requests complete.
This call is blocking.
|
private |
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.
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.
void mongo::dur::JournalWriter::start | ( | ) |
Allocates buffer memory and starts the journal writer thread.
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.
buffer | Buffer entry to be written. The buffer object must not be used anymore after it has been given to this function. |
commitNumber | What commit number to be notified once the buffer has been written to disk. |
|
friend |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |