Skip to content

Commit

Permalink
Merge pull request #479 from evoskuil/master
Browse files Browse the repository at this point in the history
Disable insert guards, these are the cause of sync thrash.
  • Loading branch information
evoskuil authored May 27, 2024
2 parents 5855f30 + 6b9c6b0 commit 604d893
Show file tree
Hide file tree
Showing 11 changed files with 157 additions and 120 deletions.
56 changes: 32 additions & 24 deletions include/bitcoin/database/impl/query/archive.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -675,11 +675,11 @@ code CLASS::set_code(tx_link& out_fk, const transaction& tx) NOEXCEPT

const auto key = tx.hash(false);

// GUARD (tx redundancy)
// This is only fully effective if there is a single database thread.
out_fk = to_tx(key);
if (!out_fk.is_terminal())
return error::success;
////// GUARD (tx redundancy)
////// This is only fully effective if there is a single database thread.
////out_fk = to_tx(key);
////if (!out_fk.is_terminal())
//// return error::success;

// Declare puts record.
const auto& ins = *tx.inputs_ptr();
Expand Down Expand Up @@ -731,15 +731,23 @@ code CLASS::set_code(tx_link& out_fk, const transaction& tx) NOEXCEPT
point_link hash_fk{};
if (hash != null_hash)
{
hash_fk = to_point(hash);
if (hash_fk.is_terminal())
// TODO: look into point table removal.
if (minimize_)
{
// Safe allocation failure, duplicates limited but expected.
if (!store_.point.put_link(hash_fk, hash, table::point::record
// GUARD (tx redundancy)
// Only fully effective if there is a single database thread.
// This reduces point store by ~45GiB, but causes thrashing.
hash_fk = to_point(hash);
if (hash_fk.is_terminal())
{
}))
{
return error::tx_point_put;
// Safe allocation failure, duplicates limited but expected.
if (!store_.point.put_link(hash_fk, hash, table::point::record
{
// Table stores no data other than the search key.
}))
{
return error::tx_point_put;
}
}
}
}
Expand Down Expand Up @@ -875,11 +883,11 @@ header_link CLASS::set_link(const header& header, const context& ctx) NOEXCEPT
{
const auto key = header.hash();

// GUARD (header redundancy)
// This is only fully effective if there is a single database thread.
auto header_fk = to_header(key);
if (!header_fk.is_terminal())
return header_fk;
////// GUARD (header redundancy)
////// This is only fully effective if there is a single database thread.
////auto header_fk = to_header(key);
////if (!header_fk.is_terminal())
//// return header_fk;

// Parent must be missing iff its hash is null.
const auto& parent_sk = header.previous_block_hash();
Expand Down Expand Up @@ -953,13 +961,13 @@ code CLASS::set_code(txs_link& out_fk, const transactions& txs,
if (key.is_terminal())
return error::txs_header;

// GUARD (block (txs) redundancy)
// This is only fully effective if there is a single database thread.
// Guard must be lifted for an existing top malleable association so
// that a non-malleable association may be accomplished.
out_fk = to_txs_link(key);
if (!out_fk.is_terminal() && !is_malleable(key))
return error::success;
////// GUARD (block (txs) redundancy)
////// This is only fully effective if there is a single database thread.
////// Guard must be lifted for an existing top malleable association so
////// that a non-malleable association may be accomplished.
////out_fk = to_txs_link(key);
////if (!out_fk.is_terminal() && !is_malleable(key))
//// return error::success;

code ec{};
tx_link tx_fk{};
Expand Down
5 changes: 5 additions & 0 deletions include/bitcoin/database/impl/query/optional.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ TEMPLATE
bool CLASS::set_filter(const header_link& link, const hash_digest& filter_head,
const filter& filter) NOEXCEPT
{
////// GUARD (filter redundancy)
////// This is only fully effective if there is a single database thread.
////if (!to_filter(link).is_terminal())
//// return true;

// ========================================================================
const auto scope = store_.get_transactor();

Expand Down
4 changes: 2 additions & 2 deletions include/bitcoin/database/impl/query/query.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ namespace libbitcoin {
namespace database {

TEMPLATE
CLASS::query(Store& value) NOEXCEPT
: store_(value)
CLASS::query(Store& store) NOEXCEPT
: store_(store), minimize_(store.minimize())
{
}

Expand Down
10 changes: 8 additions & 2 deletions include/bitcoin/database/impl/query/translate.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,15 @@ inline tx_link CLASS::to_tx(const hash_digest& key) const NOEXCEPT
}

TEMPLATE
inline txs_link CLASS::to_txs_link(const header_link& link) const NOEXCEPT
inline txs_link CLASS::to_txs_link(const header_link& key) const NOEXCEPT
{
return store_.txs.first(link);
return store_.txs.first(key);
}

TEMPLATE
inline filter_link CLASS::to_filter(const header_link& key) const NOEXCEPT
{
return store_.neutrino.first(key);
}

// put to tx (reverse navigation)
Expand Down
6 changes: 6 additions & 0 deletions include/bitcoin/database/impl/store.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,12 @@ void CLASS::report(const error_handler& handler) const NOEXCEPT
////report(buffer_body_, table_t::buffer_body);
}

TEMPLATE
bool CLASS::minimize() const NOEXCEPT
{
return configuration_.minimize;
}

BC_POP_WARNING()

} // namespace database
Expand Down
8 changes: 6 additions & 2 deletions include/bitcoin/database/query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ using point_link = table::point::link;
using spend_link = table::spend::link;
using txs_link = table::txs::link;
using tx_link = table::transaction::link;
using filter_link = table::neutrino::link;

using header_links = std_vector<header_link::integer>;
using tx_links = std_vector<tx_link::integer>;
Expand Down Expand Up @@ -80,7 +81,7 @@ class query
using heights = std_vector<size_t>;
using filter = system::data_chunk;

query(Store& value) NOEXCEPT;
query(Store& store) NOEXCEPT;

/// Store management from query-holder (not store owner) context.
/// -----------------------------------------------------------------------
Expand Down Expand Up @@ -229,7 +230,8 @@ class query
inline header_link to_header(const hash_digest& key) const NOEXCEPT;
inline point_link to_point(const hash_digest& key) const NOEXCEPT;
inline tx_link to_tx(const hash_digest& key) const NOEXCEPT;
inline txs_link to_txs_link(const header_link& link) const NOEXCEPT;
inline txs_link to_txs_link(const header_link& key) const NOEXCEPT;
inline filter_link to_filter(const header_link& key) const NOEXCEPT;

/// put to tx (reverse navigation)
tx_link to_spend_tx(const spend_link& link) const NOEXCEPT;
Expand Down Expand Up @@ -535,7 +537,9 @@ class query
static inline bool contains(const block_txs& blocks,
const block_tx& block) NOEXCEPT;

// These are thread safe.
Store& store_;
bool minimize_;
};

} // namespace database
Expand Down
1 change: 1 addition & 0 deletions include/bitcoin/database/settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ struct BCD_API settings

/// Properties.
std::filesystem::path path;
bool minimize;

/// Archives.
/// -----------------------------------------------------------------------
Expand Down
3 changes: 3 additions & 0 deletions include/bitcoin/database/store.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ class store
/// Dump all error/full conditions to handler.
void report(const error_handler& handler) const NOEXCEPT;

/// Favor minimum size over thrashing guard (requires high memory).
bool minimize() const NOEXCEPT;

/// Tables.
/// -----------------------------------------------------------------------

Expand Down
1 change: 1 addition & 0 deletions src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ using namespace bc::system;

settings::settings() NOEXCEPT
: path{ "bitcoin" },
minimize(true),

// Archives.

Expand Down
Loading

0 comments on commit 604d893

Please sign in to comment.