diff --git a/mdbx.h b/mdbx.h index 79f444c5..fa72b73d 100644 --- a/mdbx.h +++ b/mdbx.h @@ -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() diff --git a/src/core.c b/src/core.c index c4ae564e..295d8305 100644 --- a/src/core.c +++ b/src/core.c @@ -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