From 4b993b7ae0a780307729f7eb88edeb91020c4485 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Mon, 25 Sep 2023 16:55:05 +0200 Subject: [PATCH] WIP --- nano/store/lmdb/lmdb_env.cpp | 6 ++---- nano/store/transaction.cpp | 18 ++++++++++++++++++ nano/store/transaction.hpp | 12 +++++++++--- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/nano/store/lmdb/lmdb_env.cpp b/nano/store/lmdb/lmdb_env.cpp index 92a6f35455..6da194e851 100644 --- a/nano/store/lmdb/lmdb_env.cpp +++ b/nano/store/lmdb/lmdb_env.cpp @@ -96,15 +96,13 @@ nano::store::lmdb::env::operator MDB_env * () const nano::store::read_transaction nano::store::lmdb::env::tx_begin_read (store::lmdb::txn_callbacks mdb_txn_callbacks) const { - auto tx = store::read_transaction{ std::make_unique (*this, mdb_txn_callbacks) }; - tx.store_id = store_id; + auto tx = store::read_transaction{ std::make_unique (*this, mdb_txn_callbacks), store_id }; return tx; } nano::store::write_transaction nano::store::lmdb::env::tx_begin_write (store::lmdb::txn_callbacks mdb_txn_callbacks) const { - auto tx = store::write_transaction{ std::make_unique (*this, mdb_txn_callbacks) }; - tx.store_id = store_id; + auto tx = store::write_transaction{ std::make_unique (*this, mdb_txn_callbacks), store_id }; return tx; } diff --git a/nano/store/transaction.cpp b/nano/store/transaction.cpp index 7d30d403a0..05762c6f30 100644 --- a/nano/store/transaction.cpp +++ b/nano/store/transaction.cpp @@ -2,6 +2,10 @@ #include #include +/* + * read_transaction + */ + nano::store::read_transaction::read_transaction (std::unique_ptr read_transaction_impl) : impl (std::move (read_transaction_impl)) { @@ -12,6 +16,11 @@ void * nano::store::read_transaction::get_handle () const return impl->get_handle (); } +nano::id_dispenser::id_t nano::store::read_transaction::store_id () const +{ + return impl->store_id (); +} + void nano::store::read_transaction::reset () const { impl->reset (); @@ -28,6 +37,10 @@ void nano::store::read_transaction::refresh () const renew (); } +/* + * write_transaction + */ + nano::store::write_transaction::write_transaction (std::unique_ptr write_transaction_impl) : impl (std::move (write_transaction_impl)) { @@ -42,6 +55,11 @@ void * nano::store::write_transaction::get_handle () const return impl->get_handle (); } +nano::id_dispenser::id_t nano::store::write_transaction::store_id () const +{ + return impl->store_id (); +} + void nano::store::write_transaction::commit () { impl->commit (); diff --git a/nano/store/transaction.hpp b/nano/store/transaction.hpp index 18d82d9cbc..f56505def2 100644 --- a/nano/store/transaction.hpp +++ b/nano/store/transaction.hpp @@ -12,6 +12,10 @@ class transaction_impl public: virtual ~transaction_impl () = default; virtual void * get_handle () const = 0; + virtual nano::id_dispenser::id_t store_id (); + +private: + nano::id_dispenser::id_t const store_id_m; }; class read_transaction_impl : public transaction_impl @@ -31,12 +35,10 @@ class write_transaction_impl : public transaction_impl class transaction { -public: - nano::id_dispenser::id_t store_id; - public: virtual ~transaction () = default; virtual void * get_handle () const = 0; + virtual nano::id_dispenser::id_t store_id () const = 0; }; /** @@ -48,6 +50,8 @@ class read_transaction final : public transaction public: explicit read_transaction (std::unique_ptr read_transaction_impl); void * get_handle () const override; + nano::id_dispenser::id_t store_id () const override; + void reset () const; void renew () const; void refresh () const; @@ -65,6 +69,8 @@ class write_transaction final : public transaction public: explicit write_transaction (std::unique_ptr write_transaction_impl); void * get_handle () const override; + nano::id_dispenser::id_t store_id () const override; + void commit (); void renew (); void refresh ();