]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Send Clickhouse schema to all servers defined
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 26 Feb 2018 16:44:38 +0000 (16:44 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 26 Feb 2018 16:44:38 +0000 (16:44 +0000)
src/plugins/lua/clickhouse.lua

index 2336ae2fc0496bdbcda8f98516577d6daa7e1190..dc99e07a60135adb1143b6e0c8468be383b091bd 100644 (file)
@@ -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)