about summary refs log tree commit homepage
path: root/lib/PublicInbox/SearchIdxShard.pm
diff options
authorEric Wong <e@yhbt.net>2020-03-28 00:56:03 +0000
committerEric Wong <e@yhbt.net>2020-03-29 23:28:28 +0000
commit8e1ec8836dabc58dfc0115b36ed440b4371b70d7 (patch)
tree49746b343d3570a858fbde12d46be26253c9597d /lib/PublicInbox/SearchIdxShard.pm
parent6d6c6d27dd3ecafd523962dff2170d48a71680cf (diff)
For sharded v2 repositories with few-enough messages, it is
possible for shard[0] to go unused and never trigger the
->commit_txn_lazy to set the indexlevel field in Xapian

So set it immediately at initialization and avoid this case.
While we're at it, avoid triggering needless pwrite syscalls
from ->set_metadata by checking with ->get_metadata, first.
Diffstat (limited to 'lib/PublicInbox/SearchIdxShard.pm')
1 files changed, 3 insertions, 1 deletions
diff --git a/lib/PublicInbox/SearchIdxShard.pm b/lib/PublicInbox/SearchIdxShard.pm
index 2b48b1b4..1ea01095 100644
--- a/lib/PublicInbox/SearchIdxShard.pm
+++ b/lib/PublicInbox/SearchIdxShard.pm
@@ -11,9 +11,11 @@ use IO::Handle (); # autoflush
 sub new {
         my ($class, $v2writable, $shard) = @_;
-        my $self = $class->SUPER::new($v2writable->{-inbox}, 1, $shard);
+        my $ibx = $v2writable->{-inbox};
+        my $self = $class->SUPER::new($ibx, 1, $shard);
         # create the DB before forking:
+        $self->set_indexlevel;
         $self->spawn_worker($v2writable, $shard) if $v2writable->{parallel};