rippled
Loading...
Searching...
No Matches
BatchWriter.cpp
1#include <xrpl/nodestore/detail/BatchWriter.h>
2
3namespace xrpl {
4namespace NodeStore {
5
7 : m_callback(callback), m_scheduler(scheduler)
8{
10}
11
16
17void
19{
21
22 // If the batch has reached its limit, we wait
23 // until the batch writer is finished
26
27 mWriteSet.push_back(object);
28
29 if (!mWritePending)
30 {
31 mWritePending = true;
32
34 }
35}
36
37int
39{
41
42 return std::max(mWriteLoad, static_cast<int>(mWriteSet.size()));
43}
44
45void
50
51void
53{
54 for (;;)
55 {
57
59
60 {
62
64 XRPL_ASSERT(
65 mWriteSet.empty(), "xrpl::NodeStore::BatchWriter::writeBatch : writes not set");
66 mWriteLoad = set.size();
67
68 if (set.empty())
69 {
70 mWritePending = false;
72
73 // VFALCO NOTE Fix this function to not return from the middle
74 return;
75 }
76 }
77
78 BatchWriteReport report{};
79 report.writeCount = set.size();
80 auto const before = std::chrono::steady_clock::now();
81
83
84 report.elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(
86
88 }
89}
90
91void
99
100} // namespace NodeStore
101} // namespace xrpl
void store(std::shared_ptr< NodeObject > const &object)
Store the object.
void performScheduledTask() override
Performs the task.
~BatchWriter()
Destroy a batch writer.
int getWriteLoad()
Get an estimate of the amount of writing I/O pending.
BatchWriter(Callback &callback, Scheduler &scheduler)
Create a batch writer.
Scheduling for asynchronous backend activity.
virtual void scheduleTask(Task &task)=0
Schedules a task.
virtual void onBatchWrite(BatchWriteReport const &report)=0
Reports the completion of a batch write Allows the scheduler to monitor the node store's performance.
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:5
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:26
virtual void writeBatch(Batch const &batch)=0
T swap(T... args)