[PATCH 07/17] lib: Add notmuch_database_{begin,end}_atomic.
authorAustin Clements <amdragon@MIT.EDU>
Sat, 11 Jun 2011 20:04:33 +0000 (16:04 +2000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:38:35 +0000 (09:38 -0800)
69/d83662c6f381f0c091fe9db03acde6e3b9fb74 [new file with mode: 0644]

diff --git a/69/d83662c6f381f0c091fe9db03acde6e3b9fb74 b/69/d83662c6f381f0c091fe9db03acde6e3b9fb74
new file mode 100644 (file)
index 0000000..62e872a
--- /dev/null
@@ -0,0 +1,181 @@
+Return-Path: <amthrax@drake.mit.edu>\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 9CE2F429E29\r
+       for <notmuch@notmuchmail.org>; Sat, 11 Jun 2011 13:06:13 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 0PqqZ0Jj+QTT for <notmuch@notmuchmail.org>;\r
+       Sat, 11 Jun 2011 13:06:12 -0700 (PDT)\r
+Received: from dmz-mailsec-scanner-4.mit.edu (DMZ-MAILSEC-SCANNER-4.MIT.EDU\r
+       [18.9.25.15])\r
+       by olra.theworths.org (Postfix) with ESMTP id CC9D2431FB6\r
+       for <notmuch@notmuchmail.org>; Sat, 11 Jun 2011 13:06:12 -0700 (PDT)\r
+X-AuditID: 1209190f-b7b0eae000000a42-e4-4df3cab98d52\r
+Received: from mailhub-auth-1.mit.edu ( [18.9.21.35])\r
+       by dmz-mailsec-scanner-4.mit.edu (Symantec Messaging Gateway) with SMTP\r
+       id 87.DC.02626.9BAC3FD4; Sat, 11 Jun 2011 16:06:17 -0400 (EDT)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+       by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id p5BK6CiA015024; \r
+       Sat, 11 Jun 2011 16:06:12 -0400\r
+Received: from drake.mit.edu\r
+       (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com\r
+       [209.6.116.242]) (authenticated bits=0)\r
+       (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+       by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id p5BK6BmA005941\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+       Sat, 11 Jun 2011 16:06:12 -0400 (EDT)\r
+Received: from amthrax by drake.mit.edu with local (Exim 4.76)\r
+       (envelope-from <amthrax@drake.mit.edu>)\r
+       id 1QVURf-0000I8-56; Sat, 11 Jun 2011 16:06:11 -0400\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 07/17] lib: Add notmuch_database_{begin,end}_atomic.\r
+Date: Sat, 11 Jun 2011 16:04:33 -0400\r
+Message-Id: <1307822683-848-8-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 1.7.5.1\r
+In-Reply-To: <1307822683-848-1-git-send-email-amdragon@mit.edu>\r
+References: <87ei34rnc5.fsf@yoom.home.cworth.org>\r
+       <1307822683-848-1-git-send-email-amdragon@mit.edu>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFtrHIsWRmVeSWpSXmKPExsUixCmqrLvz1Gdfg/v/pCyu35zJ7MDo8WzV\r
+       LeYAxigum5TUnMyy1CJ9uwSujL51ZxkLbshUfD78n7GB8aR4FyMnh4SAicT+TdPYIGwxiQv3\r
+       1gPZXBxCAvsYJS43TmMGSQgJbGCU+NQpDZG4zyQx6fV/VghnPqPE85V3WEGq2AQ0JLbtX84I\r
+       YosISEvsvDsbKM7BwSygJvGnSwUkLCzgItFyewNYOYuAqkTr/yawzbwCdhILru1mh7hCQeLK\r
+       lXksIDangL3EvINXWSCOSJNYcms3+wRG/gWMDKsYZVNyq3RzEzNzilOTdYuTE/PyUot0TfRy\r
+       M0v0UlNKNzGCg0aSfwfjt4NKhxgFOBiVeHhV1n72FWJNLCuuzD3EKMnBpCTKq3MCKMSXlJ9S\r
+       mZFYnBFfVJqTWnyIUYKDWUmEd337J18h3pTEyqrUonyYlDQHi5I47yxJdV8hgfTEktTs1NSC\r
+       1CKYrAwHh5IE7+aTQEMFi1LTUyvSMnNKENJMHJwgw3mAhh8FqeEtLkjMLc5Mh8ifYtTleLxh\r
+       0yFGIZa8/LxUKXHe+yBFAiBFGaV5cHNg0f6KURzoLWHeXSBVPMBEATfpFdASJqAlAqVgS0oS\r
+       EVJSDYzz58vJZl699lu6h7tF0cVWNVE85cH7m0uYVY4eTc4NODT/ct28sM0uln+mbN11MmZ3\r
+       +Optj/7fqjvJkKrUbb4jYs+RBaskHSp3MLrJpyxwjEqy2pfIp9t45Yaqv/LP188WSKpF20fd\r
+       V/19QWzrf98ZC4JU9FZqTeebc9ekOlPll++ttx98OqcpsRRnJBpqMRcVJwIAffDV+9ECAAA=\r
+Cc: Austin Clements <amdragon@mit.edu>\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, 11 Jun 2011 20:06:13 -0000\r
+\r
+These operations translate into non-flushed Xapian transactions,\r
+allowing arbitrary groups of database operations to be performed\r
+atomically.\r
+---\r
+ lib/database.cc |   44 ++++++++++++++++++++++++++++++++++++++++++++\r
+ lib/notmuch.h   |   30 ++++++++++++++++++++++++++++++\r
+ 2 files changed, 74 insertions(+), 0 deletions(-)\r
+\r
+diff --git a/lib/database.cc b/lib/database.cc\r
+index 7f79cf4..ddb6167 100644\r
+--- a/lib/database.cc\r
++++ b/lib/database.cc\r
+@@ -974,6 +974,50 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,\r
+     return NOTMUCH_STATUS_SUCCESS;\r
+ }\r
\r
++notmuch_status_t\r
++notmuch_database_begin_atomic (notmuch_database_t *notmuch)\r
++{\r
++    if (notmuch->mode == NOTMUCH_DATABASE_MODE_READ_ONLY)\r
++      return NOTMUCH_STATUS_SUCCESS;\r
++\r
++    try {\r
++      (static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db))->begin_transaction (false);\r
++    } catch (const Xapian::Error &error) {\r
++      fprintf (stderr, "A Xapian exception occurred beginning transaction: %s.\n",\r
++               error.get_msg().c_str());\r
++      notmuch->exception_reported = TRUE;\r
++      return NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
++    }\r
++    return NOTMUCH_STATUS_SUCCESS;\r
++}\r
++\r
++notmuch_status_t\r
++notmuch_database_end_atomic (notmuch_database_t *notmuch)\r
++{\r
++    Xapian::WritableDatabase *db;\r
++\r
++    if (notmuch->mode == NOTMUCH_DATABASE_MODE_READ_ONLY)\r
++      return NOTMUCH_STATUS_SUCCESS;\r
++\r
++    db = static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db);\r
++    try {\r
++      db->commit_transaction ();\r
++\r
++      /* This is a hack for testing.  Xapian never flushes on a\r
++       * non-flushed commit, even if the flush threshold is 1.\r
++       * However, we rely on flushing to test atomicity. */\r
++      const char *thresh = getenv ("XAPIAN_FLUSH_THRESHOLD");\r
++      if (thresh && atoi (thresh) == 1)\r
++          db->commit ();\r
++    } catch (const Xapian::Error &error) {\r
++      fprintf (stderr, "A Xapian exception occurred committing transaction: %s.\n",\r
++               error.get_msg().c_str());\r
++      notmuch->exception_reported = TRUE;\r
++      return NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
++    }\r
++    return NOTMUCH_STATUS_SUCCESS;\r
++}\r
++\r
+ /* We allow the user to use arbitrarily long paths for directories. But\r
+  * we have a term-length limit. So if we exceed that, we'll use the\r
+  * SHA-1 of the path for the database term.\r
+diff --git a/lib/notmuch.h b/lib/notmuch.h\r
+index e508309..208d22c 100644\r
+--- a/lib/notmuch.h\r
++++ b/lib/notmuch.h\r
+@@ -214,6 +214,36 @@ notmuch_database_upgrade (notmuch_database_t *database,\r
+                                                  double progress),\r
+                         void *closure);\r
\r
++/* Begin an atomic database operation.\r
++ *\r
++ * Any modifications performed between a successful begin and a\r
++ * notmuch_database_end_atomic will be applied to the database\r
++ * atomically.  Note that, unlike a typical database transaction, this\r
++ * only ensures atomicity, not durability; neither begin nor end\r
++ * necessarily flush modifications to disk.\r
++ *\r
++ * Return value:\r
++ *\r
++ * NOTMUCH_STATUS_SUCCESS: Successfully entered atomic section.\r
++ *\r
++ * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred;\r
++ *    atomic section not entered.\r
++ */\r
++notmuch_status_t\r
++notmuch_database_begin_atomic (notmuch_database_t *notmuch);\r
++\r
++/* Indicate the end of an atomic database operation.\r
++ *\r
++ * Return value:\r
++ *\r
++ * NOTMUCH_STATUS_SUCCESS: Successfully completed atomic section.\r
++ *\r
++ * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred;\r
++ *    atomic section not ended.\r
++ */\r
++notmuch_status_t\r
++notmuch_database_end_atomic (notmuch_database_t *notmuch);\r
++\r
+ /* Retrieve a directory object from the database for 'path'.\r
+  *\r
+  * Here, 'path' should be a path relative to the path of 'database'\r
+-- \r
+1.7.5.1\r
+\r