mirror of
https://github.com/isar/libmdbx.git
synced 2025-06-24 14:22:36 +08:00
mdbx++: more Doxygen descriptions and refinement.
Change-Id: Iec4cfa220f140c0fcc858f51283af2f9c4dd7a65
This commit is contained in:
parent
16912b8a40
commit
50c25f479d
@ -116,7 +116,7 @@ the lock was restored - we have to wait until such a process releases the
|
|||||||
database, and so on.
|
database, and so on.
|
||||||
|
|
||||||
|
|
||||||
## Long-lived read transactions
|
## Long-lived read transactions {#long-lived-read}
|
||||||
Avoid long-lived read transactions, especially in the scenarios with a
|
Avoid long-lived read transactions, especially in the scenarios with a
|
||||||
high rate of write transactions. Long-lived read transactions prevents
|
high rate of write transactions. Long-lived read transactions prevents
|
||||||
recycling pages retired/freed by newer write transactions, thus the
|
recycling pages retired/freed by newer write transactions, thus the
|
||||||
|
22
mdbx.h
22
mdbx.h
@ -574,8 +574,8 @@ void LIBMDBX_API NTAPI mdbx_dll_handler(PVOID module, DWORD reason,
|
|||||||
/* OPACITY STRUCTURES *********************************************************/
|
/* OPACITY STRUCTURES *********************************************************/
|
||||||
|
|
||||||
/** \brief Opaque structure for a database environment.
|
/** \brief Opaque structure for a database environment.
|
||||||
* \details An environment supports multiple key-value databases (aka key-value
|
* \details An environment supports multiple key-value sub-databases (aka
|
||||||
* spaces or tables), all residing in the same shared-memory map.
|
* key-value spaces or tables), all residing in the same shared-memory map.
|
||||||
* \see mdbx_env_create() \see mdbx_env_close() */
|
* \see mdbx_env_create() \see mdbx_env_close() */
|
||||||
#ifndef __cplusplus
|
#ifndef __cplusplus
|
||||||
typedef struct MDBX_env MDBX_env;
|
typedef struct MDBX_env MDBX_env;
|
||||||
@ -1812,7 +1812,7 @@ LIBMDBX_API int mdbx_env_open(MDBX_env *env, const char *pathname,
|
|||||||
LIBMDBX_API int mdbx_env_copy(MDBX_env *env, const char *dest,
|
LIBMDBX_API int mdbx_env_copy(MDBX_env *env, const char *dest,
|
||||||
MDBX_copy_flags_t flags);
|
MDBX_copy_flags_t flags);
|
||||||
|
|
||||||
/** \brief Copy an MDBX environment to the specified file descriptor, with
|
/** \brief Copy an environment to the specified file descriptor, with
|
||||||
* options. \ingroup c_extra
|
* options. \ingroup c_extra
|
||||||
*
|
*
|
||||||
* This function may be used to make a backup of an existing environment.
|
* This function may be used to make a backup of an existing environment.
|
||||||
@ -3137,6 +3137,10 @@ LIBMDBX_API int mdbx_dbi_flags(MDBX_txn *txn, MDBX_dbi dbi, unsigned *flags);
|
|||||||
/** \brief Close a database handle. Normally unnecessary.
|
/** \brief Close a database handle. Normally unnecessary.
|
||||||
* \ingroup c_dbi
|
* \ingroup c_dbi
|
||||||
*
|
*
|
||||||
|
* Closing a database handle is not necessary, but lets \ref mdbx_dbi_open()
|
||||||
|
* reuse the handle value. Usually it's better to set a bigger
|
||||||
|
* \ref mdbx_env_set_maxdbs(), unless that value would be large.
|
||||||
|
*
|
||||||
* \note Use with care.
|
* \note Use with care.
|
||||||
* This call is synchronized via mutex with \ref mdbx_dbi_close(), but NOT with
|
* This call is synchronized via mutex with \ref mdbx_dbi_close(), but NOT with
|
||||||
* other transactions running by other threads. The "next" version of libmdbx
|
* other transactions running by other threads. The "next" version of libmdbx
|
||||||
@ -3145,13 +3149,9 @@ LIBMDBX_API int mdbx_dbi_flags(MDBX_txn *txn, MDBX_dbi dbi, unsigned *flags);
|
|||||||
* Handles should only be closed if no other threads are going to reference
|
* Handles should only be closed if no other threads are going to reference
|
||||||
* the database handle or one of its cursors any further. Do not close a handle
|
* the database handle or one of its cursors any further. Do not close a handle
|
||||||
* if an existing transaction has modified its database. Doing so can cause
|
* if an existing transaction has modified its database. Doing so can cause
|
||||||
* misbehavior from database corruption to errors like \ref MDBX_BAD_VALSIZE
|
* misbehavior from database corruption to errors like \ref MDBX_BAD_DBI
|
||||||
* (since the DB name is gone).
|
* (since the DB name is gone).
|
||||||
*
|
*
|
||||||
* Closing a database handle is not necessary, but lets \ref mdbx_dbi_open()
|
|
||||||
* reuse the handle value. Usually it's better to set a bigger
|
|
||||||
* \ref mdbx_env_set_maxdbs(), unless that value would be large.
|
|
||||||
*
|
|
||||||
* \param [in] env An environment handle returned by \ref mdbx_env_create().
|
* \param [in] env An environment handle returned by \ref mdbx_env_create().
|
||||||
* \param [in] dbi A database handle returned by \ref mdbx_dbi_open().
|
* \param [in] dbi A database handle returned by \ref mdbx_dbi_open().
|
||||||
*
|
*
|
||||||
@ -3865,7 +3865,7 @@ __nothrow_pure_function LIBMDBX_API int mdbx_is_dirty(const MDBX_txn *txn,
|
|||||||
LIBMDBX_API int mdbx_dbi_sequence(MDBX_txn *txn, MDBX_dbi dbi, uint64_t *result,
|
LIBMDBX_API int mdbx_dbi_sequence(MDBX_txn *txn, MDBX_dbi dbi, uint64_t *result,
|
||||||
uint64_t increment);
|
uint64_t increment);
|
||||||
|
|
||||||
/** \brief Compare two data items according to a particular database.
|
/** \brief Compare two keys according to a particular database.
|
||||||
* \ingroup c_crud
|
* \ingroup c_crud
|
||||||
*
|
*
|
||||||
* This returns a comparison as if the two data items were keys in the
|
* This returns a comparison as if the two data items were keys in the
|
||||||
@ -3999,7 +3999,7 @@ MDBX_DEPRECATED LIBMDBX_API int mdbx_txn_straggler(const MDBX_txn *txn,
|
|||||||
*
|
*
|
||||||
* \returns A non-zero error value on failure and 0 on success,
|
* \returns A non-zero error value on failure and 0 on success,
|
||||||
* or \ref MDBX_RESULT_TRUE if thread is already registered. */
|
* or \ref MDBX_RESULT_TRUE if thread is already registered. */
|
||||||
LIBMDBX_API int mdbx_thread_register(MDBX_env *env);
|
LIBMDBX_API int mdbx_thread_register(const MDBX_env *env);
|
||||||
|
|
||||||
/** \brief Unregisters the current thread as a reader for the environment.
|
/** \brief Unregisters the current thread as a reader for the environment.
|
||||||
* \ingroup c_extra
|
* \ingroup c_extra
|
||||||
@ -4014,7 +4014,7 @@ LIBMDBX_API int mdbx_thread_register(MDBX_env *env);
|
|||||||
*
|
*
|
||||||
* \returns A non-zero error value on failure and 0 on success, or
|
* \returns A non-zero error value on failure and 0 on success, or
|
||||||
* \ref MDBX_RESULT_TRUE if thread is not registered or already undegistered. */
|
* \ref MDBX_RESULT_TRUE if thread is not registered or already undegistered. */
|
||||||
LIBMDBX_API int mdbx_thread_unregister(MDBX_env *env);
|
LIBMDBX_API int mdbx_thread_unregister(const MDBX_env *env);
|
||||||
|
|
||||||
/** \brief A lack-of-space callback function to resolve issues with a laggard
|
/** \brief A lack-of-space callback function to resolve issues with a laggard
|
||||||
* readers. \ingroup c_err
|
* readers. \ingroup c_err
|
||||||
|
@ -6025,7 +6025,7 @@ static bind_rslot_result bind_rslot(MDBX_env *env, const uintptr_t tid) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
__cold int mdbx_thread_register(MDBX_env *env) {
|
__cold int mdbx_thread_register(const MDBX_env *env) {
|
||||||
int rc = check_env(env);
|
int rc = check_env(env);
|
||||||
if (unlikely(rc != MDBX_SUCCESS))
|
if (unlikely(rc != MDBX_SUCCESS))
|
||||||
return rc;
|
return rc;
|
||||||
@ -6052,10 +6052,10 @@ __cold int mdbx_thread_register(MDBX_env *env) {
|
|||||||
const uintptr_t tid = mdbx_thread_self();
|
const uintptr_t tid = mdbx_thread_self();
|
||||||
if (env->me_txn0 && unlikely(env->me_txn0->mt_owner == tid))
|
if (env->me_txn0 && unlikely(env->me_txn0->mt_owner == tid))
|
||||||
return MDBX_TXN_OVERLAPPING;
|
return MDBX_TXN_OVERLAPPING;
|
||||||
return bind_rslot(env, tid).err;
|
return bind_rslot((MDBX_env *)env, tid).err;
|
||||||
}
|
}
|
||||||
|
|
||||||
__cold int mdbx_thread_unregister(MDBX_env *env) {
|
__cold int mdbx_thread_unregister(const MDBX_env *env) {
|
||||||
int rc = check_env(env);
|
int rc = check_env(env);
|
||||||
if (unlikely(rc != MDBX_SUCCESS))
|
if (unlikely(rc != MDBX_SUCCESS))
|
||||||
return rc;
|
return rc;
|
||||||
|
198
src/mdbx.c++
198
src/mdbx.c++
@ -1002,23 +1002,23 @@ template class LIBMDBX_API_TYPE buffer<polymorphic_allocator>;
|
|||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
size_t env_ref::default_pagesize() noexcept { return ::mdbx_syspagesize(); }
|
size_t env::default_pagesize() noexcept { return ::mdbx_syspagesize(); }
|
||||||
|
|
||||||
static inline MDBX_env_flags_t mode2flags(env_ref::mode mode) {
|
static inline MDBX_env_flags_t mode2flags(env::mode mode) {
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
default:
|
default:
|
||||||
cxx20_attribute_unlikely throw std::invalid_argument("db::mode is invalid");
|
cxx20_attribute_unlikely throw std::invalid_argument("db::mode is invalid");
|
||||||
case env_ref::mode::readonly:
|
case env::mode::readonly:
|
||||||
return MDBX_RDONLY;
|
return MDBX_RDONLY;
|
||||||
case env_ref::mode::write_file_io:
|
case env::mode::write_file_io:
|
||||||
return MDBX_ENV_DEFAULTS;
|
return MDBX_ENV_DEFAULTS;
|
||||||
case env_ref::mode::write_mapped_io:
|
case env::mode::write_mapped_io:
|
||||||
return MDBX_WRITEMAP;
|
return MDBX_WRITEMAP;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
__cold MDBX_env_flags_t env_ref::operate_parameters::make_flags(
|
__cold MDBX_env_flags_t
|
||||||
bool accede, bool use_subdirectory) const {
|
env::operate_parameters::make_flags(bool accede, bool use_subdirectory) const {
|
||||||
MDBX_env_flags_t flags = mode2flags(mode);
|
MDBX_env_flags_t flags = mode2flags(mode);
|
||||||
if (accede)
|
if (accede)
|
||||||
flags |= MDBX_ACCEDE;
|
flags |= MDBX_ACCEDE;
|
||||||
@ -1044,16 +1044,16 @@ __cold MDBX_env_flags_t env_ref::operate_parameters::make_flags(
|
|||||||
default:
|
default:
|
||||||
cxx20_attribute_unlikely throw std::invalid_argument(
|
cxx20_attribute_unlikely throw std::invalid_argument(
|
||||||
"db::durability is invalid");
|
"db::durability is invalid");
|
||||||
case env_ref::durability::robust_synchronous:
|
case env::durability::robust_synchronous:
|
||||||
break;
|
break;
|
||||||
case env_ref::durability::half_synchronous_weak_last:
|
case env::durability::half_synchronous_weak_last:
|
||||||
flags |= MDBX_NOMETASYNC;
|
flags |= MDBX_NOMETASYNC;
|
||||||
break;
|
break;
|
||||||
case env_ref::durability::lazy_weak_tail:
|
case env::durability::lazy_weak_tail:
|
||||||
static_assert(MDBX_MAPASYNC == MDBX_SAFE_NOSYNC, "WTF? Obsolete C API?");
|
static_assert(MDBX_MAPASYNC == MDBX_SAFE_NOSYNC, "WTF? Obsolete C API?");
|
||||||
flags |= MDBX_SAFE_NOSYNC;
|
flags |= MDBX_SAFE_NOSYNC;
|
||||||
break;
|
break;
|
||||||
case env_ref::durability::whole_fragile:
|
case env::durability::whole_fragile:
|
||||||
flags |= MDBX_UTTERLY_NOSYNC;
|
flags |= MDBX_UTTERLY_NOSYNC;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1061,30 +1061,30 @@ __cold MDBX_env_flags_t env_ref::operate_parameters::make_flags(
|
|||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
env_ref::mode
|
env::mode
|
||||||
env_ref::operate_parameters::mode_from_flags(MDBX_env_flags_t flags) noexcept {
|
env::operate_parameters::mode_from_flags(MDBX_env_flags_t flags) noexcept {
|
||||||
if (flags & MDBX_RDONLY)
|
if (flags & MDBX_RDONLY)
|
||||||
return env_ref::mode::readonly;
|
return env::mode::readonly;
|
||||||
return (flags & MDBX_WRITEMAP) ? env_ref::mode::write_mapped_io
|
return (flags & MDBX_WRITEMAP) ? env::mode::write_mapped_io
|
||||||
: env_ref::mode::write_file_io;
|
: env::mode::write_file_io;
|
||||||
}
|
}
|
||||||
|
|
||||||
env_ref::durability env_ref::operate_parameters::durability_from_flags(
|
env::durability env::operate_parameters::durability_from_flags(
|
||||||
MDBX_env_flags_t flags) noexcept {
|
MDBX_env_flags_t flags) noexcept {
|
||||||
if ((flags & MDBX_UTTERLY_NOSYNC) == MDBX_UTTERLY_NOSYNC)
|
if ((flags & MDBX_UTTERLY_NOSYNC) == MDBX_UTTERLY_NOSYNC)
|
||||||
return env_ref::durability::whole_fragile;
|
return env::durability::whole_fragile;
|
||||||
if (flags & MDBX_SAFE_NOSYNC)
|
if (flags & MDBX_SAFE_NOSYNC)
|
||||||
return env_ref::durability::lazy_weak_tail;
|
return env::durability::lazy_weak_tail;
|
||||||
if (flags & MDBX_NOMETASYNC)
|
if (flags & MDBX_NOMETASYNC)
|
||||||
return env_ref::durability::half_synchronous_weak_last;
|
return env::durability::half_synchronous_weak_last;
|
||||||
return env_ref::durability::robust_synchronous;
|
return env::durability::robust_synchronous;
|
||||||
}
|
}
|
||||||
|
|
||||||
env_ref::reclaiming_options::reclaiming_options(MDBX_env_flags_t flags) noexcept
|
env::reclaiming_options::reclaiming_options(MDBX_env_flags_t flags) noexcept
|
||||||
: lifo((flags & MDBX_LIFORECLAIM) ? true : false),
|
: lifo((flags & MDBX_LIFORECLAIM) ? true : false),
|
||||||
coalesce((flags & MDBX_COALESCE) ? true : false) {}
|
coalesce((flags & MDBX_COALESCE) ? true : false) {}
|
||||||
|
|
||||||
env_ref::operate_options::operate_options(MDBX_env_flags_t flags) noexcept
|
env::operate_options::operate_options(MDBX_env_flags_t flags) noexcept
|
||||||
: orphan_read_transactions(
|
: orphan_read_transactions(
|
||||||
((flags & (MDBX_NOTLS | MDBX_EXCLUSIVE)) == MDBX_NOTLS) ? true
|
((flags & (MDBX_NOTLS | MDBX_EXCLUSIVE)) == MDBX_NOTLS) ? true
|
||||||
: false),
|
: false),
|
||||||
@ -1094,7 +1094,7 @@ env_ref::operate_options::operate_options(MDBX_env_flags_t flags) noexcept
|
|||||||
disable_readahead((flags & MDBX_NORDAHEAD) ? true : false),
|
disable_readahead((flags & MDBX_NORDAHEAD) ? true : false),
|
||||||
disable_clear_memory((flags & MDBX_NOMEMINIT) ? true : false) {}
|
disable_clear_memory((flags & MDBX_NOMEMINIT) ? true : false) {}
|
||||||
|
|
||||||
env_ref::operate_parameters::operate_parameters(const env_ref &env)
|
env::operate_parameters::operate_parameters(const env &env)
|
||||||
: max_maps(env.max_maps()), max_readers(env.max_readers()) {
|
: max_maps(env.max_maps()), max_readers(env.max_readers()) {
|
||||||
const auto flags = env.get_flags();
|
const auto flags = env.get_flags();
|
||||||
mode = mode_from_flags(flags);
|
mode = mode_from_flags(flags);
|
||||||
@ -1103,14 +1103,14 @@ env_ref::operate_parameters::operate_parameters(const env_ref &env)
|
|||||||
options = options_from_flags(flags);
|
options = options_from_flags(flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool env_ref::is_pristine() const {
|
bool env::is_pristine() const {
|
||||||
return get_stat().ms_mod_txnid == 0 &&
|
return get_stat().ms_mod_txnid == 0 &&
|
||||||
get_info().mi_recent_txnid == INITIAL_TXNID;
|
get_info().mi_recent_txnid == INITIAL_TXNID;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool env_ref::is_empty() const { return get_stat().ms_branch_pages == 0; }
|
bool env::is_empty() const { return get_stat().ms_branch_pages == 0; }
|
||||||
|
|
||||||
env_ref &env_ref::copy(const path &destination, bool compactify,
|
env &env::copy(const path &destination, bool compactify,
|
||||||
bool force_dynamic_size) {
|
bool force_dynamic_size) {
|
||||||
const path_to_pchar<path> utf8(destination);
|
const path_to_pchar<path> utf8(destination);
|
||||||
error::success_or_throw(
|
error::success_or_throw(
|
||||||
@ -1121,8 +1121,7 @@ env_ref &env_ref::copy(const path &destination, bool compactify,
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
env_ref &env_ref::copy(filehandle fd, bool compactify,
|
env &env::copy(filehandle fd, bool compactify, bool force_dynamic_size) {
|
||||||
bool force_dynamic_size) {
|
|
||||||
error::success_or_throw(
|
error::success_or_throw(
|
||||||
::mdbx_env_copy2fd(handle_, fd,
|
::mdbx_env_copy2fd(handle_, fd,
|
||||||
(compactify ? MDBX_CP_COMPACT : MDBX_CP_DEFAULTS) |
|
(compactify ? MDBX_CP_COMPACT : MDBX_CP_DEFAULTS) |
|
||||||
@ -1131,7 +1130,7 @@ env_ref &env_ref::copy(filehandle fd, bool compactify,
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
path env_ref::get_path() const {
|
path env::get_path() const {
|
||||||
const char *c_str;
|
const char *c_str;
|
||||||
error::success_or_throw(::mdbx_env_get_path(handle_, &c_str));
|
error::success_or_throw(::mdbx_env_get_path(handle_, &c_str));
|
||||||
return pchar_to_path<path>(c_str);
|
return pchar_to_path<path>(c_str);
|
||||||
@ -1146,13 +1145,13 @@ static inline MDBX_env *create_env() {
|
|||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
env::~env() noexcept {
|
env_managed::~env_managed() noexcept {
|
||||||
if (handle_)
|
if (handle_)
|
||||||
error::success_or_panic(::mdbx_env_close(handle_), "mdbx::~env()",
|
error::success_or_panic(::mdbx_env_close(handle_), "mdbx::~env()",
|
||||||
"mdbx_env_close");
|
"mdbx_env_close");
|
||||||
}
|
}
|
||||||
|
|
||||||
void env::close(bool dont_sync) {
|
void env_managed::close(bool dont_sync) {
|
||||||
const error rc =
|
const error rc =
|
||||||
static_cast<MDBX_error_t>(::mdbx_env_close_ex(handle_, dont_sync));
|
static_cast<MDBX_error_t>(::mdbx_env_close_ex(handle_, dont_sync));
|
||||||
switch (rc.code()) {
|
switch (rc.code()) {
|
||||||
@ -1166,27 +1165,30 @@ void env::close(bool dont_sync) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
__cold void env::setup(unsigned max_maps, unsigned max_readers) {
|
__cold void env_managed::setup(unsigned max_maps, unsigned max_readers) {
|
||||||
if (max_readers > 0)
|
if (max_readers > 0)
|
||||||
error::success_or_throw(::mdbx_env_set_maxreaders(handle_, max_readers));
|
error::success_or_throw(::mdbx_env_set_maxreaders(handle_, max_readers));
|
||||||
if (max_maps > 0)
|
if (max_maps > 0)
|
||||||
error::success_or_throw(::mdbx_env_set_maxdbs(handle_, max_maps));
|
error::success_or_throw(::mdbx_env_set_maxdbs(handle_, max_maps));
|
||||||
}
|
}
|
||||||
|
|
||||||
__cold env::env(const path &pathname, const operate_parameters &op, bool accede)
|
__cold env_managed::env_managed(const path &pathname,
|
||||||
: env(create_env()) {
|
const operate_parameters &op, bool accede)
|
||||||
|
: env_managed(create_env()) {
|
||||||
setup(op.max_maps, op.max_readers);
|
setup(op.max_maps, op.max_readers);
|
||||||
const path_to_pchar<path> utf8(pathname);
|
const path_to_pchar<path> utf8(pathname);
|
||||||
error::success_or_throw(
|
error::success_or_throw(
|
||||||
::mdbx_env_open(handle_, utf8, op.make_flags(accede), 0));
|
::mdbx_env_open(handle_, utf8, op.make_flags(accede), 0));
|
||||||
|
|
||||||
// if (po.options.nested_write_transactions && (flags() & MDBX_WRITEMAP))
|
if (op.options.nested_write_transactions &&
|
||||||
// error::throw_exception(MDBX_INCOMPATIBLE);
|
!get_options().nested_write_transactions)
|
||||||
|
error::throw_exception(MDBX_INCOMPATIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
__cold env::env(const path &pathname, const env::create_parameters &cp,
|
__cold env_managed::env_managed(const path &pathname,
|
||||||
const env_ref::operate_parameters &op, bool accede)
|
const env_managed::create_parameters &cp,
|
||||||
: env(create_env()) {
|
const env::operate_parameters &op, bool accede)
|
||||||
|
: env_managed(create_env()) {
|
||||||
setup(op.max_maps, op.max_readers);
|
setup(op.max_maps, op.max_readers);
|
||||||
const path_to_pchar<path> utf8(pathname);
|
const path_to_pchar<path> utf8(pathname);
|
||||||
set_geometry(cp.geometry);
|
set_geometry(cp.geometry);
|
||||||
@ -1194,28 +1196,29 @@ __cold env::env(const path &pathname, const env::create_parameters &cp,
|
|||||||
::mdbx_env_open(handle_, utf8, op.make_flags(accede, cp.use_subdirectory),
|
::mdbx_env_open(handle_, utf8, op.make_flags(accede, cp.use_subdirectory),
|
||||||
cp.file_mode_bits));
|
cp.file_mode_bits));
|
||||||
|
|
||||||
// if (po.options.nested_write_transactions && (flags() & MDBX_WRITEMAP))
|
if (op.options.nested_write_transactions &&
|
||||||
// error::throw_exception(MDBX_INCOMPATIBLE);
|
!get_options().nested_write_transactions)
|
||||||
|
error::throw_exception(MDBX_INCOMPATIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
txn txn_ref::start_nested() {
|
txn_managed txn::start_nested() {
|
||||||
MDBX_txn *nested;
|
MDBX_txn *nested;
|
||||||
error::throw_on_nullptr(handle_, MDBX_BAD_TXN);
|
error::throw_on_nullptr(handle_, MDBX_BAD_TXN);
|
||||||
error::success_or_throw(::mdbx_txn_begin(mdbx_txn_env(handle_), handle_,
|
error::success_or_throw(::mdbx_txn_begin(mdbx_txn_env(handle_), handle_,
|
||||||
MDBX_TXN_READWRITE, &nested));
|
MDBX_TXN_READWRITE, &nested));
|
||||||
assert(nested != nullptr);
|
assert(nested != nullptr);
|
||||||
return txn(nested);
|
return txn_managed(nested);
|
||||||
}
|
}
|
||||||
|
|
||||||
txn::~txn() noexcept {
|
txn_managed::~txn_managed() noexcept {
|
||||||
if (handle_)
|
if (handle_)
|
||||||
error::success_or_panic(::mdbx_txn_abort(handle_), "mdbx::~txn",
|
error::success_or_panic(::mdbx_txn_abort(handle_), "mdbx::~txn",
|
||||||
"mdbx_txn_abort");
|
"mdbx_txn_abort");
|
||||||
}
|
}
|
||||||
|
|
||||||
void txn::abort() {
|
void txn_managed::abort() {
|
||||||
const error err = static_cast<MDBX_error_t>(::mdbx_txn_abort(handle_));
|
const error err = static_cast<MDBX_error_t>(::mdbx_txn_abort(handle_));
|
||||||
if (mdbx_unlikely(err.code() != MDBX_SUCCESS)) {
|
if (mdbx_unlikely(err.code() != MDBX_SUCCESS)) {
|
||||||
if (err.code() != MDBX_THREAD_MISMATCH)
|
if (err.code() != MDBX_THREAD_MISMATCH)
|
||||||
@ -1224,7 +1227,7 @@ void txn::abort() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void txn::commit() {
|
void txn_managed::commit() {
|
||||||
const error err = static_cast<MDBX_error_t>(::mdbx_txn_commit(handle_));
|
const error err = static_cast<MDBX_error_t>(::mdbx_txn_commit(handle_));
|
||||||
if (mdbx_unlikely(err.code() != MDBX_SUCCESS)) {
|
if (mdbx_unlikely(err.code() != MDBX_SUCCESS)) {
|
||||||
if (err.code() != MDBX_THREAD_MISMATCH)
|
if (err.code() != MDBX_THREAD_MISMATCH)
|
||||||
@ -1235,7 +1238,7 @@ void txn::commit() {
|
|||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
bool txn_ref::drop_map(const char *name, bool ignore_nonexists) {
|
bool txn::drop_map(const char *name, bool throw_if_absent) {
|
||||||
map_handle map;
|
map_handle map;
|
||||||
const int err = ::mdbx_dbi_open(handle_, name, MDBX_DB_ACCEDE, &map.dbi);
|
const int err = ::mdbx_dbi_open(handle_, name, MDBX_DB_ACCEDE, &map.dbi);
|
||||||
switch (err) {
|
switch (err) {
|
||||||
@ -1244,7 +1247,7 @@ bool txn_ref::drop_map(const char *name, bool ignore_nonexists) {
|
|||||||
return true;
|
return true;
|
||||||
case MDBX_NOTFOUND:
|
case MDBX_NOTFOUND:
|
||||||
case MDBX_BAD_DBI:
|
case MDBX_BAD_DBI:
|
||||||
if (ignore_nonexists)
|
if (!throw_if_absent)
|
||||||
return false;
|
return false;
|
||||||
cxx17_attribute_fallthrough /* fallthrough */;
|
cxx17_attribute_fallthrough /* fallthrough */;
|
||||||
default:
|
default:
|
||||||
@ -1252,7 +1255,7 @@ bool txn_ref::drop_map(const char *name, bool ignore_nonexists) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool txn_ref::clear_map(const char *name, bool ignore_nonexists) {
|
bool txn::clear_map(const char *name, bool throw_if_absent) {
|
||||||
map_handle map;
|
map_handle map;
|
||||||
const int err = ::mdbx_dbi_open(handle_, name, MDBX_DB_ACCEDE, &map.dbi);
|
const int err = ::mdbx_dbi_open(handle_, name, MDBX_DB_ACCEDE, &map.dbi);
|
||||||
switch (err) {
|
switch (err) {
|
||||||
@ -1261,7 +1264,7 @@ bool txn_ref::clear_map(const char *name, bool ignore_nonexists) {
|
|||||||
return true;
|
return true;
|
||||||
case MDBX_NOTFOUND:
|
case MDBX_NOTFOUND:
|
||||||
case MDBX_BAD_DBI:
|
case MDBX_BAD_DBI:
|
||||||
if (ignore_nonexists)
|
if (!throw_if_absent)
|
||||||
return false;
|
return false;
|
||||||
cxx17_attribute_fallthrough /* fallthrough */;
|
cxx17_attribute_fallthrough /* fallthrough */;
|
||||||
default:
|
default:
|
||||||
@ -1271,15 +1274,13 @@ bool txn_ref::clear_map(const char *name, bool ignore_nonexists) {
|
|||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
void cursor::close() {
|
void cursor_managed::close() {
|
||||||
if (mdbx_unlikely(!handle_))
|
if (mdbx_unlikely(!handle_))
|
||||||
error::throw_exception(MDBX_EINVAL);
|
cxx20_attribute_unlikely error::throw_exception(MDBX_EINVAL);
|
||||||
::mdbx_cursor_close(handle_);
|
::mdbx_cursor_close(handle_);
|
||||||
handle_ = nullptr;
|
handle_ = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
cursor::~cursor() noexcept { ::mdbx_cursor_close(handle_); }
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
__cold ::std::ostream &operator<<(::std::ostream &out, const slice &it) {
|
__cold ::std::ostream &operator<<(::std::ostream &out, const slice &it) {
|
||||||
@ -1304,13 +1305,13 @@ __cold ::std::ostream &operator<<(::std::ostream &out, const pair &it) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
__cold ::std::ostream &operator<<(::std::ostream &out,
|
__cold ::std::ostream &operator<<(::std::ostream &out,
|
||||||
const ::mdbx::env_ref::geometry::size &it) {
|
const ::mdbx::env::geometry::size &it) {
|
||||||
switch (it.bytes) {
|
switch (it.bytes) {
|
||||||
case ::mdbx::env_ref::geometry::default_value:
|
case ::mdbx::env::geometry::default_value:
|
||||||
return out << "default";
|
return out << "default";
|
||||||
case ::mdbx::env_ref::geometry::minimal_value:
|
case ::mdbx::env::geometry::minimal_value:
|
||||||
return out << "minimal";
|
return out << "minimal";
|
||||||
case ::mdbx::env_ref::geometry::maximal_value:
|
case ::mdbx::env::geometry::maximal_value:
|
||||||
return out << "maximal";
|
return out << "maximal";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1321,19 +1322,19 @@ __cold ::std::ostream &operator<<(::std::ostream &out,
|
|||||||
const char *suffix;
|
const char *suffix;
|
||||||
} static const scales[] = {
|
} static const scales[] = {
|
||||||
#if MDBX_WORDBITS > 32
|
#if MDBX_WORDBITS > 32
|
||||||
{env::geometry::EiB, "EiB"},
|
{env_managed::geometry::EiB, "EiB"},
|
||||||
{env::geometry::EB, "EB"},
|
{env_managed::geometry::EB, "EB"},
|
||||||
{env::geometry::PiB, "PiB"},
|
{env_managed::geometry::PiB, "PiB"},
|
||||||
{env::geometry::PB, "PB"},
|
{env_managed::geometry::PB, "PB"},
|
||||||
{env::geometry::TiB, "TiB"},
|
{env_managed::geometry::TiB, "TiB"},
|
||||||
{env::geometry::TB, "TB"},
|
{env_managed::geometry::TB, "TB"},
|
||||||
#endif
|
#endif
|
||||||
{env::geometry::GiB, "GiB"},
|
{env_managed::geometry::GiB, "GiB"},
|
||||||
{env::geometry::GB, "GB"},
|
{env_managed::geometry::GB, "GB"},
|
||||||
{env::geometry::MiB, "MiB"},
|
{env_managed::geometry::MiB, "MiB"},
|
||||||
{env::geometry::MB, "MB"},
|
{env_managed::geometry::MB, "MB"},
|
||||||
{env::geometry::KiB, "KiB"},
|
{env_managed::geometry::KiB, "KiB"},
|
||||||
{env::geometry::kB, "kB"},
|
{env_managed::geometry::kB, "kB"},
|
||||||
{1, " bytes"}
|
{1, " bytes"}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1347,18 +1348,18 @@ __cold ::std::ostream &operator<<(::std::ostream &out,
|
|||||||
}
|
}
|
||||||
|
|
||||||
__cold ::std::ostream &operator<<(::std::ostream &out,
|
__cold ::std::ostream &operator<<(::std::ostream &out,
|
||||||
const env_ref::geometry &it) {
|
const env::geometry &it) {
|
||||||
return //
|
return //
|
||||||
out << "\tlower " << env_ref::geometry::size(it.size_lower) //
|
out << "\tlower " << env::geometry::size(it.size_lower) //
|
||||||
<< ",\n\tnow " << env_ref::geometry::size(it.size_now) //
|
<< ",\n\tnow " << env::geometry::size(it.size_now) //
|
||||||
<< ",\n\tupper " << env_ref::geometry::size(it.size_upper) //
|
<< ",\n\tupper " << env::geometry::size(it.size_upper) //
|
||||||
<< ",\n\tgrowth " << env_ref::geometry::size(it.growth_step) //
|
<< ",\n\tgrowth " << env::geometry::size(it.growth_step) //
|
||||||
<< ",\n\tshrink " << env_ref::geometry::size(it.shrink_threshold) //
|
<< ",\n\tshrink " << env::geometry::size(it.shrink_threshold) //
|
||||||
<< ",\n\tpagesize " << env_ref::geometry::size(it.pagesize) << "\n";
|
<< ",\n\tpagesize " << env::geometry::size(it.pagesize) << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
__cold ::std::ostream &operator<<(::std::ostream &out,
|
__cold ::std::ostream &operator<<(::std::ostream &out,
|
||||||
const env_ref::operate_parameters &it) {
|
const env::operate_parameters &it) {
|
||||||
return out << "{\n" //
|
return out << "{\n" //
|
||||||
<< "\tmax_maps " << it.max_maps //
|
<< "\tmax_maps " << it.max_maps //
|
||||||
<< ",\n\tmax_readers " << it.max_readers //
|
<< ",\n\tmax_readers " << it.max_readers //
|
||||||
@ -1369,14 +1370,13 @@ __cold ::std::ostream &operator<<(::std::ostream &out,
|
|||||||
<< "\n}";
|
<< "\n}";
|
||||||
}
|
}
|
||||||
|
|
||||||
__cold ::std::ostream &operator<<(::std::ostream &out,
|
__cold ::std::ostream &operator<<(::std::ostream &out, const env::mode &it) {
|
||||||
const env_ref::mode &it) {
|
|
||||||
switch (it) {
|
switch (it) {
|
||||||
case env_ref::mode::readonly:
|
case env::mode::readonly:
|
||||||
return out << "readonly";
|
return out << "readonly";
|
||||||
case env_ref::mode::write_file_io:
|
case env::mode::write_file_io:
|
||||||
return out << "write_file_io";
|
return out << "write_file_io";
|
||||||
case env_ref::mode::write_mapped_io:
|
case env::mode::write_mapped_io:
|
||||||
return out << "write_mapped_io";
|
return out << "write_mapped_io";
|
||||||
default:
|
default:
|
||||||
return out << "mdbx::env::mode::invalid";
|
return out << "mdbx::env::mode::invalid";
|
||||||
@ -1384,15 +1384,15 @@ __cold ::std::ostream &operator<<(::std::ostream &out,
|
|||||||
}
|
}
|
||||||
|
|
||||||
__cold ::std::ostream &operator<<(::std::ostream &out,
|
__cold ::std::ostream &operator<<(::std::ostream &out,
|
||||||
const env_ref::durability &it) {
|
const env::durability &it) {
|
||||||
switch (it) {
|
switch (it) {
|
||||||
case env_ref::durability::robust_synchronous:
|
case env::durability::robust_synchronous:
|
||||||
return out << "robust_synchronous";
|
return out << "robust_synchronous";
|
||||||
case env_ref::durability::half_synchronous_weak_last:
|
case env::durability::half_synchronous_weak_last:
|
||||||
return out << "half_synchronous_weak_last";
|
return out << "half_synchronous_weak_last";
|
||||||
case env_ref::durability::lazy_weak_tail:
|
case env::durability::lazy_weak_tail:
|
||||||
return out << "lazy_weak_tail";
|
return out << "lazy_weak_tail";
|
||||||
case env_ref::durability::whole_fragile:
|
case env::durability::whole_fragile:
|
||||||
return out << "whole_fragile";
|
return out << "whole_fragile";
|
||||||
default:
|
default:
|
||||||
return out << "mdbx::env::durability::invalid";
|
return out << "mdbx::env::durability::invalid";
|
||||||
@ -1400,7 +1400,7 @@ __cold ::std::ostream &operator<<(::std::ostream &out,
|
|||||||
}
|
}
|
||||||
|
|
||||||
__cold ::std::ostream &operator<<(::std::ostream &out,
|
__cold ::std::ostream &operator<<(::std::ostream &out,
|
||||||
const env_ref::reclaiming_options &it) {
|
const env::reclaiming_options &it) {
|
||||||
return out << "{" //
|
return out << "{" //
|
||||||
<< "lifo: " << (it.lifo ? "yes" : "no") //
|
<< "lifo: " << (it.lifo ? "yes" : "no") //
|
||||||
<< ", coalesce: " << (it.coalesce ? "yes" : "no") //
|
<< ", coalesce: " << (it.coalesce ? "yes" : "no") //
|
||||||
@ -1408,7 +1408,7 @@ __cold ::std::ostream &operator<<(::std::ostream &out,
|
|||||||
}
|
}
|
||||||
|
|
||||||
__cold ::std::ostream &operator<<(::std::ostream &out,
|
__cold ::std::ostream &operator<<(::std::ostream &out,
|
||||||
const env_ref::operate_options &it) {
|
const env::operate_options &it) {
|
||||||
static const char comma[] = ", ";
|
static const char comma[] = ", ";
|
||||||
const char *delimiter = "";
|
const char *delimiter = "";
|
||||||
out << "{";
|
out << "{";
|
||||||
@ -1438,7 +1438,7 @@ __cold ::std::ostream &operator<<(::std::ostream &out,
|
|||||||
}
|
}
|
||||||
|
|
||||||
__cold ::std::ostream &operator<<(::std::ostream &out,
|
__cold ::std::ostream &operator<<(::std::ostream &out,
|
||||||
const env::create_parameters &it) {
|
const env_managed::create_parameters &it) {
|
||||||
return out << "{\n" //
|
return out << "{\n" //
|
||||||
<< "\tfile_mode " << std::oct << it.file_mode_bits << std::dec //
|
<< "\tfile_mode " << std::oct << it.file_mode_bits << std::dec //
|
||||||
<< ",\n\tsubdirectory " << (it.use_subdirectory ? "yes" : "no") //
|
<< ",\n\tsubdirectory " << (it.use_subdirectory ? "yes" : "no") //
|
||||||
@ -1532,43 +1532,43 @@ __cold string to_string(const ::mdbx::pair &value) {
|
|||||||
return out.str();
|
return out.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
__cold string to_string(const ::mdbx::env_ref::geometry &value) {
|
__cold string to_string(const ::mdbx::env::geometry &value) {
|
||||||
ostringstream out;
|
ostringstream out;
|
||||||
out << value;
|
out << value;
|
||||||
return out.str();
|
return out.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
__cold string to_string(const ::mdbx::env_ref::operate_parameters &value) {
|
__cold string to_string(const ::mdbx::env::operate_parameters &value) {
|
||||||
ostringstream out;
|
ostringstream out;
|
||||||
out << value;
|
out << value;
|
||||||
return out.str();
|
return out.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
__cold string to_string(const ::mdbx::env_ref::mode &value) {
|
__cold string to_string(const ::mdbx::env::mode &value) {
|
||||||
ostringstream out;
|
ostringstream out;
|
||||||
out << value;
|
out << value;
|
||||||
return out.str();
|
return out.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
__cold string to_string(const ::mdbx::env_ref::durability &value) {
|
__cold string to_string(const ::mdbx::env::durability &value) {
|
||||||
ostringstream out;
|
ostringstream out;
|
||||||
out << value;
|
out << value;
|
||||||
return out.str();
|
return out.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
__cold string to_string(const ::mdbx::env_ref::reclaiming_options &value) {
|
__cold string to_string(const ::mdbx::env::reclaiming_options &value) {
|
||||||
ostringstream out;
|
ostringstream out;
|
||||||
out << value;
|
out << value;
|
||||||
return out.str();
|
return out.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
__cold string to_string(const ::mdbx::env_ref::operate_options &value) {
|
__cold string to_string(const ::mdbx::env::operate_options &value) {
|
||||||
ostringstream out;
|
ostringstream out;
|
||||||
out << value;
|
out << value;
|
||||||
return out.str();
|
return out.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
__cold string to_string(const ::mdbx::env::create_parameters &value) {
|
__cold string to_string(const ::mdbx::env_managed::create_parameters &value) {
|
||||||
ostringstream out;
|
ostringstream out;
|
||||||
out << value;
|
out << value;
|
||||||
return out.str();
|
return out.str();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user