From 415a2279a0f3ee9a820a55d90b08dd25e6d5c7d9 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 28 Sep 2015 13:09:45 +0100 Subject: [PATCH] Optimize performance of expiration. --- src/fuzzy_storage.c | 2 +- src/libserver/fuzzy_backend.c | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/fuzzy_storage.c b/src/fuzzy_storage.c index 5b5737a9f..016f0c6e0 100644 --- a/src/fuzzy_storage.c +++ b/src/fuzzy_storage.c @@ -268,7 +268,7 @@ sync_callback (gint fd, short what, void *arg) ctx = worker->ctx; /* Call backend sync */ - rspamd_fuzzy_backend_sync (ctx->backend, ctx->expire, FALSE); + rspamd_fuzzy_backend_sync (ctx->backend, ctx->expire, TRUE); server_stat->fuzzy_hashes_expired = rspamd_fuzzy_backend_expired (ctx->backend); diff --git a/src/libserver/fuzzy_backend.c b/src/libserver/fuzzy_backend.c index 48afbb379..3d4bb6c23 100644 --- a/src/libserver/fuzzy_backend.c +++ b/src/libserver/fuzzy_backend.c @@ -70,6 +70,7 @@ static const char *create_index_sql = "BEGIN;" "CREATE UNIQUE INDEX IF NOT EXISTS d ON digests(digest);" "CREATE INDEX IF NOT EXISTS t ON digests(time);" + "CREATE INDEX IF NOT EXISTS dgst_id ON shingles(digest_id);" "CREATE UNIQUE INDEX IF NOT EXISTS s ON shingles(value, number);" "COMMIT;"; enum rspamd_fuzzy_statement_idx { @@ -179,7 +180,7 @@ static struct rspamd_fuzzy_stmts { }, { .idx = RSPAMD_FUZZY_BACKEND_EXPIRE, - .sql = "DELETE FROM digests WHERE id = (SELECT id FROM digests WHERE time < ?1 LIMIT ?2);", + .sql = "DELETE FROM digests WHERE id IN (SELECT id FROM digests WHERE time < ?1 LIMIT ?2);", .args = "II", .stmt = NULL, .result = SQLITE_DONE @@ -377,10 +378,6 @@ rspamd_fuzzy_backend_create_db (const gchar *path, gboolean add_index, return NULL; } - if (add_index) { - rspamd_fuzzy_backend_run_sql (create_index_sql, bk, NULL); - } - return bk; } @@ -417,7 +414,8 @@ rspamd_fuzzy_backend_open (const gchar *path, GError **err) struct rspamd_fuzzy_backend *backend; static const char sqlite_wal[] = "PRAGMA journal_mode=\"wal\";", fallback_journal[] = "PRAGMA journal_mode=\"off\";", - foreign_keys[] = "PRAGMA foreign_keys=\"ON\";"; + foreign_keys[] = "PRAGMA foreign_keys=\"ON\";", + secure_delete[] = "PRAGMA secure_delete=\"OFF\";"; gint rc; if (path == NULL) { @@ -481,6 +479,12 @@ rspamd_fuzzy_backend_open (const gchar *path, GError **err) sqlite3_errmsg (backend->db)); } + if ((rc = sqlite3_exec (backend->db, secure_delete, NULL, NULL, NULL)) != + SQLITE_OK) { + msg_warn_fuzzy_backend ("cannot disable secure delete: %s", + sqlite3_errmsg (backend->db)); + } + rspamd_fuzzy_backend_run_simple (RSPAMD_FUZZY_BACKEND_VACUUM, backend, NULL); if (rspamd_fuzzy_backend_run_stmt (backend, RSPAMD_FUZZY_BACKEND_COUNT) @@ -489,6 +493,8 @@ rspamd_fuzzy_backend_open (const gchar *path, GError **err) prepared_stmts[RSPAMD_FUZZY_BACKEND_COUNT].stmt, 0); } + rspamd_fuzzy_backend_run_sql (create_index_sql, backend, NULL); + rspamd_fuzzy_backend_run_simple (RSPAMD_FUZZY_BACKEND_TRANSACTION_START, backend, NULL); -- 2.39.5