mdbx: backport - add mdbx_limits_xyz() (squashed).

Change-Id: I56c79704c59386a0c4d84b001020484c23925e6c
This commit is contained in:
Leonid Yuriev 2018-08-20 12:30:09 +03:00
parent 888003c072
commit bd672a5583
3 changed files with 46 additions and 12 deletions

7
mdbx.h
View File

@ -900,7 +900,7 @@ LIBMDBX_API int mdbx_env_set_maxdbs(MDBX_env *env, MDBX_dbi dbs);
*
* Returns The maximum size of a key we can write. */
LIBMDBX_API int mdbx_env_get_maxkeysize(MDBX_env *env);
LIBMDBX_API int mdbx_get_maxkeysize(size_t pagesize);
LIBMDBX_API int mdbx_get_maxkeysize(intptr_t pagesize);
/* Set application information associated with the MDBX_env.
*
@ -1673,6 +1673,11 @@ LIBMDBX_API int mdbx_is_dirty(const MDBX_txn *txn, const void *ptr);
LIBMDBX_API int mdbx_dbi_sequence(MDBX_txn *txn, MDBX_dbi dbi, uint64_t *result,
uint64_t increment);
LIBMDBX_API int mdbx_limits_pgsize_min(void);
LIBMDBX_API int mdbx_limits_pgsize_max(void);
LIBMDBX_API intptr_t mdbx_limits_dbsize_min(intptr_t pagesize);
LIBMDBX_API intptr_t mdbx_limits_dbsize_max(intptr_t pagesize);
/*----------------------------------------------------------------------------*/
/* attribute support functions for Nexenta */
typedef uint_fast64_t mdbx_attr_t;

View File

@ -4897,16 +4897,15 @@ int __cold mdbx_env_get_maxkeysize(MDBX_env *env) {
#define mdbx_maxgc_ov1page(pagesize) \
(((pagesize)-PAGEHDRSZ) / sizeof(pgno_t) - 1)
int mdbx_get_maxkeysize(size_t pagesize) {
if (pagesize == 0)
pagesize = mdbx_syspagesize();
intptr_t nodemax = mdbx_nodemax(pagesize);
if (nodemax < 0)
int mdbx_get_maxkeysize(intptr_t pagesize) {
if (pagesize < 1)
pagesize = (intptr_t)mdbx_syspagesize();
else if (unlikely(pagesize < (intptr_t)MIN_PAGESIZE ||
pagesize > (intptr_t)MAX_PAGESIZE ||
!mdbx_is_power2((size_t)pagesize)))
return -MDBX_EINVAL;
intptr_t maxkey = mdbx_maxkey(nodemax);
return (maxkey > 0 && maxkey < INT_MAX) ? (int)maxkey : -MDBX_EINVAL;
return mdbx_maxkey(mdbx_nodemax(pagesize));
}
static void __cold mdbx_setup_pagesize(MDBX_env *env, const size_t pagesize) {
@ -12233,6 +12232,36 @@ int mdbx_dbi_sequence(MDBX_txn *txn, MDBX_dbi dbi, uint64_t *result,
return MDBX_SUCCESS;
}
/*----------------------------------------------------------------------------*/
__cold int mdbx_limits_pgsize_min(void) { return MIN_PAGESIZE; }
__cold int mdbx_limits_pgsize_max(void) { return MAX_PAGESIZE; }
__cold intptr_t mdbx_limits_dbsize_min(intptr_t pagesize) {
if (pagesize < 1)
pagesize = (intptr_t)mdbx_syspagesize();
else if (unlikely(pagesize < (intptr_t)MIN_PAGESIZE ||
pagesize > (intptr_t)MAX_PAGESIZE ||
!mdbx_is_power2((size_t)pagesize)))
return -MDBX_EINVAL;
return MIN_PAGENO * pagesize;
}
__cold intptr_t mdbx_limits_dbsize_max(intptr_t pagesize) {
if (pagesize < 1)
pagesize = (intptr_t)mdbx_syspagesize();
else if (unlikely(pagesize < (intptr_t)MIN_PAGESIZE ||
pagesize > (intptr_t)MAX_PAGESIZE ||
!mdbx_is_power2((size_t)pagesize)))
return -MDBX_EINVAL;
const uint64_t limit = MAX_PAGENO * (uint64_t)pagesize;
return (limit < (intptr_t)MAX_MAPSIZE) ? (intptr_t)limit
: (intptr_t)MAX_PAGESIZE;
}
/*----------------------------------------------------------------------------*/
/* attribute support functions for Nexenta */

View File

@ -1,4 +1,4 @@
/*
/*
* Copyright 2017-2018 Leonid Yuriev <leo@yuriev.ru>
* and other libmdbx authors: please see AUTHORS file.
* All rights reserved.
@ -195,8 +195,8 @@ int main(int argc, char *const argv[]) {
}
if (config::parse_option(
argc, argv, narg, "keylen.max", params.keylen_max, config::no_scale,
0, std::min(mdbx_get_maxkeysize(0), (int)UINT16_MAX))) {
0,
std::min((unsigned)mdbx_get_maxkeysize(0), (unsigned)UINT16_MAX))) {
if (params.keylen_min > params.keylen_max)
params.keylen_min = params.keylen_max;
continue;