summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2020-08-05 11:15:12 +0100
committerGitHub <noreply@github.com>2020-08-05 11:15:12 +0100
commitc6b0f1ab7052b3c7a39622fa9a3eea8caa8b9d71 (patch)
tree12cee00bf9567f2e17051cb017f971eca1dd2b04 /src
parent024a4e2fbcd665cdd29be54e7507b1bbdb0fbbea (diff)
parenta7f6a6ed078911b9ee76e63eed5da631aa78a845 (diff)
downloadrspamd-c6b0f1ab7052b3c7a39622fa9a3eea8caa8b9d71.tar.gz
rspamd-c6b0f1ab7052b3c7a39622fa9a3eea8caa8b9d71.zip
Merge pull request #3455 from citrin/clickhouse-retention-fix
Clickhouse retention fix
Diffstat (limited to 'src')
-rw-r--r--src/plugins/lua/clickhouse.lua18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/plugins/lua/clickhouse.lua b/src/plugins/lua/clickhouse.lua
index bede3f50b..578a35365 100644
--- a/src/plugins/lua/clickhouse.lua
+++ b/src/plugins/lua/clickhouse.lua
@@ -864,15 +864,15 @@ local function clickhouse_collect(task)
used_memory, settings.limits.max_memory)
end
-local function do_remove_partition(ev_base, cfg, table_name, partition_id)
- lua_util.debugm(N, rspamd_config, "removing partition %s.%s", table_name, partition_id)
+local function do_remove_partition(ev_base, cfg, table_name, partition)
+ lua_util.debugm(N, rspamd_config, "removing partition %s.%s", table_name, partition)
local upstream = settings.upstream:get_upstream_round_robin()
- local remove_partition_sql = "ALTER TABLE ${table_name} ${remove_method} PARTITION '${partition_id}'"
+ local remove_partition_sql = "ALTER TABLE ${table_name} ${remove_method} PARTITION '${partition}'"
local remove_method = (settings.retention.method == 'drop') and 'DROP' or 'DETACH'
local sql_params = {
['table_name'] = table_name,
['remove_method'] = remove_method,
- ['partition_id'] = partition_id
+ ['partition'] = partition
}
local sql = lua_util.template(remove_partition_sql, sql_params)
@@ -887,13 +887,13 @@ local function do_remove_partition(ev_base, cfg, table_name, partition_id)
if err then
rspamd_logger.errx(rspamd_config,
"cannot detach partition %s:%s from server %s: %s",
- table_name, partition_id,
+ table_name, partition,
settings['server'], err)
return
end
rspamd_logger.infox(rspamd_config,
- 'detached partition %s:%s on server %s', table_name, partition_id,
+ 'detached partition %s:%s on server %s', table_name, partition,
settings['server'])
end
@@ -1010,8 +1010,10 @@ local function clickhouse_remove_old_partitions(cfg, ev_base)
end
local upstream = settings.upstream:get_upstream_round_robin()
- local partition_to_remove_sql = "SELECT distinct partition, table FROM system.parts WHERE " ..
- "table in ('${tables}') and max_date <= toDate(now() - interval ${month} month);"
+ local partition_to_remove_sql = "SELECT partition, table " ..
+ "FROM system.parts WHERE table IN ('${tables}') " ..
+ "GROUP BY partition, table " ..
+ "HAVING max(max_date) < toDate(now() - interval ${month} month)"
local table_names = {'rspamd'}
local tables = table.concat(table_names, "', '")