From e2ffe7a002835dd0cc3da061cd3e7b61b92e5180 Mon Sep 17 00:00:00 2001 From: Ben Gamari Date: Tue, 21 Aug 2012 11:31:42 +2000 Subject: [PATCH] [PATCH 1/3] Add notmuch_database_close_compact --- 82/b09041f20a16883bbe858a75ff430f1f1c349a | 217 ++++++++++++++++++++++ 1 file changed, 217 insertions(+) create mode 100644 82/b09041f20a16883bbe858a75ff430f1f1c349a diff --git a/82/b09041f20a16883bbe858a75ff430f1f1c349a b/82/b09041f20a16883bbe858a75ff430f1f1c349a new file mode 100644 index 000000000..8814d11eb --- /dev/null +++ b/82/b09041f20a16883bbe858a75ff430f1f1c349a @@ -0,0 +1,217 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 5A5AE431FBD + for ; Mon, 20 Aug 2012 08:31:55 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.799 +X-Spam-Level: +X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5 + tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, + FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id ErJhg5vvKABW for ; + Mon, 20 Aug 2012 08:31:54 -0700 (PDT) +Received: from mail-vc0-f181.google.com (mail-vc0-f181.google.com + [209.85.220.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 10C7D431FB6 + for ; Mon, 20 Aug 2012 08:31:54 -0700 (PDT) +Received: by vcbfl17 with SMTP id fl17so5583578vcb.26 + for ; Mon, 20 Aug 2012 08:31:53 -0700 (PDT) +DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; + h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; + bh=X8latOgPe5F1HW8xbEc0KD5kZQWSq7L2zUrP5eu0Zgo=; + b=QpaJiWOn7ebas/YPZIsc1EVMB9U4lVpvLkqSLu0n8ajWWbSiusooy8hPesbKmbmTct + atTuvcQxfFwALsXAokcJbNqksrgcv8ygoHRC2IvqSMQA8AyttP7LX2WLZbj+yMVVmCBV + sNKQ4CXAvUCCbIbyBl0qLunFZ57CztLprfiZnSPHQ55M7iUoUir2QJ7TB0i/5rC++k7k + YzBGdcQYxEjJ8Y0DGFA0rhZdfHLANpfABPHoPg8wyD8Yq0Pc7JyLrIkOtokFGF8uXOy4 + OY72CjQUYwJQxgJhZG+XKXEFNhmryhqKuMftCEq4rLNpUQM4Hwd6tv4yFkec6CrqW76q + Y0hQ== +Received: by 10.58.4.232 with SMTP id n8mr11357600ven.54.1345476713428; + Mon, 20 Aug 2012 08:31:53 -0700 (PDT) +Received: from localhost.localdomain + (pool-108-8-230-85.spfdma.east.verizon.net. [108.8.230.85]) + by mx.google.com with ESMTPS id g10sm5430786vdk.2.2012.08.20.08.31.52 + (version=SSLv3 cipher=OTHER); Mon, 20 Aug 2012 08:31:52 -0700 (PDT) +From: Ben Gamari +To: notmuch@notmuchmail.org +Subject: [PATCH 1/3] Add notmuch_database_close_compact +Date: Mon, 20 Aug 2012 11:31:42 -0400 +Message-Id: <1345476704-17091-2-git-send-email-bgamari.foss@gmail.com> +X-Mailer: git-send-email 1.7.9.5 +In-Reply-To: <1345476704-17091-1-git-send-email-bgamari.foss@gmail.com> +References: <1345476704-17091-1-git-send-email-bgamari.foss@gmail.com> +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Mon, 20 Aug 2012 15:31:55 -0000 + +--- + configure | 25 ++++++++++++++++++++++++- + lib/database.cc | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ + lib/notmuch.h | 14 ++++++++++++++ + 3 files changed, 92 insertions(+), 1 deletion(-) + +diff --git a/configure b/configure +index dc0dba4..370fedd 100755 +--- a/configure ++++ b/configure +@@ -270,7 +270,8 @@ printf "Checking for Xapian development files... " + have_xapian=0 + for xapian_config in ${XAPIAN_CONFIG}; do + if ${xapian_config} --version > /dev/null 2>&1; then +- printf "Yes (%s).\n" $(${xapian_config} --version | sed -e 's/.* //') ++ xapian_version=$(${xapian_config} --version | sed -e 's/.* //') ++ printf "Yes (%s).\n" ${xapian_version} + have_xapian=1 + xapian_cxxflags=$(${xapian_config} --cxxflags) + xapian_ldflags=$(${xapian_config} --libs) +@@ -282,6 +283,24 @@ if [ ${have_xapian} = "0" ]; then + errors=$((errors + 1)) + fi + ++have_xapian_compact=0 ++if [ ${have_xapian} = "1" ]; then ++ printf "Checking for Xapian compact support... " ++ IFS='.' ++ old_args=$@ ++ set -- ${xapian_version} ++ xapian_major_version=$1 ++ xapian_minor_version=$2 ++ xapian_subminor_version=$3 ++ set -- ${old_args} ++ if [ "${xapian_major_version}" -gt 1 ] || [ ${xapian_minor_version} -gt 2 ] || [ ${xapian_subminor_version} -ge 6 ]; then ++ printf "Yes.\n" ++ have_xapian_compact=1 ++ else ++ printf "No.\n" ++ fi ++fi ++ + printf "Checking for GMime development files... " + have_gmime=0 + IFS=';' +@@ -675,6 +694,9 @@ LINKER_RESOLVES_LIBRARY_DEPENDENCIES = ${linker_resolves_library_dependencies} + XAPIAN_CXXFLAGS = ${xapian_cxxflags} + XAPIAN_LDFLAGS = ${xapian_ldflags} + ++# Whether compact is supported by this version of Xapian ++HAVE_XAPIAN_COMPACT = ${have_xapian_compact} ++ + # Flags needed to compile and link against GMime-2.4 + GMIME_CFLAGS = ${gmime_cflags} + GMIME_LDFLAGS = ${gmime_ldflags} +@@ -711,6 +733,7 @@ CONFIGURE_CFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS) \\ + CONFIGURE_CXXFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS) \\ + \$(TALLOC_CFLAGS) -DHAVE_VALGRIND=\$(HAVE_VALGRIND) \\ + \$(VALGRIND_CFLAGS) \$(XAPIAN_CXXFLAGS) \\ ++ -DHAVE_XAPIAN_COMPACT=\$(HAVE_XAPIAN_COMPACT) \\ + -DHAVE_STRCASESTR=\$(HAVE_STRCASESTR) + CONFIGURE_LDFLAGS = \$(GMIME_LDFLAGS) \$(TALLOC_LDFLAGS) \$(XAPIAN_LDFLAGS) + EOF +diff --git a/lib/database.cc b/lib/database.cc +index 761dc1a..6e83a61 100644 +--- a/lib/database.cc ++++ b/lib/database.cc +@@ -781,6 +781,60 @@ notmuch_database_close (notmuch_database_t *notmuch) + } + + void ++notmuch_database_close_compact (notmuch_database_t *notmuch) ++{ ++ void *local = talloc_new (NULL); ++ Xapian::Compactor compactor; ++ char *notmuch_path, *xapian_path, *compact_xapian_path, *old_xapian_path; ++ ++#if HAVE_XAPIAN_COMPACT ++ if (! (notmuch_path = talloc_asprintf (local, "%s/%s", notmuch->path, ".notmuch"))) { ++ fprintf (stderr, "Out of memory\n"); ++ goto DONE; ++ } ++ ++ if (! (xapian_path = talloc_asprintf (local, "%s/%s", notmuch_path, "xapian"))) { ++ fprintf (stderr, "Out of memory\n"); ++ goto DONE; ++ } ++ ++ if (! (compact_xapian_path = talloc_asprintf (local, "%s.compact", xapian_path))) { ++ fprintf (stderr, "Out of memory\n"); ++ goto DONE; ++ } ++ ++ if (! (old_xapian_path = talloc_asprintf (local, "%s.old", xapian_path))) { ++ fprintf (stderr, "Out of memory\n"); ++ goto DONE; ++ } ++ ++ try { ++ compactor.set_renumber(false); ++ compactor.add_source(xapian_path); ++ compactor.set_destdir(compact_xapian_path); ++ compactor.compact(); ++ ++ if (rename(xapian_path, old_xapian_path)) { ++ fprintf (stderr, "Error moving old database out of the way\n"); ++ goto DONE; ++ } ++ ++ if (rename(compact_xapian_path, xapian_path)) { ++ fprintf (stderr, "Error moving compacted database\n"); ++ goto DONE; ++ } ++ } catch (Xapian::InvalidArgumentError e) { ++ fprintf (stderr, "Error while compacting: %s", e.get_msg().c_str()); ++ } ++ ++#endif ++ ++ notmuch_database_close(notmuch); ++DONE: ++ talloc_free(local); ++} ++ ++void + notmuch_database_destroy (notmuch_database_t *notmuch) + { + notmuch_database_close (notmuch); +diff --git a/lib/notmuch.h b/lib/notmuch.h +index 3633bed..50babfb 100644 +--- a/lib/notmuch.h ++++ b/lib/notmuch.h +@@ -215,6 +215,20 @@ notmuch_database_open (const char *path, + void + notmuch_database_close (notmuch_database_t *database); + ++/* Close the given notmuch database and then compact it. ++ * ++ * After notmuch_database_close_compact has been called, calls to ++ * other functions on objects derived from this database may either ++ * behave as if the database had not been closed (e.g., if the ++ * required data has been cached) or may fail with a ++ * NOTMUCH_STATUS_XAPIAN_EXCEPTION. ++ * ++ * notmuch_database_close_compact can be called multiple times. Later ++ * calls have no effect. ++ */ ++void ++notmuch_database_close_compact (notmuch_database_t *notmuch); ++ + /* Destroy the notmuch database, closing it if necessary and freeing + * all associated resources. */ + void +-- +1.7.9.5 + -- 2.26.2