Browse Source

Add command to sync fuzzy storage

It should be as simple as `rspamadm control fuzzy_sync`

Issue: #533
Reported by: @moisseev
tags/1.2.0
Vsevolod Stakhov 8 years ago
parent
commit
9656df37e1
4 changed files with 66 additions and 1 deletions
  1. 41
    0
      src/fuzzy_storage.c
  2. 14
    1
      src/libserver/rspamd_control.c
  3. 7
    0
      src/libserver/rspamd_control.h
  4. 4
    0
      src/rspamadm/control.c

+ 41
- 0
src/fuzzy_storage.c View File

@@ -807,6 +807,45 @@ sync_callback (gint fd, short what, void *arg)
evtimer_add (&tev, &tmv);
}

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,
@@ -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)) {

+ 14
- 1
src/libserver/rspamd_control.c View File

@@ -93,6 +93,13 @@ static const struct rspamd_control_cmd_match {
},
.type = RSPAMD_CONTROL_FUZZY_STAT
},
{
.name = {
.begin = "/fuzzysync",
.len = sizeof ("/fuzzysync") - 1
},
.type = RSPAMD_CONTROL_FUZZY_SYNC
},
};

void
@@ -177,7 +184,8 @@ rspamd_control_write_reply (struct rspamd_control_session *session)

DL_FOREACH (session->replies, elt) {
/* Skip incompatible worker for fuzzy_stat */
if (session->cmd.type == RSPAMD_CONTROL_FUZZY_STAT &&
if ((session->cmd.type == RSPAMD_CONTROL_FUZZY_STAT ||
session->cmd.type == RSPAMD_CONTROL_FUZZY_SYNC) &&
elt->wrk->type != g_quark_from_static_string ("fuzzy")) {
continue;
}
@@ -265,6 +273,10 @@ rspamd_control_write_reply (struct rspamd_control_session *session)
false);
}
break;
case RSPAMD_CONTROL_FUZZY_SYNC:
ucl_object_insert_key (cur, ucl_object_fromint (
elt->reply.reply.fuzzy_sync.status), "status", 0, false);
break;
default:
break;
}
@@ -501,6 +513,7 @@ rspamd_control_default_cmd_handler (gint fd,
case RSPAMD_CONTROL_RECOMPILE:
case RSPAMD_CONTROL_HYPERSCAN_LOADED:
case RSPAMD_CONTROL_FUZZY_STAT:
case RSPAMD_CONTROL_FUZZY_SYNC:
break;
case RSPAMD_CONTROL_RERESOLVE:
if (cd->worker->srv->cfg) {

+ 7
- 0
src/libserver/rspamd_control.h View File

@@ -30,6 +30,7 @@ enum rspamd_control_type {
RSPAMD_CONTROL_RECOMPILE,
RSPAMD_CONTROL_HYPERSCAN_LOADED,
RSPAMD_CONTROL_FUZZY_STAT,
RSPAMD_CONTROL_FUZZY_SYNC,
RSPAMD_CONTROL_MAX
};

@@ -60,6 +61,9 @@ struct rspamd_control_command {
struct {
guint unused;
} fuzzy_stat;
struct {
guint unused;
} fuzzy_sync;
} cmd;
};

@@ -89,6 +93,9 @@ struct rspamd_control_reply {
guint status;
gchar storage_id[MEMPOOL_UID_LEN];
} fuzzy_stat;
struct {
guint status;
} fuzzy_sync;
} reply;
};


+ 4
- 0
src/rspamadm/control.c View File

@@ -201,6 +201,10 @@ rspamadm_control (gint argc, gchar **argv)
g_ascii_strcasecmp (cmd, "fuzzy_stat") == 0) {
path = "/fuzzystat";
}
else if (g_ascii_strcasecmp (cmd, "fuzzysync") == 0 ||
g_ascii_strcasecmp (cmd, "fuzzy_sync") == 0) {
path = "/fuzzysync";
}
else {
rspamd_fprintf (stderr, "unknown command: %s\n", cmd);
exit (1);

Loading…
Cancel
Save