]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Improve maps checking frequency
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 7 Jul 2017 17:54:50 +0000 (18:54 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 7 Jul 2017 17:54:50 +0000 (18:54 +0100)
src/controller.c
src/fuzzy_storage.c
src/libutil/map.c
src/libutil/map.h
src/libutil/map_private.h
src/lua_worker.c
src/rspamd_proxy.c
src/worker.c

index f7e7bd0439af26ef32567ce75a089f76e654ec65..cef428eba8a70fe0508935aa8921fe85a61bc972 100644 (file)
@@ -3787,14 +3787,16 @@ start_controller_worker (struct rspamd_worker *worker)
 
        rspamd_upstreams_library_config (worker->srv->cfg, worker->srv->cfg->ups_ctx,
                        ctx->ev_base, ctx->resolver->r);
-       /* Maps events */
-       rspamd_map_watch (worker->srv->cfg, ctx->ev_base, ctx->resolver);
        rspamd_symbols_cache_start_refresh (worker->srv->cfg->cache, ctx->ev_base,
                        worker);
        rspamd_stat_init (worker->srv->cfg, ctx->ev_base);
 
        if (worker->index == 0) {
                rspamd_worker_init_monitored (worker, ctx->ev_base, ctx->resolver);
+               rspamd_map_watch (worker->srv->cfg, ctx->ev_base, ctx->resolver, TRUE);
+       }
+       else {
+               rspamd_map_watch (worker->srv->cfg, ctx->ev_base, ctx->resolver, FALSE);
        }
 
        event_base_loop (ctx->ev_base, 0);
index 8170b281077188eb4fbaf2fb473e28df10978fb2..66599d1f4f24ffc60808f257b4b7818b1f374968 100644 (file)
@@ -2833,7 +2833,7 @@ start_fuzzy (struct rspamd_worker *worker)
        ctx->resolver = dns_resolver_init (worker->srv->logger,
                                ctx->ev_base,
                                worker->srv->cfg);
-       rspamd_map_watch (worker->srv->cfg, ctx->ev_base, ctx->resolver);
+       rspamd_map_watch (worker->srv->cfg, ctx->ev_base, ctx->resolver, 0);
 
        /* Get peer pipe */
        memset (&srv_cmd, 0, sizeof (srv_cmd));
index 4402a79103e7ca4253e20d70ac7d69022c32bd26..0019aaa907f38e46cdaead2ab1a31f387fdb2b96 100644 (file)
@@ -1061,8 +1061,10 @@ rspamd_map_read_cached (struct rspamd_map *map, struct rspamd_map_backend *bk,
  * Async HTTP callback
  */
 static void
-rspamd_map_common_http_callback (struct rspamd_map *map, struct rspamd_map_backend *bk,
-               struct map_periodic_cbdata *periodic, gboolean check)
+rspamd_map_common_http_callback (struct rspamd_map *map,
+               struct rspamd_map_backend *bk,
+               struct map_periodic_cbdata *periodic,
+               gboolean check)
 {
        struct http_map_data *data;
        struct http_callback_data *cbd;
@@ -1080,9 +1082,15 @@ rspamd_map_common_http_callback (struct rspamd_map *map, struct rspamd_map_backe
                                rspamd_map_periodic_callback (-1, EV_TIMEOUT, periodic);
                        }
                        else {
-                               /* Switch to the next backend */
-                               periodic->cur_backend ++;
-                               rspamd_map_periodic_callback (-1, EV_TIMEOUT, periodic);
+                               if (map->active_http) {
+                                       /* Check even if there is a cached version */
+                                       goto check;
+                               }
+                               else {
+                                       /* Switch to the next backend */
+                                       periodic->cur_backend++;
+                                       rspamd_map_periodic_callback (-1, EV_TIMEOUT, periodic);
+                               }
                        }
 
                        return;
@@ -1096,7 +1104,15 @@ rspamd_map_common_http_callback (struct rspamd_map *map, struct rspamd_map_backe
                        return;
                }
        }
+       else if (!map->active_http) {
+               /* Switch to the next backend */
+               periodic->cur_backend ++;
+               rspamd_map_periodic_callback (-1, EV_TIMEOUT, periodic);
+
+               return;
+       }
 
+check:
        cbd = g_slice_alloc0 (sizeof (struct http_callback_data));
 
        cbd->ev_base = map->ev_base;
@@ -1384,9 +1400,8 @@ rspamd_map_periodic_callback (gint fd, short what, void *ud)
 
 /* Start watching event for all maps */
 void
-rspamd_map_watch (struct rspamd_config *cfg,
-               struct event_base *ev_base,
-               struct rspamd_dns_resolver *resolver)
+rspamd_map_watch (struct rspamd_config *cfg, struct event_base *ev_base,
+               struct rspamd_dns_resolver *resolver, gboolean active_http)
 {
        GList *cur = cfg->maps;
        struct rspamd_map *map;
@@ -1396,6 +1411,7 @@ rspamd_map_watch (struct rspamd_config *cfg,
                map = cur->data;
                map->ev_base = ev_base;
                map->r = resolver;
+               map->active_http = active_http;
 
                rspamd_map_schedule_periodic (map, FALSE, TRUE, FALSE);
 
index b25ef5c5405e23cb8093e27c8c90b2b78ec39b05..b1479a1b1121f118cb8b26b2a3d35d22f9321248 100644 (file)
@@ -69,9 +69,8 @@ struct rspamd_map* rspamd_map_add_from_ucl (struct rspamd_config *cfg,
 /**
  * Start watching of maps by adding events to libevent event loop
  */
-void rspamd_map_watch (struct rspamd_config *cfg,
-               struct event_base *ev_base,
-               struct rspamd_dns_resolver *resolver);
+void rspamd_map_watch (struct rspamd_config *cfg, struct event_base *ev_base,
+               struct rspamd_dns_resolver *resolver, gboolean active_http);
 
 /**
  * Remove all maps watched (remove events)
index fc2d8e27945c05ec422e4069f34be88b9d719baf..beb862cc2a8aec69d26b72d184d86e9d97d8431d 100644 (file)
@@ -81,6 +81,8 @@ struct rspamd_map {
        gchar *description;
        gchar *name;
        guint32 id;
+       /* Should we check HTTP or just load cached data */
+       gboolean active_http;
        struct timeval tv;
        gdouble poll_timeout;
        /* Shared lock for temporary disabling of map reading (e.g. when this map is written by UI) */
index 7dcb942774dcc839f64910776285a5147580b48f..e5733058a3fb911fd61c20b1d7a118ffb51ab79f 100644 (file)
@@ -393,7 +393,7 @@ start_lua_worker (struct rspamd_worker *worker)
        }
 
        /* Maps events */
-       rspamd_map_watch (worker->srv->cfg, ctx->ev_base, ctx->resolver);
+       rspamd_map_watch (worker->srv->cfg, ctx->ev_base, ctx->resolver, 0);
 
        event_base_loop (ctx->ev_base, 0);
        rspamd_worker_block_signals ();
index efb7e957be4a8f01122e9a19dbaea1b163c690bb..7134c4b526534b96af5497839913e9b158ef5144 100644 (file)
@@ -2047,7 +2047,7 @@ start_rspamd_proxy (struct rspamd_worker *worker) {
                        ctx->ev_base,
                        worker->srv->cfg);
        double_to_tv (ctx->timeout, &ctx->io_tv);
-       rspamd_map_watch (worker->srv->cfg, ctx->ev_base, ctx->resolver);
+       rspamd_map_watch (worker->srv->cfg, ctx->ev_base, ctx->resolver, 0);
 
        rspamd_upstreams_library_config (worker->srv->cfg, ctx->cfg->ups_ctx,
                        ctx->ev_base, ctx->resolver->r);
index 3889d070953f6bf23713fd4583eb8e6690d1d902..c6e419e36565e3d6921b6c6c9c29afdb1c37087c 100644 (file)
@@ -679,7 +679,7 @@ start_worker (struct rspamd_worker *worker)
        ctx->resolver = dns_resolver_init (worker->srv->logger,
                        ctx->ev_base,
                        worker->srv->cfg);
-       rspamd_map_watch (worker->srv->cfg, ctx->ev_base, ctx->resolver);
+       rspamd_map_watch (worker->srv->cfg, ctx->ev_base, ctx->resolver, 0);
        rspamd_upstreams_library_config (worker->srv->cfg, ctx->cfg->ups_ctx,
                        ctx->ev_base, ctx->resolver->r);