Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Sep 25, 2023
1 parent ce241e3 commit 4b993b7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
6 changes: 2 additions & 4 deletions nano/store/lmdb/lmdb_env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<nano::store::lmdb::read_transaction_impl> (*this, mdb_txn_callbacks) };
tx.store_id = store_id;
auto tx = store::read_transaction{ std::make_unique<nano::store::lmdb::read_transaction_impl> (*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<nano::store::lmdb::write_transaction_impl> (*this, mdb_txn_callbacks) };
tx.store_id = store_id;
auto tx = store::write_transaction{ std::make_unique<nano::store::lmdb::write_transaction_impl> (*this, mdb_txn_callbacks), store_id };
return tx;
}

Expand Down
18 changes: 18 additions & 0 deletions nano/store/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
#include <nano/lib/utility.hpp>
#include <nano/store/transaction.hpp>

/*
* read_transaction
*/

nano::store::read_transaction::read_transaction (std::unique_ptr<store::read_transaction_impl> read_transaction_impl) :
impl (std::move (read_transaction_impl))
{
Expand All @@ -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 ();
Expand All @@ -28,6 +37,10 @@ void nano::store::read_transaction::refresh () const
renew ();
}

/*
* write_transaction
*/

nano::store::write_transaction::write_transaction (std::unique_ptr<store::write_transaction_impl> write_transaction_impl) :
impl (std::move (write_transaction_impl))
{
Expand All @@ -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 ();
Expand Down
12 changes: 9 additions & 3 deletions nano/store/transaction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
};

/**
Expand All @@ -48,6 +50,8 @@ class read_transaction final : public transaction
public:
explicit read_transaction (std::unique_ptr<read_transaction_impl> 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;
Expand All @@ -65,6 +69,8 @@ class write_transaction final : public transaction
public:
explicit write_transaction (std::unique_ptr<write_transaction_impl> write_transaction_impl);
void * get_handle () const override;
nano::id_dispenser::id_t store_id () const override;

void commit ();
void renew ();
void refresh ();
Expand Down

0 comments on commit 4b993b7

Please sign in to comment.