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=-3.8 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 D15471F934 for ; Sat, 26 Dec 2020 10:16:24 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 1/4] extindex: various --watch signal handling fixes Date: Sat, 26 Dec 2020 10:16:21 +0000 Message-Id: <20201226101624.26061-2-e@80x24.org> In-Reply-To: <20201226101624.26061-1-e@80x24.org> References: <20201226101624.26061-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: We need to clobber the SIGUSR1 resync queue on SIGHUP to invalidate old inbox objects. Furthermore, the lengthy initial scan needs to ignore signals intended for the event loop to avoid unexpected behavior. Finally, add some progress output to inform users on the terminal to inform users' of progress. --- lib/PublicInbox/ExtSearchIdx.pm | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/PublicInbox/ExtSearchIdx.pm b/lib/PublicInbox/ExtSearchIdx.pm index 53ff2ca1..778154a5 100644 --- a/lib/PublicInbox/ExtSearchIdx.pm +++ b/lib/PublicInbox/ExtSearchIdx.pm @@ -1008,6 +1008,7 @@ sub eidx_reload { # -extindex --watch SIGHUP handler if ($self->{cfg}) { my $pr = $self->{-watch_sync}->{-opt}->{-progress}; $pr->('reloading ...') if $pr; + delete $self->{-resync_queue}; @{$self->{ibx_list}} = (); %{$self->{ibx_map}} = (); delete $self->{-watch_sync}->{id2pos}; @@ -1043,6 +1044,10 @@ sub event_step { # PublicInbox::DS::requeue callback sub eidx_watch { # public-inbox-extindex --watch main loop my ($self, $opt) = @_; + local %SIG = %SIG; + for my $sig (qw(HUP USR1 TSTP QUIT INT TERM)) { + $SIG{$sig} = sub { warn "SIG$sig ignored while scanning\n" }; + } require PublicInbox::InboxIdle; require PublicInbox::DS; require PublicInbox::Syscall; @@ -1052,6 +1057,8 @@ sub eidx_watch { # public-inbox-extindex --watch main loop $idler->watch_inbox($_) for @{$self->{ibx_list}}; } $_->subscribe_unlock(__PACKAGE__, $self) for @{$self->{ibx_list}}; + my $pr = $opt->{-progress}; + $pr->("performing initial scan ...\n") if $pr; my $sync = eidx_sync($self, $opt); # initial sync return if $sync->{quit}; my $oldset = PublicInbox::Sigfd::block_signals(); @@ -1067,7 +1074,7 @@ sub eidx_watch { # public-inbox-extindex --watch main loop $sig->{QUIT} = $sig->{INT} = $sig->{TERM} = $quit; my $sigfd = PublicInbox::Sigfd->new($sig, $PublicInbox::Syscall::SFD_NONBLOCK); - local %SIG = (%SIG, %$sig) if !$sigfd; + %SIG = (%SIG, %$sig) if !$sigfd; local $self->{-watch_sync} = $sync; # for ->on_inbox_unlock if (!$sigfd) { # wake up every second to accept signals if we don't @@ -1076,6 +1083,7 @@ sub eidx_watch { # public-inbox-extindex --watch main loop PublicInbox::DS->SetLoopTimeout(1000); } PublicInbox::DS->SetPostLoopCallback(sub { !$sync->{quit} }); + $pr->("initial scan complete, entering event loop\n") if $pr; PublicInbox::DS->EventLoop; # calls InboxIdle->event_step done($self); }