From: Vladimir Davydov <vdavydov.dev@gmail.com> To: kostja@tarantool.org Cc: tarantool-patches@freelists.org Subject: [PATCH] box: add sanity check for memtx_memory and vinyl_memory cfg options Date: Fri, 1 Jun 2018 13:03:41 +0300 [thread overview] Message-ID: <84f3a457c0003f01cad6c81277f3017ed48bc79d.1527846983.git.vdavydov.dev@gmail.com> (raw) Follow-up #2634 Closes #3439 --- https://github.com/tarantool/tarantool/issues/3439 https://github.com/tarantool/tarantool/commits/gh-3439-memory-cfg-check src/box/box.cc | 29 +++++++++++++++++++++++++++-- test/box-tap/cfg.test.lua | 4 +++- test/box/cfg.result | 8 ++++++++ test/box/cfg.test.lua | 2 ++ 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/box/box.cc b/src/box/box.cc index 1bdd9f76..d52dd9b4 100644 --- a/src/box/box.cc +++ b/src/box/box.cc @@ -490,6 +490,26 @@ box_check_wal_max_size(int64_t wal_max_size) return wal_max_size; } +static int64_t +box_check_memtx_memory(int64_t memory) +{ + if (memory <= 0) { + tnt_raise(ClientError, ER_CFG, "memtx_memory", + "must be greater than 0"); + } + return memory; +} + +static int64_t +box_check_vinyl_memory(int64_t memory) +{ + if (memory <= 0) { + tnt_raise(ClientError, ER_CFG, "vinyl_memory", + "must be greater than 0"); + } + return memory; +} + static void box_check_vinyl_options(void) { @@ -501,6 +521,8 @@ box_check_vinyl_options(void) double run_size_ratio = cfg_getd("vinyl_run_size_ratio"); double bloom_fpr = cfg_getd("vinyl_bloom_fpr"); + box_check_vinyl_memory(cfg_geti64("vinyl_memory")); + if (read_threads < 1) { tnt_raise(ClientError, ER_CFG, "vinyl_read_threads", "must be greater than or equal to 1"); @@ -551,6 +573,7 @@ box_check_config() box_check_wal_max_rows(cfg_geti64("rows_per_wal")); box_check_wal_max_size(cfg_geti64("wal_max_size")); box_check_wal_mode(cfg_gets("wal_mode")); + box_check_memtx_memory(cfg_geti64("memtx_memory")); box_check_memtx_min_tuple_size(cfg_geti64("memtx_min_tuple_size")); box_check_vinyl_options(); } @@ -706,7 +729,8 @@ box_set_memtx_memory(void) struct memtx_engine *memtx; memtx = (struct memtx_engine *)engine_by_name("memtx"); assert(memtx != NULL); - memtx_engine_set_memory_xc(memtx, cfg_geti("memtx_memory")); + memtx_engine_set_memory_xc(memtx, + box_check_memtx_memory(cfg_geti64("memtx_memory"))); } void @@ -752,7 +776,8 @@ box_set_vinyl_memory(void) struct vinyl_engine *vinyl; vinyl = (struct vinyl_engine *)engine_by_name("vinyl"); assert(vinyl != NULL); - vinyl_engine_set_memory_xc(vinyl, cfg_geti("vinyl_memory")); + vinyl_engine_set_memory_xc(vinyl, + box_check_vinyl_memory(cfg_geti64("vinyl_memory"))); } void diff --git a/test/box-tap/cfg.test.lua b/test/box-tap/cfg.test.lua index 453b616d..b93a21f3 100755 --- a/test/box-tap/cfg.test.lua +++ b/test/box-tap/cfg.test.lua @@ -6,7 +6,7 @@ local socket = require('socket') local fio = require('fio') local uuid = require('uuid') local msgpack = require('msgpack') -test:plan(89) +test:plan(91) -------------------------------------------------------------------------------- -- Invalid values @@ -19,6 +19,7 @@ local function invalid(name, val) test:ok(not status and result:match('Incorrect'), 'invalid '..name) end +invalid('memtx_memory', -1) invalid('memtx_min_tuple_size', 7) invalid('memtx_min_tuple_size', 0) invalid('memtx_min_tuple_size', -1) @@ -38,6 +39,7 @@ invalid('listen', '//!') invalid('log', ':') invalid('log', 'syslog:xxx=') invalid('log_level', 'unknown') +invalid('vinyl_memory', -1) invalid('vinyl_read_threads', 0) invalid('vinyl_write_threads', 1) invalid('vinyl_range_size', 0) diff --git a/test/box/cfg.result b/test/box/cfg.result index ff208f9c..7604f61d 100644 --- a/test/box/cfg.result +++ b/test/box/cfg.result @@ -238,6 +238,14 @@ box.cfg{memtx_memory = "100500"} --- - error: 'Incorrect value for option ''memtx_memory'': should be of type number' ... +box.cfg{memtx_memory = -1} +--- +- error: 'Incorrect value for option ''memtx_memory'': must be greater than 0' +... +box.cfg{vinyl_memory = -1} +--- +- error: 'Incorrect value for option ''vinyl_memory'': must be greater than 0' +... box.cfg{vinyl = "vinyl"} --- - error: 'Incorrect value for option ''vinyl'': unexpected option' diff --git a/test/box/cfg.test.lua b/test/box/cfg.test.lua index 8bed7083..17876b3e 100644 --- a/test/box/cfg.test.lua +++ b/test/box/cfg.test.lua @@ -23,6 +23,8 @@ box.cfg{replication = {}} -------------------------------------------------------------------------------- box.cfg{memtx_memory = "100500"} +box.cfg{memtx_memory = -1} +box.cfg{vinyl_memory = -1} box.cfg{vinyl = "vinyl"} box.cfg{vinyl_write_threads = "threads"} -- 2.11.0
next reply other threads:[~2018-06-01 10:03 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-06-01 10:03 Vladimir Davydov [this message] 2018-06-01 19:10 ` Konstantin Osipov
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=84f3a457c0003f01cad6c81277f3017ed48bc79d.1527846983.git.vdavydov.dev@gmail.com \ --to=vdavydov.dev@gmail.com \ --cc=kostja@tarantool.org \ --cc=tarantool-patches@freelists.org \ --subject='Re: [PATCH] box: add sanity check for memtx_memory and vinyl_memory cfg options' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox