]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/V2Writable.pm
v2writable: convert some fatal reindex errors to warnings
[public-inbox.git] / lib / PublicInbox / V2Writable.pm
index 4e7d6de1d132717712cdf5916a3b6d3268367554..269b028f5373a9fb1e99ed7c2b8166c438c6d111 100644 (file)
@@ -67,7 +67,9 @@ sub init_inbox {
        my ($self, $parallel) = @_;
        $self->{parallel} = $parallel;
        $self->idx_init;
-       $self->git_init(0);
+       my $max_git = -1;
+       git_dir_latest($self, \$max_git);
+       $self->git_init($max_git >= 0 ? $max_git : 0);
        $self->done;
 }
 
@@ -550,7 +552,7 @@ sub reindex_oid {
                $num = $$regen--;
                die "BUG: ran out of article numbers\n" if $num <= 0;
                my $mm = $self->{skel}->{mm};
-               foreach my $mid (@$mids) {
+               foreach my $mid (reverse @$mids) {
                        if ($mm->mid_set($num, $mid) == 1) {
                                $mid0 = $mid;
                                last;
@@ -558,7 +560,11 @@ sub reindex_oid {
                }
                if (!defined($mid0)) {
                        my $id = '<' . join('> <', @$mids) . '>';
-                       warn "Message-Id $id unusable for $num\n";
+                       warn "Message-ID $id unusable for $num\n";
+                       foreach my $mid (@$mids) {
+                               defined(my $n = $mm->num_for($mid)) or next;
+                               warn "#$n previously mapped for <$mid>\n";
+                       }
                }
        }
 
@@ -621,6 +627,7 @@ sub reindex {
                for (my $cur = $max_git; $cur >= 0; $cur--) {
                        die "already reindexing!\n" if $self->{reindex_pipe};
                        my $git = PublicInbox::Git->new("$pfx/$cur.git");
+                       -d $git->{git_dir} or next; # missing parts are fine
                        chomp($tip = $git->qx('rev-parse', $head)) unless $tip;
                        my $h = $cur == $max_git ? $tip : $head;
                        my @count = ('rev-list', '--count', $h, '--', 'm');
@@ -642,6 +649,7 @@ sub reindex {
                die "already reindexing!\n" if delete $self->{reindex_pipe};
                my $cmt;
                my $git_dir = "$pfx/$cur.git";
+               -d $git_dir or next; # missing parts are fine
                my $git = PublicInbox::Git->new($git_dir);
                my $h = $cur == $max_git ? $tip : $head;
                my $fh = $self->{reindex_pipe} = $git->popen(@cmd, $h);
@@ -657,8 +665,17 @@ sub reindex {
                }
                delete $self->{reindex_pipe};
        }
+       my $gaps;
+       if ($regen && $$regen != 0) {
+               warn "W: leftover article number ($$regen)\n";
+               $gaps = 1;
+       }
        my ($min, $max) = $mm_tmp->minmax;
-       defined $max and die "leftover article numbers at $min..$max\n";
+       if (defined $max) {
+               warn "W: leftover article numbers at $min..$max\n";
+               $gaps = 1;
+       }
+       warn "W: were old git partitions deleted?\n" if $gaps;
        my @d = sort keys %$D;
        if (@d) {
                warn "BUG: ", scalar(@d)," unseen deleted messages marked\n";