Skip to content

Commit

Permalink
Reimplementing nano::unchecked_store::get in terms of unchecked_store…
Browse files Browse the repository at this point in the history
…::for_each and removing backend-specific variants.
  • Loading branch information
clemahieu committed Jun 8, 2022
1 parent b4ce6c4 commit 9b5bae6
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 49 deletions.
9 changes: 0 additions & 9 deletions nano/node/lmdb/lmdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -811,15 +811,6 @@ void nano::mdb_store::create_backup_file (nano::mdb_env & env_a, boost::filesyst
}
}

std::vector<nano::unchecked_info> nano::unchecked_mdb_store::get (nano::transaction const & transaction_a, nano::block_hash const & hash_a)
{
std::vector<nano::unchecked_info> result;
for_each (transaction_a, hash_a, [&result] (nano::unchecked_key const & key, nano::unchecked_info const & info) {
result.push_back (info);
});
return result;
}

nano::unchecked_mdb_store::unchecked_mdb_store (nano::mdb_store & mdb_store_a) :
unchecked_store_partial<MDB_val, mdb_store> (mdb_store_a){};

Expand Down
1 change: 0 additions & 1 deletion nano/node/lmdb/lmdb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class unchecked_mdb_store : public unchecked_store_partial<MDB_val, mdb_store>
{
public:
explicit unchecked_mdb_store (nano::mdb_store &);
std::vector<nano::unchecked_info> get (nano::transaction const &, nano::block_hash const &);
};

/**
Expand Down
38 changes: 0 additions & 38 deletions nano/node/rocksdb/rocksdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -624,44 +624,6 @@ nano::version_rocksdb_store::version_rocksdb_store (nano::rocksdb_store & rocksd
nano::version_store_partial<rocksdb::Slice, nano::rocksdb_store> (rocksdb_store_a),
rocksdb_store{ rocksdb_store_a } {};

std::vector<nano::unchecked_info> nano::unchecked_rocksdb_store::get (nano::transaction const & transaction_a, nano::block_hash const & hash_a)
{
auto cf = rocksdb_store.table_to_column_family (tables::unchecked);

std::unique_ptr<rocksdb::Iterator> iter;
nano::qualified_root upper (hash_a, nano::block_hash (std::numeric_limits<nano::uint256_t>::max ()));
nano::rocksdb_val upper_bound (sizeof (upper), (void *)&upper);
if (is_read (transaction_a))
{
auto read_options = snapshot_options (transaction_a);
read_options.prefix_same_as_start = true;
read_options.auto_prefix_mode = true;
read_options.iterate_upper_bound = upper_bound;
read_options.fill_cache = false;
iter.reset (rocksdb_store.db->NewIterator (read_options, cf));
}
else
{
rocksdb::ReadOptions read_options;
read_options.prefix_same_as_start = true;
read_options.auto_prefix_mode = true;
read_options.iterate_upper_bound = upper_bound;
read_options.fill_cache = false;
iter.reset (rocksdb_store.tx (transaction_a)->GetIterator (read_options, cf));
}

// Uses prefix extraction
std::vector<nano::unchecked_info> result;

auto prefix = nano::rocksdb_val (hash_a);
for (iter->Seek (prefix); iter->Valid () && iter->key ().starts_with (prefix); iter->Next ())
{
auto unchecked_info = static_cast<nano::unchecked_info> (nano::rocksdb_val (iter->value ()));
result.push_back (unchecked_info);
}
return result;
}

void nano::rocksdb_store::construct_column_family_mutexes ()
{
for (auto table : all_tables ())
Expand Down
1 change: 0 additions & 1 deletion nano/node/rocksdb/rocksdb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class unchecked_rocksdb_store : public unchecked_store_partial<rocksdb::Slice, n
{
public:
explicit unchecked_rocksdb_store (nano::rocksdb_store &);
std::vector<nano::unchecked_info> get (nano::transaction const &, nano::block_hash const &);

private:
nano::rocksdb_store & rocksdb_store;
Expand Down
9 changes: 9 additions & 0 deletions nano/secure/store/unchecked_store_partial.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ class unchecked_store_partial : public unchecked_store
}
}

std::vector<nano::unchecked_info> get (nano::transaction const & tx, nano::block_hash const & hash) override
{
std::vector<nano::unchecked_info> result;
for_each (tx, hash, [&result] (nano::unchecked_key const & key, nano::unchecked_info const & info) {
result.push_back (info);
});
return result;
}

size_t count (nano::transaction const & transaction_a) override
{
return store.count (transaction_a, tables::unchecked);
Expand Down

0 comments on commit 9b5bae6

Please # to comment.