From 4378b6e9178ec60e9239ed48dcbadf7c47efbc86 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Mon, 13 May 2024 16:21:19 -0400 Subject: [PATCH] Create sizing queries for heads/bodies/both and full store. --- .../bitcoin/database/impl/query/extent.ipp | 317 +++++++----------- include/bitcoin/database/query.hpp | 57 +++- test/query/extent.cpp | 38 +-- 3 files changed, 175 insertions(+), 237 deletions(-) diff --git a/include/bitcoin/database/impl/query/extent.ipp b/include/bitcoin/database/impl/query/extent.ipp index f75456fc..754b1f87 100644 --- a/include/bitcoin/database/impl/query/extent.ipp +++ b/include/bitcoin/database/impl/query/extent.ipp @@ -22,247 +22,154 @@ #include #include -namespace libbitcoin { -namespace database { - -// Table logical byte sizes (archive bodies). -// ---------------------------------------------------------------------------- - -TEMPLATE -size_t CLASS::archive_size() const NOEXCEPT -{ - return - header_size() + - output_size() + - input_size() + - point_size() + - puts_size() + - spend_size() + - txs_size() + - tx_size(); -} - -TEMPLATE -size_t CLASS::header_size() const NOEXCEPT -{ - return store_.header.body_size(); -} - -TEMPLATE -size_t CLASS::output_size() const NOEXCEPT -{ - return store_.output.body_size(); -} - -TEMPLATE -size_t CLASS::input_size() const NOEXCEPT -{ - return store_.input.body_size(); -} - -TEMPLATE -size_t CLASS::point_size() const NOEXCEPT -{ - return store_.point.body_size(); -} - -TEMPLATE -size_t CLASS::puts_size() const NOEXCEPT -{ - return store_.puts.body_size(); -} - -TEMPLATE -size_t CLASS::spend_size() const NOEXCEPT -{ - return store_.spend.body_size(); -} - -TEMPLATE -size_t CLASS::txs_size() const NOEXCEPT -{ - return store_.txs.body_size(); -} - -TEMPLATE -size_t CLASS::tx_size() const NOEXCEPT -{ - return store_.tx.body_size(); -} - -// Table logical byte sizes (metadata bodies). -// ---------------------------------------------------------------------------- - -TEMPLATE -size_t CLASS::candidate_size() const NOEXCEPT -{ - return store_.candidate.body_size(); -} - -TEMPLATE -size_t CLASS::confirmed_size() const NOEXCEPT -{ - return store_.confirmed.body_size(); -} - -TEMPLATE -size_t CLASS::strong_tx_size() const NOEXCEPT -{ - return store_.strong_tx.body_size(); -} - -TEMPLATE -size_t CLASS::validated_tx_size() const NOEXCEPT -{ - return store_.validated_tx.body_size(); -} - -TEMPLATE -size_t CLASS::validated_bk_size() const NOEXCEPT -{ - return store_.validated_bk.body_size(); +#define DEFINE_SIZES(name) \ +TEMPLATE \ +size_t CLASS::name##_size() const NOEXCEPT \ +{ \ +return name##_head_size() + name##_body_size(); \ +} \ +TEMPLATE \ +size_t CLASS::name##_head_size() const NOEXCEPT \ +{ \ +return store_.name.head_size(); \ +} \ +TEMPLATE \ +size_t CLASS::name##_body_size() const NOEXCEPT \ +{ \ + return store_.name.body_size(); \ +} + +#define DEFINE_BUCKETS(name) \ +TEMPLATE \ +size_t CLASS::name##_buckets() const NOEXCEPT \ +{ \ + return store_.name.buckets(); \ +} + +#define DEFINE_RECORDS(name) \ +TEMPLATE \ +size_t CLASS::name##_records() const NOEXCEPT \ +{ \ + return store_.name.count(); \ } -// Table logical byte sizes (optional bodies). -// ---------------------------------------------------------------------------- - -TEMPLATE -size_t CLASS::address_size() const NOEXCEPT -{ - return store_.address.body_size(); -} - -TEMPLATE -size_t CLASS::neutrino_size() const NOEXCEPT -{ - return store_.neutrino.body_size(); -} +namespace libbitcoin { +namespace database { -// Buckets (archive hash tables). +// Store extent. // ---------------------------------------------------------------------------- TEMPLATE -size_t CLASS::header_buckets() const NOEXCEPT -{ - return store_.header.buckets(); -} - -TEMPLATE -size_t CLASS::point_buckets() const NOEXCEPT +size_t CLASS::store_size() const NOEXCEPT { - return store_.point.buckets(); + return store_body_size() + store_head_size(); } TEMPLATE -size_t CLASS::spend_buckets() const NOEXCEPT -{ - return store_.spend.buckets(); -} - -TEMPLATE -size_t CLASS::txs_buckets() const NOEXCEPT +size_t CLASS::archive_size() const NOEXCEPT { - return store_.txs.buckets(); + return archive_body_size() + archive_head_size(); } TEMPLATE -size_t CLASS::tx_buckets() const NOEXCEPT +size_t CLASS::store_body_size() const NOEXCEPT { - return store_.tx.buckets(); + return archive_body_size() + + candidate_body_size() + + confirmed_body_size() + + strong_tx_body_size() + + validated_tx_body_size() + + validated_bk_body_size() + + address_body_size() + + neutrino_body_size(); } -// Buckets (metadata hash tables). -// ---------------------------------------------------------------------------- - TEMPLATE -size_t CLASS::strong_tx_buckets() const NOEXCEPT +size_t CLASS::archive_body_size() const NOEXCEPT { - return store_.strong_tx.buckets(); + return header_body_size() + + output_body_size() + + input_body_size() + + point_body_size() + + puts_body_size() + + spend_body_size() + + txs_body_size() + + tx_body_size(); } TEMPLATE -size_t CLASS::validated_tx_buckets() const NOEXCEPT +size_t CLASS::store_head_size() const NOEXCEPT { - return store_.validated_tx.buckets(); + return archive_head_size() + + candidate_head_size() + + confirmed_head_size() + + strong_tx_head_size() + + validated_tx_head_size() + + validated_bk_head_size() + + address_head_size() + + neutrino_head_size(); } TEMPLATE -size_t CLASS::validated_bk_buckets() const NOEXCEPT +size_t CLASS::archive_head_size() const NOEXCEPT { - return store_.validated_bk.buckets(); + return header_head_size() + + output_head_size() + + input_head_size() + + point_head_size() + + puts_head_size() + + spend_head_size() + + txs_head_size() + + tx_head_size(); } -// Buckets (optional hash tables). +// Sizes. // ---------------------------------------------------------------------------- -TEMPLATE -size_t CLASS::address_buckets() const NOEXCEPT -{ - return store_.address.buckets(); -} - -TEMPLATE -size_t CLASS::neutrino_buckets() const NOEXCEPT -{ - return store_.neutrino.buckets(); -} - -// Counts (archive records). +DEFINE_SIZES(header) +DEFINE_SIZES(output) +DEFINE_SIZES(input) +DEFINE_SIZES(point) +DEFINE_SIZES(puts) +DEFINE_SIZES(spend) +DEFINE_SIZES(txs) +DEFINE_SIZES(tx) + +DEFINE_SIZES(candidate) +DEFINE_SIZES(confirmed) +DEFINE_SIZES(strong_tx) +DEFINE_SIZES(validated_tx) +DEFINE_SIZES(validated_bk) +DEFINE_SIZES(address) +DEFINE_SIZES(neutrino) + +// Buckets. // ---------------------------------------------------------------------------- -TEMPLATE -size_t CLASS::header_records() const NOEXCEPT -{ - return store_.header.count(); -} +DEFINE_BUCKETS(header) +DEFINE_BUCKETS(point) +DEFINE_BUCKETS(spend) +DEFINE_BUCKETS(txs) +DEFINE_BUCKETS(tx) -TEMPLATE -size_t CLASS::point_records() const NOEXCEPT -{ - return store_.point.count(); -} +DEFINE_BUCKETS(strong_tx) +DEFINE_BUCKETS(validated_tx) +DEFINE_BUCKETS(validated_bk) +DEFINE_BUCKETS(address) +DEFINE_BUCKETS(neutrino) -TEMPLATE -size_t CLASS::spend_records() const NOEXCEPT -{ - return store_.spend.count(); -} - -TEMPLATE -size_t CLASS::tx_records() const NOEXCEPT -{ - return store_.tx.count(); -} - -// Counts (metadata records). +// Records. // ---------------------------------------------------------------------------- -TEMPLATE -size_t CLASS::candidate_records() const NOEXCEPT -{ - return store_.candidate.count(); -} - -TEMPLATE -size_t CLASS::confirmed_records() const NOEXCEPT -{ - return store_.confirmed.count(); -} +DEFINE_RECORDS(header) +DEFINE_RECORDS(point) +DEFINE_RECORDS(spend) +DEFINE_RECORDS(tx) -TEMPLATE -size_t CLASS::strong_tx_records() const NOEXCEPT -{ - return store_.strong_tx.count(); -} - -// Counts (optional records). -// ---------------------------------------------------------------------------- - -TEMPLATE -size_t CLASS::address_records() const NOEXCEPT -{ - return store_.address.count(); -} +DEFINE_RECORDS(candidate) +DEFINE_RECORDS(confirmed) +DEFINE_RECORDS(strong_tx) +DEFINE_RECORDS(address) // Counters (archive slabs). // ---------------------------------------------------------------------------- @@ -315,4 +222,8 @@ bool CLASS::neutrino_enabled() const NOEXCEPT } // namespace database } // namespace libbitcoin +#undef DEFINE_SIZES +#undef DEFINE_BUCKETS +#undef DEFINE_RECORDS + #endif diff --git a/include/bitcoin/database/query.hpp b/include/bitcoin/database/query.hpp index 18cfeb16..19858ccb 100644 --- a/include/bitcoin/database/query.hpp +++ b/include/bitcoin/database/query.hpp @@ -123,7 +123,8 @@ class query /// Store extent. /// ----------------------------------------------------------------------- - /// Table logical byte sizes (archive bodies). + /// Body + head logical byte sizes. + size_t store_size() const NOEXCEPT; size_t archive_size() const NOEXCEPT; size_t header_size() const NOEXCEPT; size_t output_size() const NOEXCEPT; @@ -133,46 +134,72 @@ class query size_t spend_size() const NOEXCEPT; size_t txs_size() const NOEXCEPT; size_t tx_size() const NOEXCEPT; - - /// Table logical byte sizes (metadata bodies). size_t candidate_size() const NOEXCEPT; size_t confirmed_size() const NOEXCEPT; size_t strong_tx_size() const NOEXCEPT; size_t validated_tx_size() const NOEXCEPT; size_t validated_bk_size() const NOEXCEPT; - - /// Table logical byte sizes (optional bodies). size_t address_size() const NOEXCEPT; size_t neutrino_size() const NOEXCEPT; - /// Buckets (archive hash tables). + /// Body logical byte sizes. + size_t store_body_size() const NOEXCEPT; + size_t archive_body_size() const NOEXCEPT; + size_t header_body_size() const NOEXCEPT; + size_t output_body_size() const NOEXCEPT; + size_t input_body_size() const NOEXCEPT; + size_t point_body_size() const NOEXCEPT; + size_t puts_body_size() const NOEXCEPT; + size_t spend_body_size() const NOEXCEPT; + size_t txs_body_size() const NOEXCEPT; + size_t tx_body_size() const NOEXCEPT; + size_t candidate_body_size() const NOEXCEPT; + size_t confirmed_body_size() const NOEXCEPT; + size_t strong_tx_body_size() const NOEXCEPT; + size_t validated_tx_body_size() const NOEXCEPT; + size_t validated_bk_body_size() const NOEXCEPT; + size_t address_body_size() const NOEXCEPT; + size_t neutrino_body_size() const NOEXCEPT; + + /// Head logical byte sizes. + size_t store_head_size() const NOEXCEPT; + size_t archive_head_size() const NOEXCEPT; + size_t header_head_size() const NOEXCEPT; + size_t output_head_size() const NOEXCEPT; + size_t input_head_size() const NOEXCEPT; + size_t point_head_size() const NOEXCEPT; + size_t puts_head_size() const NOEXCEPT; + size_t spend_head_size() const NOEXCEPT; + size_t txs_head_size() const NOEXCEPT; + size_t tx_head_size() const NOEXCEPT; + size_t candidate_head_size() const NOEXCEPT; + size_t confirmed_head_size() const NOEXCEPT; + size_t strong_tx_head_size() const NOEXCEPT; + size_t validated_tx_head_size() const NOEXCEPT; + size_t validated_bk_head_size() const NOEXCEPT; + size_t address_head_size() const NOEXCEPT; + size_t neutrino_head_size() const NOEXCEPT; + + /// Buckets. size_t header_buckets() const NOEXCEPT; size_t point_buckets() const NOEXCEPT; size_t spend_buckets() const NOEXCEPT; size_t txs_buckets() const NOEXCEPT; size_t tx_buckets() const NOEXCEPT; - - /// Buckets (metadata hash tables). size_t strong_tx_buckets() const NOEXCEPT; size_t validated_tx_buckets() const NOEXCEPT; size_t validated_bk_buckets() const NOEXCEPT; - - /// Buckets (optional hash tables). size_t address_buckets() const NOEXCEPT; size_t neutrino_buckets() const NOEXCEPT; - /// Counts (archive records). + /// Records. size_t header_records() const NOEXCEPT; size_t point_records() const NOEXCEPT; size_t spend_records() const NOEXCEPT; size_t tx_records() const NOEXCEPT; - - /// Counts (metadata records). size_t candidate_records() const NOEXCEPT; size_t confirmed_records() const NOEXCEPT; size_t strong_tx_records() const NOEXCEPT; - - /// Counts (optional records). size_t address_records() const NOEXCEPT; /// Counters (archive slabs - txs/puts/neutrino can be derived). diff --git a/test/query/extent.cpp b/test/query/extent.cpp index 3cffb756..bd882c75 100644 --- a/test/query/extent.cpp +++ b/test/query/extent.cpp @@ -51,7 +51,7 @@ BOOST_AUTO_TEST_CASE(query__is_full__chunk_store__false) BOOST_REQUIRE(!query.is_full()); } -BOOST_AUTO_TEST_CASE(query_extent__sizes__genesis__expected) +BOOST_AUTO_TEST_CASE(query_extent__body_sizes__genesis__expected) { settings settings{}; settings.path = TEST_DIRECTORY; @@ -59,30 +59,30 @@ BOOST_AUTO_TEST_CASE(query_extent__sizes__genesis__expected) test::query_accessor query{ store }; BOOST_REQUIRE_EQUAL(store.create(events_handler), error::success); BOOST_REQUIRE(query.initialize(test::genesis)); - BOOST_REQUIRE_EQUAL(query.archive_size(), + BOOST_REQUIRE_EQUAL(query.archive_body_size(), schema::header::minrow + 81u + 79u + zero + schema::spend::minrow + schema::puts::minrow + schema::txs::minrow + schema::transaction::minrow); - BOOST_REQUIRE_EQUAL(query.header_size(), schema::header::minrow); - BOOST_REQUIRE_EQUAL(query.output_size(), 81u); - BOOST_REQUIRE_EQUAL(query.input_size(), 79u); - BOOST_REQUIRE_EQUAL(query.point_size(), zero); - BOOST_REQUIRE_EQUAL(query.spend_size(), schema::spend::minrow); - BOOST_REQUIRE_EQUAL(query.puts_size(), schema::puts::minrow); - BOOST_REQUIRE_EQUAL(query.txs_size(), schema::txs::minrow); - BOOST_REQUIRE_EQUAL(query.tx_size(), schema::transaction::minrow); - - BOOST_REQUIRE_EQUAL(query.candidate_size(), schema::height::minrow); - BOOST_REQUIRE_EQUAL(query.confirmed_size(), schema::height::minrow); - BOOST_REQUIRE_EQUAL(query.strong_tx_size(), schema::strong_tx::minrow); - BOOST_REQUIRE_EQUAL(query.validated_tx_size(), schema::validated_tx::minrow); - BOOST_REQUIRE_EQUAL(query.validated_bk_size(), schema::validated_bk::minrow); - - BOOST_REQUIRE_EQUAL(query.address_size(), schema::address::minrow); - BOOST_REQUIRE_EQUAL(query.neutrino_size(), 0u); + BOOST_REQUIRE_EQUAL(query.header_body_size(), schema::header::minrow); + BOOST_REQUIRE_EQUAL(query.output_body_size(), 81u); + BOOST_REQUIRE_EQUAL(query.input_body_size(), 79u); + BOOST_REQUIRE_EQUAL(query.point_body_size(), zero); + BOOST_REQUIRE_EQUAL(query.spend_body_size(), schema::spend::minrow); + BOOST_REQUIRE_EQUAL(query.puts_body_size(), schema::puts::minrow); + BOOST_REQUIRE_EQUAL(query.txs_body_size(), schema::txs::minrow); + BOOST_REQUIRE_EQUAL(query.tx_body_size(), schema::transaction::minrow); + + BOOST_REQUIRE_EQUAL(query.candidate_body_size(), schema::height::minrow); + BOOST_REQUIRE_EQUAL(query.confirmed_body_size(), schema::height::minrow); + BOOST_REQUIRE_EQUAL(query.strong_tx_body_size(), schema::strong_tx::minrow); + BOOST_REQUIRE_EQUAL(query.validated_tx_body_size(), schema::validated_tx::minrow); + BOOST_REQUIRE_EQUAL(query.validated_bk_body_size(), schema::validated_bk::minrow); + + BOOST_REQUIRE_EQUAL(query.address_body_size(), schema::address::minrow); + BOOST_REQUIRE_EQUAL(query.neutrino_body_size(), 0u); } BOOST_AUTO_TEST_CASE(query_extent__buckets__genesis__expected)