Tarantool development patches archive
 help / color / mirror / Atom feed
* [PATCH] box: add sanity check for memtx_memory and vinyl_memory cfg options
@ 2018-06-01 10:03 Vladimir Davydov
  2018-06-01 19:10 ` Konstantin Osipov
  0 siblings, 1 reply; 2+ messages in thread
From: Vladimir Davydov @ 2018-06-01 10:03 UTC (permalink / raw)
  To: kostja; +Cc: tarantool-patches

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-06-01 19:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-01 10:03 [PATCH] box: add sanity check for memtx_memory and vinyl_memory cfg options Vladimir Davydov
2018-06-01 19:10 ` Konstantin Osipov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox