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-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,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 8CC611F66F for ; Sat, 7 Nov 2020 10:57:07 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 09/10] extindex: SIGUSR1 supports checkpoint Date: Sat, 7 Nov 2020 10:56:59 +0000 Message-Id: <20201107105700.12586-10-e@80x24.org> In-Reply-To: <20201107105700.12586-1-e@80x24.org> References: <20201107105700.12586-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Matching the behavior of git-fast-import(1), we'll allow a user to send SIGUSR1 to checkpoint over.sqlite3 and Xapian. --- lib/PublicInbox/ExtSearchIdx.pm | 23 ++++++++++++----------- script/public-inbox-extindex | 1 + 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/lib/PublicInbox/ExtSearchIdx.pm b/lib/PublicInbox/ExtSearchIdx.pm index 50342802..7aaf8291 100644 --- a/lib/PublicInbox/ExtSearchIdx.pm +++ b/lib/PublicInbox/ExtSearchIdx.pm @@ -284,16 +284,9 @@ sub last_commits { } sub _sync_inbox ($$$) { - my ($self, $opt, $ibx) = @_; - my $sync = { - need_checkpoint => \(my $bool = 0), - reindex => $opt->{reindex}, - -opt => $opt, - self => $self, - ibx => $ibx, - nr => \(my $nr = 0), - -regen_fmt => "%u/?\n", - }; + my ($self, $sync, $ibx) = @_; + $sync->{ibx} = $ibx; + $sync->{nr} = \(my $nr = 0); my $v = $ibx->version; my $ekey = $ibx->eidx_key; if ($v == 2) { @@ -324,10 +317,18 @@ sub eidx_sync { # main entry point local $SIG{__WARN__} = sub { $warn_cb->($self->{current_info}, ': ', @_); }; + my $sync = { + need_checkpoint => \(my $need_checkpoint = 0), + reindex => $opt->{reindex}, + -opt => $opt, + self => $self, + -regen_fmt => "%u/?\n", + }; + local $SIG{USR1} = sub { $need_checkpoint = 1 }; # don't use $_ here, it'll get clobbered by reindex_checkpoint for my $ibx (@{$self->{ibx_list}}) { - _sync_inbox($self, $opt, $ibx); + _sync_inbox($self, $sync, $ibx); } $self->{oidx}->rethread_done($opt); diff --git a/script/public-inbox-extindex b/script/public-inbox-extindex index bb1e174a..864a2732 100644 --- a/script/public-inbox-extindex +++ b/script/public-inbox-extindex @@ -33,6 +33,7 @@ die "--jobs must be >= 0\n" if defined $opt->{jobs} && $opt->{jobs} < 0; # require lazily to speed up --help my $eidx_dir = shift(@ARGV) // die "E: $help"; +local $SIG{USR1} = 'IGNORE'; # to be overridden in eidx_sync require PublicInbox::Admin; my $cfg = PublicInbox::Config->new; my @ibxs = PublicInbox::Admin::resolve_inboxes(\@ARGV, $opt, $cfg);