From 0e87fa757f88e736cc5942b76e59007f6df2120e Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 26 Feb 2018 16:44:38 +0000 Subject: [PATCH] [Minor] Send Clickhouse schema to all servers defined --- src/plugins/lua/clickhouse.lua | 56 ++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/src/plugins/lua/clickhouse.lua b/src/plugins/lua/clickhouse.lua index 2336ae2fc..dc99e07a6 100644 --- a/src/plugins/lua/clickhouse.lua +++ b/src/plugins/lua/clickhouse.lua @@ -687,37 +687,39 @@ if opts then -- Create tables on load rspamd_config:add_on_load(function(cfg, ev_base, worker) if worker:is_primary_controller() then - -- XXX: need to call this script for all upstreams - local upstream = settings.upstream:get_upstream_round_robin() - local ip_addr = upstream:get_addr():to_string(true) - - local function http_cb(err_message, code, _, _) - if code ~= 200 or err_message then - rspamd_logger.errx(rspamd_config, "cannot create table in clickhouse server %s: %s", - ip_addr, err_message) - upstream:fail() - else - upstream:ok() + local upstreams = settings.upstream:all_upstreams() + + for _,up in ipairs(upstreams) do + local ip_addr = up:get_addr():to_string(true) + + local function http_cb(err_message, code, _, _) + if code ~= 200 or err_message then + rspamd_logger.errx(rspamd_config, "cannot create table in clickhouse server %s: %s", + ip_addr, err_message) + up:fail() + else + up:ok() + end end - end - local function send_req(elt, sql) - if not rspamd_http.request({ - ev_base = ev_base, - config = cfg, - url = connect_prefix .. ip_addr, - body = sql, - callback = http_cb, - mime_type = 'text/plain', - timeout = settings['timeout'], - }) then - rspamd_logger.errx(rspamd_config, "cannot create table %s in clickhouse server %s: cannot make request", - elt, settings['server']) + local function send_req(elt, sql) + if not rspamd_http.request({ + ev_base = ev_base, + config = cfg, + url = connect_prefix .. ip_addr, + body = sql, + callback = http_cb, + mime_type = 'text/plain', + timeout = settings['timeout'], + }) then + rspamd_logger.errx(rspamd_config, "cannot create table %s in clickhouse server %s: cannot make request", + elt, ip_addr]) + end end - end - for tab,sql in pairs(clickhouse_schema) do - send_req(tab, sql) + for tab,sql in pairs(clickhouse_schema) do + send_req(tab, sql) + end end end end) -- 2.39.5