From: Olga Arkhangelskaia <arkholga@tarantool.org>
To: tarantool-patches@dev.tarantool.org
Subject: [Tarantool-patches] [PATCH 2/2] box: raise on raw modifications of box.cfg values
Date: Thu, 7 Nov 2019 17:03:14 +0300 [thread overview]
Message-ID: <20191107140314.92871-3-arkholga@tarantool.org> (raw)
In-Reply-To: <20191107140314.92871-1-arkholga@tarantool.org>
Prior this patch there was a possibility to change values throw
the raw table modification, like box.cfg.log_level = , or
box.cfg["log_level"] = . Now we store cfg values in separate table,
how ever the behaviour stays the same.
Closes #2867
---
src/box/lua/load_cfg.lua | 18 +++++++++++--
test/box-tap/cfg.test.lua | 14 +++++++++-
test/box/cfg.result | 55 +++++++++++++++++++++++++++++++++++++++
test/box/cfg.test.lua | 3 +++
4 files changed, 87 insertions(+), 3 deletions(-)
diff --git a/src/box/lua/load_cfg.lua b/src/box/lua/load_cfg.lua
index 85617c8f0..602bf92c5 100644
--- a/src/box/lua/load_cfg.lua
+++ b/src/box/lua/load_cfg.lua
@@ -533,13 +533,27 @@ local function load_cfg(cfg)
end
setmetatable(box, nil)
box_configured = nil
- box.cfg = setmetatable(cfg,
+ box.cfg = {}
+ local actual = cfg
+ box.cfg = setmetatable({},
{
__newindex = function(table, index)
error('Attempt to modify a read-only table')
end,
__call = locked(reload_cfg),
- })
+ __index = function (self, k)
+ return actual[k]
+ end,
+ __serialize = function() return actual end,
+
+ __pairs = function(self)
+ local function iter(actual, k)
+ local v
+ return next(actual, k)
+ end
+ return iter, actual, nil
+ end
+ })
private.cfg_load()
for key, fun in pairs(dynamic_cfg) do
local val = cfg[key]
diff --git a/test/box-tap/cfg.test.lua b/test/box-tap/cfg.test.lua
index b61073438..b76f28893 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(104)
+test:plan(106)
--------------------------------------------------------------------------------
-- Invalid values
@@ -592,6 +592,18 @@ box.cfg{read_only=true}
]]
test:is(run_script(code), PANIC, "panic on bootstrapping a read-only instance as master")
+--
+-- gf-2867 raise on raw modifications of box.cfg values
+--
+code = [[
+box.cfg{}
+box.cfg.read_only = true
+]]
+test:is(run_script(code), PANIC, "attempt to modify a read-only table")
+code = [[
+box.cfg["read_only"] = true
+]]
+test:is(run_script(code), PANIC, "attempt to modify a read-only table")
test:check()
os.exit(0)
diff --git a/test/box/cfg.result b/test/box/cfg.result
index 5370bb870..9031e1480 100644
--- a/test/box/cfg.result
+++ b/test/box/cfg.result
@@ -236,6 +236,61 @@ box.cfg{replication = {}}
| ---
| ...
+cfg = {}
+ | ---
+ | ...
+for k, v in pairs(box.cfg) do table.insert(cfg, k) end
+ | ---
+ | ...
+cfg
+ | ---
+ | - - pid_file
+ | - checkpoint_count
+ | - feedback_host
+ | - readahead
+ | - log_level
+ | - checkpoint_interval
+ | - vinyl_page_size
+ | - coredump
+ | - replication_sync_lag
+ | - replication_timeout
+ | - wal_dir_rescan_delay
+ | - vinyl_memory
+ | - replication_skip_conflict
+ | - strip_core
+ | - feedback_enabled
+ | - wal_max_size
+ | - too_long_threshold
+ | - memtx_memory
+ | - log
+ | - background
+ | - vinyl_dir
+ | - vinyl_cache
+ | - vinyl_read_threads
+ | - vinyl_bloom_fpr
+ | - vinyl_timeout
+ | - net_msg_max
+ | - listen
+ | - force_recovery
+ | - vinyl_max_tuple_size
+ | - vinyl_run_count_per_level
+ | - hot_standby
+ | - log_format
+ | - memtx_max_tuple_size
+ | - memtx_min_tuple_size
+ | - feedback_interval
+ | - vinyl_write_threads
+ | - wal_mode
+ | - worker_pool_threads
+ | - vinyl_run_size_ratio
+ | - read_only
+ | - memtx_dir
+ | - wal_dir
+ | - slab_alloc_factor
+ | - checkpoint_wal_threshold
+ | - replication_connect_timeout
+ | - replication_sync_timeout
+ | ...
--------------------------------------------------------------------------------
-- Test of hierarchical cfg type check
--------------------------------------------------------------------------------
diff --git a/test/box/cfg.test.lua b/test/box/cfg.test.lua
index 56ccb6767..275737e7a 100644
--- a/test/box/cfg.test.lua
+++ b/test/box/cfg.test.lua
@@ -19,6 +19,9 @@ box.cfg{coredump = 'true'}
box.cfg{replication = {}}
box.cfg{replication = {}}
+cfg = {}
+for k, v in pairs(box.cfg) do table.insert(cfg, k) end
+cfg
--------------------------------------------------------------------------------
-- Test of hierarchical cfg type check
--------------------------------------------------------------------------------
--
2.20.1 (Apple Git-117)
next prev parent reply other threads:[~2019-11-07 14:03 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-07 14:03 [Tarantool-patches] [PATCH rfc 0/2] Lua 5.2 compatibility Olga Arkhangelskaia
2019-11-07 14:03 ` [Tarantool-patches] [PATCH 1/2] lua: turn on lua " Olga Arkhangelskaia
2019-11-16 13:47 ` Igor Munkin
2019-11-19 9:33 ` Olga Arkhangelskaia
2019-11-07 14:03 ` Olga Arkhangelskaia [this message]
2019-11-17 18:56 ` [Tarantool-patches] [PATCH 2/2] box: raise on raw modifications of box.cfg values Igor Munkin
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=20191107140314.92871-3-arkholga@tarantool.org \
--to=arkholga@tarantool.org \
--cc=tarantool-patches@dev.tarantool.org \
--subject='Re: [Tarantool-patches] [PATCH 2/2] box: raise on raw modifications of box.cfg values' \
/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