20#include <test/nodestore/TestBase.h>
21#include <test/unit_test/SuiteJournal.h>
23#include <xrpld/nodestore/DummyScheduler.h>
24#include <xrpld/nodestore/Manager.h>
26#include <xrpl/basics/BasicConfig.h>
27#include <xrpl/basics/ByteUtilities.h>
28#include <xrpl/basics/safe_cast.h>
29#include <xrpl/beast/unit_test.h>
30#include <xrpl/beast/unit_test/thread.h>
31#include <xrpl/beast/utility/temp_dir.h>
32#include <xrpl/beast/xor_shift_engine.h>
34#include <boost/algorithm/string.hpp>
46#ifndef NODESTORE_TIMING_DO_VERIFY
47#define NODESTORE_TIMING_DO_VERIFY 0
60 config,
megabytes(4), scheduler, journal);
64template <
class Generator>
68 using result_type =
typename Generator::result_type;
69 while (bytes >=
sizeof(result_type))
72 memcpy(buffer, &v,
sizeof(v));
73 buffer =
reinterpret_cast<std::uint8_t*
>(buffer) +
sizeof(v);
80 memcpy(buffer, &v, bytes);
172 for (
auto iter = config.
begin(); iter != config.
end(); ++iter)
173 s += (iter != config.
begin() ?
"," :
"") + iter->first +
"=" +
191 boost::split(v, s, boost::algorithm::is_any_of(
","));
200 template <
class Body>
213 template <
class... Args>
234 template <
class Body,
class... Args>
244 for (
std::size_t id = 0;
id < number_of_threads; ++id)
250 template <
class Body,
class... Args>
260 for (
std::size_t id = 0;
id < number_of_threads; ++id)
276 auto backend =
make_Backend(config, scheduler, journal);
277 BEAST_EXPECT(backend !=
nullptr);
288 explicit Body(suite& s,
Backend& backend)
289 : suite_(s), backend_(backend), seq_(1)
302 suite_.fail(e.
what());
317#if NODESTORE_TIMING_DO_VERIFY
333 auto backend =
make_Backend(config, scheduler, journal);
334 BEAST_EXPECT(backend !=
nullptr);
356 , dist_(0, params.
items - 1)
367 obj = seq1_.
obj(dist_(gen_));
368 backend_.
fetch(obj->getHash().data(), &result);
369 suite_.expect(result &&
isSame(result, obj));
373 suite_.fail(e.
what());
379 parallel_for_id<Body>(
388#if NODESTORE_TIMING_DO_VERIFY
404 auto backend =
make_Backend(config, scheduler, journal);
405 BEAST_EXPECT(backend !=
nullptr);
429 , dist_(0, params.
items - 1)
438 auto const key = seq2_.
key(i);
440 backend_.
fetch(key.data(), &result);
441 suite_.expect(!result);
445 suite_.fail(e.
what());
452 parallel_for_id<Body>(
461#if NODESTORE_TIMING_DO_VERIFY
477 auto backend =
make_Backend(config, scheduler, journal);
478 BEAST_EXPECT(backend !=
nullptr);
506 , dist_(0, params.
items - 1)
515 if (rand_(gen_) < missingNodePercent)
517 auto const key = seq2_.
key(dist_(gen_));
519 backend_.
fetch(key.data(), &result);
520 suite_.expect(!result);
526 obj = seq1_.
obj(dist_(gen_));
527 backend_.
fetch(obj->getHash().data(), &result);
528 suite_.expect(result &&
isSame(result, obj));
533 suite_.fail(e.
what());
540 parallel_for_id<Body>(
549#if NODESTORE_TIMING_DO_VERIFY
566 auto backend =
make_Backend(config, scheduler, journal);
567 BEAST_EXPECT(backend !=
nullptr);
568 backend->setDeletePath();
596 , older_(0, params.
items - 1)
605 if (rand_(gen_) < 200)
610 auto const j = older_(gen_);
613 backend_.
fetch(obj->getHash().data(), &result);
614 suite_.expect(result !=
nullptr);
615 suite_.expect(
isSame(result, obj));
619 p[0] = rand_(gen_) < 50 ? 0 : 1;
621 for (
int q = 0; q < 2; ++q)
629 auto const j = recent_(gen_);
631 backend_.
fetch(obj->getHash().data(), &result);
632 suite_.expect(!result ||
isSame(result, obj));
638 auto const j = i + params_.
items;
647 suite_.fail(e.
what());
654 parallel_for_id<Body>(
663#if NODESTORE_TIMING_DO_VERIFY
685 (this->*f)(config, params, journal);
686 return std::chrono::duration_cast<duration_type>(
698 for (
auto const& test : tests)
699 if (w < test.first.size())
700 w = test.first.size();
701 log << threads <<
" Thread" << (threads > 1 ?
"s" :
"") <<
", "
706 for (
auto const& test : tests)
707 ss <<
" " << setw(w) << test.first;
714 for (
auto const& config_string : config_strings)
723 config.
set(
"path", tempDir.
path());
727 for (
auto const& test : tests)
730 do_test(test.second, config, params, journal));
750#if RIPPLE_ROCKSDB_AVAILABLE
751 ";type=rocksdb,open_files=2000,filter_bits=12,cache_mb=256,"
752 "file_size_mb=8,file_size_mult=2"
755 ";type=memory|path=NodeStore"
768 boost::split(config_strings, args, boost::algorithm::is_any_of(
";"));
769 for (
auto iter = config_strings.
begin(); iter != config_strings.
end();)
771 iter = config_strings.
erase(iter);
782BEAST_DEFINE_TESTSUITE_MANUAL_PRIO(Timing, NodeStore,
ripple, 1);
A generic endpoint for log messages.
void seed(result_type seed)
RAII temporary directory.
std::string path() const
Get the native path for the temporary directory.
log_os< char > log
Logging output stream.
testcase_t testcase
Memberspace for declaring test cases.
std::string const & arg() const
Return the argument associated with the runner.
static std::shared_ptr< NodeObject > createObject(NodeObjectType type, Blob &&data, uint256 const &hash)
Create an object from fields.
A backend used for the NodeStore.
virtual Status fetch(void const *key, std::shared_ptr< NodeObject > *pObject)=0
Fetch a single object.
virtual void store(std::shared_ptr< NodeObject > const &object)=0
Store a single object.
Simple NodeStore Scheduler that just peforms the tasks synchronously.
virtual std::unique_ptr< Backend > make_Backend(Section const ¶meters, std::size_t burstSize, Scheduler &scheduler, beast::Journal journal)=0
Create a backend.
static Manager & instance()
Returns the instance of the manager singleton.
Scheduling for asynchronous backend activity.
std::discrete_distribution< std::uint32_t > d_type_
Sequence(std::uint8_t prefix)
std::shared_ptr< NodeObject > obj(std::size_t n)
void batch(std::size_t n, Batch &b, std::size_t size)
uint256 key(std::size_t n)
beast::xor_shift_engine gen_
std::uniform_int_distribution< std::uint32_t > d_size_
parallel_for_lambda(std::size_t n, std::atomic< std::size_t > &c)
void operator()(Args &&... args)
std::atomic< std::size_t > & c_
void run() override
Runs the suite.
void do_fetch(Section const &config, Params const ¶ms, beast::Journal journal)
static std::string to_string(duration_type const &d)
void(Timing_test::*)(Section const &, Params const &, beast::Journal) test_func
void do_work(Section const &config, Params const ¶ms, beast::Journal journal)
static std::string to_string(Section const &config)
static Section parse(std::string s)
void do_tests(std::size_t threads, test_list const &tests, std::vector< std::string > const &config_strings)
duration_type do_test(test_func f, Section const &config, Params const ¶ms, beast::Journal journal)
void parallel_for(std::size_t const n, std::size_t number_of_threads, Args const &... args)
void do_mixed(Section const &config, Params const ¶ms, beast::Journal journal)
std::size_t const default_repeat
std::size_t const default_items
void do_missing(Section const &config, Params const ¶ms, beast::Journal journal)
void do_insert(Section const &config, Params const ¶ms, beast::Journal journal)
void parallel_for_id(std::size_t const n, std::size_t number_of_threads, Args const &... args)
Holds a collection of configuration values.
void set(std::string const &key, std::string const &value)
Set a key/value pair.
const_iterator begin() const
void append(std::vector< std::string > const &lines)
Append a set of lines to this section.
const_iterator end() const
static constexpr std::size_t size()
T emplace_back(T... args)
A namespace for easy access to logging severity values.
std::unique_ptr< Backend > make_Backend(Section const &config, Scheduler &scheduler, beast::Journal journal)
static void rngcpy(void *buffer, std::size_t bytes, Generator &g)
bool isSame(std::shared_ptr< NodeObject > const &lhs, std::shared_ptr< NodeObject > const &rhs)
Returns true if objects are identical.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
constexpr auto megabytes(T value) noexcept
T get(Section const §ion, std::string const &name, T const &defaultValue=T{})
Retrieve a key/value pair from a section.
void Rethrow()
Rethrow the exception currently being handled.
T setprecision(T... args)