about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2023-04-07 12:40:49 +0000
committerEric Wong <e@80x24.org>2023-04-07 22:17:20 +0000
commitd384871de4593676fe653b0966117925883648f9 (patch)
treecf82aef75f5a43eb4e7a2f54bcfeec3bbdfe74cd /lib
parent3eb53b197cff2ad12cb585a7e40e9ac74f1ac54d (diff)
downloadpublic-inbox-d384871de4593676fe653b0966117925883648f9.tar.gz
This matches the behavior of mail indexers and ensures `medium'
indices don't grow unexpectedly to be come `full' indices.
Diffstat (limited to 'lib')
-rw-r--r--lib/PublicInbox/CodeSearchIdx.pm15
-rw-r--r--lib/PublicInbox/SearchIdx.pm2
2 files changed, 14 insertions, 3 deletions
diff --git a/lib/PublicInbox/CodeSearchIdx.pm b/lib/PublicInbox/CodeSearchIdx.pm
index 5f20325a..3a3fc03e 100644
--- a/lib/PublicInbox/CodeSearchIdx.pm
+++ b/lib/PublicInbox/CodeSearchIdx.pm
@@ -85,7 +85,6 @@ sub new {
                 xpfx => "$dir/cidx".  PublicInbox::CodeSearch::CIDX_SCHEMA_VER,
                 cidx_dir => $dir,
                 creat => 1, # TODO: get rid of this, should be implicit
-                indexlevel => $l,
                 transact_bytes => 0, # for checkpoint
                 total_bytes => 0, # for lock_release
                 current_info => '',
@@ -617,16 +616,28 @@ sub cidx_init ($) {
         }
         $self->lock_acquire;
         my @shards;
+        my $l = $self->{indexlevel} //= $self->{-opt}->{indexlevel};
+
         for my $n (0..($self->{nshard} - 1)) {
                 my $shard = bless { %$self, shard => $n }, ref($self);
                 delete @$shard{qw(lockfh lock_path)};
-                $shard->idx_acquire;
+                my $xdb = $shard->idx_acquire;
+                if (!$n) {
+                        if (($l // '') eq 'medium') {
+                                $xdb->set_metadata('indexlevel', $l);
+                        } elsif (($l // '') eq 'full') {
+                                $xdb->set_metadata('indexlevel', ''); # unset
+                        }
+                        $l ||= $xdb->get_metadata('indexlevel') || 'full';
+                }
+                $shard->{indexlevel} = $l;
                 $shard->idx_release;
                 $shard->wq_workers_start("cidx shard[$n]", 1, $SIGSET, {
                         siblings => \@shards, # for ipc_atfork_child
                 }, \&shard_done_wait, $self);
                 push @shards, $shard;
         }
+        $self->{indexlevel} //= $l;
         # this warning needs to happen after idx_acquire
         state $once;
         warn <<EOM if $PublicInbox::Search::X{CLOEXEC_UNSET} && !$once++;
diff --git a/lib/PublicInbox/SearchIdx.pm b/lib/PublicInbox/SearchIdx.pm
index f36c8f97..699af432 100644
--- a/lib/PublicInbox/SearchIdx.pm
+++ b/lib/PublicInbox/SearchIdx.pm
@@ -90,7 +90,7 @@ sub new {
         $self;
 }
 
-sub need_xapian ($) { $_[0]->{indexlevel} =~ $xapianlevels }
+sub need_xapian ($) { ($_[0]->{indexlevel} // 'full') =~ $xapianlevels }
 
 sub idx_release {
         my ($self, $wake) = @_;