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), mWriteLoad(0), mWritePending(false)
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(mWriteSet.empty(), "xrpl::NodeStore::BatchWriter::writeBatch : writes not set");
65 mWriteLoad = set.size();
66
67 if (set.empty())
68 {
69 mWritePending = false;
71
72 // VFALCO NOTE Fix this function to not return from the middle
73 return;
74 }
75 }
76
77 BatchWriteReport report;
78 report.writeCount = set.size();
79 auto const before = std::chrono::steady_clock::now();
80
82
83 report.elapsed =
84 std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - before);
85
87 }
88}
89
90void
98
99} // namespace NodeStore
100} // 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)