X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=lib%2Fdatabase.cc;h=df83e2048673b235e6c1055ccb47d39923f480a7;hp=96458f6ff104a18ba28d59929b7597cf284feeec;hb=2786aa4d548d28579c761e9358d44c84dfb29068;hpb=9d6f4641d17a6100cb8d96bc1e09d3d4999c34f3 diff --git a/lib/database.cc b/lib/database.cc index 96458f6f..df83e204 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -309,6 +309,10 @@ notmuch_status_to_string (notmuch_status_t status) return "No database found"; case NOTMUCH_STATUS_DATABASE_EXISTS: return "Database exists, not recreated"; + case NOTMUCH_STATUS_BAD_QUERY_SYNTAX: + return "Syntax error in query"; + case NOTMUCH_STATUS_NO_MAIL_ROOT: + return "No mail root found"; default: case NOTMUCH_STATUS_LAST_STATUS: return "Unknown error status value"; @@ -502,17 +506,9 @@ notmuch_database_close (notmuch_database_t *notmuch) * close it. Thus, we explicitly close it here. */ if (notmuch->open) { try { - /* If there's an outstanding transaction, it's unclear if - * closing the Xapian database commits everything up to - * that transaction, or may discard committed (but - * unflushed) transactions. To be certain, explicitly - * cancel any outstanding transaction before closing. */ - if (_notmuch_database_mode (notmuch) == NOTMUCH_DATABASE_MODE_READ_WRITE && - notmuch->atomic_nesting) - notmuch->writable_xapian_db->cancel_transaction (); - /* Close the database. This implicitly flushes - * outstanding changes. */ + * outstanding changes. If there is an open (non-flushed) + * transaction, ALL pending changes will be discarded */ notmuch->xapian_db->close (); } catch (const Xapian::Error &error) { status = NOTMUCH_STATUS_XAPIAN_EXCEPTION; @@ -596,10 +592,12 @@ notmuch_database_compact (const char *path, notmuch_database_t *notmuch = NULL; char *message = NULL; - ret = notmuch_database_open_verbose (path, - NOTMUCH_DATABASE_MODE_READ_WRITE, - ¬much, - &message); + ret = notmuch_database_open_with_config (path, + NOTMUCH_DATABASE_MODE_READ_WRITE, + "", + NULL, + ¬much, + &message); if (ret) { if (status_cb) status_cb (message, closure); return ret; @@ -733,6 +731,15 @@ notmuch_status_t notmuch_database_destroy (notmuch_database_t *notmuch) { notmuch_status_t status; + const char *talloc_report; + + talloc_report = getenv ("NOTMUCH_TALLOC_REPORT"); + if (talloc_report && strcmp (talloc_report, "") != 0) { + FILE *report = fopen (talloc_report, "a"); + if (report) { + talloc_report_full (notmuch, report); + } + } status = notmuch_database_close (notmuch); @@ -748,6 +755,8 @@ notmuch_database_destroy (notmuch_database_t *notmuch) notmuch->date_range_processor = NULL; delete notmuch->last_mod_range_processor; notmuch->last_mod_range_processor = NULL; + delete notmuch->stemmer; + notmuch->stemmer = NULL; talloc_free (notmuch); @@ -1133,13 +1142,21 @@ notmuch_database_end_atomic (notmuch_database_t *notmuch) db = notmuch->writable_xapian_db; try { db->commit_transaction (); - - /* This is a hack for testing. Xapian never flushes on a - * non-flushed commit, even if the flush threshold is 1. - * However, we rely on flushing to test atomicity. */ + notmuch->transaction_count++; + + /* Xapian never flushes on a non-flushed commit, even if the + * flush threshold is 1. However, we rely on flushing to test + * atomicity. On the other hand, we can't straight replace + * XAPIAN_FLUSH_THRESHOLD with our autocommit counter, because + * the former also applies outside notmuch atomic + * commits. Hence the follow complicated test */ const char *thresh = getenv ("XAPIAN_FLUSH_THRESHOLD"); - if (thresh && atoi (thresh) == 1) + if ((notmuch->transaction_threshold > 0 && + notmuch->transaction_count >= notmuch->transaction_threshold) || + (thresh && atoi (thresh) == 1)) { db->commit (); + notmuch->transaction_count = 0; + } } catch (const Xapian::Error &error) { _notmuch_database_log (notmuch, "A Xapian exception occurred committing transaction: %s.\n", error.get_msg ().c_str ());