]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
xcpdb: preserve indexlevel for extindex
authorEric Wong <e@80x24.org>
Wed, 26 Apr 2023 00:49:29 +0000 (00:49 +0000)
committerEric Wong <e@80x24.org>
Wed, 26 Apr 2023 19:09:58 +0000 (19:09 +0000)
This likely fixes indexlevel preservation for some v2 on some
systems, too, since (apparently) we need to sort shards
numerically to get Xapian metadata working properly on a
combined (multi-shard) Xapian DB.

lib/PublicInbox/Xapcmd.pm
t/extsearch.t

index c87baa7bbe74f7c067e7b442a55b2992c6520459..3a4c5622ea150cbbe61e2903716b6bc0c0183332 100644 (file)
@@ -219,7 +219,7 @@ sub prepare_run {
                my @old_shards;
                while (defined(my $dn = readdir($dh))) {
                        if ($dn =~ /\A[0-9]+\z/) {
-                               push @old_shards, $dn;
+                               push(@old_shards, $dn + 0);
                        } elsif ($dn eq '.' || $dn eq '..') {
                        } elsif ($dn =~ /\Aover\.sqlite3/) {
                        } elsif ($dn eq 'misc' && $misc_ok) {
@@ -228,7 +228,7 @@ sub prepare_run {
                        }
                }
                die "No Xapian shards found in $old\n" unless @old_shards;
-
+               @old_shards = sort { $a <=> $b } @old_shards;
                my ($src, $max_shard);
                if (!defined($reshard) || $reshard == scalar(@old_shards)) {
                        # 1:1 copy
@@ -464,11 +464,10 @@ sub cpdb ($$) { # cb_spawn callback
                        $dst->set_metadata('last_commit', $lc) if $lc;
 
                        # only the first xapian shard (0) gets 'indexlevel'
-                       if ($new =~ m!(?:xapian[0-9]+|xap[0-9]+/0)\b!) {
+                       if ($new =~ m!/(?:xapian[0-9]+|(?:ei|xap)[0-9]+/0)\b!) {
                                my $l = $src->get_metadata('indexlevel');
-                               if ($l eq 'medium') {
+                               $l eq 'medium' and
                                        $dst->set_metadata('indexlevel', $l);
-                               }
                        }
                        if ($pr_data) {
                                my $tot = $src->get_doccount;
index 03bcad95ee5b162bcddb922bb640d6565a49f46c..8cbd26f07a3f451d73a9913de9b834ef2965c0da 100644 (file)
@@ -1,8 +1,7 @@
 #!perl -w
 # Copyright (C) all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
-use strict;
-use Test::More;
+use v5.12;
 use PublicInbox::TestCommon;
 use PublicInbox::Config;
 use PublicInbox::InboxWritable;
@@ -554,4 +553,32 @@ EOM
        is_deeply($x, $o, 'xref3 and over docids match');
 }
 
+{
+       my $d = "$home/eidx-med";
+       ok(run_script([qw(-extindex --dangerous --all -L medium -j3), $d]),
+               'extindex medium init');
+       my $es = PublicInbox::ExtSearch->new($d);
+       is($es->xdb->get_metadata('indexlevel'), 'medium',
+               'es indexlevel before');
+       my @xdb = $es->xdb_shards_flat;
+       is($xdb[0]->get_metadata('indexlevel'), 'medium',
+               '0 indexlevel before');
+       shift @xdb;
+       for (@xdb) {
+               ok(!$_->get_metadata('indexlevel'), 'no indexlevel in >0 shard')
+       }
+       is($es->xdb->get_metadata('indexlevel'), 'medium', 'indexlevel before');
+       ok(run_script([qw(-xcpdb -R5), $d]), 'xcpdb R5');
+       $es = PublicInbox::ExtSearch->new($d);
+       is($es->xdb->get_metadata('indexlevel'), 'medium',
+               '0 indexlevel after');
+       @xdb = $es->xdb_shards_flat;
+       is(scalar(@xdb), 5, 'got 5 shards');
+       is($xdb[0]->get_metadata('indexlevel'), 'medium', '0 indexlevel after');
+       shift @xdb;
+       for (@xdb) {
+               ok(!$_->get_metadata('indexlevel'), 'no indexlevel in >0 shard')
+       }
+}
+
 done_testing;