commit 8026452: [Minor] Improve trivial maps handling

Vsevolod Stakhov vsevolod at highsecure.ru
Mon Oct 28 12:14:07 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-10-28 12:08:29 +0000
URL: https://github.com/rspamd/rspamd/commit/80264529d0c16f28223f827f46eaa2838046a84d (HEAD -> master)

[Minor] Improve trivial maps handling

---
 src/libutil/map.c         | 20 +++++++++++++++++---
 src/libutil/map_private.h |  2 ++
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/src/libutil/map.c b/src/libutil/map.c
index 808b2a69a..6bcf8d081 100644
--- a/src/libutil/map.c
+++ b/src/libutil/map.c
@@ -1006,6 +1006,11 @@ rspamd_map_schedule_periodic (struct rspamd_map *map, int how)
 		return;
 	}
 
+	if (!(how & RSPAMD_MAP_SCHEDULE_INIT) && map->static_only) {
+		/* No need to schedule anything for static maps */
+		return;
+	}
+
 	if (map->non_trivial && map->next_check != 0) {
 		timeout = map->next_check - rspamd_get_calendar_ticks ();
 
@@ -1850,7 +1855,7 @@ rspamd_map_process_periodic (struct map_periodic_cbdata *cbd)
 	map = cbd->map;
 	map->scheduled_check = NULL;
 
-	if (!cbd->locked) {
+	if (!map->file_only && !cbd->locked) {
 		if (!g_atomic_int_compare_and_exchange (cbd->map->locked, 0, 1)) {
 			msg_debug_map (
 					"don't try to reread map %s as it is locked by other process, "
@@ -1996,6 +2001,9 @@ rspamd_map_watch (struct rspamd_config *cfg,
 			}
 		}
 
+		map->file_only = TRUE;
+		map->static_only = TRUE;
+
 		PTR_ARRAY_FOREACH (map->backends, i, bk) {
 			bk->event_loop = event_loop;
 
@@ -2008,10 +2016,16 @@ rspamd_map_watch (struct rspamd_config *cfg,
 						data->filename, map->poll_timeout * cfg->map_file_watch_multiplier);
 				data->st_ev.data = map;
 				ev_stat_start (event_loop, &data->st_ev);
+				map->static_only = FALSE;
 			}
 			else if ((bk->protocol == MAP_PROTO_HTTP ||
-					  bk->protocol == MAP_PROTO_HTTPS) && map->active_http) {
-				map->non_trivial = TRUE;
+					  bk->protocol == MAP_PROTO_HTTPS)) {
+				if (map->active_http) {
+					map->non_trivial = TRUE;
+				}
+
+				map->static_only = FALSE;
+				map->file_only = FALSE;
 			}
 		}
 
diff --git a/src/libutil/map_private.h b/src/libutil/map_private.h
index c45f55f4b..347f63538 100644
--- a/src/libutil/map_private.h
+++ b/src/libutil/map_private.h
@@ -157,6 +157,8 @@ struct rspamd_map {
 	time_t next_check;
 	gboolean active_http;
 	gboolean non_trivial; /* E.g. has http backends in active mode */
+	gboolean file_only; /* No HTTP backends found */
+	gboolean static_only; /* No need to check */
 	/* Shared lock for temporary disabling of map reading (e.g. when this map is written by UI) */
 	gint *locked;
 	gchar tag[MEMPOOL_UID_LEN];


More information about the Commits mailing list