xrpld
Loading...
Searching...
No Matches
BatchWriter.h
1#pragma once
2
3#include <xrpl/nodestore/NodeObject.h>
4#include <xrpl/nodestore/Scheduler.h>
5#include <xrpl/nodestore/Task.h>
6#include <xrpl/nodestore/Types.h>
7
8#include <condition_variable>
9#include <memory>
10#include <mutex>
11
12namespace xrpl::node_store {
13
23class BatchWriter : private Task
24{
25public:
29 struct Callback
30 {
31 virtual ~Callback() = default;
32 Callback() = default;
33 Callback(Callback const&) = delete;
35 operator=(Callback const&) = delete;
36
37 virtual void
38 writeBatch(Batch const& batch) = 0;
39 };
40
44 BatchWriter(Callback& callback, Scheduler& scheduler);
45
51 ~BatchWriter() override;
52
59 void
61
65 int
67
68private:
69 void
70 performScheduledTask() override;
71 void
72 writeBatch();
73 void
75
76private:
79
84 int writeLoad_{0};
85 bool writePending_{false};
87};
88
89} // namespace xrpl::node_store
int getWriteLoad()
Get an estimate of the amount of writing I/O pending.
void performScheduledTask() override
Performs the task.
void store(std::shared_ptr< NodeObject > const &object)
Store the object.
~BatchWriter() override
Destroy a batch writer.
BatchWriter(Callback &callback, Scheduler &scheduler)
Create a batch writer.
std::condition_variable_any CondvarType
Definition BatchWriter.h:78
std::recursive_mutex LockType
Definition BatchWriter.h:77
Scheduling for asynchronous backend activity.
std::vector< std::shared_ptr< NodeObject > > Batch
A batch of NodeObjects to write at once.
This callback does the actual writing.
Definition BatchWriter.h:30
virtual void writeBatch(Batch const &batch)=0
Callback & operator=(Callback const &)=delete
Callback(Callback const &)=delete
Derived classes perform scheduled tasks.
Definition Task.h:9