1 Return-Path: <bgamari.foss@gmail.com>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id 48DF8431E62
\r
6 for <notmuch@notmuchmail.org>; Fri, 23 Aug 2013 19:55:35 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5
\r
12 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
\r
13 FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled
\r
14 Received: from olra.theworths.org ([127.0.0.1])
\r
15 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
16 with ESMTP id nnH2MZ49YdQH for <notmuch@notmuchmail.org>;
\r
17 Fri, 23 Aug 2013 19:55:30 -0700 (PDT)
\r
18 Received: from mail-qc0-f171.google.com (mail-qc0-f171.google.com
\r
19 [209.85.216.171]) (using TLSv1 with cipher RC4-SHA (128/128 bits))
\r
20 (No client certificate requested)
\r
21 by olra.theworths.org (Postfix) with ESMTPS id 4CE7E431FD7
\r
22 for <notmuch@notmuchmail.org>; Fri, 23 Aug 2013 19:55:30 -0700 (PDT)
\r
23 Received: by mail-qc0-f171.google.com with SMTP id n1so737386qcw.2
\r
24 for <notmuch@notmuchmail.org>; Fri, 23 Aug 2013 19:55:29 -0700 (PDT)
\r
25 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;
\r
26 h=from:to:cc:subject:date:message-id:in-reply-to:references;
\r
27 bh=hlQqk+MmeNUNq23AGd9XgbumhNnZh2sjLjbG6vkf7UA=;
\r
28 b=joD96F+JC91W2H+mDErV0Uqbzr/9r7sYMhp+SMJ9q6LEfRcPQSFWOvU6S8RlT6P0ph
\r
29 35ui062g3/BI25MRckVlelhwOhOIbgKHe3lEG3clZyq1w2IhTT7hLbUiRuKngjrihNsK
\r
30 cnOU98VDSPUzY+PPfHd05kRo6xtayw/Eyh65aZLqdesjOAsE6Qka+ok3Sc+BVTRTpQMr
\r
31 Ge77phqh41FJiy3MnsImq2Pe9s/Nx4qoIZoOi/2YMsVKAhWaTASRnXvBOgWcV34aj/Sh
\r
32 u6A2bclCuSvCQ9WRqNnZatbd+mCtIHRxsL9we+qhyciP/4COTmRNuSkNl2kwyGTBJ4/L
\r
34 X-Received: by 10.49.94.115 with SMTP id db19mr3345825qeb.27.1377312929785;
\r
35 Fri, 23 Aug 2013 19:55:29 -0700 (PDT)
\r
36 Received: from localhost.localdomain
\r
37 (pool-108-8-228-201.spfdma.east.verizon.net. [108.8.228.201])
\r
38 by mx.google.com with ESMTPSA id a2sm4350757qek.7.1969.12.31.16.00.00
\r
39 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
\r
40 Fri, 23 Aug 2013 19:55:29 -0700 (PDT)
\r
41 From: Ben Gamari <bgamari.foss@gmail.com>
\r
42 To: notmuch@notmuchmail.org
\r
43 Subject: [PATCH 1/3] database: Add notmuch_database_compact_close
\r
44 Date: Fri, 23 Aug 2013 22:55:21 -0400
\r
45 Message-Id: <1377312923-32274-2-git-send-email-bgamari.foss@gmail.com>
\r
46 X-Mailer: git-send-email 1.8.1.2
\r
47 In-Reply-To: <1377312923-32274-1-git-send-email-bgamari.foss@gmail.com>
\r
48 References: <1377312923-32274-1-git-send-email-bgamari.foss@gmail.com>
\r
49 X-BeenThere: notmuch@notmuchmail.org
\r
50 X-Mailman-Version: 2.1.13
\r
52 List-Id: "Use and development of the notmuch mail system."
\r
53 <notmuch.notmuchmail.org>
\r
54 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
55 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
56 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
57 List-Post: <mailto:notmuch@notmuchmail.org>
\r
58 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
59 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
60 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
61 X-List-Received-Date: Sat, 24 Aug 2013 02:55:35 -0000
\r
63 This function uses Xapian's Compactor machinery to compact the notmuch
\r
64 database. The compacted database is built in a temporary directory and
\r
65 later moved into place while the original uncompacted database is
\r
68 Signed-off-by: Ben Gamari <bgamari.foss@gmail.com>
\r
70 configure | 27 +++++++++++++++--
\r
71 lib/database.cc | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
\r
72 lib/notmuch.h | 15 ++++++++++
\r
73 3 files changed, 130 insertions(+), 3 deletions(-)
\r
75 diff --git a/configure b/configure
\r
76 index 6166917..ee9e887 100755
\r
79 @@ -277,7 +277,8 @@ printf "Checking for Xapian development files... "
\r
81 for xapian_config in ${XAPIAN_CONFIG}; do
\r
82 if ${xapian_config} --version > /dev/null 2>&1; then
\r
83 - printf "Yes (%s).\n" $(${xapian_config} --version | sed -e 's/.* //')
\r
84 + xapian_version=$(${xapian_config} --version | sed -e 's/.* //')
\r
85 + printf "Yes (%s).\n" ${xapian_version}
\r
87 xapian_cxxflags=$(${xapian_config} --cxxflags)
\r
88 xapian_ldflags=$(${xapian_config} --libs)
\r
89 @@ -289,6 +290,21 @@ if [ ${have_xapian} = "0" ]; then
\r
90 errors=$((errors + 1))
\r
93 +# Compaction is only supported on Xapian > 1.2.6
\r
94 +have_xapian_compact=0
\r
95 +if [ ${have_xapian} = "1" ]; then
\r
96 + printf "Checking for Xapian compact support... "
\r
97 + case "${xapian_version}" in
\r
98 + 0.*|1.[01].*|1.2.[0-5])
\r
99 + printf "No (only available with Xapian > 1.2.6).\n" ;;
\r
100 + [1-9]*.[0-9]*.[0-9]*)
\r
101 + have_xapian_compact=1
\r
102 + printf "Yes.\n" ;;
\r
104 + printf "Unknown version.\n" ;;
\r
108 printf "Checking for GMime development files... "
\r
111 @@ -729,6 +745,9 @@ HAVE_STRCASESTR = ${have_strcasestr}
\r
112 # build its own version)
\r
113 HAVE_STRSEP = ${have_strsep}
\r
115 +# Whether the Xapian version in use supports compaction
\r
116 +HAVE_XAPIAN_COMPACT = ${have_xapian_compact}
\r
118 # Whether the getpwuid_r function is standards-compliant
\r
119 # (if not, then notmuch will #define _POSIX_PTHREAD_SEMANTICS
\r
120 # to enable the standards-compliant version -- needed for Solaris)
\r
121 @@ -787,13 +806,15 @@ CONFIGURE_CFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS) \\
\r
122 -DHAVE_STRCASESTR=\$(HAVE_STRCASESTR) \\
\r
123 -DHAVE_STRSEP=\$(HAVE_STRSEP) \\
\r
124 -DSTD_GETPWUID=\$(STD_GETPWUID) \\
\r
125 - -DSTD_ASCTIME=\$(STD_ASCTIME)
\r
126 + -DSTD_ASCTIME=\$(STD_ASCTIME) \\
\r
127 + -DHAVE_XAPIAN_COMPACT=\$(HAVE_XAPIAN_COMPACT)
\r
128 CONFIGURE_CXXFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS) \\
\r
129 \$(TALLOC_CFLAGS) -DHAVE_VALGRIND=\$(HAVE_VALGRIND) \\
\r
130 \$(VALGRIND_CFLAGS) \$(XAPIAN_CXXFLAGS) \\
\r
131 -DHAVE_STRCASESTR=\$(HAVE_STRCASESTR) \\
\r
132 -DHAVE_STRSEP=\$(HAVE_STRSEP) \\
\r
133 -DSTD_GETPWUID=\$(STD_GETPWUID) \\
\r
134 - -DSTD_ASCTIME=\$(STD_ASCTIME)
\r
135 + -DSTD_ASCTIME=\$(STD_ASCTIME) \\
\r
136 + -DHAVE_XAPIAN_COMPACT=\$(HAVE_XAPIAN_COMPACT)
\r
137 CONFIGURE_LDFLAGS = \$(GMIME_LDFLAGS) \$(TALLOC_LDFLAGS) \$(XAPIAN_LDFLAGS)
\r
139 diff --git a/lib/database.cc b/lib/database.cc
\r
140 index 5cc0765..b71751d 100644
\r
141 --- a/lib/database.cc
\r
142 +++ b/lib/database.cc
\r
143 @@ -268,6 +268,8 @@ notmuch_status_to_string (notmuch_status_t status)
\r
144 return "Unbalanced number of calls to notmuch_message_freeze/thaw";
\r
145 case NOTMUCH_STATUS_UNBALANCED_ATOMIC:
\r
146 return "Unbalanced number of calls to notmuch_database_begin_atomic/end_atomic";
\r
147 + case NOTMUCH_STATUS_UNSUPPORTED_OPERATION:
\r
148 + return "Unsupported operation";
\r
150 case NOTMUCH_STATUS_LAST_STATUS:
\r
151 return "Unknown error status value";
\r
152 @@ -800,6 +802,95 @@ notmuch_database_close (notmuch_database_t *notmuch)
\r
153 notmuch->date_range_processor = NULL;
\r
156 +class NotmuchCompactor : public Xapian::Compactor
\r
160 + set_status (const std::string &table, const std::string &status)
\r
162 + if (status.length() == 0)
\r
163 + printf ("compacting table %s:\n", table.c_str());
\r
165 + printf (" %s\n", status.c_str());
\r
169 +#if HAVE_XAPIAN_COMPACT
\r
171 +notmuch_database_compact_close (notmuch_database_t *notmuch)
\r
173 + void *local = talloc_new (NULL);
\r
174 + NotmuchCompactor compactor;
\r
175 + char *notmuch_path, *xapian_path, *compact_xapian_path, *old_xapian_path;
\r
176 + notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS;
\r
178 + if (! (notmuch_path = talloc_asprintf (local, "%s/%s", notmuch->path, ".notmuch"))) {
\r
179 + ret = NOTMUCH_STATUS_OUT_OF_MEMORY;
\r
183 + if (! (xapian_path = talloc_asprintf (local, "%s/%s", notmuch_path, "xapian"))) {
\r
184 + ret = NOTMUCH_STATUS_OUT_OF_MEMORY;
\r
188 + if (! (compact_xapian_path = talloc_asprintf (local, "%s.compact", xapian_path))) {
\r
189 + ret = NOTMUCH_STATUS_OUT_OF_MEMORY;
\r
193 + if (! (old_xapian_path = talloc_asprintf (local, "%s.old", xapian_path))) {
\r
194 + ret = NOTMUCH_STATUS_OUT_OF_MEMORY;
\r
199 + compactor.set_renumber(false);
\r
200 + compactor.add_source(xapian_path);
\r
201 + compactor.set_destdir(compact_xapian_path);
\r
202 + compactor.compact();
\r
204 + if (rename(xapian_path, old_xapian_path)) {
\r
205 + fprintf (stderr, "Error moving old database out of the way\n");
\r
206 + ret = NOTMUCH_STATUS_FILE_ERROR;
\r
210 + if (rename(compact_xapian_path, xapian_path)) {
\r
211 + fprintf (stderr, "Error moving compacted database\n");
\r
212 + ret = NOTMUCH_STATUS_FILE_ERROR;
\r
215 + } catch (Xapian::InvalidArgumentError e) {
\r
216 + fprintf (stderr, "Error while compacting: %s", e.get_msg().c_str());
\r
217 + ret = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
\r
221 + fprintf (stderr, "\n");
\r
222 + fprintf (stderr, "\n");
\r
223 + fprintf (stderr, "Old database has been moved to %s", old_xapian_path);
\r
224 + fprintf (stderr, "\n");
\r
225 + fprintf (stderr, "To delete run,\n");
\r
226 + fprintf (stderr, "\n");
\r
227 + fprintf (stderr, " rm -R %s\n", old_xapian_path);
\r
228 + fprintf (stderr, "\n");
\r
230 + notmuch_database_close(notmuch);
\r
233 + talloc_free(local);
\r
238 +notmuch_database_compact_close (unused (notmuch_database_t *notmuch))
\r
240 + fprintf (stderr, "notmuch was compiled against a xapian version lacking compaction support.\n");
\r
241 + return NOTMUCH_STATUS_UNSUPPORTED_OPERATION;
\r
246 notmuch_database_destroy (notmuch_database_t *notmuch)
\r
248 diff --git a/lib/notmuch.h b/lib/notmuch.h
\r
249 index 998a4ae..e9abd90 100644
\r
250 --- a/lib/notmuch.h
\r
251 +++ b/lib/notmuch.h
\r
252 @@ -101,6 +101,7 @@ typedef enum _notmuch_status {
\r
253 NOTMUCH_STATUS_TAG_TOO_LONG,
\r
254 NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW,
\r
255 NOTMUCH_STATUS_UNBALANCED_ATOMIC,
\r
256 + NOTMUCH_STATUS_UNSUPPORTED_OPERATION,
\r
258 NOTMUCH_STATUS_LAST_STATUS
\r
259 } notmuch_status_t;
\r
260 @@ -215,6 +216,20 @@ notmuch_database_open (const char *path,
\r
262 notmuch_database_close (notmuch_database_t *database);
\r
264 +/* Close the given notmuch database and then compact it.
\r
266 + * After notmuch_database_close_compact has been called, calls to
\r
267 + * other functions on objects derived from this database may either
\r
268 + * behave as if the database had not been closed (e.g., if the
\r
269 + * required data has been cached) or may fail with a
\r
270 + * NOTMUCH_STATUS_XAPIAN_EXCEPTION.
\r
272 + * notmuch_database_close_compact can be called multiple times. Later
\r
273 + * calls have no effect.
\r
276 +notmuch_database_compact_close (notmuch_database_t *notmuch);
\r
278 /* Destroy the notmuch database, closing it if necessary and freeing
\r
279 * all associated resources. */
\r