enum rspamd_stat_sqlite3_stmt_idx {
RSPAMD_STAT_BACKEND_TRANSACTION_START_IM = 0,
RSPAMD_STAT_BACKEND_TRANSACTION_START_DEF,
+ RSPAMD_STAT_BACKEND_TRANSACTION_START_EXCL,
RSPAMD_STAT_BACKEND_TRANSACTION_COMMIT,
RSPAMD_STAT_BACKEND_TRANSACTION_ROLLBACK,
RSPAMD_STAT_BACKEND_GET_TOKEN,
.result = SQLITE_DONE,
.ret = ""
},
+ {
+ .idx = RSPAMD_STAT_BACKEND_TRANSACTION_START_EXCL,
+ .sql = "BEGIN EXCLUSIVE TRANSACTION;",
+ .args = "",
+ .stmt = NULL,
+ .result = SQLITE_DONE,
+ .ret = ""
+ },
{
.idx = RSPAMD_STAT_BACKEND_TRANSACTION_COMMIT,
.sql = "COMMIT;",
struct rspamd_stat_tokenizer *tokenizer;
gpointer tk_conf;
guint64 sz;
+ struct timespec sleep_ts = {
+ .tv_sec = 0,
+ .tv_nsec = 1000000
+ };
bk = g_slice_alloc0 (sizeof (*bk));
bk->sqlite = rspamd_sqlite3_open_or_create (path, create_tables_sql, err);
}
/* Check tokenizer configuration */
+
+ while (rspamd_sqlite3_run_prstmt (bk->sqlite, bk->prstmt,
+ RSPAMD_STAT_BACKEND_TRANSACTION_START_EXCL) != SQLITE_OK) {
+ nanosleep (&sleep_ts, NULL);
+ }
+
if (rspamd_sqlite3_run_prstmt (bk->sqlite, bk->prstmt,
RSPAMD_STAT_BACKEND_LOAD_TOKENIZER, &sz, &tk_conf) != SQLITE_OK) {
g_assert (stcf->clcf->tokenizer != NULL);
g_assert (tokenizer != NULL);
tk_conf = tokenizer->get_config (pool, stcf->clcf->tokenizer, (gsize *)&sz);
- if (!rspamd_sqlite3_run_prstmt (bk->sqlite, bk->prstmt,
+ if (rspamd_sqlite3_run_prstmt (bk->sqlite, bk->prstmt,
RSPAMD_STAT_BACKEND_SAVE_TOKENIZER, sz, tk_conf) != SQLITE_OK) {
sqlite3_close (bk->sqlite);
g_slice_free1 (sizeof (*bk), bk);
g_free (tk_conf);
}
+ rspamd_sqlite3_run_prstmt (bk->sqlite, bk->prstmt,
+ RSPAMD_STAT_BACKEND_TRANSACTION_COMMIT);
+
return bk;
}
memcpy (copied_conf, tk_conf, sz);
g_free (tk_conf);
- if (*len) {
+ if (len) {
*len = sz;
}