Re: [PATCH 1/3] Add notmuch_database_close_compact
authorTomi Ollila <tomi.ollila@iki.fi>
Thu, 18 Oct 2012 06:44:04 +0000 (09:44 +0300)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:49:51 +0000 (09:49 -0800)
c5/1d9eed1c924c7e0554e7d46a4ae3b63677a217 [new file with mode: 0644]

diff --git a/c5/1d9eed1c924c7e0554e7d46a4ae3b63677a217 b/c5/1d9eed1c924c7e0554e7d46a4ae3b63677a217
new file mode 100644 (file)
index 0000000..8ba23fe
--- /dev/null
@@ -0,0 +1,221 @@
+Return-Path: <tomi.ollila@iki.fi>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id E226E431FC2\r
+       for <notmuch@notmuchmail.org>; Wed, 17 Oct 2012 23:44:02 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+       autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id BsfIFA5JngjT for <notmuch@notmuchmail.org>;\r
+       Wed, 17 Oct 2012 23:44:01 -0700 (PDT)\r
+Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
+       by olra.theworths.org (Postfix) with ESMTP id 7ADBD431FB6\r
+       for <notmuch@notmuchmail.org>; Wed, 17 Oct 2012 23:44:01 -0700 (PDT)\r
+Received: from guru.guru-group.fi (localhost [IPv6:::1])\r
+       by guru.guru-group.fi (Postfix) with ESMTP id B7D8B1000E5;\r
+       Thu, 18 Oct 2012 09:44:04 +0300 (EEST)\r
+From: Tomi Ollila <tomi.ollila@iki.fi>\r
+To: Ben Gamari <bgamari.foss@gmail.com>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH 1/3] Add notmuch_database_close_compact\r
+In-Reply-To: <1350487737-32058-2-git-send-email-bgamari.foss@gmail.com>\r
+References: <1350487737-32058-1-git-send-email-bgamari.foss@gmail.com>\r
+       <1350487737-32058-2-git-send-email-bgamari.foss@gmail.com>\r
+User-Agent: Notmuch/0.14+51~g62cd13b (http://notmuchmail.org) Emacs/24.2.1\r
+       (x86_64-unknown-linux-gnu)\r
+X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL\r
+       $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F\r
+       !)g;OY^,BjTbr)Np:%c_o'jj,Z\r
+Date: Thu, 18 Oct 2012 09:44:04 +0300\r
+Message-ID: <m262681dqj.fsf@guru.guru-group.fi>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Thu, 18 Oct 2012 06:44:03 -0000\r
+\r
+On Wed, Oct 17 2012, Ben Gamari <bgamari.foss@gmail.com> wrote:\r
+\r
+> ---\r
+>  configure       |   21 ++++++++++++++++++++-\r
+>  lib/database.cc |   54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++\r
+>  lib/notmuch.h   |   14 ++++++++++++++\r
+>  3 files changed, 88 insertions(+), 1 deletion(-)\r
+>\r
+> diff --git a/configure b/configure\r
+> index acb90a8..6551b13 100755\r
+> --- a/configure\r
+> +++ b/configure\r
+> @@ -270,7 +270,8 @@ printf "Checking for Xapian development files... "\r
+>  have_xapian=0\r
+>  for xapian_config in ${XAPIAN_CONFIG}; do\r
+>      if ${xapian_config} --version > /dev/null 2>&1; then\r
+> -    printf "Yes (%s).\n" $(${xapian_config} --version | sed -e 's/.* //')\r
+> +    xapian_version=$(${xapian_config} --version | sed -e 's/.* //')\r
+> +    printf "Yes (%s).\n" ${xapian_version}\r
+>      have_xapian=1\r
+>      xapian_cxxflags=$(${xapian_config} --cxxflags)\r
+>      xapian_ldflags=$(${xapian_config} --libs)\r
+> @@ -282,6 +283,20 @@ if [ ${have_xapian} = "0" ]; then\r
+>      errors=$((errors + 1))\r
+>  fi\r
+>  \r
+> +have_xapian_compact=0\r
+> +if [ ${have_xapian} = "1" ]; then\r
+> +    printf "Checking for Xapian compact support... "\r
+> +    case "${xapian_version}" in\r
+> +        0.*|1.[01].*|1.2.[0-5])\r
+> +            printf "No.\n" ;;\r
+> +        [1-9]*.[0-9]*.[0-9]*) \r
+> +            have_xapian_compact=1\r
+> +            printf "Yes.\n" ;;\r
+> +        *)\r
+> +            printf "Unknown version.\n" ;;\r
+> +    esac\r
+> +fi\r
+\r
+This is pretty good approximation(*) for the version check, but some\r
+comments are in place, like mentioning that compaction is supported\r
+in Xapian versions 1.2.6 and newer (as the code is not obvious to\r
+casual reader).\r
+\r
+(*) The match for yes part gives some room for non-digit version\r
+parts (if that would ever be needed) and also it rules out (most) \r
+cases where garbage were assigned to xapian_version.\r
+\r
+Tomi\r
+\r
+> +\r
+>  printf "Checking for GMime development files... "\r
+>  have_gmime=0\r
+>  IFS=';'\r
+> @@ -679,6 +694,9 @@ LINKER_RESOLVES_LIBRARY_DEPENDENCIES = ${linker_resolves_library_dependencies}\r
+>  XAPIAN_CXXFLAGS = ${xapian_cxxflags}\r
+>  XAPIAN_LDFLAGS = ${xapian_ldflags}\r
+>  \r
+> +# Whether compact is supported by this version of Xapian\r
+> +HAVE_XAPIAN_COMPACT = ${have_xapian_compact}\r
+> +\r
+>  # Flags needed to compile and link against GMime-2.4\r
+>  GMIME_CFLAGS = ${gmime_cflags}\r
+>  GMIME_LDFLAGS = ${gmime_ldflags}\r
+> @@ -715,6 +733,7 @@ CONFIGURE_CFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS)      \\\r
+>  CONFIGURE_CXXFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS)    \\\r
+>                   \$(TALLOC_CFLAGS) -DHAVE_VALGRIND=\$(HAVE_VALGRIND) \\\r
+>                   \$(VALGRIND_CFLAGS) \$(XAPIAN_CXXFLAGS)             \\\r
+> +                     -DHAVE_XAPIAN_COMPACT=\$(HAVE_XAPIAN_COMPACT)       \\\r
+>                       -DHAVE_STRCASESTR=\$(HAVE_STRCASESTR)\r
+>  CONFIGURE_LDFLAGS =  \$(GMIME_LDFLAGS) \$(TALLOC_LDFLAGS) \$(XAPIAN_LDFLAGS)\r
+>  EOF\r
+> diff --git a/lib/database.cc b/lib/database.cc\r
+> index 761dc1a..6e83a61 100644\r
+> --- a/lib/database.cc\r
+> +++ b/lib/database.cc\r
+> @@ -781,6 +781,60 @@ notmuch_database_close (notmuch_database_t *notmuch)\r
+>  }\r
+>  \r
+>  void\r
+> +notmuch_database_close_compact (notmuch_database_t *notmuch)\r
+> +{\r
+> +    void *local = talloc_new (NULL);\r
+> +    Xapian::Compactor compactor;\r
+> +    char *notmuch_path, *xapian_path, *compact_xapian_path, *old_xapian_path;\r
+> +\r
+> +#if HAVE_XAPIAN_COMPACT\r
+> +    if (! (notmuch_path = talloc_asprintf (local, "%s/%s", notmuch->path, ".notmuch"))) {\r
+> +    fprintf (stderr, "Out of memory\n");\r
+> +    goto DONE;\r
+> +    }\r
+> +\r
+> +    if (! (xapian_path = talloc_asprintf (local, "%s/%s", notmuch_path, "xapian"))) {\r
+> +    fprintf (stderr, "Out of memory\n");\r
+> +    goto DONE;\r
+> +    }\r
+> +\r
+> +    if (! (compact_xapian_path = talloc_asprintf (local, "%s.compact", xapian_path))) {\r
+> +    fprintf (stderr, "Out of memory\n");\r
+> +    goto DONE;\r
+> +    }\r
+> +\r
+> +    if (! (old_xapian_path = talloc_asprintf (local, "%s.old", xapian_path))) {\r
+> +    fprintf (stderr, "Out of memory\n");\r
+> +    goto DONE;\r
+> +    }\r
+> +\r
+> +    try {\r
+> +    compactor.set_renumber(false);\r
+> +    compactor.add_source(xapian_path);\r
+> +    compactor.set_destdir(compact_xapian_path);\r
+> +    compactor.compact();\r
+> +\r
+> +    if (rename(xapian_path, old_xapian_path)) {\r
+> +        fprintf (stderr, "Error moving old database out of the way\n");\r
+> +        goto DONE;\r
+> +    }\r
+> +\r
+> +    if (rename(compact_xapian_path, xapian_path)) {\r
+> +        fprintf (stderr, "Error moving compacted database\n");\r
+> +        goto DONE;\r
+> +    }\r
+> +    } catch (Xapian::InvalidArgumentError e) {\r
+> +    fprintf (stderr, "Error while compacting: %s", e.get_msg().c_str());\r
+> +    }\r
+> +    \r
+> +#endif\r
+> +\r
+> +    notmuch_database_close(notmuch);\r
+> +DONE:\r
+> +    talloc_free(local);\r
+> +}\r
+> +\r
+> +void\r
+>  notmuch_database_destroy (notmuch_database_t *notmuch)\r
+>  {\r
+>      notmuch_database_close (notmuch);\r
+> diff --git a/lib/notmuch.h b/lib/notmuch.h\r
+> index 3633bed..50babfb 100644\r
+> --- a/lib/notmuch.h\r
+> +++ b/lib/notmuch.h\r
+> @@ -215,6 +215,20 @@ notmuch_database_open (const char *path,\r
+>  void\r
+>  notmuch_database_close (notmuch_database_t *database);\r
+>  \r
+> +/* Close the given notmuch database and then compact it.\r
+> + *\r
+> + * After notmuch_database_close_compact has been called, calls to\r
+> + * other functions on objects derived from this database may either\r
+> + * behave as if the database had not been closed (e.g., if the\r
+> + * required data has been cached) or may fail with a\r
+> + * NOTMUCH_STATUS_XAPIAN_EXCEPTION.\r
+> + *\r
+> + * notmuch_database_close_compact can be called multiple times.  Later\r
+> + * calls have no effect.\r
+> + */\r
+> +void\r
+> +notmuch_database_close_compact (notmuch_database_t *notmuch);\r
+> +\r
+>  /* Destroy the notmuch database, closing it if necessary and freeing\r
+>  * all associated resources. */\r
+>  void\r
+> -- \r
+> 1.7.10.4\r
+>\r
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r