Skip to content

Commit 1d9db1b

Browse files
authored
Asynchronously write batches to NuDB. (XRPLF#4503)
1 parent 3b5fcd5 commit 1d9db1b

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

src/ripple/nodestore/Types.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ enum {
3636
// This sets a limit on the maximum number of writes
3737
// in a batch. Actual usage can be twice this since
3838
// we have a new batch growing as we write the old.
39+
// The main goal is to avoid delays while persisting the ledger.
3940
//
40-
batchWriteLimitSize = 65536
41+
batchWriteLimitSize = 262144
4142
};
4243

4344
/** Return codes from Backend operations. */

src/ripple/nodestore/backend/NuDBFactory.cpp

+13-9
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <ripple/basics/contract.h>
2121
#include <ripple/nodestore/Factory.h>
2222
#include <ripple/nodestore/Manager.h>
23+
#include <ripple/nodestore/impl/BatchWriter.h>
2324
#include <ripple/nodestore/impl/DecodedBlob.h>
2425
#include <ripple/nodestore/impl/EncodedBlob.h>
2526
#include <ripple/nodestore/impl/codec.h>
@@ -35,7 +36,7 @@
3536
namespace ripple {
3637
namespace NodeStore {
3738

38-
class NuDBBackend : public Backend
39+
class NuDBBackend : public Backend, public BatchWriter::Callback
3940
{
4041
public:
4142
static constexpr std::uint64_t currentType = 1;
@@ -46,6 +47,7 @@ class NuDBBackend : public Backend
4647

4748
beast::Journal const j_;
4849
size_t const keyBytes_;
50+
BatchWriter batch_;
4951
std::size_t const burstSize_;
5052
std::string const name_;
5153
nudb::store db_;
@@ -60,6 +62,7 @@ class NuDBBackend : public Backend
6062
beast::Journal journal)
6163
: j_(journal)
6264
, keyBytes_(keyBytes)
65+
, batch_(*this, scheduler)
6366
, burstSize_(burstSize)
6467
, name_(get(keyValues, "path"))
6568
, deletePath_(false)
@@ -79,6 +82,7 @@ class NuDBBackend : public Backend
7982
beast::Journal journal)
8083
: j_(journal)
8184
, keyBytes_(keyBytes)
85+
, batch_(*this, scheduler)
8286
, burstSize_(burstSize)
8387
, name_(get(keyValues, "path"))
8488
, db_(context)
@@ -262,13 +266,7 @@ class NuDBBackend : public Backend
262266
void
263267
store(std::shared_ptr<NodeObject> const& no) override
264268
{
265-
BatchWriteReport report;
266-
report.writeCount = 1;
267-
auto const start = std::chrono::steady_clock::now();
268-
do_insert(no);
269-
report.elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(
270-
std::chrono::steady_clock::now() - start);
271-
scheduler_.onBatchWrite(report);
269+
batch_.store(no);
272270
}
273271

274272
void
@@ -329,7 +327,7 @@ class NuDBBackend : public Backend
329327
int
330328
getWriteLoad() override
331329
{
332-
return 0;
330+
return batch_.getWriteLoad();
333331
}
334332

335333
void
@@ -357,6 +355,12 @@ class NuDBBackend : public Backend
357355
Throw<nudb::system_error>(ec);
358356
}
359357

358+
void
359+
writeBatch(Batch const& batch) override
360+
{
361+
storeBatch(batch);
362+
}
363+
360364
int
361365
fdRequired() const override
362366
{

0 commit comments

Comments
 (0)