rippled
Loading...
Searching...
No Matches
BatchWriter.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#include <xrpld/nodestore/detail/BatchWriter.h>
21
22namespace ripple {
23namespace NodeStore {
24
26 : m_callback(callback)
27 , m_scheduler(scheduler)
28 , mWriteLoad(0)
29 , mWritePending(false)
30{
32}
33
38
39void
41{
43
44 // If the batch has reached its limit, we wait
45 // until the batch writer is finished
48
49 mWriteSet.push_back(object);
50
51 if (!mWritePending)
52 {
53 mWritePending = true;
54
56 }
57}
58
59int
61{
63
64 return std::max(mWriteLoad, static_cast<int>(mWriteSet.size()));
65}
66
67void
72
73void
75{
76 for (;;)
77 {
79
81
82 {
84
86 XRPL_ASSERT(
88 "ripple::NodeStore::BatchWriter::writeBatch : writes not set");
89 mWriteLoad = set.size();
90
91 if (set.empty())
92 {
93 mWritePending = false;
95
96 // VFALCO NOTE Fix this function to not return from the middle
97 return;
98 }
99 }
100
101 BatchWriteReport report;
102 report.writeCount = set.size();
103 auto const before = std::chrono::steady_clock::now();
104
106
107 report.elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(
109
111 }
112}
113
114void
122
123} // namespace NodeStore
124} // 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:25
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:46
virtual void writeBatch(Batch const &batch)=0
T swap(T... args)