libmdbx  0.11.6.39 (2022-04-13T11:05:50+03:00)
One of the fastest compact embeddable key-value ACID database without WAL.
mdbx::txn Class Reference

Unmanaged database transaction. More...

#include <mdbx.h++>

Inherited by mdbx::txn_managed.

Public Types

using info = ::MDBX_txn_info
 
using map_stat = ::MDBX_stat
 
using canary = ::MDBX_canary
 

Public Member Functions

MDBX_CXX11_CONSTEXPR txn () noexcept=default
 
 txn (const txn &) noexcept=default
 
txnoperator= (txn &&other) noexcept
 
 txn (txn &&other) noexcept
 
 ~txn () noexcept
 
MDBX_CXX14_CONSTEXPR operator bool () const noexcept
 
MDBX_CXX14_CONSTEXPR operator const MDBX_txn * () const
 
MDBX_CXX14_CONSTEXPR operator MDBX_txn * ()
 
inline ::mdbx::env env () const noexcept
 Returns the transaction's environment. More...
 
MDBX_txn_flags_t flags () const
 Returns transaction's flags. More...
 
uint64_t id () const
 Return the transaction's ID. More...
 
bool is_dirty (const void *ptr) const
 Checks whether the given data is on a dirty page. More...
 
bool is_readonly () const
 Checks whether the transaction is read-only. More...
 
bool is_readwrite () const
 Checks whether the transaction is read-write. More...
 
info get_info (bool scan_reader_lock_table=false) const
 Returns information about the MDBX transaction. More...
 
size_t size_max () const
 Returns maximal write transaction size (i.e. limit for summary volume of dirty pages) in bytes. More...
 
size_t size_current () const
 Returns current write transaction size (i.e.summary volume of dirty pages) in bytes. More...
 
void reset_reading ()
 Reset a read-only transaction. More...
 
void renew_reading ()
 Renew a read-only transaction. More...
 
txn_managed start_nested ()
 Start nested write transaction. More...
 
cursor_managed open_cursor (map_handle map)
 Opens cursor for specified key-value map handle. More...
 
map_handle open_map (const char *name, const ::mdbx::key_mode key_mode=::mdbx::key_mode::usual, const ::mdbx::value_mode value_mode=::mdbx::value_mode::single) const
 Open existing key-value map. More...
 
map_handle open_map (const ::std::string &name, const ::mdbx::key_mode key_mode=::mdbx::key_mode::usual, const ::mdbx::value_mode value_mode=::mdbx::value_mode::single) const
 Open existing key-value map. More...
 
map_handle create_map (const char *name, const ::mdbx::key_mode key_mode=::mdbx::key_mode::usual, const ::mdbx::value_mode value_mode=::mdbx::value_mode::single)
 Create new or open existing key-value map. More...
 
map_handle create_map (const ::std::string &name, const ::mdbx::key_mode key_mode=::mdbx::key_mode::usual, const ::mdbx::value_mode value_mode=::mdbx::value_mode::single)
 Create new or open existing key-value map. More...
 
void drop_map (map_handle map)
 Drops key-value map using handle. More...
 
bool drop_map (const char *name, bool throw_if_absent=false)
 Drops key-value map using name. More...
 
bool drop_map (const ::std::string &name, bool throw_if_absent=false)
 Drop key-value map. More...
 
void clear_map (map_handle map)
 Clear key-value map. More...
 
bool clear_map (const char *name, bool throw_if_absent=false)
 
bool clear_map (const ::std::string &name, bool throw_if_absent=false)
 
map_stat get_map_stat (map_handle map) const
 Returns statistics for a sub-database. More...
 
uint32_t get_tree_deepmask (map_handle map) const
 Returns depth (bitmask) information of nested dupsort (multi-value) B+trees for given database. More...
 
map_handle::info get_handle_info (map_handle map) const
 Returns information about key-value map (aka sub-database) handle. More...
 
txnput_canary (const canary &)
 Set integers markers (aka "canary") associated with the environment. More...
 
canary get_canary () const
 Returns fours integers markers (aka "canary") associated with the environment. More...
 
uint64_t sequence (map_handle map) const
 
uint64_t sequence (map_handle map, uint64_t increment)
 Reads and increment sequence generator associated with a key-value map (aka sub-database). More...
 
int compare_keys (map_handle map, const slice &a, const slice &b) const noexcept
 Compare two keys according to a particular key-value map (aka sub-database). More...
 
int compare_values (map_handle map, const slice &a, const slice &b) const noexcept
 Compare two values according to a particular key-value map (aka sub-database). More...
 
int compare_keys (map_handle map, const pair &a, const pair &b) const noexcept
 Compare keys of two pairs according to a particular key-value map (aka sub-database). More...
 
int compare_values (map_handle map, const pair &a, const pair &b) const noexcept
 Compare values of two pairs according to a particular key-value map (aka sub-database). More...
 
slice get (map_handle map, const slice &key) const
 Get value by key from a key-value map (aka sub-database). More...
 
slice get (map_handle map, slice key, size_t &values_count) const
 Get first of multi-value and values count by key from a key-value multimap (aka sub-database). More...
 
slice get (map_handle map, const slice &key, const slice &value_at_absence) const
 Get value by key from a key-value map (aka sub-database). More...
 
slice get (map_handle map, slice key, size_t &values_count, const slice &value_at_absence) const
 Get first of multi-value and values count by key from a key-value multimap (aka sub-database). More...
 
pair_result get_equal_or_great (map_handle map, const slice &key) const
 Get value for equal or great key from a database. More...
 
pair_result get_equal_or_great (map_handle map, const slice &key, const slice &value_at_absence) const
 Get value for equal or great key from a database. More...
 
MDBX_error_t put (map_handle map, const slice &key, slice *value, MDBX_put_flags_t flags) noexcept
 
void put (map_handle map, const slice &key, slice value, put_mode mode)
 
void insert (map_handle map, const slice &key, slice value)
 
value_result try_insert (map_handle map, const slice &key, slice value)
 
slice insert_reserve (map_handle map, const slice &key, size_t value_length)
 
value_result try_insert_reserve (map_handle map, const slice &key, size_t value_length)
 
void upsert (map_handle map, const slice &key, const slice &value)
 
slice upsert_reserve (map_handle map, const slice &key, size_t value_length)
 
void update (map_handle map, const slice &key, const slice &value)
 
bool try_update (map_handle map, const slice &key, const slice &value)
 
slice update_reserve (map_handle map, const slice &key, size_t value_length)
 
value_result try_update_reserve (map_handle map, const slice &key, size_t value_length)
 
bool erase (map_handle map, const slice &key)
 Removes all values for given key. More...
 
bool erase (map_handle map, const slice &key, const slice &value)
 Removes the particular multi-value entry of the key. More...
 
void replace (map_handle map, const slice &key, slice old_value, const slice &new_value)
 Replaces the particular multi-value of the key with a new value. More...
 
template<class ALLOCATOR , typename CAPACITY_POLICY >
buffer< ALLOCATOR, CAPACITY_POLICY > extract (map_handle map, const slice &key, const typename buffer< ALLOCATOR, CAPACITY_POLICY >::allocator_type &allocator=buffer< ALLOCATOR, CAPACITY_POLICY >::allocator_type())
 Removes and return a value of the key. More...
 
template<class ALLOCATOR , typename CAPACITY_POLICY >
buffer< ALLOCATOR, CAPACITY_POLICY > replace (map_handle map, const slice &key, const slice &new_value, const typename buffer< ALLOCATOR, CAPACITY_POLICY >::allocator_type &allocator=buffer< ALLOCATOR, CAPACITY_POLICY >::allocator_type())
 Replaces and returns a value of the key with new one. More...
 
template<class ALLOCATOR , typename CAPACITY_POLICY >
buffer< ALLOCATOR, CAPACITY_POLICY > replace_reserve (map_handle map, const slice &key, slice &new_value, const typename buffer< ALLOCATOR, CAPACITY_POLICY >::allocator_type &allocator=buffer< ALLOCATOR, CAPACITY_POLICY >::allocator_type())
 
void append (map_handle map, const slice &key, const slice &value, bool multivalue_order_preserved=true)
 Adding a key-value pair, provided that ascending order of the keys and (optionally) values are preserved. More...
 
size_t put_multiple (map_handle map, const slice &key, const size_t value_length, const void *values_array, size_t values_count, put_mode mode, bool allow_partial=false)
 
template<typename VALUE >
void put_multiple (map_handle map, const slice &key, const ::std::vector< VALUE > &vector, put_mode mode)
 
ptrdiff_t estimate (map_handle map, pair from, pair to) const
 
ptrdiff_t estimate (map_handle map, slice from, slice to) const
 
ptrdiff_t estimate_from_first (map_handle map, slice to) const
 
ptrdiff_t estimate_to_last (map_handle map, slice from) const
 

Protected Member Functions

MDBX_CXX11_CONSTEXPR txn (MDBX_txn *ptr) noexcept
 

Protected Attributes

MDBX_txnhandle_ {nullptr}
 

Friends

class cursor
 
MDBX_CXX11_CONSTEXPR bool operator== (const txn &a, const txn &b) noexcept
 
MDBX_CXX11_CONSTEXPR bool operator!= (const txn &a, const txn &b) noexcept
 

Detailed Description

Unmanaged database transaction.

Like other unmanaged classes, txn allows copying and assignment for instances, but does not destroys the represented underlying object from the own class destructor.

All database operations require a transaction handle. Transactions may be read-only or read-write.

Member Typedef Documentation

◆ canary

◆ info

◆ map_stat

Constructor & Destructor Documentation

◆ txn() [1/4]

MDBX_CXX11_CONSTEXPR mdbx::txn::txn ( MDBX_txn ptr)
protectednoexcept

◆ txn() [2/4]

MDBX_CXX11_CONSTEXPR mdbx::txn::txn ( )
defaultnoexcept

◆ txn() [3/4]

mdbx::txn::txn ( const txn )
defaultnoexcept

◆ txn() [4/4]

mdbx::txn::txn ( txn &&  other)
inlinenoexcept

◆ ~txn()

mdbx::txn::~txn ( )
inlinenoexcept

Member Function Documentation

◆ append()

void mdbx::txn::append ( map_handle  map,
const slice key,
const slice value,
bool  multivalue_order_preserved = true 
)
inline

Adding a key-value pair, provided that ascending order of the keys and (optionally) values are preserved.

Instead of splitting the full b+tree pages, the data will be placed on new ones. Thus appending is about two times faster than insertion, and the pages will be filled in completely mostly but not half as after splitting ones. On the other hand, any subsequent insertion or update with an increase in the length of the value will be twice as slow, since it will require splitting already filled pages.

Parameters
[in]mapA map handle to append
[in]keyA key to be append
[in]valueA value to store with the key
[in]multivalue_order_preservedIf multivalue_order_preserved == true then the same rules applied for to pages of nested b+tree of multimap's values.

◆ clear_map() [1/3]

bool mdbx::txn::clear_map ( const ::std::string &  name,
bool  throw_if_absent = false 
)
inline
Returns
True if the key-value map existed and was cleared, either false if the key-value map did not exist and there is nothing to clear.

◆ clear_map() [2/3]

bool mdbx::txn::clear_map ( const char *  name,
bool  throw_if_absent = false 
)
Returns
True if the key-value map existed and was cleared, either false if the key-value map did not exist and there is nothing to clear.

◆ clear_map() [3/3]

void mdbx::txn::clear_map ( map_handle  map)
inline

Clear key-value map.

◆ compare_keys() [1/2]

int mdbx::txn::compare_keys ( map_handle  map,
const pair a,
const pair b 
) const
inlinenoexcept

Compare keys of two pairs according to a particular key-value map (aka sub-database).

◆ compare_keys() [2/2]

int mdbx::txn::compare_keys ( map_handle  map,
const slice a,
const slice b 
) const
inlinenoexcept

Compare two keys according to a particular key-value map (aka sub-database).

◆ compare_values() [1/2]

int mdbx::txn::compare_values ( map_handle  map,
const pair a,
const pair b 
) const
inlinenoexcept

Compare values of two pairs according to a particular key-value map (aka sub-database).

◆ compare_values() [2/2]

int mdbx::txn::compare_values ( map_handle  map,
const slice a,
const slice b 
) const
inlinenoexcept

Compare two values according to a particular key-value map (aka sub-database).

◆ create_map() [1/2]

mdbx::map_handle mdbx::txn::create_map ( const ::std::string &  name,
const ::mdbx::key_mode  key_mode = ::mdbx::key_mode::usual,
const ::mdbx::value_mode  value_mode = ::mdbx::value_mode::single 
)
inline

Create new or open existing key-value map.

◆ create_map() [2/2]

mdbx::map_handle mdbx::txn::create_map ( const char *  name,
const ::mdbx::key_mode  key_mode = ::mdbx::key_mode::usual,
const ::mdbx::value_mode  value_mode = ::mdbx::value_mode::single 
)
inline

Create new or open existing key-value map.

◆ drop_map() [1/3]

bool mdbx::txn::drop_map ( const ::std::string &  name,
bool  throw_if_absent = false 
)
inline

Drop key-value map.

Returns
True if the key-value map existed and was deleted, either false if the key-value map did not exist and there is nothing to delete.

◆ drop_map() [2/3]

bool mdbx::txn::drop_map ( const char *  name,
bool  throw_if_absent = false 
)

Drops key-value map using name.

Returns
True if the key-value map existed and was deleted, either false if the key-value map did not exist and there is nothing to delete.

◆ drop_map() [3/3]

void mdbx::txn::drop_map ( map_handle  map)
inline

Drops key-value map using handle.

◆ env()

mdbx::env mdbx::txn::env ( ) const
inlinenoexcept

Returns the transaction's environment.

◆ erase() [1/2]

bool mdbx::txn::erase ( map_handle  map,
const slice key 
)
inline

Removes all values for given key.

◆ erase() [2/2]

bool mdbx::txn::erase ( map_handle  map,
const slice key,
const slice value 
)
inline

Removes the particular multi-value entry of the key.

◆ estimate() [1/2]

ptrdiff_t mdbx::txn::estimate ( map_handle  map,
pair  from,
pair  to 
) const
inline

◆ estimate() [2/2]

ptrdiff_t mdbx::txn::estimate ( map_handle  map,
slice  from,
slice  to 
) const
inline

◆ estimate_from_first()

ptrdiff_t mdbx::txn::estimate_from_first ( map_handle  map,
slice  to 
) const
inline

◆ estimate_to_last()

ptrdiff_t mdbx::txn::estimate_to_last ( map_handle  map,
slice  from 
) const
inline

◆ extract()

template<class ALLOCATOR , typename CAPACITY_POLICY >
buffer< ALLOCATOR, CAPACITY_POLICY > mdbx::txn::extract ( map_handle  map,
const slice key,
const typename buffer< ALLOCATOR, CAPACITY_POLICY >::allocator_type &  allocator = buffer<ALLOCATOR, CAPACITY_POLICY>::allocator_type() 
)
inline

Removes and return a value of the key.

◆ flags()

MDBX_txn_flags_t mdbx::txn::flags ( ) const
inline

Returns transaction's flags.

◆ get() [1/4]

slice mdbx::txn::get ( map_handle  map,
const slice key 
) const
inline

Get value by key from a key-value map (aka sub-database).

◆ get() [2/4]

slice mdbx::txn::get ( map_handle  map,
const slice key,
const slice value_at_absence 
) const
inline

Get value by key from a key-value map (aka sub-database).

◆ get() [3/4]

slice mdbx::txn::get ( map_handle  map,
slice  key,
size_t &  values_count 
) const
inline

Get first of multi-value and values count by key from a key-value multimap (aka sub-database).

◆ get() [4/4]

slice mdbx::txn::get ( map_handle  map,
slice  key,
size_t &  values_count,
const slice value_at_absence 
) const
inline

Get first of multi-value and values count by key from a key-value multimap (aka sub-database).

◆ get_canary()

txn::canary mdbx::txn::get_canary ( ) const
inline

Returns fours integers markers (aka "canary") associated with the environment.

◆ get_equal_or_great() [1/2]

pair_result mdbx::txn::get_equal_or_great ( map_handle  map,
const slice key 
) const
inline

Get value for equal or great key from a database.

Returns
Bundle of key-value pair and boolean flag, which will be true if the exact key was found and false otherwise.

◆ get_equal_or_great() [2/2]

pair_result mdbx::txn::get_equal_or_great ( map_handle  map,
const slice key,
const slice value_at_absence 
) const
inline

Get value for equal or great key from a database.

Returns
Bundle of key-value pair and boolean flag, which will be true if the exact key was found and false otherwise.

◆ get_handle_info()

map_handle::info mdbx::txn::get_handle_info ( map_handle  map) const
inline

Returns information about key-value map (aka sub-database) handle.

◆ get_info()

txn::info mdbx::txn::get_info ( bool  scan_reader_lock_table = false) const
inline

Returns information about the MDBX transaction.

◆ get_map_stat()

txn::map_stat mdbx::txn::get_map_stat ( map_handle  map) const
inline

Returns statistics for a sub-database.

◆ get_tree_deepmask()

uint32_t mdbx::txn::get_tree_deepmask ( map_handle  map) const
inline

Returns depth (bitmask) information of nested dupsort (multi-value) B+trees for given database.

◆ id()

uint64_t mdbx::txn::id ( ) const
inline

Return the transaction's ID.

◆ insert()

void mdbx::txn::insert ( map_handle  map,
const slice key,
slice  value 
)
inline

◆ insert_reserve()

slice mdbx::txn::insert_reserve ( map_handle  map,
const slice key,
size_t  value_length 
)
inline

◆ is_dirty()

bool mdbx::txn::is_dirty ( const void *  ptr) const
inline

Checks whether the given data is on a dirty page.

◆ is_readonly()

bool mdbx::txn::is_readonly ( ) const
inline

Checks whether the transaction is read-only.

◆ is_readwrite()

bool mdbx::txn::is_readwrite ( ) const
inline

Checks whether the transaction is read-write.

◆ open_cursor()

cursor_managed mdbx::txn::open_cursor ( map_handle  map)
inline

Opens cursor for specified key-value map handle.

◆ open_map() [1/2]

mdbx::map_handle mdbx::txn::open_map ( const ::std::string &  name,
const ::mdbx::key_mode  key_mode = ::mdbx::key_mode::usual,
const ::mdbx::value_mode  value_mode = ::mdbx::value_mode::single 
) const
inline

Open existing key-value map.

◆ open_map() [2/2]

mdbx::map_handle mdbx::txn::open_map ( const char *  name,
const ::mdbx::key_mode  key_mode = ::mdbx::key_mode::usual,
const ::mdbx::value_mode  value_mode = ::mdbx::value_mode::single 
) const
inline

Open existing key-value map.

◆ operator bool()

MDBX_CXX14_CONSTEXPR mdbx::txn::operator bool ( ) const
noexcept

◆ operator const MDBX_txn *()

MDBX_CXX14_CONSTEXPR mdbx::txn::operator const MDBX_txn * ( ) const

◆ operator MDBX_txn *()

MDBX_CXX14_CONSTEXPR mdbx::txn::operator MDBX_txn * ( )

◆ operator=()

txn & mdbx::txn::operator= ( txn &&  other)
inlinenoexcept

◆ put() [1/2]

MDBX_error_t mdbx::txn::put ( map_handle  map,
const slice key,
slice value,
MDBX_put_flags_t  flags 
)
inlinenoexcept

◆ put() [2/2]

void mdbx::txn::put ( map_handle  map,
const slice key,
slice  value,
put_mode  mode 
)
inline

◆ put_canary()

txn & mdbx::txn::put_canary ( const canary canary)
inline

Set integers markers (aka "canary") associated with the environment.

◆ put_multiple() [1/2]

template<typename VALUE >
void mdbx::txn::put_multiple ( map_handle  map,
const slice key,
const ::std::vector< VALUE > &  vector,
put_mode  mode 
)
inline

◆ put_multiple() [2/2]

size_t mdbx::txn::put_multiple ( map_handle  map,
const slice key,
const size_t  value_length,
const void *  values_array,
size_t  values_count,
put_mode  mode,
bool  allow_partial = false 
)
inline

◆ renew_reading()

void mdbx::txn::renew_reading ( )
inline

Renew a read-only transaction.

◆ replace() [1/2]

template<class ALLOCATOR , typename CAPACITY_POLICY >
buffer< ALLOCATOR, CAPACITY_POLICY > mdbx::txn::replace ( map_handle  map,
const slice key,
const slice new_value,
const typename buffer< ALLOCATOR, CAPACITY_POLICY >::allocator_type &  allocator = buffer<ALLOCATOR, CAPACITY_POLICY>::allocator_type() 
)
inline

Replaces and returns a value of the key with new one.

◆ replace() [2/2]

void mdbx::txn::replace ( map_handle  map,
const slice key,
slice  old_value,
const slice new_value 
)
inline

Replaces the particular multi-value of the key with a new value.

◆ replace_reserve()

template<class ALLOCATOR , typename CAPACITY_POLICY >
buffer< ALLOCATOR, CAPACITY_POLICY > mdbx::txn::replace_reserve ( map_handle  map,
const slice key,
slice new_value,
const typename buffer< ALLOCATOR, CAPACITY_POLICY >::allocator_type &  allocator = buffer<ALLOCATOR, CAPACITY_POLICY>::allocator_type() 
)
inline

◆ reset_reading()

void mdbx::txn::reset_reading ( )
inline

Reset a read-only transaction.

◆ sequence() [1/2]

uint64_t mdbx::txn::sequence ( map_handle  map) const
inline

Reads sequence generator associated with a key-value map (aka sub-database).

◆ sequence() [2/2]

uint64_t mdbx::txn::sequence ( map_handle  map,
uint64_t  increment 
)
inline

Reads and increment sequence generator associated with a key-value map (aka sub-database).

◆ size_current()

size_t mdbx::txn::size_current ( ) const
inline

Returns current write transaction size (i.e.summary volume of dirty pages) in bytes.

◆ size_max()

size_t mdbx::txn::size_max ( ) const
inline

Returns maximal write transaction size (i.e. limit for summary volume of dirty pages) in bytes.

◆ start_nested()

txn_managed mdbx::txn::start_nested ( )

Start nested write transaction.

◆ try_insert()

value_result mdbx::txn::try_insert ( map_handle  map,
const slice key,
slice  value 
)
inline

◆ try_insert_reserve()

value_result mdbx::txn::try_insert_reserve ( map_handle  map,
const slice key,
size_t  value_length 
)
inline

◆ try_update()

bool mdbx::txn::try_update ( map_handle  map,
const slice key,
const slice value 
)
inline

◆ try_update_reserve()

value_result mdbx::txn::try_update_reserve ( map_handle  map,
const slice key,
size_t  value_length 
)
inline

◆ update()

void mdbx::txn::update ( map_handle  map,
const slice key,
const slice value 
)
inline

◆ update_reserve()

slice mdbx::txn::update_reserve ( map_handle  map,
const slice key,
size_t  value_length 
)
inline

◆ upsert()

void mdbx::txn::upsert ( map_handle  map,
const slice key,
const slice value 
)
inline

◆ upsert_reserve()

slice mdbx::txn::upsert_reserve ( map_handle  map,
const slice key,
size_t  value_length 
)
inline

Friends And Related Function Documentation

◆ cursor

friend class cursor
friend

◆ operator!=

MDBX_CXX11_CONSTEXPR bool operator!= ( const txn a,
const txn b 
)
friend

◆ operator==

MDBX_CXX11_CONSTEXPR bool operator== ( const txn a,
const txn b 
)
friend

Member Data Documentation

◆ handle_

MDBX_txn* mdbx::txn::handle_ {nullptr}
protected

The documentation for this class was generated from the following file: