From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id UHSMGADCmmCXEwEAgWs5BA (envelope-from ) for ; Tue, 11 May 2021 19:42:24 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id mMIYFADCmmBgXQAAB5/wlQ (envelope-from ) for ; Tue, 11 May 2021 17:42:24 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [144.217.243.247]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 1D2F51194F for ; Tue, 11 May 2021 19:42:24 +0200 (CEST) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 0682127185; Tue, 11 May 2021 13:42:19 -0400 (EDT) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by mail.notmuchmail.org (Postfix) with ESMTP id C27392717A for ; Tue, 11 May 2021 13:42:15 -0400 (EDT) Received: by fethera.tethera.net (Postfix, from userid 1001) id 59F6360016; Tue, 11 May 2021 13:42:15 -0400 (EDT) Received: (nullmailer pid 779942 invoked by uid 1000); Tue, 11 May 2021 17:42:13 -0000 From: David Bremner To: Michael J Gruber , Alexander Adolf , David Bremner , notmuch@notmuchmail.org Subject: [PATCH] lib/notmuch_database_reopen: reload some database metada Date: Tue, 11 May 2021 14:42:09 -0300 Message-Id: <20210511174209.779891-1-david@tethera.net> X-Mailer: git-send-email 2.30.2 In-Reply-To: <162075216869.247978.11973039285204032566.git@grubix.eu> References: <162075216869.247978.11973039285204032566.git@grubix.eu> MIME-Version: 1.0 Message-ID-Hash: NOHO5XUBZQORGD5NOXJTW2FTWDU3CDV2 X-Message-ID-Hash: NOHO5XUBZQORGD5NOXJTW2FTWDU3CDV2 X-MailFrom: bremner@tethera.net X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.1 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1620754944; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=pUtefotqX+vz4wwmFMxA+oSgfVr1W0VRtYcf9rXg7uA=; b=VfDY5MDmP6dPbIpePOFM5RPOsH/60UAHcgSZAR9DdnUJl+jDK6FZTjEHNIx/lnMgj+F8e6 YjhxTKyikkcdBnc8E7ySNA5sBwDY2h+/wfeLKin5aXJwhMvIZv+CRk6cp+ePBeCNp/VADE aZNKCIIzv7x3rOXJSxibohHbNofVHg43ueHUD1uIVtnEoKawlgP7MugG/6RElL6Sw5fu4H oJqworL1hyAIa+zuL1fWWMyuXwvKYWEofZRCV/ZhIK2z8Yhc+u8PUQQCsdV2vIM1OqVE6G HvX/t7weHeFUH4adFBkqpf37uXI0+kIWtcYdvqaShp0Z5bcPWqXajXMknJfxog== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1620754944; a=rsa-sha256; cv=none; b=POdYKG2ZM4uW30qQ0li8BwNq4qV8R7F0IlY5eFjKx7edWbff2R5PCabe0zZD9iypsqBi9T 02+hoKrRyDiYMh+y4pmkcIJbyg6rLrrhjcwhYklbRhbv1b965PmgkfQaukkm+Q35jAFF/N nNWPl3ZM/Esg9NtrkNqYJ7j8d9/iIPhS+shG49YXGbZoIO01RVFTyD5wZ5PZIgwACLAK0J Jr6PRzjLmic9lckAFhMP/nuO20bO9v/Y6ityvoRperiSgRQ/l/qAAnYwyBkCD/LigHvRzJ NU9lFOfDyadxs4FZWfT3XeQeVDDHlY5UIor5RBa9mGOsUW8fqQOyHngG+R6QVw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 144.217.243.247 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: 0.44 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 144.217.243.247 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: 1D2F51194F X-Spam-Score: 0.44 X-Migadu-Scanner: scn0.migadu.com X-TUID: bmQd1pj3VMvv In some uses of reopen, new documents and threads maybe have been added, and e.g. compaction may have changed the uuid. --- lib/open.cc | 58 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/lib/open.cc b/lib/open.cc index bdb695fe..0ceca921 100644 --- a/lib/open.cc +++ b/lib/open.cc @@ -325,6 +325,36 @@ _init_libs () } } +static void +_load_database_state (notmuch_database_t *notmuch) { + std::string last_thread_id; + std::string last_mod; + + notmuch->last_doc_id = notmuch->xapian_db->get_lastdocid (); + last_thread_id = notmuch->xapian_db->get_metadata ("last_thread_id"); + if (last_thread_id.empty ()) { + notmuch->last_thread_id = 0; + } else { + const char *str; + char *end; + + str = last_thread_id.c_str (); + notmuch->last_thread_id = strtoull (str, &end, 16); + if (*end != '\0') + INTERNAL_ERROR ("Malformed database last_thread_id: %s", str); + } + + /* Get current highest revision number. */ + last_mod = notmuch->xapian_db->get_value_upper_bound ( + NOTMUCH_VALUE_LAST_MOD); + if (last_mod.empty ()) + notmuch->revision = 0; + else + notmuch->revision = Xapian::sortable_unserialise (last_mod); + notmuch->uuid = talloc_strdup ( + notmuch, notmuch->xapian_db->get_uuid ().c_str ()); +} + static notmuch_status_t _finish_open (notmuch_database_t *notmuch, const char *profile, @@ -339,8 +369,6 @@ _finish_open (notmuch_database_t *notmuch, const char *database_path = notmuch_database_get_path (notmuch); try { - std::string last_thread_id; - std::string last_mod; if (mode == NOTMUCH_DATABASE_MODE_READ_WRITE) { notmuch->writable_xapian_db = new Xapian::WritableDatabase (notmuch->xapian_path, @@ -384,29 +412,7 @@ _finish_open (notmuch_database_t *notmuch, goto DONE; } - notmuch->last_doc_id = notmuch->xapian_db->get_lastdocid (); - last_thread_id = notmuch->xapian_db->get_metadata ("last_thread_id"); - if (last_thread_id.empty ()) { - notmuch->last_thread_id = 0; - } else { - const char *str; - char *end; - - str = last_thread_id.c_str (); - notmuch->last_thread_id = strtoull (str, &end, 16); - if (*end != '\0') - INTERNAL_ERROR ("Malformed database last_thread_id: %s", str); - } - - /* Get current highest revision number. */ - last_mod = notmuch->xapian_db->get_value_upper_bound ( - NOTMUCH_VALUE_LAST_MOD); - if (last_mod.empty ()) - notmuch->revision = 0; - else - notmuch->revision = Xapian::sortable_unserialise (last_mod); - notmuch->uuid = talloc_strdup ( - notmuch, notmuch->xapian_db->get_uuid ().c_str ()); + _load_database_state (notmuch); notmuch->query_parser = new Xapian::QueryParser; notmuch->term_gen = new Xapian::TermGenerator; @@ -733,6 +739,8 @@ notmuch_database_reopen (notmuch_database_t *notmuch, DB_ACTION); } } + + _load_database_state (notmuch); } catch (const Xapian::Error &error) { if (! notmuch->exception_reported) { _notmuch_database_log (notmuch, "Error: A Xapian exception reopening database: %s\n", -- 2.30.2