From 5051603c56757d4443382de0b3db40224d53be28 Mon Sep 17 00:00:00 2001 From: Leonid Yuriev Date: Fri, 31 Aug 2018 17:05:00 +0300 Subject: [PATCH] mdbx-test: refine key/value min/max handling. Change-Id: If37e5fc2fe30ce309cb4ff540fe93dd9f87ec87f --- test/config.cc | 24 ++++++++++++++++++++++++ test/config.h | 5 +++++ test/main.cc | 51 +++++++++++++++++++++++++++++++++----------------- 3 files changed, 63 insertions(+), 17 deletions(-) diff --git a/test/config.cc b/test/config.cc index bfc66132..e9b71b3b 100644 --- a/test/config.cc +++ b/test/config.cc @@ -542,3 +542,27 @@ bool actor_config::deserialize(const char *str, actor_config &config) { TRACE("<< actor_config::deserialize: OK\n"); return true; } + +unsigned actor_params::mdbx_keylen_min() const { + return (table_flags & MDBX_INTEGERKEY) ? 4 : 0; +} + +unsigned actor_params::mdbx_keylen_max() const { + return (table_flags & MDBX_INTEGERKEY) + ? 8 + : std::min((unsigned)mdbx_limits_keysize_max(pagesize), + (unsigned)UINT16_MAX); +} + +unsigned actor_params::mdbx_datalen_min() const { + return (table_flags & MDBX_INTEGERDUP) ? 4 : 0; +} + +unsigned actor_params::mdbx_datalen_max() const { + return (table_flags & MDBX_INTEGERDUP) + ? 8 + : std::min((table_flags & MDBX_DUPSORT) + ? (unsigned)mdbx_limits_keysize_max(pagesize) + : (unsigned)MDBX_MAXDATASIZE, + (unsigned)UINT16_MAX); +} diff --git a/test/config.h b/test/config.h index e8dc8757..fb029fca 100644 --- a/test/config.h +++ b/test/config.h @@ -264,6 +264,11 @@ struct actor_params : public config::actor_params_pod { std::string pathname_log; std::string pathname_db; void set_defaults(const std::string &tmpdir); + + unsigned mdbx_keylen_min() const; + unsigned mdbx_keylen_max() const; + unsigned mdbx_datalen_min() const; + unsigned mdbx_datalen_max() const; }; struct actor_config : public config::actor_config_pod { diff --git a/test/main.cc b/test/main.cc index 1cac3506..2c83d96e 100644 --- a/test/main.cc +++ b/test/main.cc @@ -56,10 +56,10 @@ void actor_params::set_defaults(const std::string &tmpdir) { nrepeat = 1; nthreads = 1; - keylen_min = 0; - keylen_max = 42; - datalen_min = 0; - datalen_max = 256; + keylen_min = mdbx_keylen_min(); + keylen_max = mdbx_keylen_max(); + datalen_min = mdbx_datalen_min(); + datalen_max = std::min(mdbx_datalen_max(), 256u * 1024 + 42); batch_read = 4; batch_write = 4; @@ -159,8 +159,19 @@ int main(int argc, char *const argv[]) { if (config::parse_option(argc, argv, narg, "pagesize", params.pagesize, mdbx_limits_pgsize_min(), - mdbx_limits_pgsize_max())) + mdbx_limits_pgsize_max())) { + const unsigned keylen_max = params.mdbx_keylen_max(); + if (params.keylen_min > keylen_max) + params.keylen_min = keylen_max; + if (params.keylen_max > keylen_max) + params.keylen_max = keylen_max; + const unsigned datalen_max = params.mdbx_datalen_max(); + if (params.datalen_min > datalen_max) + params.datalen_min = datalen_max; + if (params.datalen_max > datalen_max) + params.datalen_max = datalen_max; continue; + } if (config::parse_option(argc, argv, narg, "size-lower", params.size_lower, mdbx_limits_dbsize_min(params.pagesize), mdbx_limits_dbsize_max(params.pagesize))) @@ -220,30 +231,36 @@ int main(int argc, char *const argv[]) { config::duration, 1)) continue; if (config::parse_option(argc, argv, narg, "keylen.min", params.keylen_min, - config::no_scale, 0, UINT8_MAX)) { - if (params.keylen_max < params.keylen_min) + config::no_scale, params.mdbx_keylen_min(), + params.mdbx_keylen_max())) { + if ((params.table_flags & MDBX_INTEGERKEY) || + params.keylen_max < params.keylen_min) params.keylen_max = params.keylen_min; continue; } if (config::parse_option(argc, argv, narg, "keylen.max", params.keylen_max, - config::no_scale, 0, - std::min((unsigned)mdbx_limits_keysize_max(0), - (unsigned)UINT16_MAX))) { - if (params.keylen_min > params.keylen_max) + config::no_scale, params.mdbx_keylen_min(), + params.mdbx_keylen_max())) { + if ((params.table_flags & MDBX_INTEGERKEY) || + params.keylen_min > params.keylen_max) params.keylen_min = params.keylen_max; continue; } if (config::parse_option(argc, argv, narg, "datalen.min", - params.datalen_min, config::no_scale, 0, - UINT8_MAX)) { - if (params.datalen_max < params.datalen_min) + params.datalen_min, config::no_scale, + params.mdbx_datalen_min(), + params.mdbx_datalen_max())) { + if ((params.table_flags & MDBX_DUPFIXED) || + params.datalen_max < params.datalen_min) params.datalen_max = params.datalen_min; continue; } if (config::parse_option(argc, argv, narg, "datalen.max", - params.datalen_max, config::no_scale, 0, - std::min((int)UINT16_MAX, MDBX_MAXDATASIZE))) { - if (params.datalen_min > params.datalen_max) + params.datalen_max, config::no_scale, + params.mdbx_datalen_min(), + params.mdbx_datalen_max())) { + if ((params.table_flags & MDBX_DUPFIXED) || + params.datalen_min > params.datalen_max) params.datalen_min = params.datalen_max; continue; }