rippled
Loading...
Searching...
No Matches
BatchWriter.cpp
1#include <xrpl/nodestore/detail/BatchWriter.h>
2
3namespace ripple {
4namespace NodeStore {
5
7 : m_callback(callback)
8 , m_scheduler(scheduler)
9 , mWriteLoad(0)
10 , mWritePending(false)
11{
13}
14
19
20void
22{
24
25 // If the batch has reached its limit, we wait
26 // until the batch writer is finished
29
30 mWriteSet.push_back(object);
31
32 if (!mWritePending)
33 {
34 mWritePending = true;
35
37 }
38}
39
40int
42{
44
45 return std::max(mWriteLoad, static_cast<int>(mWriteSet.size()));
46}
47
48void
53
54void
56{
57 for (;;)
58 {
60
62
63 {
65
67 XRPL_ASSERT(
69 "ripple::NodeStore::BatchWriter::writeBatch : writes not set");
70 mWriteLoad = set.size();
71
72 if (set.empty())
73 {
74 mWritePending = false;
76
77 // VFALCO NOTE Fix this function to not return from the middle
78 return;
79 }
80 }
81
82 BatchWriteReport report;
83 report.writeCount = set.size();
84 auto const before = std::chrono::steady_clock::now();
85
87
88 report.elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(
90
92 }
93}
94
95void
103
104} // namespace NodeStore
105} // namespace ripple
void store(std::shared_ptr< NodeObject > const &object)
Store the object.
int getWriteLoad()
Get an estimate of the amount of writing I/O pending.
void performScheduledTask() override
Performs the task.
BatchWriter(Callback &callback, Scheduler &scheduler)
Create a batch writer.
~BatchWriter()
Destroy a batch writer.
Scheduling for asynchronous backend activity.
virtual void onBatchWrite(BatchWriteReport const &report)=0
Reports the completion of a batch write Allows the scheduler to monitor the node store's performance.
virtual void scheduleTask(Task &task)=0
Schedules a task.
T empty(T... args)
T max(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
bool set(T &target, std::string const &name, Section const &section)
Set a value from a configuration Section If the named value is not found or doesn't parse as a T,...
T push_back(T... args)
T reserve(T... args)
T size(T... args)
Contains information about a batch write operation.
This callback does the actual writing.
Definition BatchWriter.h:27
virtual void writeBatch(Batch const &batch)=0
T swap(T... args)