]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Support read only backends for stats
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 21 Oct 2021 13:51:42 +0000 (14:51 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 21 Oct 2021 13:51:42 +0000 (14:51 +0100)
src/libstat/backends/backends.h
src/libstat/stat_config.c
src/libstat/stat_process.c

index 7b61093bbb6367c94981cc37b6cead8845c78f4f..434377850c6fd3afbfb8608e5dc7cf4a0535a3b2 100644 (file)
@@ -36,6 +36,7 @@ struct rspamd_task;
 
 struct rspamd_stat_backend {
        const char *name;
+       bool read_only;
 
        gpointer (*init) (struct rspamd_stat_ctx *ctx, struct rspamd_config *cfg,
                                          struct rspamd_statfile *st);
index 0c9ae2ed085f17e9c454a7f6b32c5c6181f15d14..5f48cf1f9c7be5a68054bae8b8ba5a585df4b62a 100644 (file)
@@ -55,9 +55,10 @@ static struct rspamd_stat_tokenizer stat_tokenizers[] = {
 };
 
 #define RSPAMD_STAT_BACKEND_ELT(nam, eltn) { \
-               .name = #nam, \
-               .init = rspamd_##eltn##_init, \
-               .runtime = rspamd_##eltn##_runtime, \
+               .name = #nam,                              \
+        .read_only = false,                        \
+               .init = rspamd_##eltn##_init,              \
+               .runtime = rspamd_##eltn##_runtime,        \
                .process_tokens = rspamd_##eltn##_process_tokens, \
                .finalize_process = rspamd_##eltn##_finalize_process, \
                .learn_tokens = rspamd_##eltn##_learn_tokens, \
@@ -69,10 +70,27 @@ static struct rspamd_stat_tokenizer stat_tokenizers[] = {
                .load_tokenizer_config = rspamd_##eltn##_load_tokenizer_config, \
                .close = rspamd_##eltn##_close \
        }
+#define RSPAMD_STAT_BACKEND_ELT_READONLY(nam, eltn) { \
+               .name = #nam,                              \
+        .read_only = true,                         \
+               .init = rspamd_##eltn##_init,              \
+               .runtime = rspamd_##eltn##_runtime,        \
+               .process_tokens = rspamd_##eltn##_process_tokens, \
+               .finalize_process = rspamd_##eltn##_finalize_process, \
+               .learn_tokens = NULL, \
+               .finalize_learn = NULL, \
+               .total_learns = rspamd_##eltn##_total_learns, \
+               .inc_learns = NULL, \
+               .dec_learns = NULL, \
+               .get_stat = rspamd_##eltn##_get_stat, \
+               .load_tokenizer_config = rspamd_##eltn##_load_tokenizer_config, \
+               .close = rspamd_##eltn##_close \
+       }
 
 static struct rspamd_stat_backend stat_backends[] = {
                RSPAMD_STAT_BACKEND_ELT(mmap, mmaped_file),
                RSPAMD_STAT_BACKEND_ELT(sqlite3, sqlite3),
+               RSPAMD_STAT_BACKEND_ELT_READONLY(cdb, cdb),
 #ifdef WITH_HIREDIS
                RSPAMD_STAT_BACKEND_ELT(redis, redis)
 #endif
@@ -275,24 +293,29 @@ rspamd_stat_init (struct rspamd_config *cfg, struct ev_loop *ev_base)
                /* Init classifier cache */
                cache_name = NULL;
 
-               if (clf->opts) {
-                       cache_obj = ucl_object_lookup (clf->opts, "cache");
-                       cache_name_obj = NULL;
+               if (!bk->read_only) {
+                       if (clf->opts) {
+                               cache_obj = ucl_object_lookup(clf->opts, "cache");
+                               cache_name_obj = NULL;
 
-                       if (cache_obj && ucl_object_type (cache_obj) == UCL_NULL) {
-                               skip_cache = TRUE;
-                       }
-                       else {
-                               if (cache_obj) {
-                                       cache_name_obj = ucl_object_lookup_any (cache_obj,
-                                                       "name", "type", NULL);
+                               if (cache_obj && ucl_object_type(cache_obj) == UCL_NULL) {
+                                       skip_cache = TRUE;
                                }
+                               else {
+                                       if (cache_obj) {
+                                               cache_name_obj = ucl_object_lookup_any(cache_obj,
+                                                               "name", "type", NULL);
+                                       }
 
-                               if (cache_name_obj) {
-                                       cache_name = ucl_object_tostring (cache_name_obj);
+                                       if (cache_name_obj) {
+                                               cache_name = ucl_object_tostring(cache_name_obj);
+                                       }
                                }
                        }
                }
+               else {
+                       skip_cache = true;
+               }
 
                if (cache_name == NULL && !skip_cache) {
                        /* We assume that learn cache is the same as backend */
index 2ebc8f599e52953686f53507c352b0cef0111f7b..35c9d1215642d09d0f9c4bfdf666530b420af972 100644 (file)
@@ -314,6 +314,12 @@ rspamd_stat_preprocess (struct rspamd_stat_ctx *st_ctx,
                        continue;
                }
 
+               if (st->backend->read_only) {
+                       /* Read only backend, skip it */
+                       g_ptr_array_index (task->stat_runtimes, i) = NULL;
+                       continue;
+               }
+
                if (!rspamd_symcache_is_symbol_enabled (task, task->cfg->cache,
                                st->stcf->symbol)) {
                        g_ptr_array_index (task->stat_runtimes, i) = NULL;