Re: [PATCH 1/7] Split notmuch_database_close into two functions
authorMark Walters <markwalters1009@gmail.com>
Sat, 31 Mar 2012 17:17:15 +0000 (18:17 +0100)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:45:54 +0000 (09:45 -0800)
49/2d7b1ac0337d2ddbc46f8e779ec2e5bc429d66 [new file with mode: 0644]

diff --git a/49/2d7b1ac0337d2ddbc46f8e779ec2e5bc429d66 b/49/2d7b1ac0337d2ddbc46f8e779ec2e5bc429d66
new file mode 100644 (file)
index 0000000..7462e1d
--- /dev/null
@@ -0,0 +1,225 @@
+Return-Path: <m.walters@qmul.ac.uk>\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 82114431FAF\r
+       for <notmuch@notmuchmail.org>; Sat, 31 Mar 2012 10:17:14 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -1.098\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-1.098 tagged_above=-999 required=5\r
+       tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001,\r
+       NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_MED=-2.3] 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 Y0UdHVOkPrGa for <notmuch@notmuchmail.org>;\r
+       Sat, 31 Mar 2012 10:17:13 -0700 (PDT)\r
+Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6])\r
+       (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 54593431FAE\r
+       for <notmuch@notmuchmail.org>; Sat, 31 Mar 2012 10:17:13 -0700 (PDT)\r
+Received: from smtp.qmul.ac.uk ([138.37.6.40])\r
+       by mail2.qmul.ac.uk with esmtp (Exim 4.71)\r
+       (envelope-from <m.walters@qmul.ac.uk>)\r
+       id 1SE1vG-0003RQ-ID; Sat, 31 Mar 2012 18:17:09 +0100\r
+Received: from 94-192-233-223.zone6.bethere.co.uk ([94.192.233.223]\r
+       helo=localhost)\r
+       by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.69)\r
+       (envelope-from <m.walters@qmul.ac.uk>)\r
+       id 1SE1vG-0000RL-3i; Sat, 31 Mar 2012 18:17:06 +0100\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: Justus Winter <4winter@informatik.uni-hamburg.de>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH 1/7] Split notmuch_database_close into two functions\r
+In-Reply-To:\r
+ <1332291311-28954-2-git-send-email-4winter@informatik.uni-hamburg.de>\r
+References:\r
+ <1332291311-28954-1-git-send-email-4winter@informatik.uni-hamburg.de>\r
+       <1332291311-28954-2-git-send-email-4winter@informatik.uni-hamburg.de>\r
+User-Agent: Notmuch/0.12+88~gb9fb613 (http://notmuchmail.org) Emacs/23.3.1\r
+       (x86_64-pc-linux-gnu)\r
+Date: Sat, 31 Mar 2012 18:17:15 +0100\r
+Message-ID: <87fwcopu5g.fsf@qmul.ac.uk>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+X-Sender-Host-Address: 94.192.233.223\r
+X-QM-SPAM-Info: Sender has good ham record.  :)\r
+X-QM-Body-MD5: afb81fd1a941e6f44213228b1e25b7d9 (of first 20000 bytes)\r
+X-SpamAssassin-Score: -1.8\r
+X-SpamAssassin-SpamBar: -\r
+X-SpamAssassin-Report: The QM spam filters have analysed this message to\r
+       determine if it is\r
+       spam. We require at least 5.0 points to mark a message as spam.\r
+       This message scored -1.8 points.\r
+       Summary of the scoring: \r
+       * -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/,\r
+       *      medium trust\r
+       *      [138.37.6.40 listed in list.dnswl.org]\r
+       * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail\r
+       provider *      (markwalters1009[at]gmail.com)\r
+       * -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay\r
+       *      domain\r
+       *  0.5 AWL AWL: From: address is in the auto white-list\r
+X-QM-Scan-Virus: ClamAV says the message is clean\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: Sat, 31 Mar 2012 17:17:14 -0000\r
+\r
+Justus Winter <4winter@informatik.uni-hamburg.de> writes:\r
+\r
+> Formerly notmuch_database_close closed the xapian database and\r
+> destroyed the talloc structure associated with the notmuch database\r
+> object. Split notmuch_database_close into notmuch_database_close and\r
+> notmuch_database_destroy.\r
+>\r
+> This makes it possible for long running programs to close the xapian\r
+> database and thus release the lock associated with it without\r
+> destroying the data structures obtained from it.\r
+>\r
+> This also makes the api more consistent since every other data\r
+> structure has a destructor function.\r
+\r
+I like the idea of this series but have two queries before reviewing it.\r
+\r
+The first is a concern that if we change the library functions we should\r
+update the library version otherwise out of tree users won't know which\r
+to call. (I don't actually know how versioning is done but I think we\r
+should at least be able to make new out-of-tree code cope with the old\r
+or new version). It might be worth keeping notmuch_database_close as it\r
+is for now and adding something like notmuch_database_weak_close with\r
+the new functionality. Then whenever the library version is next going\r
+to get bumped we could move to the destroy/close nomenclature.\r
+\r
+Secondly, I think the patch series could be made clearer and easier to\r
+review. If you do it in three steps\r
+\r
+1) change of notmuch_database_close to notmuch_database_destroy (just\r
+   the function name change)\r
+2) split the new notmuch_database_destroy into two as in the current\r
+   first patch\r
+3) Make any changes (if there are any) of notmuch_database_destroy to\r
+   notmuch_database_close.\r
+\r
+The advantage is that the first change is easy to test (essentially does\r
+it build) and then changes from notmuch_database_destroy to\r
+notmuch_database_close in step 3 are explicit rather than the current\r
+situation where we need to grep the code to see if some instances of\r
+notmuch_database_close were not changed to notmuch_database_destroy.\r
+\r
+Of course if the decision is to go via the weak_close version then you\r
+just need to do the analogues of 2 and 3.\r
+\r
+Best wishes\r
+\r
+Mark\r
+\r
+>\r
+> Signed-off-by: Justus Winter <4winter@informatik.uni-hamburg.de>\r
+> ---\r
+>  lib/database.cc |   14 ++++++++++++--\r
+>  lib/notmuch.h   |   15 +++++++++++----\r
+>  2 files changed, 23 insertions(+), 6 deletions(-)\r
+>\r
+> diff --git a/lib/database.cc b/lib/database.cc\r
+> index 16c4354..2fefcad 100644\r
+> --- a/lib/database.cc\r
+> +++ b/lib/database.cc\r
+> @@ -642,7 +642,7 @@ notmuch_database_open (const char *path,\r
+>                       "       read-write mode.\n",\r
+>                       notmuch_path, version, NOTMUCH_DATABASE_VERSION);\r
+>              notmuch->mode = NOTMUCH_DATABASE_MODE_READ_ONLY;\r
+> -            notmuch_database_close (notmuch);\r
+> +            notmuch_database_destroy (notmuch);\r
+>              notmuch = NULL;\r
+>              goto DONE;\r
+>          }\r
+> @@ -702,7 +702,7 @@ notmuch_database_open (const char *path,\r
+>      } catch (const Xapian::Error &error) {\r
+>      fprintf (stderr, "A Xapian exception occurred opening database: %s\n",\r
+>               error.get_msg().c_str());\r
+> -    notmuch_database_close (notmuch);\r
+> +    notmuch_database_destroy (notmuch);\r
+>      notmuch = NULL;\r
+>      }\r
+>  \r
+> @@ -738,9 +738,19 @@ notmuch_database_close (notmuch_database_t *notmuch)\r
+>      }\r
+>  \r
+>      delete notmuch->term_gen;\r
+> +    notmuch->term_gen = NULL;\r
+>      delete notmuch->query_parser;\r
+> +    notmuch->query_parser = NULL;\r
+>      delete notmuch->xapian_db;\r
+> +    notmuch->xapian_db = NULL;\r
+>      delete notmuch->value_range_processor;\r
+> +    notmuch->value_range_processor = NULL;\r
+> +}\r
+> +\r
+> +void\r
+> +notmuch_database_destroy (notmuch_database_t *notmuch)\r
+> +{\r
+> +    notmuch_database_close (notmuch);\r
+>      talloc_free (notmuch);\r
+>  }\r
+>  \r
+> diff --git a/lib/notmuch.h b/lib/notmuch.h\r
+> index babd208..6114f36 100644\r
+> --- a/lib/notmuch.h\r
+> +++ b/lib/notmuch.h\r
+> @@ -133,7 +133,7 @@ typedef struct _notmuch_filenames notmuch_filenames_t;\r
+>   *\r
+>   * After a successful call to notmuch_database_create, the returned\r
+>   * database will be open so the caller should call\r
+> - * notmuch_database_close when finished with it.\r
+> + * notmuch_database_destroy when finished with it.\r
+>   *\r
+>   * The database will not yet have any data in it\r
+>   * (notmuch_database_create itself is a very cheap function). Messages\r
+> @@ -165,7 +165,7 @@ typedef enum {\r
+>   * An existing notmuch database can be identified by the presence of a\r
+>   * directory named ".notmuch" below 'path'.\r
+>   *\r
+> - * The caller should call notmuch_database_close when finished with\r
+> + * The caller should call notmuch_database_destroy when finished with\r
+>   * this database.\r
+>   *\r
+>   * In case of any failure, this function returns NULL, (after printing\r
+> @@ -175,11 +175,18 @@ notmuch_database_t *\r
+>  notmuch_database_open (const char *path,\r
+>                     notmuch_database_mode_t mode);\r
+>  \r
+> -/* Close the given notmuch database, freeing all associated\r
+> - * resources. See notmuch_database_open. */\r
+> +/* Close the given notmuch database.\r
+> + *\r
+> + * This function is called by notmuch_database_destroyed and can be\r
+> + * called multiple times. */\r
+>  void\r
+>  notmuch_database_close (notmuch_database_t *database);\r
+>  \r
+> +/* Destroy the notmuch database freeing all associated\r
+> + * resources */\r
+> +void\r
+> +notmuch_database_destroy (notmuch_database_t *database);\r
+> +\r
+>  /* Return the database path of the given database.\r
+>   *\r
+>   * The return value is a string owned by notmuch so should not be\r
+> -- \r
+> 1.7.9.1\r
+>\r
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r