From ed9511d39ff9e44f3a29d8fd708c565d16dec76d Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 10 Jan 2025 23:18:10 +0000 Subject: [PATCH] (ext)index: move {-regen_fmt} from $sync to $self We rely on `local' anyways in some cases. This is yet another step towards eliminating the $sync structure. --- lib/PublicInbox/ExtSearchIdx.pm | 12 ++++++------ lib/PublicInbox/V2Writable.pm | 17 ++++++++--------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/lib/PublicInbox/ExtSearchIdx.pm b/lib/PublicInbox/ExtSearchIdx.pm index 25f2d8e72..21f6b33a7 100644 --- a/lib/PublicInbox/ExtSearchIdx.pm +++ b/lib/PublicInbox/ExtSearchIdx.pm @@ -794,7 +794,7 @@ sub eidxq_process ($$) { # for reindexing my $dbh = $self->{oidx}->dbh; my $tot = $dbh->selectrow_array('SELECT COUNT(*) FROM eidxq') or return; $self->{nrec} = 0; - local $sync->{-regen_fmt} = "%u/$tot\n"; + local $self->{-regen_fmt} = "%u/$tot\n"; my $pr = $self->{-opt}->{-progress}; if ($pr) { my $min = $dbh->selectrow_array('SELECT MIN(docid) FROM eidxq'); @@ -899,7 +899,7 @@ sub _reindex_check_ibx ($$$) { # first, check if we missed any messages in target $ibx my $msgs; my $pr = $self->{-opt}->{-progress}; - local $sync->{-regen_fmt} = "$ekey checking %u/$max\n"; + local $self->{-regen_fmt} = "$ekey checking %u/$max\n"; $self->{nrec} = 0; my $fast = $self->{-opt}->{fast}; my $usr; # _unref_stale_range (< $lo) called @@ -1047,7 +1047,7 @@ sub eidx_dedupe ($$$) { my ($max_id) = $self->{oidx}->dbh->selectrow_array(<{-regen_fmt} = "dedupe %u/$max_id\n"; + local $self->{-regen_fmt} = "dedupe %u/$max_id\n"; # note: we could write this query more intelligently, # but that causes lock contention with read-only processes @@ -1118,12 +1118,12 @@ sub eidx_sync { # main entry point local $self->{need_checkpoint} = 0; local $self->{nrec} = 0; local $self->{-opt} = $opt; + local $self->{-regen_fmt} = "%u/?\n"; my $sync = { # DO NOT SET {reindex} here, it's incompatible with reused # V2Writable code, reindex is totally different here # compared to v1/v2 inboxes because we have multiple histories self => $self, - -regen_fmt => "%u/?\n", }; local $SIG{USR1} = sub { $self->{need_checkpoint} = 1 }; my $quit = PublicInbox::SearchIdx::quit_cb($sync); @@ -1298,9 +1298,9 @@ sub _watch_commit { # PublicInbox::DS::add_timer callback delete $self->{-commit_timer}; eidxq_process($self, $self->{-watch_sync}); eidxq_release($self); - my $fmt = delete $self->{-watch_sync}->{-regen_fmt}; + my $fmt = delete $self->{-regen_fmt}; reindex_checkpoint($self, $self->{-watch_sync}); - $self->{-watch_sync}->{-regen_fmt} = $fmt; + $self->{-regen_fmt} = $fmt; # call event_step => done unless commit_timer is armed PublicInbox::DS::requeue($self); diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm index 74281fed4..ca231e0c5 100644 --- a/lib/PublicInbox/V2Writable.pm +++ b/lib/PublicInbox/V2Writable.pm @@ -710,8 +710,8 @@ sub reindex_checkpoint ($$) { $self->done; # release lock } - if (my $pr = $sync->{-regen_fmt} ? $self->{-opt}->{-progress} : undef) { - $pr->(sprintf $sync->{-regen_fmt}, $self->{nrec}); + if (my $pr = $self->{-regen_fmt} ? $self->{-opt}->{-progress} : undef) { + $pr->(sprintf $self->{-regen_fmt}, $self->{nrec}); } # allow -watch or -mda to write... @@ -986,14 +986,14 @@ sub sync_prepare ($$) { } return 0 if $sync->{quit}; if (!$regen_max) { - $sync->{-regen_fmt} = "%u/?\n"; + $self->{-regen_fmt} = "%u/?\n"; return 0; } # reindex should NOT see new commits anymore, if we do, # it's a problem and we need to notice it via die() my $pad = length($regen_max) + 1; - $sync->{-regen_fmt} = "% ${pad}u/$regen_max\n"; + $self->{-regen_fmt} = "% ${pad}u/$regen_max\n"; $self->{nrec} = 0; return -1 if $sync->{reindex}; $regen_max + $self->artnum_max || 0; @@ -1176,10 +1176,8 @@ sub xapian_only ($;$$) { local $self->{parallel} = 0 if $seq; $self->idx_init($self->{-opt}); # acquire lock if (my $art_end = $self->{ibx}->mm->max) { - $sync //= { - self => $self, - -regen_fmt => "%u/?\n", - }; + $self->{-regen_fmt} //= "%u/?\n"; + $sync //= { self => $self }; $sync->{art_end} = $art_end; if ($seq || !$self->{parallel}) { my $shard_end = $self->{shards} - 1; @@ -1206,6 +1204,7 @@ sub index_sync { local $self->{need_checkpoint} = 0; local $self->{nrec} = 0; local $self->{-opt} = $opt; + local $self->{-regen_fmt}; return xapian_only($self) if $opt->{xapian_only}; my $epoch_max = $self->{ibx}->max_git_epoch // return; @@ -1263,7 +1262,7 @@ sub index_sync { if (my $nrec = $self->{nrec}) { my $pr = $self->{-opt}->{-progress}; - $pr->('all.git '.sprintf($sync->{-regen_fmt}, $nrec)) if $pr; + $pr->('all.git '.sprintf($self->{-regen_fmt}, $nrec)) if $pr; } my $quit_warn; -- 2.47.2