Skip to content

Commit

Permalink
Use TransactionDB rather than OptimisticTransactionDB.
Browse files Browse the repository at this point in the history
  • Loading branch information
clemahieu authored and RickiNano committed Jul 5, 2024
1 parent 3566c81 commit 8191ce7
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
4 changes: 2 additions & 2 deletions nano/secure/ledger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1244,15 +1244,15 @@ bool nano::ledger::migrate_lmdb_to_rocksdb (std::filesystem::path const & data_p
// Open rocksdb database
nano::rocksdb_config rocksdb_config;
rocksdb_config.enable = true;
rocksdb_config.memory_multiplier = std::numeric_limits<uint8_t>::max ();
//rocksdb_config.memory_multiplier = 4;
auto rocksdb_store = nano::make_store (logger, data_path_a, nano::dev::constants, false, true, rocksdb_config);

if (!rocksdb_store->init_error ())
{
auto table_size = store.count (store.tx_begin_read (), tables::blocks);
logger.info (nano::log::type::ledger, "Step 1 of 7: Converting {} million entries from blocks table", table_size / 1000000);
std::atomic<std::size_t> count = 0;
auto refresh_interval = 20ms;
auto refresh_interval = 100ms;
store.block.for_each_par (
[&] (store::read_transaction const & /*unused*/, auto i, auto n) {
auto rocksdb_transaction (rocksdb_store->tx_begin_write ({}, { nano::tables::blocks }));
Expand Down
3 changes: 2 additions & 1 deletion nano/store/rocksdb/rocksdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ void nano::store::rocksdb::component::open (bool & error_a, std::filesystem::pat
}
else
{
s = ::rocksdb::OptimisticTransactionDB::Open (options_a, path_a.string (), column_families, &handles_l, &optimistic_db);
::rocksdb::TransactionDBOptions options;
s = ::rocksdb::TransactionDB::Open (options_a, options, path_a.string (), column_families, &handles_l, &optimistic_db);
if (optimistic_db)
{
db.reset (optimistic_db);
Expand Down
4 changes: 2 additions & 2 deletions nano/store/rocksdb/rocksdb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <rocksdb/options.h>
#include <rocksdb/slice.h>
#include <rocksdb/table.h>
#include <rocksdb/utilities/optimistic_transaction_db.h>
#include <rocksdb/utilities/transaction_db.h>

namespace nano
{
Expand Down Expand Up @@ -106,7 +106,7 @@ class component : public nano::store::component
nano::logger & logger;
nano::ledger_constants & constants;
// Optimistic transactions are used in write mode
::rocksdb::OptimisticTransactionDB * optimistic_db = nullptr;
::rocksdb::TransactionDB * optimistic_db = nullptr;
std::unique_ptr<::rocksdb::DB> db;
std::vector<std::unique_ptr<::rocksdb::ColumnFamilyHandle>> handles;
std::shared_ptr<::rocksdb::TableFactory> small_table_factory;
Expand Down
6 changes: 3 additions & 3 deletions nano/store/rocksdb/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ void * nano::store::rocksdb::read_transaction_impl::get_handle () const
return (void *)&options;
}

nano::store::rocksdb::write_transaction_impl::write_transaction_impl (::rocksdb::OptimisticTransactionDB * db_a, std::vector<nano::tables> const & tables_requiring_locks_a, std::vector<nano::tables> const & tables_no_locks_a, std::unordered_map<nano::tables, nano::mutex> & mutexes_a) :
nano::store::rocksdb::write_transaction_impl::write_transaction_impl (::rocksdb::TransactionDB * db_a, std::vector<nano::tables> const & tables_requiring_locks_a, std::vector<nano::tables> const & tables_no_locks_a, std::unordered_map<nano::tables, nano::mutex> & mutexes_a) :
db (db_a),
tables_requiring_locks (tables_requiring_locks_a),
tables_no_locks (tables_no_locks_a),
mutexes (mutexes_a)
{
lock ();
::rocksdb::OptimisticTransactionOptions txn_options;
::rocksdb::TransactionOptions txn_options;
txn_options.set_snapshot = true;
txn = db->BeginTransaction (::rocksdb::WriteOptions (), txn_options);
}
Expand Down Expand Up @@ -76,7 +76,7 @@ void nano::store::rocksdb::write_transaction_impl::commit ()

void nano::store::rocksdb::write_transaction_impl::renew ()
{
::rocksdb::OptimisticTransactionOptions txn_options;
::rocksdb::TransactionOptions txn_options;
txn_options.set_snapshot = true;
db->BeginTransaction (::rocksdb::WriteOptions (), txn_options, txn);
active = true;
Expand Down
6 changes: 3 additions & 3 deletions nano/store/rocksdb/transaction_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include <rocksdb/db.h>
#include <rocksdb/options.h>
#include <rocksdb/utilities/optimistic_transaction_db.h>
#include <rocksdb/utilities/transaction_db.h>
#include <rocksdb/utilities/transaction.h>

namespace nano::store::rocksdb
Expand All @@ -26,7 +26,7 @@ class read_transaction_impl final : public store::read_transaction_impl
class write_transaction_impl final : public store::write_transaction_impl
{
public:
write_transaction_impl (::rocksdb::OptimisticTransactionDB * db_a, std::vector<nano::tables> const & tables_requiring_locks_a, std::vector<nano::tables> const & tables_no_locks_a, std::unordered_map<nano::tables, nano::mutex> & mutexes_a);
write_transaction_impl (::rocksdb::TransactionDB * db_a, std::vector<nano::tables> const & tables_requiring_locks_a, std::vector<nano::tables> const & tables_no_locks_a, std::unordered_map<nano::tables, nano::mutex> & mutexes_a);
~write_transaction_impl ();
void commit () override;
void renew () override;
Expand All @@ -35,7 +35,7 @@ class write_transaction_impl final : public store::write_transaction_impl

private:
::rocksdb::Transaction * txn;
::rocksdb::OptimisticTransactionDB * db;
::rocksdb::TransactionDB * db;
std::vector<nano::tables> tables_requiring_locks;
std::vector<nano::tables> tables_no_locks;
std::unordered_map<nano::tables, nano::mutex> & mutexes;
Expand Down

0 comments on commit 8191ce7

Please sign in to comment.