aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2019-11-18 11:45:52 +0000
committerGitHub <noreply@github.com>2019-11-18 11:45:52 +0000
commit677173f90b0df5d54d29734d0f46799a85787544 (patch)
treeda866a1db96f4f1674d19d0414d608423b5ddb00
parent41f6d3951de214aa2ef87926dd5dd3c552d771c8 (diff)
parent901e31e9772fcdf1043ace5536805c3c5e5b90c3 (diff)
downloadrspamd-677173f90b0df5d54d29734d0f46799a85787544.tar.gz
rspamd-677173f90b0df5d54d29734d0f46799a85787544.zip
Merge pull request #3147 from resec/master
[Fix] Fixing multiple classifiers on redis
-rw-r--r--src/libstat/backends/redis_backend.c11
-rw-r--r--src/libstat/stat_process.c61
2 files changed, 27 insertions, 45 deletions
diff --git a/src/libstat/backends/redis_backend.c b/src/libstat/backends/redis_backend.c
index f21431590..2a2636f5f 100644
--- a/src/libstat/backends/redis_backend.c
+++ b/src/libstat/backends/redis_backend.c
@@ -1325,13 +1325,10 @@ rspamd_redis_connected (redisAsyncContext *c, gpointer r, gpointer priv)
}
}
else {
- if (!rt->err) {
- g_set_error (&rt->err, rspamd_redis_stat_quark (), c->err,
- "skip obtaining bayes tokens for %s: "
- "not enough learns %d; %d required",
- rt->stcf->symbol, (int)rt->learned,
- rt->stcf->clcf->min_learns);
- }
+ msg_warn_task ("skip obtaining bayes tokens for %s of classifier "
+ "%s: not enough learns %d; %d required",
+ rt->stcf->symbol, rt->stcf->clcf->name,
+ (int)rt->learned, rt->stcf->clcf->min_learns);
}
}
}
diff --git a/src/libstat/stat_process.c b/src/libstat/stat_process.c
index 486a9069f..603e0ac96 100644
--- a/src/libstat/stat_process.c
+++ b/src/libstat/stat_process.c
@@ -261,38 +261,6 @@ rspamd_stat_backends_process (struct rspamd_stat_ctx *st_ctx,
}
}
-static gboolean
-rspamd_stat_backends_post_process (struct rspamd_stat_ctx *st_ctx,
- struct rspamd_task *task)
-{
- guint i;
- struct rspamd_statfile *st;
- struct rspamd_classifier *cl;
- gpointer bk_run;
- gboolean ret = TRUE;
-
- g_assert (task->stat_runtimes != NULL);
-
- for (i = 0; i < st_ctx->statfiles->len; i++) {
- st = g_ptr_array_index (st_ctx->statfiles, i);
- cl = st->classifier;
-
- if (cl->cfg->flags & RSPAMD_FLAG_CLASSIFIER_NO_BACKEND) {
- continue;
- }
-
- bk_run = g_ptr_array_index (task->stat_runtimes, i);
-
- if (bk_run != NULL) {
- if (!st->backend->finalize_process (task, bk_run, st_ctx)) {
- ret = FALSE;
- }
- }
- }
-
- return ret;
-}
-
static void
rspamd_stat_classifiers_process (struct rspamd_stat_ctx *st_ctx,
struct rspamd_task *task)
@@ -327,6 +295,8 @@ rspamd_stat_classifiers_process (struct rspamd_stat_ctx *st_ctx,
cl->ham_learns = 0;
}
+ g_assert (task->stat_runtimes != NULL);
+
for (i = 0; i < st_ctx->statfiles->len; i++) {
st = g_ptr_array_index (st_ctx->statfiles, i);
cl = st->classifier;
@@ -357,10 +327,28 @@ rspamd_stat_classifiers_process (struct rspamd_stat_ctx *st_ctx,
g_assert (cl != NULL);
- /* Ensure that all symbols enabled */
skip = FALSE;
- if (!(cl->cfg->flags & RSPAMD_FLAG_CLASSIFIER_NO_BACKEND)) {
+ /* Do not process classifiers on backend failures */
+ for (j = 0; j < cl->statfiles_ids->len; j++) {
+ if (cl->cfg->flags & RSPAMD_FLAG_CLASSIFIER_NO_BACKEND) {
+ continue;
+ }
+
+ id = g_array_index (cl->statfiles_ids, gint, j);
+ bk_run = g_ptr_array_index (task->stat_runtimes, id);
+ st = g_ptr_array_index (st_ctx->statfiles, id);
+
+ if (bk_run != NULL) {
+ if (!st->backend->finalize_process (task, bk_run, st_ctx)) {
+ skip = TRUE;
+ break;
+ }
+ }
+ }
+
+ /* Ensure that all symbols enabled */
+ if (!skip && !(cl->cfg->flags & RSPAMD_FLAG_CLASSIFIER_NO_BACKEND)) {
for (j = 0; j < cl->statfiles_ids->len; j++) {
id = g_array_index (cl->statfiles_ids, gint, j);
bk_run = g_ptr_array_index (task->stat_runtimes, id);
@@ -425,10 +413,7 @@ rspamd_stat_classify (struct rspamd_task *task, lua_State *L, guint stage,
}
else if (stage == RSPAMD_TASK_STAGE_CLASSIFIERS_POST) {
/* Process classifiers */
- if (rspamd_stat_backends_post_process (st_ctx, task)) {
- rspamd_stat_classifiers_process (st_ctx, task);
- }
- /* Do not process classifiers on backend failures */
+ rspamd_stat_classifiers_process (st_ctx, task);
}
task->processed_stages |= stage;