diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-07-27 19:24:14 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-07-27 19:24:14 +0100 |
commit | d03b0e9878f3221bebd712685fd112a190d3028f (patch) | |
tree | 4b2d746edecec34d5b8129f0e2d97a3c56c40c3c /src/libstat | |
parent | 93c21c9d66c5e4dd356dfa2c991448d53d81fb83 (diff) | |
download | rspamd-d03b0e9878f3221bebd712685fd112a190d3028f.tar.gz rspamd-d03b0e9878f3221bebd712685fd112a190d3028f.zip |
Fix sqlite3 backend initialization.
Diffstat (limited to 'src/libstat')
-rw-r--r-- | src/libstat/backends/sqlite3_backend.c | 26 | ||||
-rw-r--r-- | src/libstat/tokenizers/osb.c | 1 |
2 files changed, 25 insertions, 2 deletions
diff --git a/src/libstat/backends/sqlite3_backend.c b/src/libstat/backends/sqlite3_backend.c index c9c78df8f..f6df87174 100644 --- a/src/libstat/backends/sqlite3_backend.c +++ b/src/libstat/backends/sqlite3_backend.c @@ -85,6 +85,7 @@ static const char *create_tables_sql = 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, @@ -120,6 +121,14 @@ static struct rspamd_sqlite3_prstmt prepared_stmts[RSPAMD_STAT_BACKEND_MAX] = .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;", .args = "", @@ -339,6 +348,10 @@ rspamd_sqlite3_opendb (rspamd_mempool_t *pool, 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); @@ -360,6 +373,12 @@ rspamd_sqlite3_opendb (rspamd_mempool_t *pool, } /* 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); @@ -367,7 +386,7 @@ rspamd_sqlite3_opendb (rspamd_mempool_t *pool, 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); @@ -379,6 +398,9 @@ rspamd_sqlite3_opendb (rspamd_mempool_t *pool, g_free (tk_conf); } + rspamd_sqlite3_run_prstmt (bk->sqlite, bk->prstmt, + RSPAMD_STAT_BACKEND_TRANSACTION_COMMIT); + return bk; } @@ -753,7 +775,7 @@ rspamd_sqlite3_load_tokenizer_config (gpointer runtime, memcpy (copied_conf, tk_conf, sz); g_free (tk_conf); - if (*len) { + if (len) { *len = sz; } diff --git a/src/libstat/tokenizers/osb.c b/src/libstat/tokenizers/osb.c index 4ba141e4f..10d7649e4 100644 --- a/src/libstat/tokenizers/osb.c +++ b/src/libstat/tokenizers/osb.c @@ -361,6 +361,7 @@ rspamd_tokenizer_osb_load_config (rspamd_mempool_t *pool, msg_err ("cannot load tokenizer configuration from a legacy statfile," " maybe you have forgotten to set 'compat' option in the " "tokenizer configuration"); + return FALSE; } } |