mdbx: добавление mdbx_env_get_pairsize4page_max() и mdbx_env_get_valsize4page_max().

This commit is contained in:
Леонид Юрьев (Leonid Yuriev) 2022-10-10 16:33:51 +03:00
parent 9cdee2adb5
commit c3dd60fcb6
2 changed files with 44 additions and 2 deletions

26
mdbx.h
View File

@ -3307,6 +3307,32 @@ mdbx_env_get_maxvalsize_ex(const MDBX_env *env, MDBX_db_flags_t flags);
MDBX_DEPRECATED MDBX_NOTHROW_PURE_FUNCTION LIBMDBX_API int
mdbx_env_get_maxkeysize(const MDBX_env *env);
/** \brief Returns maximal size of key-value pair to fit in a single page
* for specified database flags.
* \ingroup c_statinfo
*
* \param [in] env An environment handle returned by \ref mdbx_env_create().
* \param [in] flags Database options (\ref MDBX_DUPSORT, \ref MDBX_INTEGERKEY
* and so on). \see db_flags
*
* \returns The maximum size of a data can write,
* or -1 if something is wrong. */
MDBX_NOTHROW_PURE_FUNCTION LIBMDBX_API int
mdbx_env_get_pairsize4page_max(const MDBX_env *env, MDBX_db_flags_t flags);
/** \brief Returns maximal data size in bytes to fit in a leaf-page or
* single overflow/large-page for specified database flags.
* \ingroup c_statinfo
*
* \param [in] env An environment handle returned by \ref mdbx_env_create().
* \param [in] flags Database options (\ref MDBX_DUPSORT, \ref MDBX_INTEGERKEY
* and so on). \see db_flags
*
* \returns The maximum size of a data can write,
* or -1 if something is wrong. */
MDBX_NOTHROW_PURE_FUNCTION LIBMDBX_API int
mdbx_env_get_valsize4page_max(const MDBX_env *env, MDBX_db_flags_t flags);
/** \brief Sets application information (a context pointer) associated with
* the environment.
* \see mdbx_env_get_userctx()

View File

@ -546,8 +546,16 @@ __cold intptr_t mdbx_limits_pairsize4page_max(intptr_t pagesize,
return LEAF_NODE_MAX(pagesize) - NODESIZE;
}
intptr_t mdbx_limits_valsize4page_max(intptr_t pagesize,
MDBX_db_flags_t flags) {
__cold int mdbx_env_get_pairsize4page_max(const MDBX_env *env,
MDBX_db_flags_t flags) {
if (unlikely(!env || env->me_signature.weak != MDBX_ME_SIGNATURE))
return -1;
return (int)mdbx_limits_pairsize4page_max((intptr_t)env->me_psize, flags);
}
__cold intptr_t mdbx_limits_valsize4page_max(intptr_t pagesize,
MDBX_db_flags_t flags) {
if (pagesize < 1)
pagesize = (intptr_t)mdbx_default_pagesize();
if (unlikely(pagesize < (intptr_t)MIN_PAGESIZE ||
@ -562,6 +570,14 @@ intptr_t mdbx_limits_valsize4page_max(intptr_t pagesize,
return PAGEROOM(pagesize);
}
__cold int mdbx_env_get_valsize4page_max(const MDBX_env *env,
MDBX_db_flags_t flags) {
if (unlikely(!env || env->me_signature.weak != MDBX_ME_SIGNATURE))
return -1;
return (int)mdbx_limits_valsize4page_max((intptr_t)env->me_psize, flags);
}
/* Calculate the size of a leaf node.
*
* The size depends on the environment's page size; if a data item