LogDevice API
Classes | Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
facebook::logdevice::BufferedWriter Class Reference

Classes

struct  Append
 
class  AppendCallback
 
struct  LogOptions
 
struct  Options
 

Public Types

using PayloadVariant = std::variant< std::string, PayloadGroup >
 

Public Member Functions

int append (logid_t logid, std::string &&payload, AppendCallback::Context callback_context, AppendAttributes &&attrs=AppendAttributes())
 
int append (logid_t logid, PayloadGroup &&payload_group, AppendCallback::Context callback_context, AppendAttributes &&attrs=AppendAttributes())
 
std::vector< Status > append (std::vector< Append > &&appends)
 
int flushAll ()
 
virtual ~BufferedWriter ()
 

Static Public Member Functions

static std::unique_ptr< BufferedWritercreate (std::shared_ptr< Client > client, AppendCallback *callback, Options options=Options())
 

Friends

class BufferedWriterImpl
 

Member Typedef Documentation

◆ PayloadVariant

using facebook::logdevice::BufferedWriter::PayloadVariant = std::variant<std::string, PayloadGroup>

Variants of payloads, which can be appended using BufferedWriter.

Constructor & Destructor Documentation

◆ ~BufferedWriter()

virtual facebook::logdevice::BufferedWriter::~BufferedWriter ( )
inlinevirtual

NOTE: involves communication with LogDevice threads, blocks until they acknowledge the destruction.

Member Function Documentation

◆ append() [1/2]

int facebook::logdevice::BufferedWriter::append ( logid_t  logid,
std::string &&  payload,
AppendCallback::Context  callback_context,
AppendAttributes &&  attrs = AppendAttributes() 
)

Same as Client::append() except the append may get buffered. If the call succeeds it is added into a buffer, and finally appended to the log as a batch of appends. Once it has been successfully stored in LogDevice, BufferedWriter::AppendCallback::onSuccess (passed in create()) is invoked with a ContextSet containing callback_context.

If the call succeeds (returns 0), the class assumes ownership of the payload. If the call fails, the payload remains in the given parameter. See Client::append for explanation of AppendAttributes

◆ append() [2/2]

std::vector<Status> facebook::logdevice::BufferedWriter::append ( std::vector< Append > &&  appends)

Multi-write version of append(). Requires less interthread communication than calling append() for each record.

Returns
A vector of Status objects, one for each input append. The status is E::OK if the append was successfully queued for writing, or otherwise one of the `err' codes documented for the single-write append(). If some of the appends fail, their payloads remain in the input vector.

◆ create()

static std::unique_ptr<BufferedWriter> facebook::logdevice::BufferedWriter::create ( std::shared_ptr< Client client,
AppendCallback callback,
Options  options = Options() 
)
static

Constructing and destructing a BufferedWriter involves interthread communication (with LogDevice library threads) and may block if those threads are busy. BufferedWriter instances are meant to be long-lived (and clients will typically use just one).

Uses client as sink for sending buffered appends.

◆ flushAll()

int facebook::logdevice::BufferedWriter::flushAll ( )

Instructs the class to immediately flush all buffered appends. Does not block, just passes messages to LogDevice threads.

It is not intended for this to be called often in production as it can limit the amount of batching; space- and time-based flushing should be preferred.

Returns
0 on success, -1 if messages could not be posted to some LogDevice threads

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