mirror of
https://github.com/isar/libmdbx.git
synced 2025-02-07 15:59:36 +08:00
mdbx++: добавление в C++ API поддержки расширенных опций времени выполнения enum MDBX_option_t
.
https://gitflic.ru/project/erthink/libmdbx/issue/4
This commit is contained in:
parent
22405885f6
commit
7db014c4fc
8
mdbx.h
8
mdbx.h
@ -2060,7 +2060,9 @@ LIBMDBX_API const char *mdbx_strerror_r_ANSI2OEM(int errnum, char *buf,
|
|||||||
* \returns a non-zero error value on failure and 0 on success. */
|
* \returns a non-zero error value on failure and 0 on success. */
|
||||||
LIBMDBX_API int mdbx_env_create(MDBX_env **penv);
|
LIBMDBX_API int mdbx_env_create(MDBX_env **penv);
|
||||||
|
|
||||||
/** \brief MDBX environment options. */
|
/** \brief MDBX environment extra runtime options.
|
||||||
|
* \ingroup c_settings
|
||||||
|
* \see mdbx_env_set_option() \see mdbx_env_get_option() */
|
||||||
enum MDBX_option_t {
|
enum MDBX_option_t {
|
||||||
/** \brief Controls the maximum number of named databases for the environment.
|
/** \brief Controls the maximum number of named databases for the environment.
|
||||||
*
|
*
|
||||||
@ -2268,7 +2270,7 @@ enum MDBX_option_t {
|
|||||||
typedef enum MDBX_option_t MDBX_option_t;
|
typedef enum MDBX_option_t MDBX_option_t;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/** \brief Sets the value of a runtime options for an environment.
|
/** \brief Sets the value of a extra runtime options for an environment.
|
||||||
* \ingroup c_settings
|
* \ingroup c_settings
|
||||||
*
|
*
|
||||||
* \param [in] env An environment handle returned by \ref mdbx_env_create().
|
* \param [in] env An environment handle returned by \ref mdbx_env_create().
|
||||||
@ -2281,7 +2283,7 @@ typedef enum MDBX_option_t MDBX_option_t;
|
|||||||
LIBMDBX_API int mdbx_env_set_option(MDBX_env *env, const MDBX_option_t option,
|
LIBMDBX_API int mdbx_env_set_option(MDBX_env *env, const MDBX_option_t option,
|
||||||
uint64_t value);
|
uint64_t value);
|
||||||
|
|
||||||
/** \brief Gets the value of runtime options from an environment.
|
/** \brief Gets the value of extra runtime options from an environment.
|
||||||
* \ingroup c_settings
|
* \ingroup c_settings
|
||||||
*
|
*
|
||||||
* \param [in] env An environment handle returned by \ref mdbx_env_create().
|
* \param [in] env An environment handle returned by \ref mdbx_env_create().
|
||||||
|
198
mdbx.h++
198
mdbx.h++
@ -84,6 +84,11 @@
|
|||||||
#include <experimental/filesystem>
|
#include <experimental/filesystem>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if __cplusplus >= 201103L
|
||||||
|
#include <chrono>
|
||||||
|
#include <ratio>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "mdbx.h"
|
#include "mdbx.h"
|
||||||
|
|
||||||
#if (defined(__cpp_lib_bit_cast) && __cpp_lib_bit_cast >= 201806L) || \
|
#if (defined(__cpp_lib_bit_cast) && __cpp_lib_bit_cast >= 201806L) || \
|
||||||
@ -386,6 +391,11 @@ using path = ::std::wstring;
|
|||||||
using path = ::std::string;
|
using path = ::std::string;
|
||||||
#endif /* mdbx::path */
|
#endif /* mdbx::path */
|
||||||
|
|
||||||
|
#if __cplusplus >= 201103L || defined(DOXYGEN)
|
||||||
|
/// \brief Duration in 1/65536 units of second.
|
||||||
|
using duration = ::std::chrono::duration<unsigned, ::std::ratio<1, 65536>>;
|
||||||
|
#endif /* Duration for C++11 */
|
||||||
|
|
||||||
/// \defgroup cxx_exceptions exceptions and errors
|
/// \defgroup cxx_exceptions exceptions and errors
|
||||||
/// @{
|
/// @{
|
||||||
|
|
||||||
@ -3346,9 +3356,11 @@ public:
|
|||||||
|
|
||||||
/// \brief Returns the maximum number of threads/reader slots for the
|
/// \brief Returns the maximum number of threads/reader slots for the
|
||||||
/// environment.
|
/// environment.
|
||||||
|
/// \see extra_runtime_option::max_readers
|
||||||
inline unsigned max_readers() const;
|
inline unsigned max_readers() const;
|
||||||
|
|
||||||
/// \brief Returns the maximum number of named databases for the environment.
|
/// \brief Returns the maximum number of named databases for the environment.
|
||||||
|
/// \see extra_runtime_option::max_maps
|
||||||
inline unsigned max_maps() const;
|
inline unsigned max_maps() const;
|
||||||
|
|
||||||
/// \brief Returns the application context associated with the environment.
|
/// \brief Returns the application context associated with the environment.
|
||||||
@ -3360,59 +3372,117 @@ public:
|
|||||||
/// \brief Sets threshold to force flush the data buffers to disk, for
|
/// \brief Sets threshold to force flush the data buffers to disk, for
|
||||||
/// non-sync durability modes.
|
/// non-sync durability modes.
|
||||||
///
|
///
|
||||||
/// The threshold value affects all processes which operates with given
|
/// \details The threshold value affects all processes which operates with
|
||||||
/// environment until the last process close environment or a new value will
|
/// given environment until the last process close environment or a new value
|
||||||
/// be settled.
|
/// will be settled. Data is always written to disk when \ref
|
||||||
/// Data is always written to disk when \ref txn_managed::commit() is called,
|
/// txn_managed::commit() is called, but the operating system may keep it
|
||||||
/// but the operating system may keep it buffered. MDBX always flushes the OS
|
/// buffered. MDBX always flushes the OS buffers upon commit as well, unless
|
||||||
/// buffers upon commit as well, unless the environment was opened with \ref
|
/// the environment was opened with \ref whole_fragile, \ref lazy_weak_tail or
|
||||||
/// whole_fragile, \ref lazy_weak_tail or in part \ref
|
/// in part \ref half_synchronous_weak_last.
|
||||||
/// half_synchronous_weak_last. The default is 0, than mean no any threshold
|
|
||||||
/// checked, and no additional flush will be made.
|
|
||||||
///
|
///
|
||||||
|
/// The default is 0, than mean no any threshold checked, and no additional
|
||||||
|
/// flush will be made.
|
||||||
|
/// \see extra_runtime_option::sync_bytes
|
||||||
inline env &set_sync_threshold(size_t bytes);
|
inline env &set_sync_threshold(size_t bytes);
|
||||||
|
|
||||||
|
/// \brief Gets threshold used to force flush the data buffers to disk, for
|
||||||
|
/// non-sync durability modes.
|
||||||
|
///
|
||||||
|
/// \copydetails set_sync_threshold()
|
||||||
|
/// \see extra_runtime_option::sync_bytes
|
||||||
|
inline size_t sync_threshold() const;
|
||||||
|
|
||||||
|
#if __cplusplus >= 201103L || defined(DOXYGEN)
|
||||||
/// \brief Sets relative period since the last unsteady commit to force flush
|
/// \brief Sets relative period since the last unsteady commit to force flush
|
||||||
/// the data buffers to disk, for non-sync durability modes.
|
/// the data buffers to disk, for non-sync durability modes.
|
||||||
///
|
///
|
||||||
/// The relative period value affects all processes which operates with given
|
/// \details The relative period value affects all processes which operates
|
||||||
/// environment until the last process close environment or a new value will
|
/// with given environment until the last process close environment or a new
|
||||||
/// be settled.
|
/// value will be settled. Data is always written to disk when \ref
|
||||||
/// Data is always written to disk when \ref txn_managed::commit() is called,
|
/// txn_managed::commit() is called, but the operating system may keep it
|
||||||
/// but the operating system may keep it buffered. MDBX always flushes the OS
|
/// buffered. MDBX always flushes the OS buffers upon commit as well, unless
|
||||||
/// buffers upon commit as well, unless the environment was opened with \ref
|
/// the environment was opened with \ref whole_fragile, \ref lazy_weak_tail or
|
||||||
/// whole_fragile, \ref lazy_weak_tail or in part \ref
|
/// in part \ref half_synchronous_weak_last. Settled period don't checked
|
||||||
/// half_synchronous_weak_last. Settled period don't checked asynchronously,
|
/// asynchronously, but only by the \ref txn_managed::commit() and \ref
|
||||||
/// but only by the \ref txn_managed::commit() and \ref env::sync_to_disk()
|
/// env::sync_to_disk() functions. Therefore, in cases where transactions are
|
||||||
/// functions. Therefore, in cases where transactions are committed
|
/// committed infrequently and/or irregularly, polling by \ref
|
||||||
/// infrequently and/or irregularly, polling by \ref env::poll_sync_to_disk()
|
/// env::poll_sync_to_disk() may be a reasonable solution to timeout
|
||||||
/// may be a reasonable solution to timeout enforcement. The default is 0,
|
/// enforcement.
|
||||||
/// than mean no any timeout checked, and no additional flush will be made.
|
|
||||||
///
|
///
|
||||||
|
/// The default is 0, than mean no any timeout checked, and no additional
|
||||||
|
/// flush will be made.
|
||||||
|
/// \see extra_runtime_option::sync_period
|
||||||
|
inline env &set_sync_period(const duration &period);
|
||||||
|
|
||||||
|
/// \brief Gets relative period since the last unsteady commit that used to
|
||||||
|
/// force flush the data buffers to disk, for non-sync durability modes.
|
||||||
|
/// \copydetails set_sync_period(const duration&)
|
||||||
|
/// \see set_sync_period(const duration&)
|
||||||
|
/// \see extra_runtime_option::sync_period
|
||||||
|
inline duration sync_period() const;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/// \copydoc set_sync_period(const duration&)
|
||||||
/// \param [in] seconds_16dot16 The period in 1/65536 of second when a
|
/// \param [in] seconds_16dot16 The period in 1/65536 of second when a
|
||||||
/// synchronous flush would be made since the last unsteady commit.
|
/// synchronous flush would be made since the last unsteady commit.
|
||||||
inline env &set_sync_period(unsigned seconds_16dot16);
|
inline env &set_sync_period__seconds_16dot16(unsigned seconds_16dot16);
|
||||||
|
|
||||||
/// \brief Sets relative period since the last unsteady commit to force flush
|
/// \copydoc sync_period()
|
||||||
/// the data buffers to disk, for non-sync durability modes.
|
/// \see sync_period__seconds_16dot16(unsigned)
|
||||||
///
|
inline unsigned sync_period__seconds_16dot16() const;
|
||||||
/// The relative period value affects all processes which operates with given
|
|
||||||
/// environment until the last process close environment or a new value will
|
/// \copydoc set_sync_period(const duration&)
|
||||||
/// be settled.
|
|
||||||
/// Data is always written to disk when \ref txn_managed::commit() is called,
|
|
||||||
/// but the operating system may keep it buffered. MDBX always flushes the OS
|
|
||||||
/// buffers upon commit as well, unless the environment was opened with \ref
|
|
||||||
/// whole_fragile, \ref lazy_weak_tail or in part \ref
|
|
||||||
/// half_synchronous_weak_last. Settled period don't checked asynchronously,
|
|
||||||
/// but only by the \ref txn_managed::commit() and \ref env::sync_to_disk()
|
|
||||||
/// functions. Therefore, in cases where transactions are committed
|
|
||||||
/// infrequently and/or irregularly, polling by \ref env::poll_sync_to_disk()
|
|
||||||
/// may be a reasonable solution to timeout enforcement. The default is 0,
|
|
||||||
/// than mean no any timeout checked, and no additional flush will be made.
|
|
||||||
///
|
|
||||||
/// \param [in] seconds The period in second when a synchronous flush would
|
/// \param [in] seconds The period in second when a synchronous flush would
|
||||||
/// be made since the last unsteady commit.
|
/// be made since the last unsteady commit.
|
||||||
inline env &set_sync_period(double seconds);
|
inline env &set_sync_period__seconds_double(double seconds);
|
||||||
|
|
||||||
|
/// \copydoc sync_period()
|
||||||
|
/// \see set_sync_period__seconds_double(double)
|
||||||
|
inline double sync_period__seconds_double() const;
|
||||||
|
|
||||||
|
/// \copydoc MDBX_option_t
|
||||||
|
enum class extra_runtime_option {
|
||||||
|
/// \copydoc MDBX_opt_max_db
|
||||||
|
/// \see max_maps() \see env::operate_parameters::max_maps
|
||||||
|
max_maps = MDBX_opt_max_db,
|
||||||
|
/// \copydoc MDBX_opt_max_readers
|
||||||
|
/// \see max_readers() \see env::operate_parameters::max_readers
|
||||||
|
max_readers = MDBX_opt_max_readers,
|
||||||
|
/// \copydoc MDBX_opt_sync_bytes
|
||||||
|
/// \see sync_threshold() \see set_sync_threshold()
|
||||||
|
sync_bytes = MDBX_opt_sync_bytes,
|
||||||
|
/// \copydoc MDBX_opt_sync_period
|
||||||
|
/// \see sync_period() \see set_sync_period()
|
||||||
|
sync_period = MDBX_opt_sync_period,
|
||||||
|
/// \copydoc MDBX_opt_rp_augment_limit
|
||||||
|
rp_augment_limit = MDBX_opt_rp_augment_limit,
|
||||||
|
/// \copydoc MDBX_opt_loose_limit
|
||||||
|
loose_limit = MDBX_opt_loose_limit,
|
||||||
|
/// \copydoc MDBX_opt_dp_reserve_limit
|
||||||
|
dp_reserve_limit = MDBX_opt_dp_reserve_limit,
|
||||||
|
/// \copydoc MDBX_opt_txn_dp_limit
|
||||||
|
dp_limit = MDBX_opt_txn_dp_limit,
|
||||||
|
/// \copydoc MDBX_opt_txn_dp_initial
|
||||||
|
dp_initial = MDBX_opt_txn_dp_initial,
|
||||||
|
/// \copydoc MDBX_opt_spill_max_denominator
|
||||||
|
spill_max_denominator = MDBX_opt_spill_max_denominator,
|
||||||
|
/// \copydoc MDBX_opt_spill_min_denominator
|
||||||
|
spill_min_denominator = MDBX_opt_spill_min_denominator,
|
||||||
|
/// \copydoc MDBX_opt_spill_parent4child_denominator
|
||||||
|
spill_parent4child_denominator = MDBX_opt_spill_parent4child_denominator,
|
||||||
|
/// \copydoc MDBX_opt_merge_threshold_16dot16_percent
|
||||||
|
merge_threshold_16dot16_percent = MDBX_opt_merge_threshold_16dot16_percent,
|
||||||
|
/// \copydoc MDBX_opt_writethrough_threshold
|
||||||
|
writethrough_threshold = MDBX_opt_writethrough_threshold,
|
||||||
|
/// \copydoc MDBX_opt_prefault_write_enable
|
||||||
|
prefault_write_enable = MDBX_opt_prefault_write_enable,
|
||||||
|
};
|
||||||
|
|
||||||
|
/// \copybrief mdbx_env_set_option()
|
||||||
|
inline env &set_extra_option(extra_runtime_option option, uint64_t value);
|
||||||
|
|
||||||
|
/// \copybrief mdbx_env_get_option()
|
||||||
|
inline uint64_t extra_option(extra_runtime_option option) const;
|
||||||
|
|
||||||
/// \brief Alter environment flags.
|
/// \brief Alter environment flags.
|
||||||
inline env &alter_flags(MDBX_env_flags_t flags, bool on_off);
|
inline env &alter_flags(MDBX_env_flags_t flags, bool on_off);
|
||||||
@ -5068,13 +5138,53 @@ inline env &env::set_sync_threshold(size_t bytes) {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline env &env::set_sync_period(unsigned seconds_16dot16) {
|
inline size_t env::sync_threshold() const {
|
||||||
|
size_t bytes;
|
||||||
|
error::success_or_throw(::mdbx_env_get_syncbytes(handle_, &bytes));
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline env &env::set_sync_period__seconds_16dot16(unsigned seconds_16dot16) {
|
||||||
error::success_or_throw(::mdbx_env_set_syncperiod(handle_, seconds_16dot16));
|
error::success_or_throw(::mdbx_env_set_syncperiod(handle_, seconds_16dot16));
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline env &env::set_sync_period(double seconds) {
|
inline unsigned env::sync_period__seconds_16dot16() const {
|
||||||
return set_sync_period(unsigned(seconds * 65536));
|
unsigned seconds_16dot16;
|
||||||
|
error::success_or_throw(::mdbx_env_get_syncperiod(handle_, &seconds_16dot16));
|
||||||
|
return seconds_16dot16;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline env &env::set_sync_period__seconds_double(double seconds) {
|
||||||
|
return set_sync_period__seconds_16dot16(unsigned(seconds * 65536));
|
||||||
|
}
|
||||||
|
|
||||||
|
inline double env::sync_period__seconds_double() const {
|
||||||
|
return sync_period__seconds_16dot16() / 65536.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if __cplusplus >= 201103L
|
||||||
|
inline env &env::set_sync_period(const duration &period) {
|
||||||
|
return set_sync_period__seconds_16dot16(period.count());
|
||||||
|
}
|
||||||
|
|
||||||
|
inline duration env::sync_period() const {
|
||||||
|
return duration(sync_period__seconds_16dot16());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
inline env &env::set_extra_option(enum env::extra_runtime_option option,
|
||||||
|
uint64_t value) {
|
||||||
|
error::success_or_throw(
|
||||||
|
::mdbx_env_set_option(handle_, ::MDBX_option_t(option), value));
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline uint64_t env::extra_option(enum env::extra_runtime_option option) const {
|
||||||
|
uint64_t value;
|
||||||
|
error::success_or_throw(
|
||||||
|
::mdbx_env_get_option(handle_, ::MDBX_option_t(option), &value));
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline env &env::alter_flags(MDBX_env_flags_t flags, bool on_off) {
|
inline env &env::alter_flags(MDBX_env_flags_t flags, bool on_off) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user