From: Eric Wong Date: Fri, 10 Jan 2025 23:18:08 +0000 (+0000) Subject: (ext)index: ${$sync->{nr}} to $self->{nrec} X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ae88b144a392c40f04aaac8db33a49abae61246a;p=thirdparty%2Fpublic-inbox.git (ext)index: ${$sync->{nr}} to $self->{nrec} {nrec} is probably less confusing as a name in a long-lived context and we can get rid of the awkward scalar dereferencing by using $self. --- diff --git a/lib/PublicInbox/ExtSearchIdx.pm b/lib/PublicInbox/ExtSearchIdx.pm index 970d5eb31..ebbb2af13 100644 --- a/lib/PublicInbox/ExtSearchIdx.pm +++ b/lib/PublicInbox/ExtSearchIdx.pm @@ -349,7 +349,7 @@ sub index_oid { # git->cat_async callback for 'm' blob => $oid, }, 'PublicInbox::Smsg'; $new_smsg->set_bytes($$bref, $size); - ++${$req->{nr}}; + ++$self->{nrec}; my $mismatch = []; $req->{xnum} = cur_ibx_xnum($req, $bref, $mismatch) // do { warn "# deleted\n"; @@ -397,7 +397,7 @@ sub _sync_inbox ($$$) { return "W: skipping $ekey ($err)"; } $sync->{ibx} = $ibx; - $sync->{nr} = \(my $nr = 0); + $self->{nrec} = 0; my $v = $ibx->version; if ($v == 2) { $sync->{epoch_max} = $ibx->max_git_epoch // return; @@ -528,10 +528,8 @@ sub eidx_gc { # top-level entry point $opt->{-idx_gc} = 1; local $self->{checkpoint_unlocks} = 1; local $self->{need_checkpoint} = 0; - my $sync = { - -opt => $opt, - self => $self, - }; + local $self->{nrec}; + my $sync = { -opt => $opt, self => $self }; $self->idx_init($opt); # acquire lock via V2Writable::_idx_init eidx_gc_scan_inboxes($self, $sync); eidx_gc_scan_shards($self, $sync); @@ -793,7 +791,7 @@ sub eidxq_process ($$) { # for reindexing return unless ($self->{cfg} && eidxq_lock_acquire($self)); my $dbh = $self->{oidx}->dbh; my $tot = $dbh->selectrow_array('SELECT COUNT(*) FROM eidxq') or return; - ${$sync->{nr}} = 0; + $self->{nrec} = 0; local $sync->{-regen_fmt} = "%u/$tot\n"; my $pr = $sync->{-opt}->{-progress}; if ($pr) { @@ -815,7 +813,7 @@ restart: warn "E: #$docid does not exist in over\n"; } $del->execute($docid); - ++${$sync->{nr}}; + ++$self->{nrec}; if (update_checkpoint $self) { $dbh = $del = $iter = undef; @@ -825,7 +823,7 @@ restart: } } $self->git->async_wait_all; - $pr->("reindexed ${$sync->{nr}}/$tot\n") if $pr; + $pr->("reindexed $self->{nrec}/$tot\n") if $pr; } sub _reindex_unseen { # git->cat_async callback @@ -900,12 +898,12 @@ sub _reindex_check_ibx ($$$) { my $msgs; my $pr = $sync->{-opt}->{-progress}; local $sync->{-regen_fmt} = "$ekey checking %u/$max\n"; - ${$sync->{nr}} = 0; + $self->{nrec} = 0; my $fast = $sync->{-opt}->{fast}; my $usr; # _unref_stale_range (< $lo) called my ($lo, $hi); while (scalar(@{$msgs = $ibx->over->query_xover($beg, $end, $opt)})) { - ${$sync->{nr}} = $beg; + $self->{nrec} = $beg; $beg = $msgs->[-1]->{num} + 1; $end = $beg + $slice; $end = $max if $end > $max; @@ -1067,7 +1065,7 @@ EOS while (my ($mid, $id) = $iter->fetchrow_array) { last if $sync->{quit}; $self->{current_info} = "dedupe $mid"; - ${$sync->{nr}} = $min_id = $id; + $self->{nrec} = $min_id = $id; my ($prv, @smsg); while (my $x = $self->{oidx}->next_by_mid($mid, \$id, \$prv)) { push @smsg, $x; @@ -1105,7 +1103,7 @@ EOS if (my $pr = $sync->{-opt}->{-progress}) { $pr->("culled $n/$candidates candidates ($nr_mid msgids)\n"); } - ${$sync->{nr}} = 0; + $self->{nrec} = 0; } sub eidx_sync { # main entry point @@ -1116,6 +1114,7 @@ sub eidx_sync { # main entry point $self->idx_init($opt); # acquire lock via V2Writable::_idx_init $self->{oidx}->rethread_prepare($opt); local $self->{need_checkpoint} = 0; + local $self->{nrec} = 0; my $sync = { -opt => $opt, # DO NOT SET {reindex} here, it's incompatible with reused diff --git a/lib/PublicInbox/SearchIdx.pm b/lib/PublicInbox/SearchIdx.pm index 8ac8cac31..34df5c90c 100644 --- a/lib/PublicInbox/SearchIdx.pm +++ b/lib/PublicInbox/SearchIdx.pm @@ -801,7 +801,6 @@ sub update_checkpoint ($;$) { sub index_both { # git->cat_async callback my ($bref, $oid, $type, $size, $sync) = @_; return if is_bad_blob($oid, $type, $size, $sync->{oid}); - ++${$sync->{nr}}; my $smsg = bless { blob => $oid }, 'PublicInbox::Smsg'; $smsg->set_bytes($$bref, $size); my $self = $sync->{sidx}; @@ -812,6 +811,7 @@ sub index_both { # git->cat_async callback die "E: could not generate NNTP article number for $oid"; add_message($self, $eml, $smsg, $sync); ++$self->{nidx}; + ++$self->{nrec}; my $cur_cmt = $sync->{cur_cmt} // die 'BUG: {cur_cmt} missing'; ${$sync->{latest_cmt}} = $cur_cmt; } @@ -891,11 +891,11 @@ sub v1_checkpoint ($$;$) { } commit_txn_lazy($self); $sync->{ibx}->git->cleanup; - my $nr = ${$sync->{nr}}; - idx_release($self, $nr); + my $nrec = $self->{nrec}; + idx_release($self, $nrec); # let another process do some work... if (my $pr = $sync->{-opt}->{-progress}) { - $pr->("indexed $nr/$sync->{ntodo}\n") if $nr; + $pr->("indexed $nrec/$sync->{ntodo}\n") if $nrec; } if (!$stk && !$sync->{quit}) { # more to come begin_txn_lazy($self); @@ -909,8 +909,7 @@ sub v1_checkpoint ($$;$) { sub process_stack { my ($self, $sync, $stk) = @_; my $git = $sync->{ibx}->git; - my $nr = 0; - $sync->{nr} = \$nr; + $self->{nrec} = 0; $sync->{sidx} = $self; local $self->{need_checkpoint} = 0; $sync->{latest_cmt} = \(my $latest_cmt); diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm index 61c41b605..dd3258f39 100644 --- a/lib/PublicInbox/V2Writable.pm +++ b/lib/PublicInbox/V2Writable.pm @@ -711,7 +711,7 @@ sub reindex_checkpoint ($$) { } if (my $pr = $sync->{-regen_fmt} ? $sync->{-opt}->{-progress} : undef) { - $pr->(sprintf($sync->{-regen_fmt}, ${$sync->{nr}})); + $pr->(sprintf $sync->{-regen_fmt}, $self->{nrec}); } # allow -watch or -mda to write... @@ -803,7 +803,7 @@ sub index_oid { # cat_async callback warn "E: $oid <", join('> <', @$mids), "> is a duplicate\n"; return; } - ++${$arg->{nr}}; + ++$self->{nrec}; my $smsg = bless { num => $num, blob => $oid, @@ -994,7 +994,7 @@ sub sync_prepare ($$) { # 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"; - $sync->{nr} = \(my $nr = 0); + $self->{nrec} = 0; return -1 if $sync->{reindex}; $regen_max + $self->artnum_max || 0; } @@ -1115,7 +1115,7 @@ sub index_xap_step ($$$;$) { # have timeout problems like SQLite my $n = $self->{transact_bytes} += $smsg->{bytes}; if ($n >= $self->{batch_bytes}) { - ${$sync->{nr}} = $num; + $self->{nrec} = $num; reindex_checkpoint($self, $sync); } } @@ -1179,7 +1179,6 @@ sub xapian_only { $sync //= { -opt => $opt, self => $self, - nr => \(my $nr = 0), -regen_fmt => "%u/?\n", }; $sync->{art_end} = $art_end; @@ -1206,6 +1205,7 @@ sub index_sync { my ($self, $opt) = @_; $opt //= {}; local $self->{need_checkpoint} = 0; + local $self->{nrec} = 0; return xapian_only($self, $opt) if $opt->{xapian_only}; my $epoch_max = $self->{ibx}->max_git_epoch // return; @@ -1262,9 +1262,9 @@ sub index_sync { $self->{oidx}->rethread_done($opt) unless $sync->{quit}; $self->done; - if (my $nr = $sync->{nr}) { + if (my $nrec = $self->{nrec}) { my $pr = $sync->{-opt}->{-progress}; - $pr->('all.git '.sprintf($sync->{-regen_fmt}, $$nr)) if $pr; + $pr->('all.git '.sprintf($sync->{-regen_fmt}, $nrec)) if $pr; } my $quit_warn;