aboutsummaryrefslogtreecommitdiffstats
path: root/src/libserver/fuzzy_backend.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-11-06 20:51:08 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-11-06 20:51:08 +0000
commit73ea10e0646c8ad4990b16fdf04474e7effb6f84 (patch)
treec0e69901d82a44b2b41e0ec9c37a9319e3432253 /src/libserver/fuzzy_backend.c
parent5f1a0db220442cce61381875e5f5cf8b8c373d9e (diff)
downloadrspamd-73ea10e0646c8ad4990b16fdf04474e7effb6f84.tar.gz
rspamd-73ea10e0646c8ad4990b16fdf04474e7effb6f84.zip
Add busy handler for fuzzy backend to sync workers
Diffstat (limited to 'src/libserver/fuzzy_backend.c')
-rw-r--r--src/libserver/fuzzy_backend.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/libserver/fuzzy_backend.c b/src/libserver/fuzzy_backend.c
index 23c4d6c64..d34617521 100644
--- a/src/libserver/fuzzy_backend.c
+++ b/src/libserver/fuzzy_backend.c
@@ -37,6 +37,9 @@ struct rspamd_fuzzy_backend {
rspamd_mempool_t *pool;
};
+static const gdouble sql_sleep_time = 0.1;
+static const guint max_retries = 10;
+
#define msg_err_fuzzy_backend(...) rspamd_default_log_function (G_LOG_LEVEL_CRITICAL, \
backend->pool->tag.tagname, backend->pool->tag.uid, \
G_STRFUNC, \
@@ -244,6 +247,8 @@ rspamd_fuzzy_backend_run_stmt (struct rspamd_fuzzy_backend *backend, int idx, ..
sqlite3_stmt *stmt;
int i;
const char *argtypes;
+ guint retries = 0;
+ struct timespec ts;
if (idx < 0 || idx >= RSPAMD_FUZZY_BACKEND_MAX) {
@@ -288,12 +293,20 @@ rspamd_fuzzy_backend_run_stmt (struct rspamd_fuzzy_backend *backend, int idx, ..
}
va_end (ap);
+
+retry:
retcode = sqlite3_step (stmt);
if (retcode == prepared_stmts[idx].result) {
return SQLITE_OK;
}
else if (retcode != SQLITE_DONE) {
+ if (retcode == SQLITE_BUSY && retries++ < max_retries) {
+ double_to_ts (sql_sleep_time, &ts);
+ nanosleep (&ts, NULL);
+ goto retry;
+ }
+
msg_debug_fuzzy_backend ("failed to execute query %s: %d, %s", prepared_stmts[idx].sql,
retcode, sqlite3_errmsg (backend->db));
}