Browse Source

[Minor] Fix configwizard behaviour when DB is empty

tags/1.8.2
Vsevolod Stakhov 5 years ago
parent
commit
e55b2d55dd
2 changed files with 16 additions and 9 deletions
  1. 7
    7
      lualib/lua_stat.lua
  2. 9
    2
      lualib/rspamadm/configwizard.lua

+ 7
- 7
lualib/lua_stat.lua View File

@@ -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


+ 9
- 2
lualib/rspamadm/configwizard.lua View File

@@ -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.",

Loading…
Cancel
Save