From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 89AF51F87D for ; Thu, 30 Nov 2023 11:41:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1701344471; bh=GZUJCgl5bykYVTchZhzLoFGMC/FRtDZRU5qiAq+0e/I=; h=From:To:Subject:Date:In-Reply-To:References:From; b=1VLZggQGOWHnPpjtkYrDClTc4S2Dv/Hk5WVEDh+JU9HX4Fmpwhe3x23q5E1pGSi0S 0F3BtFMMZ0Zksdy6yBaiXrYCgyknTkwPYehS9kX/avHKygv+4CQ2ojgzmvyWNd4na6 0PoSbe5lGjJ+sMS3Brw757GaPbCOyc3v1vaUAdhI= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 15/15] codesearch: use retry_reopen for WWW Date: Thu, 30 Nov 2023 11:41:08 +0000 Message-ID: <20231130114109.2577708-16-e@80x24.org> In-Reply-To: <20231130114109.2577708-1-e@80x24.org> References: <20231130114109.2577708-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: As with mail search, a cindex may be updated while WWW is serving requests. Thus we must reopen the Xapian DB when the revision we're using becomes stale. --- lib/PublicInbox/CodeSearch.pm | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/lib/PublicInbox/CodeSearch.pm b/lib/PublicInbox/CodeSearch.pm index f4694686..a2f4bae8 100644 --- a/lib/PublicInbox/CodeSearch.pm +++ b/lib/PublicInbox/CodeSearch.pm @@ -256,17 +256,22 @@ sub load_ct { # retry_reopen cb } } +sub load_ct { # retry_reopen cb + my ($self, $git_dir) = @_; + my @ids = docids_of_git_dir $self, $git_dir or return; + for (@ids) { + my $doc = $self->get_doc($_) // next; + return int_val($doc, CT); + } +} + sub load_commit_times { # each_cindex callback my ($self, $todo) = @_; # todo = [ [ time, git ], [ time, git ] ...] - my (@pending, $rec, $dir, @ids, $doc); + my (@pending, $rec, $ct); while ($rec = shift @$todo) { - @ids = docids_of_git_dir $self, $rec->[1]->{git_dir}; - if (@ids) { - for (@ids) { - $doc = $self->get_doc($_) // next; - $rec->[0] = int_val($doc, CT); - last; - } + $ct = $self->retry_reopen(\&load_ct, $rec->[1]->{git_dir}); + if (defined $ct) { + $rec->[0] = $ct; } else { # may be in another cindex: push @pending, $rec; } @@ -295,7 +300,7 @@ EOM $git; }; } - my $jd = join_data($self) or return warn <retry_reopen(\&join_data, $self) or return warn <{topdir} has no usable join data for $cfg_f EOM my ($ekeys, $roots, $ibx2root) = @$jd{qw(ekeys roots ibx2root)}; @@ -366,7 +371,7 @@ sub repos_sorted { my @recs = map { [ 0, $_ ] } @_; # PublicInbox::Git objects my @todo = @recs; $pi_cfg->each_cindex(\&load_commit_times, \@todo); - @recs = sort { $b->[0] <=> $a->[0] } @recs; + @recs = sort { $b->[0] <=> $a->[0] } @recs; # sort by commit time } 1;