]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Xapcmd.pm
searchidx: store indexlevel=medium as metadata
[public-inbox.git] / lib / PublicInbox / Xapcmd.pm
index a294d539d292e564ef7d9733da90fe80430c2343..906723104d553d2cb25465c4dfd488e213914a0f 100644 (file)
@@ -22,6 +22,8 @@ sub commit_changes ($$$) {
        my $im = $ibx->importer(0);
        $im->lock_acquire if !$opt->{-coarse_lock};
 
+       $SIG{INT} or die 'BUG: $SIG{INT} not handled';
+
        while (my ($old, $new) = each %$tmp) {
                my @st = stat($old) or die "failed to stat($old): $!\n";
 
@@ -84,18 +86,6 @@ sub prepare_reindex ($$) {
        }
 }
 
-sub progress_prepare ($) {
-       my ($opt) = @_;
-       if ($opt->{quiet}) {
-               open my $null, '>', '/dev/null' or
-                       die "failed to open /dev/null: $!\n";
-               $opt->{1} = fileno($null);
-               $opt->{-dev_null} = $null;
-       } else {
-               $opt->{-progress} = sub { print STDERR @_ };
-       }
-}
-
 sub same_fs_or_die ($$) {
        my ($x, $y) = @_;
        return if ((stat($x))[0] == (stat($y))[0]); # 0 - st_dev
@@ -130,7 +120,7 @@ sub process_queue {
 sub run {
        my ($ibx, $task, $opt) = @_; # task = 'cpdb' or 'compact'
        my $cb = \&${\"PublicInbox::Xapcmd::$task"};
-       progress_prepare($opt ||= {});
+       PublicInbox::Admin::progress_prepare($opt ||= {});
        my $dir = $ibx->{mainrepo} or die "no mainrepo in inbox\n";
        runnable_or_die($XAPIAN_COMPACT) if $opt->{compact};
        my $reindex; # v1:{ from => $x40 }, v2:{ from => [ $x40, $x40, .. ] } }
@@ -285,6 +275,14 @@ sub cpdb ($$) {
                        my $lc = $src->get_metadata('last_commit');
                        $dst->set_metadata('last_commit', $lc) if $lc;
 
+                       # only the first xapian partition (0) gets 'indexlevel'
+                       if ($old =~ m!(?:xapian\d+|xap\d+/0)\z!) {
+                               my $l = $src->get_metadata('indexlevel');
+                               if ($l eq 'medium') {
+                                       $dst->set_metadata('indexlevel', $l);
+                               }
+                       }
+
                        $it = $src->postlist_begin('');
                        $end = $src->postlist_end('');
                        if ($pr) {
@@ -346,7 +344,12 @@ sub new {
 sub done {
        my ($self) = @_;
        delete $owner{"$self"};
-       $SIG{INT} = $SIG{HUP} = $SIG{PIPE} = $SIG{TERM} = 'DEFAULT';
+
+       my %known_pids;
+       $known_pids{$_}++ foreach values %owner;
+       if (!$known_pids{$$}) {
+               $SIG{INT} = $SIG{HUP} = $SIG{PIPE} = $SIG{TERM} = 'DEFAULT';
+       }
        %$self = ();
 }
 
@@ -357,7 +360,7 @@ sub DESTROY {
        foreach my $new (values %$self) {
                remove_tree($new) unless -d "$new/old";
        }
-       $SIG{INT} = $SIG{HUP} = $SIG{PIPE} = $SIG{TERM} = 'DEFAULT';
+       done($self);
 }
 
 1;