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 C9AED431FB6 for ; Tue, 17 Apr 2012 01:42:38 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -1.098 X-Spam-Level: X-Spam-Status: No, score=-1.098 tagged_above=-999 required=5 tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001, NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_MED=-2.3] 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 mvQIniGsOOzB for ; Tue, 17 Apr 2012 01:42:38 -0700 (PDT) Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 0F77C431FAE for ; Tue, 17 Apr 2012 01:42:38 -0700 (PDT) Received: from smtp.qmul.ac.uk ([138.37.6.40]) by mail2.qmul.ac.uk with esmtp (Exim 4.71) (envelope-from ) id 1SK3zf-00043w-Aq; Tue, 17 Apr 2012 09:42:35 +0100 Received: from 94-192-233-223.zone6.bethere.co.uk ([94.192.233.223] helo=localhost) by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.69) (envelope-from ) id 1SK3ze-0001IF-PN; Tue, 17 Apr 2012 09:42:34 +0100 From: Mark Walters To: Austin Clements , Justus Winter <4winter@informatik.uni-hamburg.de> Subject: Re: [RFC] Split notmuch_database_close into two functions In-Reply-To: <20120412165744.GF13549@mit.edu> References: <1332291311-28954-1-git-send-email-4winter@informatik.uni-hamburg.de> <20120401032323.GH5949@mit.edu> <20120412090533.2074.78211@thinkbox.jade-hamburg.de> <20120412165744.GF13549@mit.edu> User-Agent: Notmuch/0.12+110~gbc97b4a (http://notmuchmail.org) Emacs/23.3.1 (x86_64-pc-linux-gnu) Date: Tue, 17 Apr 2012 09:42:55 +0100 Message-ID: <87mx6a4uls.fsf@qmul.ac.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Sender-Host-Address: 94.192.233.223 X-QM-SPAM-Info: Sender has good ham record. :) X-QM-Body-MD5: 193c4160caa46f9f63d218ae448bbf9e (of first 20000 bytes) X-SpamAssassin-Score: -1.8 X-SpamAssassin-SpamBar: - X-SpamAssassin-Report: The QM spam filters have analysed this message to determine if it is spam. We require at least 5.0 points to mark a message as spam. This message scored -1.8 points. Summary of the scoring: * -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, * medium trust * [138.37.6.40 listed in list.dnswl.org] * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider * (markwalters1009[at]gmail.com) * -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay * domain * 0.5 AWL AWL: From: address is in the auto white-list X-QM-Scan-Virus: ClamAV says the message is clean Cc: notmuch@notmuchmail.org 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: Tue, 17 Apr 2012 08:42:38 -0000 On Thu, 12 Apr 2012, Austin Clements wrote: > Quoth Justus Winter on Apr 12 at 11:05 am: >> Quoting Austin Clements (2012-04-01 05:23:23) >> >Quoth Justus Winter on Mar 21 at 1:55 am: >> >> I propose to split the function notmuch_database_close into >> >> notmuch_database_close and notmuch_database_destroy so that long >> >> running processes like alot can close the database while still using >> >> data obtained from queries to that database. >> > >> >Is this actually safe? My understanding of Xapian::Database::close is >> >that, once you've closed the database, basically anything can throw a >> >Xapian exception. A lot of data is retrieved lazily, both by notmuch >> >and by Xapian, so simply having, say, a notmuch_message_t object isn't >> >enough to guarantee that you'll be able to get data out of it after >> >closing the database. Hence, I don't see how this interface could be >> >used correctly. >> >> I do not know how, but both alot and afew (and occasionally the >> notmuch binary) are somehow safely using this interface on my box for >> the last three weeks. > > I see. TL;DR: This isn't safe, but that's okay if we document it. > > The bug report [0] you pointed to was quite informative. At its core, > this is really a memory management issue. To sum up for the record > (and to check my own thinking): It sounds like alot is careful not to > use any notmuch objects after closing the database. The problem is > that, currently, closing the database also talloc_free's it, which > recursively free's everything derived from it. Python later GCs the > wrapper objects, which *also* try to free their underlying objects, > resulting in a double free. > > Before the change to expose notmuch_database_close, the Python > bindings would only talloc_free from destructors. Furthermore, they > prevented the library from recursively freeing things at other times > by internally maintaining a reverse reference for every library talloc > reference (e.g., message is a sub-allocation of query, so the bindings > keep a reference from each message to its query to ensure the query > doesn't get freed). The ability to explicitly talloc_free the > database subverts this mechanism. > > > So, I've come around to thinking that splitting notmuch_database_close > and _destroy is okay. It certainly parallels the rest of the API > better. However, notmuch_database_close needs a big warning similar > to Xapian::Database::close's warning that retrieving information from > objects derived from this database may not work after calling close. > notmuch_database_close is really a specialty interface, and about the > only thing you can guarantee after closing the database is that you > can destroy other objects. This is also going to require a SONAME > major version bump, as mentioned by others. Which, to be fair, would > be a good opportunity to fix some other issues, too, like how > notmuch_database_open can't return errors and how > notmuch_database_get_directory is broken on read-only databases. The > actual bump should be done at release time, but maybe we should drop a > note somewhere (NEWS?) so we don't forget. Can I just check that there is no way to reopen the Xapian database readonly? (I may be using the wrong term: I mean is there a way of switching an open read-write database to read-only without losing the attached structures/messages/threads etc) If I understand it this would be sufficient as it would free the lock, but could be more generally useful for long lived notmuch processes. Best wishes Mark