char *path;
gsize count;
gsize expired;
+ rspamd_mempool_t *pool;
};
+#define msg_err_fuzzy_backend(...) rspamd_default_log_function (G_LOG_LEVEL_CRITICAL, \
+ backend->pool->tag.tagname, backend->pool->tag.uid, \
+ G_STRFUNC, \
+ __VA_ARGS__)
+#define msg_warn_fuzzy_backend(...) rspamd_default_log_function (G_LOG_LEVEL_WARNING, \
+ backend->pool->tag.tagname, backend->pool->tag.uid, \
+ G_STRFUNC, \
+ __VA_ARGS__)
+#define msg_info_fuzzy_backend(...) rspamd_default_log_function (G_LOG_LEVEL_INFO, \
+ backend->pool->tag.tagname, backend->pool->tag.uid, \
+ G_STRFUNC, \
+ __VA_ARGS__)
+#define msg_debug_fuzzy_backend(...) rspamd_default_log_function (G_LOG_LEVEL_DEBUG, \
+ backend->pool->tag.tagname, backend->pool->tag.uid, \
+ G_STRFUNC, \
+ __VA_ARGS__)
+
static const char *create_tables_sql =
"BEGIN;"
"CREATE TABLE digests("
}
static int
-rspamd_fuzzy_backend_run_stmt (struct rspamd_fuzzy_backend *bk, int idx, ...)
+rspamd_fuzzy_backend_run_stmt (struct rspamd_fuzzy_backend *backend, int idx, ...)
{
int retcode;
va_list ap;
stmt = prepared_stmts[idx].stmt;
if (stmt == NULL) {
- if ((retcode = sqlite3_prepare_v2 (bk->db, prepared_stmts[idx].sql, -1,
+ if ((retcode = sqlite3_prepare_v2 (backend->db, prepared_stmts[idx].sql, -1,
&prepared_stmts[idx].stmt, NULL)) != SQLITE_OK) {
- msg_err ("Cannot initialize prepared sql `%s`: %s",
- prepared_stmts[idx].sql, sqlite3_errmsg (bk->db));
+ msg_err_fuzzy_backend ("Cannot initialize prepared sql `%s`: %s",
+ prepared_stmts[idx].sql, sqlite3_errmsg (backend->db));
return retcode;
}
stmt = prepared_stmts[idx].stmt;
}
- msg_debug ("executing `%s`", prepared_stmts[idx].sql);
+ msg_debug_fuzzy_backend ("executing `%s`", prepared_stmts[idx].sql);
argtypes = prepared_stmts[idx].args;
sqlite3_reset (stmt);
va_start (ap, idx);
return SQLITE_OK;
}
else if (retcode != SQLITE_DONE) {
- msg_debug ("failed to execute query %s: %d, %s", prepared_stmts[idx].sql,
- retcode, sqlite3_errmsg (bk->db));
+ msg_debug_fuzzy_backend ("failed to execute query %s: %d, %s", prepared_stmts[idx].sql,
+ retcode, sqlite3_errmsg (backend->db));
}
return retcode;
bk->db = sqlite;
bk->expired = 0;
bk->count = 0;
+ bk->pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), "fuzzy_backend");
/*
* Here we need to run create prior to preparing other statements
bk->path = g_strdup (path);
bk->db = sqlite;
bk->expired = 0;
+ bk->pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), "fuzzy_backend");
return bk;
}
{
gchar *dir;
gint fd;
- struct rspamd_fuzzy_backend *res;
+ struct rspamd_fuzzy_backend *backend;
static const char sqlite_wal[] = "PRAGMA journal_mode=\"wal\";",
fallback_journal[] = "PRAGMA journal_mode=\"off\";";
int rc;
close (fd);
/* Open database */
- if ((res = rspamd_fuzzy_backend_open_db (path, err)) == NULL) {
+ if ((backend = rspamd_fuzzy_backend_open_db (path, err)) == NULL) {
GError *tmp = NULL;
- if ((res = rspamd_fuzzy_backend_create_db (path, TRUE, &tmp)) == NULL) {
+ if ((backend = rspamd_fuzzy_backend_create_db (path, TRUE, &tmp)) == NULL) {
g_clear_error (err);
g_propagate_error (err, tmp);
return NULL;
g_clear_error (err);
}
- if ((rc = sqlite3_exec (res->db, sqlite_wal, NULL, NULL, NULL)) != SQLITE_OK) {
- msg_warn ("WAL mode is not supported (%d), locking issues might occur",
+ if ((rc = sqlite3_exec (backend->db, sqlite_wal, NULL, NULL, NULL)) != SQLITE_OK) {
+ msg_warn_fuzzy_backend ("WAL mode is not supported (%d), locking issues might occur",
rc);
- sqlite3_exec (res->db, fallback_journal, NULL, NULL, NULL);
+ sqlite3_exec (backend->db, fallback_journal, NULL, NULL, NULL);
}
/* Cleanup database */
- rspamd_fuzzy_backend_run_simple (RSPAMD_FUZZY_BACKEND_VACUUM, res, NULL);
+ rspamd_fuzzy_backend_run_simple (RSPAMD_FUZZY_BACKEND_VACUUM, backend, NULL);
- if (rspamd_fuzzy_backend_run_stmt (res, RSPAMD_FUZZY_BACKEND_COUNT)
+ if (rspamd_fuzzy_backend_run_stmt (backend, RSPAMD_FUZZY_BACKEND_COUNT)
== SQLITE_OK) {
- res->count = sqlite3_column_int64 (
+ backend->count = sqlite3_column_int64 (
prepared_stmts[RSPAMD_FUZZY_BACKEND_COUNT].stmt, 0);
}
rspamd_fuzzy_backend_run_simple (RSPAMD_FUZZY_BACKEND_TRANSACTION_START,
- res, NULL);
+ backend, NULL);
- return res;
+ return backend;
}
static gint
prepared_stmts[RSPAMD_FUZZY_BACKEND_CHECK].stmt, 1);
if (time (NULL) - timestamp > expire) {
/* Expire element */
- msg_debug ("requested hash has been expired");
+ msg_debug_fuzzy_backend ("requested hash has been expired");
rspamd_fuzzy_backend_run_stmt (backend, RSPAMD_FUZZY_BACKEND_DELETE,
cmd->digest);
backend->expired ++;
else {
shingle_values[i] = -1;
}
- msg_debug ("looking for shingle %d -> %L: %d", i, shcmd->sgl.hashes[i], rc);
+ msg_debug_fuzzy_backend ("looking for shingle %d -> %L: %d", i, shcmd->sgl.hashes[i], rc);
}
qsort (shingle_values, RSPAMD_SHINGLE_SIZE, sizeof (gint64),
rspamd_fuzzy_backend_int64_cmp);
if (sel_id != -1) {
/* We have some id selected here */
rep.prob = (gdouble)max_cnt / (gdouble)RSPAMD_SHINGLE_SIZE;
- msg_debug ("found fuzzy hash with probability %.2f", rep.prob);
+ msg_debug_fuzzy_backend ("found fuzzy hash with probability %.2f", rep.prob);
rc = rspamd_fuzzy_backend_run_stmt (backend,
RSPAMD_FUZZY_BACKEND_GET_DIGEST_BY_ID, sel_id);
if (rc == SQLITE_OK) {
prepared_stmts[RSPAMD_FUZZY_BACKEND_GET_DIGEST_BY_ID].stmt, 2);
if (time (NULL) - timestamp > expire) {
/* Expire element */
- msg_debug ("requested hash has been expired");
+ msg_debug_fuzzy_backend ("requested hash has been expired");
backend->expired ++;
rspamd_fuzzy_backend_run_stmt (backend, RSPAMD_FUZZY_BACKEND_DELETE,
digest);
rspamd_fuzzy_backend_run_stmt (backend,
RSPAMD_FUZZY_BACKEND_INSERT_SHINGLE,
shcmd->sgl.hashes[i], i, id);
- msg_debug ("add shingle %d -> %L: %d", i, shcmd->sgl.hashes[i], id);
+ msg_debug_fuzzy_backend ("add shingle %d -> %L: %d", i, shcmd->sgl.hashes[i], id);
}
}
}
if (expired > 0) {
backend->expired += expired;
- msg_info ("expired %L hashes", expired);
+ msg_info_fuzzy_backend ("expired %L hashes", expired);
}
}
else {
- msg_warn ("cannot execute expired statement: %s",
+ msg_warn_fuzzy_backend ("cannot execute expired statement: %s",
sqlite3_errmsg (backend->db));
}
}
backend, NULL);
}
else {
- msg_warn ("cannot synchronise fuzzy backend: %e", err);
+ msg_warn_fuzzy_backend ("cannot synchronise fuzzy backend: %e", err);
g_error_free (err);
}
g_free (backend->path);
}
+ if (backend->pool) {
+ rspamd_mempool_delete (backend->pool);
+ }
+
g_slice_free1 (sizeof (*backend), backend);
}
}
struct rspamd_stat_sqlite3_ctx {
GHashTable *files;
+ rspamd_mempool_t *pool;
};
struct rspamd_stat_sqlite3_rt {
/* XXX: We ignore now mime recipients as they could be easily forged */
if (user != NULL) {
- rc = rspamd_sqlite3_run_prstmt (db->sqlite, db->prstmt,
+ rc = rspamd_sqlite3_run_prstmt (task->task_pool, db->sqlite, db->prstmt,
RSPAMD_STAT_BACKEND_GET_USER, user, &id);
if (rc != SQLITE_OK && learn) {
/* We need to insert a new user */
if (!db->in_transaction) {
- rspamd_sqlite3_run_prstmt (db->sqlite, db->prstmt,
+ rspamd_sqlite3_run_prstmt (task->task_pool, db->sqlite, db->prstmt,
RSPAMD_STAT_BACKEND_TRANSACTION_START_IM);
db->in_transaction = TRUE;
}
- rc = rspamd_sqlite3_run_prstmt (db->sqlite, db->prstmt,
+ rc = rspamd_sqlite3_run_prstmt (task->task_pool, db->sqlite, db->prstmt,
RSPAMD_STAT_BACKEND_INSERT_USER, user, &id);
}
}
/* XXX: We ignore multiple languages but default + extra */
if (language != NULL) {
- rc = rspamd_sqlite3_run_prstmt (db->sqlite, db->prstmt,
+ rc = rspamd_sqlite3_run_prstmt (task->task_pool, db->sqlite, db->prstmt,
RSPAMD_STAT_BACKEND_GET_LANGUAGE, language, &id);
if (rc != SQLITE_OK && learn) {
/* We need to insert a new language */
if (!db->in_transaction) {
- rspamd_sqlite3_run_prstmt (db->sqlite, db->prstmt,
+ rspamd_sqlite3_run_prstmt (task->task_pool, db->sqlite, db->prstmt,
RSPAMD_STAT_BACKEND_TRANSACTION_START_IM);
db->in_transaction = TRUE;
}
- rc = rspamd_sqlite3_run_prstmt (db->sqlite, db->prstmt,
+ rc = rspamd_sqlite3_run_prstmt (task->task_pool, db->sqlite, db->prstmt,
RSPAMD_STAT_BACKEND_INSERT_LANGUAGE, language, &id);
}
}
};
bk = g_slice_alloc0 (sizeof (*bk));
- bk->sqlite = rspamd_sqlite3_open_or_create (path, create_tables_sql, err);
+ bk->sqlite = rspamd_sqlite3_open_or_create (pool, path, create_tables_sql, err);
if (bk->sqlite == NULL) {
g_slice_free1 (sizeof (*bk), bk);
/* Check tokenizer configuration */
- while (rspamd_sqlite3_run_prstmt (bk->sqlite, bk->prstmt,
+ while (rspamd_sqlite3_run_prstmt (pool, 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,
+ if (rspamd_sqlite3_run_prstmt (pool, bk->sqlite, bk->prstmt,
RSPAMD_STAT_BACKEND_LOAD_TOKENIZER, &sz, &tk_conf) != SQLITE_OK) {
g_assert (stcf->clcf->tokenizer != NULL);
tokenizer = rspamd_stat_get_tokenizer (stcf->clcf->tokenizer->name);
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 (pool, 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_sqlite3_run_prstmt (pool, bk->sqlite, bk->prstmt,
RSPAMD_STAT_BACKEND_TRANSACTION_COMMIT);
return bk;
new = rspamd_mempool_alloc0 (cfg->cfg_pool, sizeof (*new));
new->files = g_hash_table_new (g_direct_hash, g_direct_equal);
+ new->pool = cfg->cfg_pool;
/* Iterate over all classifiers and load matching statfiles */
cur = cfg->classifiers;
if (filenameo == NULL || ucl_object_type (filenameo) != UCL_STRING) {
filenameo = ucl_object_find_key (stf->opts, "path");
if (filenameo == NULL || ucl_object_type (filenameo) != UCL_STRING) {
- msg_err ("statfile %s has no filename defined", stf->symbol);
+ msg_err_config ("statfile %s has no filename defined", stf->symbol);
curst = curst->next;
continue;
}
if ((bk = rspamd_sqlite3_opendb (cfg->cfg_pool, stf, filename,
stf->opts, TRUE, &err)) == NULL) {
- msg_err ("cannot open sqlite3 db: %e", err);
+ msg_err_config ("cannot open sqlite3 db: %e", err);
}
if (bk != NULL) {
if (bk->sqlite) {
if (bk->in_transaction) {
- rspamd_sqlite3_run_prstmt (bk->sqlite, bk->prstmt,
+ rspamd_sqlite3_run_prstmt (ctx->pool, bk->sqlite, bk->prstmt,
RSPAMD_STAT_BACKEND_TRANSACTION_COMMIT);
}
}
if (!bk->in_transaction) {
- rspamd_sqlite3_run_prstmt (bk->sqlite, bk->prstmt,
+ rspamd_sqlite3_run_prstmt (task->task_pool, bk->sqlite, bk->prstmt,
RSPAMD_STAT_BACKEND_TRANSACTION_START_DEF);
bk->in_transaction = TRUE;
}
memcpy (&idx, tok->data, sizeof (idx));
- if (rspamd_sqlite3_run_prstmt (bk->sqlite, bk->prstmt,
+ if (rspamd_sqlite3_run_prstmt (task->task_pool, bk->sqlite, bk->prstmt,
RSPAMD_STAT_BACKEND_GET_TOKEN,
idx, rt->user_id, rt->lang_id, &iv) == SQLITE_OK) {
res->value = iv;
bk = rt->db;
if (bk->in_transaction) {
- rspamd_sqlite3_run_prstmt (bk->sqlite, bk->prstmt,
+ rspamd_sqlite3_run_prstmt (task->task_pool, bk->sqlite, bk->prstmt,
RSPAMD_STAT_BACKEND_TRANSACTION_COMMIT);
bk->in_transaction = FALSE;
}
}
if (!bk->in_transaction) {
- rspamd_sqlite3_run_prstmt (bk->sqlite, bk->prstmt,
+ rspamd_sqlite3_run_prstmt (task->task_pool, bk->sqlite, bk->prstmt,
RSPAMD_STAT_BACKEND_TRANSACTION_START_IM);
bk->in_transaction = TRUE;
}
iv = res->value;
memcpy (&idx, tok->data, sizeof (idx));
- if (rspamd_sqlite3_run_prstmt (bk->sqlite, bk->prstmt,
+ if (rspamd_sqlite3_run_prstmt (task->task_pool, bk->sqlite, bk->prstmt,
RSPAMD_STAT_BACKEND_SET_TOKEN,
idx, rt->user_id, rt->lang_id, iv) != SQLITE_OK) {
return FALSE;
bk = rt->db;
if (bk->in_transaction) {
- rspamd_sqlite3_run_prstmt (bk->sqlite, bk->prstmt,
+ rspamd_sqlite3_run_prstmt (task->task_pool, bk->sqlite, bk->prstmt,
RSPAMD_STAT_BACKEND_TRANSACTION_COMMIT);
bk->in_transaction = FALSE;
}
g_assert (rt != NULL);
bk = rt->db;
- rspamd_sqlite3_run_prstmt (bk->sqlite, bk->prstmt,
+ rspamd_sqlite3_run_prstmt (task->task_pool, bk->sqlite, bk->prstmt,
RSPAMD_STAT_BACKEND_GET_LEARNS, &res);
return res;
g_assert (rt != NULL);
bk = rt->db;
- rspamd_sqlite3_run_prstmt (bk->sqlite, bk->prstmt,
+ rspamd_sqlite3_run_prstmt (task->task_pool, bk->sqlite, bk->prstmt,
RSPAMD_STAT_BACKEND_INC_LEARNS,
rt->user_id, rt->lang_id);
if (bk->in_transaction) {
- rspamd_sqlite3_run_prstmt (bk->sqlite, bk->prstmt,
+ rspamd_sqlite3_run_prstmt (task->task_pool, bk->sqlite, bk->prstmt,
RSPAMD_STAT_BACKEND_TRANSACTION_COMMIT);
bk->in_transaction = FALSE;
}
- rspamd_sqlite3_run_prstmt (bk->sqlite, bk->prstmt,
+ rspamd_sqlite3_run_prstmt (task->task_pool, bk->sqlite, bk->prstmt,
RSPAMD_STAT_BACKEND_GET_LEARNS, &res);
return res;
g_assert (rt != NULL);
bk = rt->db;
- rspamd_sqlite3_run_prstmt (bk->sqlite, bk->prstmt,
+ rspamd_sqlite3_run_prstmt (task->task_pool, bk->sqlite, bk->prstmt,
RSPAMD_STAT_BACKEND_DEC_LEARNS,
rt->user_id, rt->lang_id);
if (bk->in_transaction) {
- rspamd_sqlite3_run_prstmt (bk->sqlite, bk->prstmt,
+ rspamd_sqlite3_run_prstmt (task->task_pool, bk->sqlite, bk->prstmt,
RSPAMD_STAT_BACKEND_TRANSACTION_COMMIT);
bk->in_transaction = FALSE;
}
- rspamd_sqlite3_run_prstmt (bk->sqlite, bk->prstmt,
+ rspamd_sqlite3_run_prstmt (task->task_pool, bk->sqlite, bk->prstmt,
RSPAMD_STAT_BACKEND_GET_LEARNS, &res);
return res;
g_assert (rt != NULL);
bk = rt->db;
- rspamd_sqlite3_run_prstmt (bk->sqlite, bk->prstmt,
+ rspamd_sqlite3_run_prstmt (task->task_pool, bk->sqlite, bk->prstmt,
RSPAMD_STAT_BACKEND_GET_LEARNS, &res);
return res;
ucl_object_t *res = NULL;
struct rspamd_stat_sqlite3_rt *rt = runtime;
struct rspamd_stat_sqlite3_db *bk;
+ rspamd_mempool_t *pool;
struct stat st;
gint64 rev;
g_assert (rt != NULL);
bk = rt->db;
+ pool = rt->ctx->pool;
(void)stat (bk->fname, &st);
- rspamd_sqlite3_run_prstmt (bk->sqlite, bk->prstmt,
+ rspamd_sqlite3_run_prstmt (pool, bk->sqlite, bk->prstmt,
RSPAMD_STAT_BACKEND_GET_LEARNS, &rev);
res = ucl_object_typed_new (UCL_OBJECT);
0, false);
ucl_object_insert_key (res, ucl_object_fromint (st.st_size), "size",
0, false);
- rspamd_sqlite3_run_prstmt (bk->sqlite, bk->prstmt,
+ rspamd_sqlite3_run_prstmt (pool, bk->sqlite, bk->prstmt,
RSPAMD_STAT_BACKEND_NTOKENS, &rev);
ucl_object_insert_key (res, ucl_object_fromint (rev), "total", 0, false);
ucl_object_insert_key (res, ucl_object_fromint (rev), "used", 0, false);
"symbol", 0, false);
ucl_object_insert_key (res, ucl_object_fromstring ("sqlite3"),
"type", 0, false);
- rspamd_sqlite3_run_prstmt (bk->sqlite, bk->prstmt,
+ rspamd_sqlite3_run_prstmt (pool, bk->sqlite, bk->prstmt,
RSPAMD_STAT_BACKEND_NLANGUAGES, &rev);
ucl_object_insert_key (res, ucl_object_fromint (rev),
"languages", 0, false);
- rspamd_sqlite3_run_prstmt (bk->sqlite, bk->prstmt,
+ rspamd_sqlite3_run_prstmt (pool, bk->sqlite, bk->prstmt,
RSPAMD_STAT_BACKEND_NUSERS, &rev);
ucl_object_insert_key (res, ucl_object_fromint (rev),
"users", 0, false);
g_assert (rt != NULL);
bk = rt->db;
- g_assert (rspamd_sqlite3_run_prstmt (bk->sqlite, bk->prstmt,
+ g_assert (rspamd_sqlite3_run_prstmt (rt->ctx->pool, bk->sqlite, bk->prstmt,
RSPAMD_STAT_BACKEND_LOAD_TOKENIZER, &sz, &tk_conf) == SQLITE_OK);
g_assert (sz > 0);
copied_conf = rspamd_mempool_alloc (rt->task->task_pool, sz);
}
if (has_sqlite_cache) {
- sqlite = rspamd_sqlite3_open_or_create (dbpath, create_tables_sql, &err);
+ sqlite = rspamd_sqlite3_open_or_create (cfg->cfg_pool,
+ dbpath, create_tables_sql, &err);
if (sqlite == NULL) {
msg_err_config ("cannot open sqlite3 cache: %e", err);
}
static rspamd_learn_t
-rspamd_stat_cache_sqlite3_check (const guchar *h, gsize len, gboolean is_spam,
+rspamd_stat_cache_sqlite3_check (rspamd_mempool_t *pool,
+ const guchar *h, gsize len, gboolean is_spam,
struct rspamd_stat_sqlite3_ctx *ctx)
{
gint rc, ret = RSPAMD_LEARN_OK;
gint64 flag;
- rspamd_sqlite3_run_prstmt (ctx->db, ctx->prstmt,
+ rspamd_sqlite3_run_prstmt (pool, ctx->db, ctx->prstmt,
RSPAMD_STAT_CACHE_TRANSACTION_START_DEF);
- rc = rspamd_sqlite3_run_prstmt (ctx->db, ctx->prstmt,
+ rc = rspamd_sqlite3_run_prstmt (pool, ctx->db, ctx->prstmt,
RSPAMD_STAT_CACHE_GET_LEARN, (gint64)len, h, &flag);
- rspamd_sqlite3_run_prstmt (ctx->db, ctx->prstmt,
+ rspamd_sqlite3_run_prstmt (pool, ctx->db, ctx->prstmt,
RSPAMD_STAT_CACHE_TRANSACTION_COMMIT);
if (rc == SQLITE_OK) {
else {
/* Need to relearn */
flag = is_spam ? 1 : 0;
- rspamd_sqlite3_run_prstmt (ctx->db, ctx->prstmt,
+ rspamd_sqlite3_run_prstmt (pool, ctx->db, ctx->prstmt,
RSPAMD_STAT_CACHE_TRANSACTION_START_IM);
- rspamd_sqlite3_run_prstmt (ctx->db, ctx->prstmt,
+ rspamd_sqlite3_run_prstmt (pool, ctx->db, ctx->prstmt,
RSPAMD_STAT_CACHE_UPDATE_LEARN, (gint64)len, h, flag);
- rspamd_sqlite3_run_prstmt (ctx->db, ctx->prstmt,
+ rspamd_sqlite3_run_prstmt (pool, ctx->db, ctx->prstmt,
RSPAMD_STAT_CACHE_TRANSACTION_COMMIT);
return RSPAMD_LEARN_UNLEARN;
else {
/* Insert result new id */
flag = is_spam ? 1 : 0;
- rspamd_sqlite3_run_prstmt (ctx->db, ctx->prstmt,
+ rspamd_sqlite3_run_prstmt (pool, ctx->db, ctx->prstmt,
RSPAMD_STAT_CACHE_TRANSACTION_START_IM);
- rspamd_sqlite3_run_prstmt (ctx->db, ctx->prstmt,
+ rspamd_sqlite3_run_prstmt (pool, ctx->db, ctx->prstmt,
RSPAMD_STAT_CACHE_ADD_LEARN, (gint64)len, h, flag);
- rspamd_sqlite3_run_prstmt (ctx->db, ctx->prstmt,
+ rspamd_sqlite3_run_prstmt (pool, ctx->db, ctx->prstmt,
RSPAMD_STAT_CACHE_TRANSACTION_COMMIT);
}
blake2b_final (&st, out, sizeof (out));
- return rspamd_stat_cache_sqlite3_check (out, sizeof (out), is_spam, ctx);
+ return rspamd_stat_cache_sqlite3_check (task->task_pool,
+ out, sizeof (out), is_spam, ctx);
}
return RSPAMD_LEARN_OK;
}
int
-rspamd_sqlite3_run_prstmt (sqlite3 *db, GArray *stmts,
+rspamd_sqlite3_run_prstmt (rspamd_mempool_t *pool, sqlite3 *db, GArray *stmts,
gint idx, ...)
{
gint retcode;
g_assert (nst != NULL);
- msg_debug ("executing `%s`", nst->sql);
+ msg_debug_pool ("executing `%s`", nst->sql);
argtypes = nst->args;
sqlite3_reset (stmt);
va_start (ap, idx);
return SQLITE_OK;
}
else if (retcode != SQLITE_DONE) {
- msg_debug ("failed to execute query %s: %d, %s", nst->sql,
+ msg_debug_pool ("failed to execute query %s: %d, %s", nst->sql,
retcode, sqlite3_errmsg (db));
}
}
static gboolean
-rspamd_sqlite3_wait (const gchar *lock)
+rspamd_sqlite3_wait (rspamd_mempool_t *pool, const gchar *lock)
{
gint fd;
struct timespec sleep_ts = {
fd = open (lock, O_RDONLY);
if (fd == -1) {
- msg_err ("cannot open lock file %s: %s", lock, strerror (errno));
+ msg_err_pool ("cannot open lock file %s: %s", lock, strerror (errno));
return FALSE;
}
while (!rspamd_file_lock (fd, TRUE)) {
if (nanosleep (&sleep_ts, NULL) == -1 && errno != EINTR) {
close (fd);
- msg_err ("cannot sleep open lock file %s: %s", lock, strerror (errno));
+ msg_err_pool ("cannot sleep open lock file %s: %s", lock, strerror (errno));
return FALSE;
}
sqlite3 *
-rspamd_sqlite3_open_or_create (const gchar *path, const
+rspamd_sqlite3_open_or_create (rspamd_mempool_t *pool, const gchar *path, const
gchar *create_sql, GError **err)
{
sqlite3 *sqlite;
lock_fd = open (lock_path, O_WRONLY|O_CREAT|O_EXCL, 00600);
if (lock_fd == -1 && (errno == EEXIST || errno == EBUSY)) {
- msg_debug ("checking %s to wait for db being initialized", lock_path);
+ msg_debug_pool ("checking %s to wait for db being initialized", lock_path);
- if (!rspamd_sqlite3_wait (lock_path)) {
+ if (!rspamd_sqlite3_wait (pool, lock_path)) {
g_set_error (err, rspamd_sqlite3_quark (),
errno, "cannot create sqlite file %s: %s",
path, strerror (errno));
has_lock = FALSE;
}
else {
- msg_debug ("locking %s to block other processes", lock_path);
+ msg_debug_pool ("locking %s to block other processes", lock_path);
g_assert (rspamd_file_lock (lock_fd, FALSE));
has_lock = TRUE;
if (create) {
if (sqlite3_exec (sqlite, sqlite_wal, NULL, NULL, NULL) != SQLITE_OK) {
- msg_warn ("WAL mode is not supported (%s), locking issues might occur",
+ msg_warn_pool ("WAL mode is not supported (%s), locking issues might occur",
sqlite3_errmsg (sqlite));
}
if (sqlite3_exec (sqlite, exclusive_lock_sql, NULL, NULL, NULL) != SQLITE_OK) {
- msg_warn ("cannot exclusively lock database to create schema: %s",
+ msg_warn_pool ("cannot exclusively lock database to create schema: %s",
sqlite3_errmsg (sqlite));
}
/* Reopen in normal mode */
- msg_debug ("reopening %s in normal mode", path);
+ msg_debug_pool ("reopening %s in normal mode", path);
flags &= ~SQLITE_OPEN_CREATE;
if ((rc = sqlite3_open_v2 (path, &sqlite,
}
if (sqlite3_exec (sqlite, sqlite_wal, NULL, NULL, NULL) != SQLITE_OK) {
- msg_warn ("WAL mode is not supported (%s), locking issues might occur",
+ msg_warn_pool ("WAL mode is not supported (%s), locking issues might occur",
sqlite3_errmsg (sqlite));
}
if (has_lock) {
- msg_debug ("removing lock from %s", lock_path);
+ msg_debug_pool ("removing lock from %s", lock_path);
rspamd_file_unlock (lock_fd, FALSE);
unlink (lock_path);
close (lock_fd);
#define SRC_LIBUTIL_SQLITE_UTILS_H_
#include "config.h"
+#include "mem_pool.h"
#include "sqlite3.h"
#define RSPAMD_SQLITE3_STMT_MULTIPLE (1 << 0)
* @param idx
* @return
*/
-gint rspamd_sqlite3_run_prstmt (sqlite3 *db, GArray *stmts,
+gint rspamd_sqlite3_run_prstmt (rspamd_mempool_t *pool, sqlite3 *db, GArray *stmts,
gint idx, ...);
/**
* @param create_sql
* @return
*/
-sqlite3 * rspamd_sqlite3_open_or_create (const gchar *path, const
+sqlite3 * rspamd_sqlite3_open_or_create (rspamd_mempool_t *pool, const gchar *path, const
gchar *create_sql, GError **err);
#endif /* SRC_LIBUTIL_SQLITE_UTILS_H_ */