From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id BEF5C1F462; Wed, 12 Jun 2019 00:18:01 +0000 (UTC) Date: Wed, 12 Jun 2019 00:18:01 +0000 From: Eric Wong To: Konstantin Ryabitsev Cc: meta@public-inbox.org Subject: [PATCH] searchidx: improve error message when Xapian fails Message-ID: <20190612001801.rncuzyvuul724zhu@dcvr> References: <20190609025147.24966-1-e@80x24.org> <20190610150647.GA16418@chatter.i7.local> <20190610154058.jqaawkktvb5u2itj@dcvr> <20190610185730.GC16418@chatter.i7.local> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: List-Id: Konstantin Ryabitsev wrote: > > Exception: Expected block 102325 to be level 2, not 0 > > In the process of helping me debug this, Eric pointed out that the > xapian-db was corrupted. Apparently, this happened while I was copying > the lkml dir to a safe location for testing purposes. Once I had a > non-corrupted version of the database, I was able to successfully edit > the necessary message. Also, for public reference, using the flock(1) command (or similar) can be used to safely copy while -mda or -watch runs: flock /path/to/inbox.lock cp -a .... I suppose this is also possible, to minimize lock time: # unlocked copy step rsync -a $SRC $DST # locked copy using a remote destination to force delta-transmission: flock /path/to/inbox.lock rsync -a $SRC $REMOTE_DST But to make Xapian corruption more apparent in the future: ---------------8<------------- Subject: [PATCH] searchidx: improve error message when Xapian fails Make it easier to detect if a partition is corrupt. --- lib/PublicInbox/SearchIdx.pm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/PublicInbox/SearchIdx.pm b/lib/PublicInbox/SearchIdx.pm index 9985628..7cd67f1 100644 --- a/lib/PublicInbox/SearchIdx.pm +++ b/lib/PublicInbox/SearchIdx.pm @@ -117,7 +117,11 @@ sub _xdb_acquire { } } return unless defined $flag; - $self->{xdb} = Search::Xapian::WritableDatabase->new($dir, $flag); + my $xdb = eval { Search::Xapian::WritableDatabase->new($dir, $flag) }; + if ($@) { + die "Failed opening $dir: ", $@; + } + $self->{xdb} = $xdb; } sub add_val ($$$) { -- EW