xrpld
Loading...
Searching...
No Matches
xrpl::NodeStore::BatchWriter Class Reference

Batch-writing assist logic. More...

#include <BatchWriter.h>

Inheritance diagram for xrpl::NodeStore::BatchWriter:
Collaboration diagram for xrpl::NodeStore::BatchWriter:

Classes

struct  Callback
 This callback does the actual writing. More...

Public Member Functions

 BatchWriter (Callback &callback, Scheduler &scheduler)
 Create a batch writer.
 ~BatchWriter () override
 Destroy a batch writer.
void store (std::shared_ptr< NodeObject > const &object)
 Store the object.
int getWriteLoad ()
 Get an estimate of the amount of writing I/O pending.

Private Types

using LockType = std::recursive_mutex
using CondvarType = std::condition_variable_any

Private Member Functions

void performScheduledTask () override
 Performs the task.
void writeBatch ()
void waitForWriting ()

Private Attributes

Callbackcallback_
Schedulerscheduler_
LockType writeMutex_
CondvarType writeCondition_
int writeLoad_ {0}
bool writePending_ {false}
Batch writeSet_

Detailed Description

Batch-writing assist logic.

The batch writes are performed with a scheduled task. Use of the class it not required. A backend can implement its own write batching, or skip write batching if doing so yields a performance benefit.

See also
Scheduler

Definition at line 20 of file BatchWriter.h.

Member Typedef Documentation

◆ LockType

Definition at line 66 of file BatchWriter.h.

◆ CondvarType

Constructor & Destructor Documentation

◆ BatchWriter()

xrpl::NodeStore::BatchWriter::BatchWriter ( Callback & callback,
Scheduler & scheduler )

Create a batch writer.

Definition at line 16 of file BatchWriter.cpp.

◆ ~BatchWriter()

xrpl::NodeStore::BatchWriter::~BatchWriter ( )
override

Destroy a batch writer.

Anything pending in the batch is written out before this returns.

Definition at line 22 of file BatchWriter.cpp.

Member Function Documentation

◆ store()

void xrpl::NodeStore::BatchWriter::store ( std::shared_ptr< NodeObject > const & object)

Store the object.

This will add to the batch and initiate a scheduled task to write the batch out.

Definition at line 28 of file BatchWriter.cpp.

◆ getWriteLoad()

int xrpl::NodeStore::BatchWriter::getWriteLoad ( )

Get an estimate of the amount of writing I/O pending.

Definition at line 48 of file BatchWriter.cpp.

◆ performScheduledTask()

void xrpl::NodeStore::BatchWriter::performScheduledTask ( )
overrideprivatevirtual

Performs the task.

The call may take place on a foreign thread.

Implements xrpl::NodeStore::Task.

Definition at line 56 of file BatchWriter.cpp.

◆ writeBatch()

void xrpl::NodeStore::BatchWriter::writeBatch ( )
private

Definition at line 62 of file BatchWriter.cpp.

◆ waitForWriting()

void xrpl::NodeStore::BatchWriter::waitForWriting ( )
private

Definition at line 102 of file BatchWriter.cpp.

Member Data Documentation

◆ callback_

Callback& xrpl::NodeStore::BatchWriter::callback_
private

Definition at line 69 of file BatchWriter.h.

◆ scheduler_

Scheduler& xrpl::NodeStore::BatchWriter::scheduler_
private

Definition at line 70 of file BatchWriter.h.

◆ writeMutex_

LockType xrpl::NodeStore::BatchWriter::writeMutex_
private

Definition at line 71 of file BatchWriter.h.

◆ writeCondition_

CondvarType xrpl::NodeStore::BatchWriter::writeCondition_
private

Definition at line 72 of file BatchWriter.h.

◆ writeLoad_

int xrpl::NodeStore::BatchWriter::writeLoad_ {0}
private

Definition at line 73 of file BatchWriter.h.

◆ writePending_

bool xrpl::NodeStore::BatchWriter::writePending_ {false}
private

Definition at line 74 of file BatchWriter.h.

◆ writeSet_

Batch xrpl::NodeStore::BatchWriter::writeSet_
private

Definition at line 75 of file BatchWriter.h.