LogCabin
|
A producer/consumer monitor for a queue of files to use for open segments. More...
Public Types | |
typedef std::pair< std::string, FilesystemUtil::File > | OpenSegment |
The type of element that is queued in openSegments. | |
Public Member Functions | |
PreparedSegments (uint64_t queueSize) | |
Constructor. | |
~PreparedSegments () | |
Destructor. | |
void | exit () |
Do not block any more waiting threads, and return immediately. | |
void | foundFile (uint64_t fileId) |
Ensure that future filenames will be larger than this one. | |
std::deque< OpenSegment > | releaseAll () |
Immediately return all currently prepared segments. | |
void | submitOpenSegment (OpenSegment segment) |
Producers call this when they're done creating a new file. | |
uint64_t | waitForDemand () |
Producers call this first to block until work becomes needed. | |
OpenSegment | waitForOpenSegment () |
Consumers call this when they need a prepared segment file. | |
Public Attributes | |
bool | quietForUnitTests |
Reduce log message verbosity for unit tests. | |
Private Attributes | |
Core::Mutex | mutex |
Mutual exclusion for all of the members of this class. | |
Core::ConditionVariable | consumed |
Notified when openSegments shrinks in size or when exiting becomes true. | |
Core::ConditionVariable | produced |
Notified when openSegments grows in size or when exiting becomes true. | |
bool | exiting |
Set to true when waiters should exit. | |
uint64_t | demanded |
The number of producers that may be started to fulfill demand. | |
uint64_t | filenameCounter |
Used to assign filenames to open segments (which is done before the indexes they contain is known). | |
std::deque< OpenSegment > | openSegments |
The queue where open segments sit before they're consumed. |
A producer/consumer monitor for a queue of files to use for open segments.
These are created asynchronously, hopefully ahead of the log appends.
This class is written in a monitor style; each public method acquires mutex.
Definition at line 151 of file SegmentedLog.h.
typedef std::pair<std::string, FilesystemUtil::File> LogCabin::Storage::SegmentedLog::PreparedSegments::OpenSegment |
The type of element that is queued in openSegments.
The first element of each pair is its filename relative to dir. The second element is its open file descriptor.
Definition at line 158 of file SegmentedLog.h.
LogCabin::Storage::SegmentedLog::PreparedSegments::PreparedSegments | ( | uint64_t | queueSize | ) | [explicit] |
Constructor.
queueSize | The maximum number of prepared segments to hold in the queue at a time. |
Definition at line 78 of file SegmentedLog.cc.
Destructor.
Definition at line 90 of file SegmentedLog.cc.
Do not block any more waiting threads, and return immediately.
Definition at line 95 of file SegmentedLog.cc.
void LogCabin::Storage::SegmentedLog::PreparedSegments::foundFile | ( | uint64_t | fileId | ) |
Ensure that future filenames will be larger than this one.
This should generally be invoked before any producers are started, since once they're started, there's no stopping them.
fileId | A lower bound on future IDs. |
Definition at line 104 of file SegmentedLog.cc.
std::deque< SegmentedLog::PreparedSegments::OpenSegment > LogCabin::Storage::SegmentedLog::PreparedSegments::releaseAll | ( | ) |
Immediately return all currently prepared segments.
Definition at line 112 of file SegmentedLog.cc.
Producers call this when they're done creating a new file.
This must be called once after each call waitForDemand(); otherwise, the internal bookkeeping won't work.
segment | File to queue up for a consumer. |
Definition at line 121 of file SegmentedLog.cc.
Producers call this first to block until work becomes needed.
Core::Util::ThreadInterruptedException | If exit() has been called. |
Definition at line 129 of file SegmentedLog.cc.
SegmentedLog::PreparedSegments::OpenSegment LogCabin::Storage::SegmentedLog::PreparedSegments::waitForOpenSegment | ( | ) |
Consumers call this when they need a prepared segment file.
Core::Util::ThreadInterruptedException | If exit() has been called. |
Definition at line 144 of file SegmentedLog.cc.
Reduce log message verbosity for unit tests.
Definition at line 220 of file SegmentedLog.h.
Mutual exclusion for all of the members of this class.
Definition at line 226 of file SegmentedLog.h.
Notified when openSegments shrinks in size or when exiting becomes true.
Definition at line 231 of file SegmentedLog.h.
Notified when openSegments grows in size or when exiting becomes true.
Definition at line 236 of file SegmentedLog.h.
bool LogCabin::Storage::SegmentedLog::PreparedSegments::exiting [private] |
Set to true when waiters should exit.
Definition at line 240 of file SegmentedLog.h.
uint64_t LogCabin::Storage::SegmentedLog::PreparedSegments::demanded [private] |
The number of producers that may be started to fulfill demand.
Definition at line 244 of file SegmentedLog.h.
uint64_t LogCabin::Storage::SegmentedLog::PreparedSegments::filenameCounter [private] |
Used to assign filenames to open segments (which is done before the indexes they contain is known).
This number is the largest of all previously known numbers so that it can be incremented then assigned to a new file. It's possible that numbers are reused across reboots.
Definition at line 251 of file SegmentedLog.h.
std::deque<OpenSegment> LogCabin::Storage::SegmentedLog::PreparedSegments::openSegments [private] |
The queue where open segments sit before they're consumed.
These are available for the log to use as future open segments.
Definition at line 256 of file SegmentedLog.h.