LogCabin
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Public Types | Public Member Functions | Public Attributes | Private Attributes
LogCabin::Storage::SegmentedLog::PreparedSegments Class Reference

A producer/consumer monitor for a queue of files to use for open segments. More...

List of all members.

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< OpenSegmentreleaseAll ()
 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< OpenSegmentopenSegments
 The queue where open segments sit before they're consumed.

Detailed Description

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.


Member Typedef Documentation

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.


Constructor & Destructor Documentation

Constructor.

Parameters:
queueSizeThe 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.


Member Function Documentation

Do not block any more waiting threads, and return immediately.

Definition at line 95 of file SegmentedLog.cc.

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.

Parameters:
fileIdA lower bound on future IDs.

Definition at line 104 of file SegmentedLog.cc.

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.

Parameters:
segmentFile to queue up for a consumer.

Definition at line 121 of file SegmentedLog.cc.

Producers call this first to block until work becomes needed.

Returns:
ID for new filename.
Exceptions:
Core::Util::ThreadInterruptedExceptionIf exit() has been called.

Definition at line 129 of file SegmentedLog.cc.

Consumers call this when they need a prepared segment file.

Exceptions:
Core::Util::ThreadInterruptedExceptionIf exit() has been called.

Definition at line 144 of file SegmentedLog.cc.


Member Data Documentation

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.

Set to true when waiters should exit.

Definition at line 240 of file SegmentedLog.h.

The number of producers that may be started to fulfill demand.

Definition at line 244 of file SegmentedLog.h.

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.

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.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines