]> Sergey Matveev's repositories - public-inbox.git/commitdiff
v2writable: detect shard count for ExtSearchIdx properly
authorEric Wong <e@80x24.org>
Sun, 29 Nov 2020 05:09:34 +0000 (05:09 +0000)
committerEric Wong <e@80x24.org>
Sun, 29 Nov 2020 06:41:59 +0000 (06:41 +0000)
Otherwise, any explicitly set shard counts were ignored and
we'd be counting CPUs every single time.

lib/PublicInbox/V2Writable.pm

index a3938b5628f854ea1508b7063623c312dcf2a4f1..e9a4300072846d70e1376fe978405b508c55dbc9 100644 (file)
@@ -65,13 +65,21 @@ sub nproc_shards ($) {
 
 sub count_shards ($) {
        my ($self) = @_;
-       $self->{ibx} ? do {
+       if (my $ibx = $self->{ibx}) {
                # always load existing shards in case core count changes:
                # Also, shard count may change while -watch is running
-               my $srch = $self->{ibx}->search or return 0;
-               delete $self->{ibx}->{search};
+               my $srch = $ibx->search or return 0;
+               delete $ibx->{search};
                $srch->{nshard} // 0
-       } : $self->{nshard}; # self->{nshard} is for ExtSearchIdx
+       } else { # ExtSearchIdx
+               $self->{nshard} // do {
+                       if ($self->xdb_sharded) {
+                               $self->{nshard} // die 'BUG: {nshard} unset';
+                       } else {
+                               0;
+                       }
+               }
+       }
 }
 
 sub new {