aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-04-19 12:35:07 +0100
committerGitHub <noreply@github.com>2018-04-19 12:35:07 +0100
commit91466aa2a1abffd923615a6b9315bd71e7b96ac0 (patch)
treeb09ef310a2cc3e1730ed84125397016a3f6fa93e
parent7e18a13c219334e7467baf7bb7e07a0508196e0f (diff)
parent077972c7344ada8b36eb8ced71520b5245690fc8 (diff)
downloadrspamd-91466aa2a1abffd923615a6b9315bd71e7b96ac0.tar.gz
rspamd-91466aa2a1abffd923615a6b9315bd71e7b96ac0.zip
Merge pull request #2185 from moisseev/expiry
[Minor] Keep expiry step number in Redis
-rw-r--r--src/plugins/lua/bayes_expiry.lua27
1 files changed, 14 insertions, 13 deletions
diff --git a/src/plugins/lua/bayes_expiry.lua b/src/plugins/lua/bayes_expiry.lua
index e75a8527c..0c3d277a8 100644
--- a/src/plugins/lua/bayes_expiry.lua
+++ b/src/plugins/lua/bayes_expiry.lua
@@ -163,7 +163,9 @@ end
-- returns new cursor
local expiry_script = [[
local expire = math.floor(KEYS[2])
- local lock_key = redis.sha1hex(KEYS[1]) .. '_lock' -- Check locking
+ local pattern_sha1 = redis.sha1hex(KEYS[1])
+
+ local lock_key = pattern_sha1 .. '_lock' -- Check locking
local lock = redis.call('GET', lock_key)
if lock then
@@ -175,13 +177,14 @@ local expiry_script = [[
redis.replicate_commands()
redis.call('SETEX', lock_key, ${expire_step}, '${hostname}')
- local cursor_key = redis.sha1hex(KEYS[1]) .. '_cursor'
- local cursor = redis.call('GET', cursor_key)
+ local cursor_key = pattern_sha1 .. '_cursor'
+ local cursor = tonumber(redis.call('GET', cursor_key) or 0)
- if not cursor then
- cursor = 0
- else
- cursor = tonumber(cursor)
+ local step = 1
+ local step_key = pattern_sha1 .. '_step'
+ if cursor > 0 then
+ step = redis.call('GET', step_key)
+ step = step and (tonumber(step) + 1) or 1
end
local ret = redis.call('SCAN', cursor, 'MATCH', KEYS[1], 'COUNT', '${count}')
@@ -259,23 +262,22 @@ local expiry_script = [[
end
redis.call('SETEX', cursor_key, ${expire_step} * 10, tostring(next))
+ redis.call('SETEX', step_key, ${expire_step} * 10, tostring(step))
redis.call('DEL', lock_key)
- return {next, nelts, extended, discriminated, mean, stddev, common, significant, infrequent, ttls_set}
+ return {next, step, nelts, extended, discriminated, mean, stddev, common, significant, infrequent, ttls_set}
]]
-local cur = 0
local c_data = {0,0,0,0,0,0,0,0,0};
-local step = 0
local function expire_step(cls, ev_base, worker)
local function redis_step_cb(err, data)
if err then
logger.errx(rspamd_config, 'cannot perform expiry step: %s', err)
elseif type(data) == 'table' then
- step = step + 1
for k,v in pairs(data) do data[k] = tonumber(v) end
- cur = table.remove(data, 1)
+ local cur = table.remove(data, 1)
+ local step = table.remove(data, 1)
for k,v in pairs(data) do
if k == 4 then
@@ -315,7 +317,6 @@ local function expire_step(cls, ev_base, worker)
if cur == 0 then
log_stat(true)
c_data = {0,0,0,0,0,0,0,0,0};
- step = 0
end
elseif type(data) == 'string' then
logger.infox(rspamd_config, 'skip expiry step: %s', data)