diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-10-25 14:22:20 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-10-25 14:22:20 +0100 |
commit | e55b2d55dd4beffc4aa9a935da419b51bab3dbbe (patch) | |
tree | b1ec917a009bd31fdca5e4d4704429d75b59bd78 | |
parent | 55fd8637509981e691f1163948b1b2c472aba2d6 (diff) | |
download | rspamd-e55b2d55dd4beffc4aa9a935da419b51bab3dbbe.tar.gz rspamd-e55b2d55dd4beffc4aa9a935da419b51bab3dbbe.zip |
[Minor] Fix configwizard behaviour when DB is empty
-rw-r--r-- | lualib/lua_stat.lua | 14 | ||||
-rw-r--r-- | lualib/rspamadm/configwizard.lua | 11 |
2 files changed, 16 insertions, 9 deletions
diff --git a/lualib/lua_stat.lua b/lualib/lua_stat.lua index b5eaafcd3..ff7d192ac 100644 --- a/lualib/lua_stat.lua +++ b/lualib/lua_stat.lua @@ -101,30 +101,30 @@ return nconverted local keys = redis.call('SMEMBERS', KEYS[1]..'_keys') for _,k in ipairs(keys) do - local learns = redis.call('HGET', k, 'learns') + local learns = redis.call('HGET', k, 'learns') or 0 local neutral_prefix = string.gsub(k, KEYS[1], 'RS') redis.call('HSET', neutral_prefix, KEYS[2], learns) redis.call('SADD', KEYS[1]..'_keys', neutral_prefix) redis.call('SREM', KEYS[1]..'_keys', k) - redis.call('DEL', k) - redis.call('SET', KEYS[1]..'_version', '2') + redis.call('DEL', KEYS[1]) + redis.call('SET', k ..'_version', '2') end ]] conn:add_cmd('EVAL', {lua_script, '2', symbol_spam, 'learns_spam'}) - ret = conn:exec() + ret,res = conn:exec() if not ret then - logger.errx('error converting metadata for symbol %s', symbol_spam) + logger.errx('error converting metadata for symbol %s: %s', symbol_spam, res) return false end conn:add_cmd('EVAL', {lua_script, '2', symbol_ham, 'learns_ham'}) - ret = conn:exec() + ret, res = conn:exec() if not ret then - logger.errx('error converting metadata for symbol %s', symbol_ham) + logger.errx('error converting metadata for symbol %s', symbol_ham, res) return false end diff --git a/lualib/rspamadm/configwizard.lua b/lualib/rspamadm/configwizard.lua index fb4caf20c..a4bccd7ab 100644 --- a/lualib/rspamadm/configwizard.lua +++ b/lualib/rspamadm/configwizard.lua @@ -395,6 +395,13 @@ local function check_redis_classifier(cls, changes) end local function get_version(conn) + conn:add_cmd("SMEMBERS", {"RS_keys"}) + + local ret,members = conn:exec() + + -- Empty db + if not ret or #members == 0 then return false,0 end + -- We still need to check versions local lua_script = [[ local ver = 0 @@ -469,8 +476,8 @@ return ttl local r,ver = get_version(conn) if not r then return false end if ver ~= 2 then - printf("You have configured new schema for %s/%s but your DB has old data", - symbol_spam, symbol_ham) + printf("You have configured new schema for %s/%s but your DB has old version: %s", + symbol_spam, symbol_ham, ver) try_convert(false) else printf("You have configured new schema for %s/%s and your DB already has new layout (v. %s). DB conversion is not needed.", |