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 E91D5431FC0 for ; Thu, 1 Jan 2015 10:22:00 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[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 kwOSoCmIUgiI for ; Thu, 1 Jan 2015 10:21:57 -0800 (PST) Received: from mail-wi0-f174.google.com (mail-wi0-f174.google.com [209.85.212.174]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 806D4431FAF for ; Thu, 1 Jan 2015 10:21:57 -0800 (PST) Received: by mail-wi0-f174.google.com with SMTP id h11so26827084wiw.1 for ; Thu, 01 Jan 2015 10:21:56 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=0uSzEjuDOGI7a2nIRhECAFVYQEhm/l4emJvljfVRG9A=; b=Lh1iw7qttnpROzfvKwvXkWmJMwO8B+uPQP9lh/tI4KJn1Hv9XgF3BAPpKNyRQVAsLg ZLXgRGwJ+gJ9Wf/ZY8FXCjinnWPR4j9oOQ+PmWbX4fDGZBIvijF8qwQMg+Jar74iHxgv q+jmTSzNC4e1XD3tXO7ACqiOJstr3fv0NgfN8qsnX7txuXIqJW51sKNa4TqGRX2mYfIw bH12k7B1m6PqVV/kgsrvJgE5RSkQFIE/r+yzci8gtV4tRd/K/FDU5hrCQLJ3g7R8Hp6g bmm3D1JGopuhpoYGIHcjl8uzKFIMVsahtIfzDHeojEfvS6MlqL1gRai/B5HDJ2dG5dN3 Sh7w== X-Gm-Message-State: ALoCoQmJpAWME6es/3LeMYTA+0SElJR0+BjRGS9VnYiSKUZqpxJHcWuePcSg0b8XHGC+teEREdFr X-Received: by 10.194.175.69 with SMTP id by5mr139926544wjc.32.1420136516193; Thu, 01 Jan 2015 10:21:56 -0800 (PST) Received: from localhost (dsl-hkibrasgw2-58c371-91.dhcp.inet.fi. [88.195.113.91]) by mx.google.com with ESMTPSA id lg7sm51493931wic.0.2015.01.01.10.21.55 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Jan 2015 10:21:55 -0800 (PST) From: Jani Nikula To: notmuch@notmuchmail.org Subject: [PATCH] HACK: lib: add brute and ignorant handling of database lock errors Date: Thu, 1 Jan 2015 20:22:03 +0200 Message-Id: <1420136523-27100-1-git-send-email-jani@nikula.org> X-Mailer: git-send-email 2.1.4 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: Thu, 01 Jan 2015 18:22:01 -0000 From: Jani Nikula Instead of failing at first try, back off for an increasing number of seconds, and only fail after three attempts. One of my notmuch installations that gets plenty of mail hits db locked exceptions quite often, and even more than before since I switched to using notmuch insert. These are quite annoying in the Emacs UI as there is virtually no error handling for tagging, and the tag change highlighting gets confused. This is a dirty hack, but for me it's much more preferrable to the the db locked exceptions. With the retries and increasing back-off timeout I hardly ever see the exceptions now. Maybe this inspires someone to fix this for real. ;) --- lib/database.cc | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/database.cc b/lib/database.cc index 3601f9ded307..50063c55969b 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -819,8 +819,23 @@ notmuch_database_open (const char *path, string last_thread_id; if (mode == NOTMUCH_DATABASE_MODE_READ_WRITE) { - notmuch->xapian_db = new Xapian::WritableDatabase (xapian_path, - Xapian::DB_CREATE_OR_OPEN); + /* + * Brute and ignorant handling of database lock errors. + * Instead of failing at first try, back off for an + * increasing number of seconds. + */ + for (unsigned int tries = 1; ! notmuch->xapian_db; tries++) { + try { + notmuch->xapian_db = + new Xapian::WritableDatabase (xapian_path, + Xapian::DB_CREATE_OR_OPEN); + } catch (const Xapian::DatabaseLockError &error) { + if (tries > 3) + throw; + + sleep(tries); + } + } } else { notmuch->xapian_db = new Xapian::Database (xapian_path); } -- 2.1.4