summaryrefslogtreecommitdiffstats
path: root/src/fuzzy_storage.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-02-22 14:10:36 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-02-22 14:10:36 +0000
commit9656df37e15b22894143a76d8d96f61ac4d974d5 (patch)
treefc6c022e46b34293d401206c8509aba3ad81a234 /src/fuzzy_storage.c
parented6b1e861c1deb28cafbb46bed1e764be3a8d9d3 (diff)
downloadrspamd-9656df37e15b22894143a76d8d96f61ac4d974d5.tar.gz
rspamd-9656df37e15b22894143a76d8d96f61ac4d974d5.zip
Add command to sync fuzzy storage
It should be as simple as `rspamadm control fuzzy_sync` Issue: #533 Reported by: @moisseev
Diffstat (limited to 'src/fuzzy_storage.c')
-rw-r--r--src/fuzzy_storage.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/fuzzy_storage.c b/src/fuzzy_storage.c
index e4ce81d42..b847d7865 100644
--- a/src/fuzzy_storage.c
+++ b/src/fuzzy_storage.c
@@ -808,6 +808,45 @@ sync_callback (gint fd, short what, void *arg)
}
static gboolean
+rspamd_fuzzy_storage_sync (struct rspamd_main *rspamd_main,
+ struct rspamd_worker *worker, gint fd,
+ struct rspamd_control_command *cmd,
+ gpointer ud)
+{
+ struct rspamd_fuzzy_storage_ctx *ctx = ud;
+ gdouble next_check;
+ guint64 old_expired, new_expired;
+ struct rspamd_control_reply rep;
+
+ if (ctx->backend) {
+ rspamd_fuzzy_process_updates_queue (ctx);
+ /* Call backend sync */
+ old_expired = rspamd_fuzzy_backend_expired (ctx->backend);
+ rspamd_fuzzy_backend_sync (ctx->backend, ctx->expire, TRUE);
+ new_expired = rspamd_fuzzy_backend_expired (ctx->backend);
+
+ if (old_expired < new_expired) {
+ ctx->stat.fuzzy_hashes_expired += new_expired - old_expired;
+ }
+ }
+
+ rep.reply.fuzzy_sync.status = 0;
+
+ /* Handle next timer event */
+ event_del (&tev);
+ next_check = rspamd_time_jitter (ctx->sync_timeout, 0);
+ double_to_tv (next_check, &tmv);
+ evtimer_add (&tev, &tmv);
+
+ if (write (fd, &rep, sizeof (rep)) != sizeof (rep)) {
+ msg_err ("cannot write reply to the control socket: %s",
+ strerror (errno));
+ }
+
+ return TRUE;
+}
+
+static gboolean
rspamd_fuzzy_storage_reload (struct rspamd_main *rspamd_main,
struct rspamd_worker *worker, gint fd,
struct rspamd_control_command *cmd,
@@ -1382,6 +1421,8 @@ start_fuzzy (struct rspamd_worker *worker)
rspamd_fuzzy_storage_reload, ctx);
rspamd_control_worker_add_cmd_handler (worker, RSPAMD_CONTROL_FUZZY_STAT,
rspamd_fuzzy_storage_stat, ctx);
+ rspamd_control_worker_add_cmd_handler (worker, RSPAMD_CONTROL_FUZZY_SYNC,
+ rspamd_fuzzy_storage_sync, ctx);
/* Create radix tree */
if (ctx->update_map != NULL) {
if (!rspamd_map_is_map (ctx->update_map)) {