commit 5bd4216: [Fix] Allow to disable/enable composite symbols

Vsevolod Stakhov vsevolod at highsecure.ru
Thu Feb 21 15:14:03 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-02-21 15:12:47 +0000
URL: https://github.com/rspamd/rspamd/commit/5bd42168b60530c267782530e3ed915cb6f504f4 (HEAD -> master)

[Fix] Allow to disable/enable composite symbols

---
 src/libserver/cfg_rcl.c         |   2 +-
 src/libserver/composites.c      |   7 +--
 src/libserver/rspamd_symcache.c | 114 ++++++++++++++++++++++++----------------
 src/libserver/rspamd_symcache.h |  12 +++++
 4 files changed, 86 insertions(+), 49 deletions(-)

diff --git a/src/libserver/cfg_rcl.c b/src/libserver/cfg_rcl.c
index 59656392d..f2a49212c 100644
--- a/src/libserver/cfg_rcl.c
+++ b/src/libserver/cfg_rcl.c
@@ -1402,7 +1402,7 @@ rspamd_rcl_composite_handler (rspamd_mempool_t *pool,
 
 	if (new) {
 		rspamd_symcache_add_symbol (cfg->cache, composite_name, 0,
-				NULL, NULL, SYMBOL_TYPE_COMPOSITE, -1);
+				NULL, composite, SYMBOL_TYPE_COMPOSITE, -1);
 	}
 
 	return TRUE;
diff --git a/src/libserver/composites.c b/src/libserver/composites.c
index f46f8276d..b1bb2f694 100644
--- a/src/libserver/composites.c
+++ b/src/libserver/composites.c
@@ -559,9 +559,10 @@ composites_metric_callback (struct rspamd_metric_result *metric_res,
 			NBYTES (g_hash_table_size (task->cfg->composite_symbols) * 2));
 
 	/* Process hash table */
-	g_hash_table_foreach (task->cfg->composite_symbols,
-		composites_foreach_callback,
-		cd);
+	rspamd_symcache_composites_foreach (task,
+			task->cfg->cache,
+			composites_foreach_callback,
+			cd);
 
 	/* Remove symbols that are in composites */
 	g_hash_table_foreach (cd->symbols_to_remove, composites_remove_symbols, cd);
diff --git a/src/libserver/rspamd_symcache.c b/src/libserver/rspamd_symcache.c
index e3db8d6ef..a41d1b9cd 100644
--- a/src/libserver/rspamd_symcache.c
+++ b/src/libserver/rspamd_symcache.c
@@ -23,6 +23,7 @@
 #include "unix-std.h"
 #include "contrib/t1ha/t1ha.h"
 #include "libserver/worker_util.h"
+#include "khash.h"
 #include <math.h>
 
 #if defined(__STDC_VERSION__) &&  __STDC_VERSION__ >= 201112L
@@ -81,51 +82,6 @@ struct symcache_order {
 	ref_entry_t ref;
 };
 
-struct rspamd_symcache {
-	/* Hash table for fast access */
-	GHashTable *items_by_symbol;
-	GPtrArray *items_by_id;
-	struct symcache_order *items_by_order;
-	GPtrArray *filters;
-	GPtrArray *prefilters;
-	GPtrArray *postfilters;
-	GPtrArray *composites;
-	GPtrArray *idempotent;
-	GPtrArray *virtual;
-	GPtrArray *squeezed;
-	GList *delayed_deps;
-	GList *delayed_conditions;
-	rspamd_mempool_t *static_pool;
-	guint64 cksum;
-	gdouble total_weight;
-	guint used_items;
-	guint stats_symbols_count;
-	guint64 total_hits;
-	guint id;
-	struct rspamd_config *cfg;
-	gdouble reload_time;
-	gint peak_cb;
-};
-
-struct item_stat {
-	struct rspamd_counter_data time_counter;
-	gdouble avg_time;
-	gdouble weight;
-	guint hits;
-	guint64 total_hits;
-	struct rspamd_counter_data frequency_counter;
-	gdouble avg_frequency;
-	gdouble stddev_frequency;
-};
-
-struct rspamd_symcache_dynamic_item {
-	guint16 start_msec; /* Relative to task time */
-	unsigned started:1;
-	unsigned finished:1;
-	/* unsigned pad:14; */
-	guint32 async_events;
-};
-
 struct rspamd_symcache_item {
 	/* This block is likely shared */
 	struct item_stat *st;
@@ -165,6 +121,53 @@ struct rspamd_symcache_item {
 	GPtrArray *rdeps;
 };
 
+struct item_stat {
+	struct rspamd_counter_data time_counter;
+	gdouble avg_time;
+	gdouble weight;
+	guint hits;
+	guint64 total_hits;
+	struct rspamd_counter_data frequency_counter;
+	gdouble avg_frequency;
+	gdouble stddev_frequency;
+};
+
+struct rspamd_symcache {
+	/* Hash table for fast access */
+	GHashTable *items_by_symbol;
+	GPtrArray *items_by_id;
+	struct symcache_order *items_by_order;
+	GPtrArray *filters;
+	GPtrArray *prefilters;
+	GPtrArray *postfilters;
+	GPtrArray *composites;
+	GPtrArray *idempotent;
+	GPtrArray *virtual;
+	GPtrArray *squeezed;
+	GList *delayed_deps;
+	GList *delayed_conditions;
+	rspamd_mempool_t *static_pool;
+	guint64 cksum;
+	gdouble total_weight;
+	guint used_items;
+	guint stats_symbols_count;
+	guint64 total_hits;
+	guint id;
+	struct rspamd_config *cfg;
+	gdouble reload_time;
+	gint peak_cb;
+};
+
+struct rspamd_symcache_dynamic_item {
+	guint16 start_msec; /* Relative to task time */
+	unsigned started:1;
+	unsigned finished:1;
+	/* unsigned pad:14; */
+	guint32 async_events;
+};
+
+
+
 struct cache_dependency {
 	struct rspamd_symcache_item *item;
 	gchar *sym;
@@ -2841,4 +2844,25 @@ rspamd_symcache_get_symbol_flags (struct rspamd_symcache *cache,
 	}
 
 	return 0;
+}
+
+void
+rspamd_symcache_composites_foreach (struct rspamd_task *task,
+										 struct rspamd_symcache *cache,
+										 GHFunc func,
+										 gpointer fd)
+{
+	guint i;
+	struct rspamd_symcache_item *item;
+	struct rspamd_symcache_dynamic_item *dyn_item;
+
+	PTR_ARRAY_FOREACH (cache->composites, i, item) {
+		dyn_item = rspamd_symcache_get_dynamic (task->checkpoint, item);
+
+		if (!CHECK_START_BIT (task->checkpoint, dyn_item)) {
+			SET_START_BIT (task->checkpoint, dyn_item);
+			func (item->symbol, item->specific.normal.user_data, fd);
+			SET_FINISH_BIT (task->checkpoint, dyn_item);
+		}
+	}
 }
\ No newline at end of file
diff --git a/src/libserver/rspamd_symcache.h b/src/libserver/rspamd_symcache.h
index 965895221..69eac1f01 100644
--- a/src/libserver/rspamd_symcache.h
+++ b/src/libserver/rspamd_symcache.h
@@ -402,4 +402,16 @@ gboolean rspamd_symcache_item_async_dec_check_full (struct rspamd_task *task,
 void rspamd_symcache_disable_all_symbols (struct rspamd_task *task,
 										  struct rspamd_symcache *cache,
 										  guint skip_mask);
+
+/**
+ * Iterates over the list of the enabled composites calling specified function
+ * @param task
+ * @param cache
+ * @param func
+ * @param fd
+ */
+void rspamd_symcache_composites_foreach (struct rspamd_task *task,
+										 struct rspamd_symcache *cache,
+										 GHFunc func,
+										 gpointer fd);
 #endif


More information about the Commits mailing list