20 #include <ripple/basics/BasicConfig.h>
21 #include <ripple/basics/safe_cast.h>
22 #include <ripple/beast/unit_test.h>
23 #include <ripple/beast/utility/temp_dir.h>
24 #include <ripple/beast/xor_shift_engine.h>
25 #include <ripple/nodestore/DummyScheduler.h>
26 #include <ripple/nodestore/Manager.h>
27 #include <ripple/unity/rocksdb.h>
28 #include <boost/algorithm/string.hpp>
30 #include <beast/unit_test/thread.hpp>
38 #include <test/nodestore/TestBase.h>
39 #include <test/unit_test/SuiteJournal.h>
44 #ifndef NODESTORE_TIMING_DO_VERIFY
45 #define NODESTORE_TIMING_DO_VERIFY 0
52 template <
class Generator>
56 using result_type =
typename Generator::result_type;
57 while (bytes >=
sizeof(result_type))
60 memcpy(buffer, &v,
sizeof(v));
61 buffer =
reinterpret_cast<std::uint8_t*
>(buffer) +
sizeof(v);
68 memcpy(buffer, &v, bytes);
160 for (
auto iter = config.begin(); iter != config.end(); ++iter)
161 s += (iter != config.begin() ?
"," :
"") + iter->first +
"=" +
179 boost::split(v, s, boost::algorithm::is_any_of(
","));
188 template <
class Body>
201 template <
class... Args>
222 template <
class Body,
class... Args>
232 for (
std::size_t id = 0;
id < number_of_threads; ++id)
238 template <
class Body,
class... Args>
248 for (
std::size_t id = 0;
id < number_of_threads; ++id)
265 BEAST_EXPECT(backend !=
nullptr);
276 explicit Body(suite& s,
Backend& backend)
277 : suite_(s), backend_(backend), seq_(1)
290 suite_.fail(e.
what());
305 #if NODESTORE_TIMING_DO_VERIFY
322 BEAST_EXPECT(backend !=
nullptr);
344 , dist_(0, params.
items - 1)
355 obj = seq1_.
obj(dist_(gen_));
356 backend_.
fetch(obj->getHash().data(), &result);
357 suite_.expect(result &&
isSame(result, obj));
361 suite_.fail(e.
what());
367 parallel_for_id<Body>(
376 #if NODESTORE_TIMING_DO_VERIFY
393 BEAST_EXPECT(backend !=
nullptr);
417 , dist_(0, params.
items - 1)
426 auto const key = seq2_.
key(i);
428 backend_.
fetch(key.data(), &result);
429 suite_.expect(!result);
433 suite_.fail(e.
what());
440 parallel_for_id<Body>(
449 #if NODESTORE_TIMING_DO_VERIFY
466 BEAST_EXPECT(backend !=
nullptr);
494 , dist_(0, params.
items - 1)
505 auto const key = seq2_.
key(dist_(gen_));
507 backend_.
fetch(key.data(), &result);
508 suite_.expect(!result);
514 obj = seq1_.
obj(dist_(gen_));
515 backend_.
fetch(obj->getHash().data(), &result);
516 suite_.expect(result &&
isSame(result, obj));
521 suite_.fail(e.
what());
528 parallel_for_id<Body>(
537 #if NODESTORE_TIMING_DO_VERIFY
555 BEAST_EXPECT(backend !=
nullptr);
556 backend->setDeletePath();
584 , older_(0, params.
items - 1)
593 if (rand_(gen_) < 200)
598 auto const j = older_(gen_);
601 backend_.
fetch(obj->getHash().data(), &result);
602 suite_.expect(result !=
nullptr);
603 suite_.expect(
isSame(result, obj));
607 p[0] = rand_(gen_) < 50 ? 0 : 1;
609 for (
int q = 0; q < 2; ++q)
617 auto const j = recent_(gen_);
619 backend_.
fetch(obj->getHash().data(), &result);
620 suite_.expect(!result ||
isSame(result, obj));
626 auto const j = i + params_.
items;
635 suite_.fail(e.
what());
642 parallel_for_id<Body>(
651 #if NODESTORE_TIMING_DO_VERIFY
673 (this->*f)(config, params, journal);
674 return std::chrono::duration_cast<duration_type>(
686 for (
auto const& test : tests)
687 if (w < test.first.size())
688 w = test.first.size();
689 log << threads <<
" Thread" << (threads > 1 ?
"s" :
"") <<
", "
694 for (
auto const& test : tests)
695 ss <<
" " << setw(w) << test.first;
702 for (
auto const& config_string : config_strings)
711 config.
set(
"path", tempDir.
path());
715 for (
auto const& test : tests)
718 do_test(test.second, config, params, journal));
728 testcase(
"Timing", beast::unit_test::abort_on_fail);
738 #if RIPPLE_ROCKSDB_AVAILABLE
739 ";type=rocksdb,open_files=2000,filter_bits=12,cache_mb=256,"
740 "file_size_mb=8,file_size_mult=2"
743 ";type=memory|path=NodeStore"
754 auto args = arg().empty() ? default_args : arg();
756 boost::split(config_strings, args, boost::algorithm::is_any_of(
";"));
757 for (
auto iter = config_strings.
begin(); iter != config_strings.
end();)
759 iter = config_strings.
erase(iter);
static std::string to_string(Section const &config)
Simple NodeStore Scheduler that just peforms the tasks synchronously.
void batch(std::size_t n, Batch &b, std::size_t size)
Holds a collection of configuration values.
T setprecision(T... args)
std::uniform_int_distribution< std::uint32_t > d_size_
std::unique_ptr< Backend > make_Backend(Section const &config, std::size_t burstSize, Scheduler &scheduler, beast::Journal journal)
Create a Backend.
const std::size_t default_repeat
void do_insert(Section const &config, Params const ¶ms, beast::Journal journal)
Produces a sequence of secp256k1 key pairs.
static std::shared_ptr< NodeObject > createObject(NodeObjectType type, Blob &&data, uint256 const &hash)
Create an object from fields.
std::discrete_distribution< std::uint32_t > d_type_
void operator()(Args &&... args)
A namespace for easy access to logging severity values.
std::atomic< std::size_t > & c_
virtual void store(std::shared_ptr< NodeObject > const &object)=0
Store a single object.
void do_fetch(Section const &config, Params const ¶ms, beast::Journal journal)
constexpr static std::size_t size()
void append(std::vector< std::string > const &lines)
Append a set of lines to this section.
Integers of any length that is a multiple of 32-bits.
static void rngcpy(void *buffer, std::size_t bytes, Generator &g)
void do_tests(std::size_t threads, test_list const &tests, std::vector< std::string > const &config_strings)
void parallel_for(std::size_t const n, std::size_t number_of_threads, Args const &... args)
BEAST_DEFINE_TESTSUITE_MANUAL_PRIO(Timing, NodeStore, ripple, 1)
void do_mixed(Section const &config, Params const ¶ms, beast::Journal journal)
std::shared_ptr< NodeObject > obj(std::size_t n)
void Rethrow()
Rethrow the exception currently being handled.
void do_work(Section const &config, Params const ¶ms, beast::Journal journal)
constexpr auto megabytes(T value) noexcept
void seed(result_type seed)
A generic endpoint for log messages.
void do_missing(Section const &config, Params const ¶ms, beast::Journal journal)
Sequence(std::uint8_t prefix)
std::string path() const
Get the native path for the temporary directory.
uint256 key(std::size_t n)
T emplace_back(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
void set(std::string const &key, std::string const &value)
Set a key/value pair.
static Section parse(std::string s)
bool isSame(std::shared_ptr< NodeObject > const &lhs, std::shared_ptr< NodeObject > const &rhs)
Returns true if objects are identical.
static std::string to_string(duration_type const &d)
parallel_for_lambda(std::size_t n, std::atomic< std::size_t > &c)
void(Timing_test::*)(Section const &, Params const &, beast::Journal) test_func
beast::xor_shift_engine gen_
const std::size_t default_items
duration_type do_test(test_func f, Section const &config, Params const ¶ms, beast::Journal journal)
virtual Status fetch(void const *key, std::shared_ptr< NodeObject > *pObject)=0
Fetch a single object.
RAII temporary directory.
T & get(EitherAmount &amt)
void parallel_for_id(std::size_t const n, std::size_t number_of_threads, Args const &... args)
A backend used for the NodeStore.