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 BC2CC429E26 for ; Thu, 8 Sep 2011 19:42:37 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.699 X-Spam-Level: X-Spam-Status: No, score=-0.699 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-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 ei6CnuOMjWTA for ; Thu, 8 Sep 2011 19:42:37 -0700 (PDT) Received: from mail-qy0-f174.google.com (mail-qy0-f174.google.com [209.85.216.174]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id F4012431FD0 for ; Thu, 8 Sep 2011 19:42:36 -0700 (PDT) Received: by qyk7 with SMTP id 7so896065qyk.5 for ; Thu, 08 Sep 2011 19:42:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=lf2TaXP2nZAoIf286C2Onf9t2F/+PV6xBmEjsI3oGpw=; b=OpJ1N3UELhMMSTTNUovMEihCWxBfQQuSpwQFBEaNwS9gFUqxK7o5qJRkh2KrD4sINx 6oC0iJ5uUoVLfeciEvZS5jg7zHTUszpk4D5NQnenrObMFRMrXJeBXmRu9zePMIvwWrmB 1t+O8B1FSUb1DgqB9tgCSCePgkTF5W3in83ds= MIME-Version: 1.0 Received: by 10.229.100.213 with SMTP id z21mr1085242qcn.102.1315536152616; Thu, 08 Sep 2011 19:42:32 -0700 (PDT) Sender: amdragon@gmail.com Received: by 10.229.2.201 with HTTP; Thu, 8 Sep 2011 19:42:32 -0700 (PDT) In-Reply-To: <1315445674.32058.183.camel@delen> References: <1315445674.32058.183.camel@delen> Date: Thu, 8 Sep 2011 22:42:32 -0400 X-Google-Sender-Auth: m4ikT1hSvmTZ1jcWgxtuVTIXAYA Message-ID: Subject: Re: Patch: Flush and Reopen From: Austin Clements To: Martin Owens Content-Type: text/plain; charset=ISO-8859-1 Cc: Paul Tagliamonte , Notmuch developer list 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: Fri, 09 Sep 2011 02:42:37 -0000 On Wed, Sep 7, 2011 at 9:34 PM, Martin Owens wrote: > Hello, > > Per discussions on irc, I've attached a patch for your consideration > which allows the developer to run two new database commands; > > notmuch_database_flush - used on read_write databases to commit changes > to disk > notmuch_database_reopen - used on read_only databases to reload from the > disk > > Used in conjunction they can allow access by multiple programs at the > same time. There are also changes to the python bindings to add these > two methods to the database class. > > Regards, Martin Owens Ages ago, there was a lot of discussion about improving notmuch's concurrency so that other commands could run simultaneously with long-running operations like notmuch new (whereas currently many commands always abort and others are likely to fail with a concurrent modification exception). This patch, combined with the atomicity changes (assuming they ever get in), would make it possible to implement the concurrency protocol I suggested way back in id:"AANLkTi=KOx8aTJipkiArFVjEHE6zt_JypoASMiiAWBZ6@mail.gmail.com". A few comments on your patch: --- a/debian/control +++ b/debian/control @@ -5,7 +5,7 @@ Maintainer: Carl Worth Uploaders: Jameson Graef Rollins , martin f. krafft , David Bremner Build-Depends: debhelper (>= 7.0.50~), pkg-config, libxapian-dev, - libgmime-2.4-dev, libtalloc-dev, libz-dev, python-all (>= 2.6.6-3~), + libgmime-2.4-dev, libtalloc-dev, libz-dev, python-all (>= 2.6.6), Did you mean to change this? --- a/lib/database.cc +++ b/lib/database.cc @@ -700,18 +700,37 @@ notmuch_database_open (const char *path, } void -notmuch_database_close (notmuch_database_t *notmuch) +notmuch_database_reopen (notmuch_database_t *notmuch) { try { - if (notmuch->mode == NOTMUCH_DATABASE_MODE_READ_WRITE) - (static_cast (notmuch->xapian_db))->flush (); + if (notmuch->mode == NOTMUCH_DATABASE_MODE_READ_ONLY) + (static_cast (notmuch->xapian_db))->reopen(); This cast will fail. Shouldn't this just be a wrapper around notmuch->xapian_db->reopen? --- a/lib/query.cc +++ b/lib/query.cc @@ -185,10 +185,14 @@ notmuch_query_search_messages (notmuch_query_t *query) messages->iterator_end = mset.end (); return &messages->base; - + } catch (const Xapian::DatabaseModifiedError &error) { + fprintf (stderr, "Database changed, you need to reopen it before performing queries.\n"); + notmuch->exception_reported = TRUE; + talloc_free (messages); + return NULL; There are many places where DatabaseModifiedError could be thrown besides this function. This needs to be handled more systematically. Also, your patch has a number of code- and patch-formatting problems. Please take a look at the (work-in-progress) patch formatting guidelines at http://notmuchmail.org/patchformatting/ . For the code style, I'd recommend looking at the code around what you're changing. For example, notmuch uses tab indentation and a space before the open paren of an argument list.