]> Sergey Matveev's repositories - public-inbox.git/blob - lib/PublicInbox/V2Writable.pm
v2writable: convert some fatal reindex errors to warnings
[public-inbox.git] / lib / PublicInbox / V2Writable.pm
1 # Copyright (C) 2018 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
3
4 # This interface wraps and mimics PublicInbox::Import
5 package PublicInbox::V2Writable;
6 use strict;
7 use warnings;
8 use base qw(PublicInbox::Lock);
9 use PublicInbox::SearchIdxPart;
10 use PublicInbox::SearchIdxSkeleton;
11 use PublicInbox::MIME;
12 use PublicInbox::Git;
13 use PublicInbox::Import;
14 use PublicInbox::MID qw(mids);
15 use PublicInbox::ContentId qw(content_id content_digest);
16 use PublicInbox::Inbox;
17
18 # an estimate of the post-packed size to the raw uncompressed size
19 my $PACKING_FACTOR = 0.4;
20
21 # assume 2 cores if GNU nproc(1) is not available
22 sub nproc () {
23         int($ENV{NPROC} || `nproc 2>/dev/null` || 2);
24 }
25
26 sub new {
27         my ($class, $v2ibx, $creat) = @_;
28         my $dir = $v2ibx->{mainrepo} or die "no mainrepo in inbox\n";
29         unless (-d $dir) {
30                 if ($creat) {
31                         require File::Path;
32                         File::Path::mkpath($dir);
33                 } else {
34                         die "$dir does not exist\n";
35                 }
36         }
37
38         my $nparts = 0;
39         my $xpfx = "$dir/xap" . PublicInbox::Search::SCHEMA_VERSION;
40
41         # always load existing partitions in case core count changes:
42         if (-d $xpfx) {
43                 foreach my $part (<$xpfx/*>) {
44                         -d $part && $part =~ m!/\d+\z! or next;
45                         eval {
46                                 Search::Xapian::Database->new($part)->close;
47                                 $nparts++;
48                         };
49                 }
50         }
51         $nparts = nproc() if ($nparts == 0);
52
53         my $self = {
54                 -inbox => $v2ibx,
55                 im => undef, #  PublicInbox::Import
56                 partitions => $nparts,
57                 parallel => 1,
58                 transact_bytes => 0,
59                 lock_path => "$dir/inbox.lock",
60                 # limit each repo to 1GB or so
61                 rotate_bytes => int((1024 * 1024 * 1024) / $PACKING_FACTOR),
62         };
63         bless $self, $class;
64 }
65
66 sub init_inbox {
67         my ($self, $parallel) = @_;
68         $self->{parallel} = $parallel;
69         $self->idx_init;
70         my $max_git = -1;
71         git_dir_latest($self, \$max_git);
72         $self->git_init($max_git >= 0 ? $max_git : 0);
73         $self->done;
74 }
75
76 # returns undef on duplicate or spam
77 # mimics Import::add and wraps it for v2
78 sub add {
79         my ($self, $mime, $check_cb) = @_;
80
81         # spam check:
82         if ($check_cb) {
83                 $mime = $check_cb->($mime) or return;
84         }
85
86         # All pipes (> $^F) known to Perl 5.6+ have FD_CLOEXEC set,
87         # as does SQLite 3.4.1+ (released in 2007-07-20), and
88         # Xapian 1.3.2+ (released 2015-03-15).
89         # For the most part, we can spawn git-fast-import without
90         # leaking FDs to it...
91         $self->idx_init;
92
93         my $mid0;
94         my $num = num_for($self, $mime, \$mid0);
95         defined $num or return; # duplicate
96         defined $mid0 or die "BUG: $mid0 undefined\n";
97         my $im = $self->importer;
98         my $cmt = $im->add($mime);
99         $cmt = $im->get_mark($cmt);
100         my ($oid, $len, $msgref) = @{$im->{last_object}};
101
102         my $nparts = $self->{partitions};
103         my $part = $num % $nparts;
104         my $idx = $self->idx_part($part);
105         $idx->index_raw($len, $msgref, $num, $oid, $mid0, $mime);
106         my $n = $self->{transact_bytes} += $len;
107         if ($n > (PublicInbox::SearchIdx::BATCH_BYTES * $nparts)) {
108                 $self->checkpoint;
109         }
110
111         $mime;
112 }
113
114 sub num_for {
115         my ($self, $mime, $mid0) = @_;
116         my $mids = mids($mime->header_obj);
117         if (@$mids) {
118                 my $mid = $mids->[0];
119                 my $num = $self->{skel}->{mm}->mid_insert($mid);
120                 if (defined $num) { # common case
121                         $$mid0 = $mid;
122                         return $num;
123                 };
124
125                 # crap, Message-ID is already known, hope somebody just resent:
126                 $self->barrier;
127                 foreach my $m (@$mids) {
128                         # read-only lookup now safe to do after above barrier
129                         my $existing = $self->lookup_content($mime, $m);
130                         # easy, don't store duplicates
131                         # note: do not add more diagnostic info here since
132                         # it gets noisy on public-inbox-watch restarts
133                         return if $existing;
134                 }
135
136                 # very unlikely:
137                 warn "<$mid> reused for mismatched content\n";
138
139                 # try the rest of the mids
140                 foreach my $i (1..$#$mids) {
141                         my $m = $mids->[$i];
142                         $num = $self->{skel}->{mm}->mid_insert($m);
143                         if (defined $num) {
144                                 warn "alternative <$m> for <$mid> found\n";
145                                 $$mid0 = $m;
146                                 return $num;
147                         }
148                 }
149         }
150         # none of the existing Message-IDs are good, generate a new one:
151         num_for_harder($self, $mime, $mid0);
152 }
153
154 sub num_for_harder {
155         my ($self, $mime, $mid0) = @_;
156
157         my $hdr = $mime->header_obj;
158         my $dig = content_digest($mime);
159         $$mid0 = PublicInbox::Import::digest2mid($dig);
160         my $num = $self->{skel}->{mm}->mid_insert($$mid0);
161         unless (defined $num) {
162                 # it's hard to spoof the last Received: header
163                 my @recvd = $hdr->header_raw('Received');
164                 $dig->add("Received: $_") foreach (@recvd);
165                 $$mid0 = PublicInbox::Import::digest2mid($dig);
166                 $num = $self->{skel}->{mm}->mid_insert($$mid0);
167
168                 # fall back to a random Message-ID and give up determinism:
169                 until (defined($num)) {
170                         $dig->add(rand);
171                         $$mid0 = PublicInbox::Import::digest2mid($dig);
172                         warn "using random Message-ID <$$mid0> as fallback\n";
173                         $num = $self->{skel}->{mm}->mid_insert($$mid0);
174                 }
175         }
176         PublicInbox::Import::append_mid($hdr, $$mid0);
177         $num;
178 }
179
180 sub idx_part {
181         my ($self, $part) = @_;
182         $self->{idx_parts}->[$part];
183 }
184
185 # idempotent
186 sub idx_init {
187         my ($self) = @_;
188         return if $self->{idx_parts};
189         my $ibx = $self->{-inbox};
190
191         # do not leak read-only FDs to child processes, we only have these
192         # FDs for duplicate detection so they should not be
193         # frequently activated.
194         delete $ibx->{$_} foreach (qw(git mm search));
195
196         $self->lock_acquire;
197
198         # first time initialization, first we create the skeleton pipe:
199         my $skel = $self->{skel} = PublicInbox::SearchIdxSkeleton->new($self);
200
201         # need to create all parts before initializing msgmap FD
202         my $max = $self->{partitions} - 1;
203         my $idx = $self->{idx_parts} = [];
204         for my $i (0..$max) {
205                 push @$idx, PublicInbox::SearchIdxPart->new($self, $i, $skel);
206         }
207
208         # Now that all subprocesses are up, we can open the FD for SQLite:
209         $skel->_msgmap_init->{dbh}->begin_work;
210 }
211
212 sub purge_oids {
213         my ($self, $purge) = @_; # $purge = { $object_id => 1, ... }
214         $self->done;
215         my $pfx = "$self->{-inbox}->{mainrepo}/git";
216         foreach my $i (0..$self->{max_git}) {
217                 my $git = PublicInbox::Git->new("$pfx/$i.git");
218                 my $im = $self->import_init($git, 0);
219                 $im->purge_oids($purge);
220         }
221 }
222
223 sub remove_internal {
224         my ($self, $mime, $cmt_msg, $purge) = @_;
225         $self->barrier;
226         $self->idx_init;
227         my $im = $self->importer unless $purge;
228         my $ibx = $self->{-inbox};
229         my $srch = $ibx->search;
230         my $cid = content_id($mime);
231         my $skel = $self->{skel};
232         my $parts = $self->{idx_parts};
233         my $mm = $skel->{mm};
234         my $removed;
235         my $mids = mids($mime->header_obj);
236
237         # We avoid introducing new blobs into git since the raw content
238         # can be slightly different, so we do not need the user-supplied
239         # message now that we have the mids and content_id
240         $mime = undef;
241
242         foreach my $mid (@$mids) {
243                 $srch->reopen->each_smsg_by_mid($mid, sub {
244                         my ($smsg) = @_;
245                         $smsg->load_expand;
246                         my $msg = $ibx->msg_by_smsg($smsg);
247                         if (!defined($msg)) {
248                                 warn "broken smsg for $mid\n";
249                                 return 1; # continue
250                         }
251                         my $orig = $$msg;
252                         my $cur = PublicInbox::MIME->new($msg);
253                         if (content_id($cur) eq $cid) {
254                                 $mm->num_delete($smsg->num);
255                                 # $removed should only be set once assuming
256                                 # no bugs in our deduplication code:
257                                 $removed = $smsg;
258                                 $removed->{mime} = $cur;
259                                 my $oid = $smsg->{blob};
260                                 if ($purge) {
261                                         $purge->{$oid} = 1;
262                                 } else {
263                                         $im->remove(\$orig, $cmt_msg);
264                                 }
265                                 $orig = undef;
266                                 $removed->num; # memoize this for callers
267
268                                 foreach my $idx (@$parts, $skel) {
269                                         $idx->remote_remove($oid, $mid);
270                                 }
271                         }
272                         1; # continue
273                 });
274                 $self->barrier;
275         }
276         if ($purge && scalar keys %$purge) {
277                 purge_oids($self, $purge);
278         }
279         $removed;
280 }
281
282 sub remove {
283         my ($self, $mime, $cmt_msg) = @_;
284         remove_internal($self, $mime, $cmt_msg);
285 }
286
287 sub purge {
288         my ($self, $mime) = @_;
289         remove_internal($self, $mime, undef, {});
290 }
291
292
293 sub done {
294         my ($self) = @_;
295         my $locked = defined $self->{idx_parts};
296         my $im = delete $self->{im};
297         $im->done if $im; # PublicInbox::Import::done
298         $self->searchidx_checkpoint(0);
299         $self->lock_release if $locked;
300 }
301
302 sub checkpoint {
303         my ($self) = @_;
304         my $im = $self->{im};
305         $im->checkpoint if $im; # PublicInbox::Import::checkpoint
306         $self->searchidx_checkpoint(1);
307 }
308
309 # issue a write barrier to ensure all data is visible to other processes
310 # and read-only ops.  Order of data importance is: git > SQLite > Xapian
311 sub barrier {
312         my ($self) = @_;
313
314         if (my $im = $self->{im}) {
315                 $im->barrier;
316         }
317         my $skel = $self->{skel};
318         my $parts = $self->{idx_parts};
319         if ($parts && $skel) {
320                 my $dbh = $skel->{mm}->{dbh};
321                 $dbh->commit; # SQLite data is second in importance
322
323                 # Now deal with Xapian
324                 $skel->barrier_init(scalar(@$parts));
325                 # each partition needs to issue a barrier command to skel:
326                 $_->remote_barrier foreach @$parts;
327
328                 $skel->barrier_wait; # wait for each Xapian partition
329
330                 $dbh->begin_work;
331         }
332         $self->{transact_bytes} = 0;
333 }
334
335 sub searchidx_checkpoint {
336         my ($self, $more) = @_;
337
338         # order matters, we can only close {skel} after all partitions
339         # are done because the partitions also write to {skel}
340         if (my $parts = $self->{idx_parts}) {
341                 foreach my $idx (@$parts) {
342                         $idx->remote_commit; # propagates commit to skel
343                         $idx->remote_close unless $more;
344                 }
345                 delete $self->{idx_parts} unless $more;
346         }
347
348         if (my $skel = $self->{skel}) {
349                 my $dbh = $skel->{mm}->{dbh};
350                 $dbh->commit;
351                 if ($more) {
352                         $dbh->begin_work;
353                 } else {
354                         $skel->remote_close;
355                         delete $self->{skel};
356                 }
357         }
358         $self->{transact_bytes} = 0;
359 }
360
361 sub git_init {
362         my ($self, $new) = @_;
363         my $pfx = "$self->{-inbox}->{mainrepo}/git";
364         my $git_dir = "$pfx/$new.git";
365         my @cmd = (qw(git init --bare -q), $git_dir);
366         PublicInbox::Import::run_die(\@cmd);
367
368         my $all = "$self->{-inbox}->{mainrepo}/all.git";
369         unless (-d $all) {
370                 @cmd = (qw(git init --bare -q), $all);
371                 PublicInbox::Import::run_die(\@cmd);
372                 @cmd = (qw/git config/, "--file=$all/config",
373                                 'repack.writeBitmaps', 'true');
374                 PublicInbox::Import::run_die(\@cmd);
375         }
376
377         @cmd = (qw/git config/, "--file=$git_dir/config",
378                         'include.path', '../../all.git/config');
379         PublicInbox::Import::run_die(\@cmd);
380
381         my $alt = "$all/objects/info/alternates";
382         my $new_obj_dir = "../../git/$new.git/objects";
383         my %alts;
384         if (-e $alt) {
385                 open(my $fh, '<', $alt) or die "open < $alt: $!\n";
386                 %alts = map { chomp; $_ => 1 } (<$fh>);
387         }
388         return $git_dir if $alts{$new_obj_dir};
389         open my $fh, '>>', $alt or die "open >> $alt: $!\n";
390         print $fh "$new_obj_dir\n" or die "print >> $alt: $!\n";
391         close $fh or die "close $alt: $!\n";
392         $git_dir
393 }
394
395 sub git_dir_latest {
396         my ($self, $max) = @_;
397         $$max = -1;
398         my $pfx = "$self->{-inbox}->{mainrepo}/git";
399         return unless -d $pfx;
400         my $latest;
401         opendir my $dh, $pfx or die "opendir $pfx: $!\n";
402         while (defined(my $git_dir = readdir($dh))) {
403                 $git_dir =~ m!\A(\d+)\.git\z! or next;
404                 if ($1 > $$max) {
405                         $$max = $1;
406                         $latest = "$pfx/$git_dir";
407                 }
408         }
409         $latest;
410 }
411
412 sub importer {
413         my ($self) = @_;
414         my $im = $self->{im};
415         if ($im) {
416                 if ($im->{bytes_added} < $self->{rotate_bytes}) {
417                         return $im;
418                 } else {
419                         $self->{im} = undef;
420                         $im->done;
421                         $self->searchidx_checkpoint(1);
422                         $im = undef;
423                         my $git_dir = $self->git_init(++$self->{max_git});
424                         my $git = PublicInbox::Git->new($git_dir);
425                         return $self->import_init($git, 0);
426                 }
427         }
428         my $new = 0;
429         my $max;
430         my $latest = git_dir_latest($self, \$max);
431         if (defined $latest) {
432                 my $git = PublicInbox::Git->new($latest);
433                 my $packed_bytes = $git->packed_bytes;
434                 if ($packed_bytes >= $self->{rotate_bytes}) {
435                         $new = $max + 1;
436                 } else {
437                         $self->{max_git} = $max;
438                         return $self->import_init($git, $packed_bytes);
439                 }
440         }
441         $self->{max_git} = $new;
442         $latest = $self->git_init($new);
443         $self->import_init(PublicInbox::Git->new($latest), 0);
444 }
445
446 sub import_init {
447         my ($self, $git, $packed_bytes) = @_;
448         my $im = PublicInbox::Import->new($git, undef, undef, $self->{-inbox});
449         $im->{bytes_added} = int($packed_bytes / $PACKING_FACTOR);
450         $im->{want_object_info} = 1;
451         $im->{lock_path} = undef;
452         $im->{path_type} = 'v2';
453         $self->{im} = $im;
454 }
455
456 # XXX experimental
457 sub diff ($$$) {
458         my ($mid, $cur, $new) = @_;
459         use File::Temp qw(tempfile);
460         use PublicInbox::Spawn qw(spawn);
461
462         my ($ah, $an) = tempfile('email-cur-XXXXXXXX', TMPDIR => 1);
463         print $ah $cur->as_string or die "print: $!";
464         close $ah or die "close: $!";
465         my ($bh, $bn) = tempfile('email-new-XXXXXXXX', TMPDIR => 1);
466         PublicInbox::Import::drop_unwanted_headers($new);
467         print $bh $new->as_string or die "print: $!";
468         close $bh or die "close: $!";
469         my $cmd = [ qw(diff -u), $an, $bn ];
470         print STDERR "# MID conflict <$mid>\n";
471         my $pid = spawn($cmd, undef, { 1 => 2 });
472         defined $pid or die "diff failed to spawn $!";
473         waitpid($pid, 0) == $pid or die "diff did not finish";
474         unlink($an, $bn);
475 }
476
477 sub lookup_content {
478         my ($self, $mime, $mid) = @_;
479         my $ibx = $self->{-inbox};
480
481         my $srch = $ibx->search->reopen;
482         my $cid = content_id($mime);
483         my $found;
484         $srch->each_smsg_by_mid($mid, sub {
485                 my ($smsg) = @_;
486                 $smsg->load_expand;
487                 my $msg = $ibx->msg_by_smsg($smsg);
488                 if (!defined($msg)) {
489                         warn "broken smsg for $mid\n";
490                         return 1; # continue
491                 }
492                 my $cur = PublicInbox::MIME->new($msg);
493                 if (content_id($cur) eq $cid) {
494                         $smsg->{mime} = $cur;
495                         $found = $smsg;
496                         return 0; # break out of loop
497                 }
498
499                 # XXX DEBUG_DIFF is experimental and may be removed
500                 diff($mid, $cur, $mime) if $ENV{DEBUG_DIFF};
501
502                 1; # continue
503         });
504         $found;
505 }
506
507 sub atfork_child {
508         my ($self) = @_;
509         my $fh = delete $self->{reindex_pipe};
510         close $fh if $fh;
511         if (my $parts = $self->{idx_parts}) {
512                 $_->atfork_child foreach @$parts;
513         }
514         if (my $im = $self->{im}) {
515                 $im->atfork_child;
516         }
517 }
518
519 sub mark_deleted {
520         my ($self, $D, $git, $oid) = @_;
521         my $msgref = $git->cat_file($oid);
522         my $mime = PublicInbox::MIME->new($$msgref);
523         my $mids = mids($mime->header_obj);
524         my $cid = content_id($mime);
525         foreach my $mid (@$mids) {
526                 $D->{"$mid\0$cid"} = 1;
527         }
528 }
529
530 sub reindex_oid {
531         my ($self, $mm_tmp, $D, $git, $oid, $regen) = @_;
532         my $len;
533         my $msgref = $git->cat_file($oid, \$len);
534         my $mime = PublicInbox::MIME->new($$msgref);
535         my $mids = mids($mime->header_obj);
536         my $cid = content_id($mime);
537
538         # get the NNTP article number we used before, highest number wins
539         # and gets deleted from mm_tmp;
540         my $mid0;
541         my $num = -1;
542         my $del = 0;
543         foreach my $mid (@$mids) {
544                 $del += (delete $D->{"$mid\0$cid"} || 0);
545                 my $n = $mm_tmp->num_for($mid);
546                 if (defined $n && $n > $num) {
547                         $mid0 = $mid;
548                         $num = $n;
549                 }
550         }
551         if (!defined($mid0) && $regen && !$del) {
552                 $num = $$regen--;
553                 die "BUG: ran out of article numbers\n" if $num <= 0;
554                 my $mm = $self->{skel}->{mm};
555                 foreach my $mid (reverse @$mids) {
556                         if ($mm->mid_set($num, $mid) == 1) {
557                                 $mid0 = $mid;
558                                 last;
559                         }
560                 }
561                 if (!defined($mid0)) {
562                         my $id = '<' . join('> <', @$mids) . '>';
563                         warn "Message-ID $id unusable for $num\n";
564                         foreach my $mid (@$mids) {
565                                 defined(my $n = $mm->num_for($mid)) or next;
566                                 warn "#$n previously mapped for <$mid>\n";
567                         }
568                 }
569         }
570
571         if (!defined($mid0) || $del) {
572                 if (!defined($mid0) && $del) { # expected for deletes
573                         $$regen--;
574                         return
575                 }
576
577                 my $id = '<' . join('> <', @$mids) . '>';
578                 defined($mid0) or
579                         warn "Skipping $id, no article number found\n";
580                 if ($del && defined($mid0)) {
581                         warn "$id was deleted $del " .
582                                 "time(s) but mapped to article #$num\n";
583                 }
584                 return;
585
586         }
587         $mm_tmp->mid_delete($mid0) or
588                 die "failed to delete <$mid0> for article #$num\n";
589
590         my $nparts = $self->{partitions};
591         my $part = $num % $nparts;
592         my $idx = $self->idx_part($part);
593         $idx->index_raw($len, $msgref, $num, $oid, $mid0, $mime);
594         my $n = $self->{transact_bytes} += $len;
595         if ($n > (PublicInbox::SearchIdx::BATCH_BYTES * $nparts)) {
596                 $git->cleanup;
597                 $mm_tmp->atfork_prepare;
598                 $self->done; # release lock
599                 # allow -watch or -mda to write...
600                 $self->idx_init; # reacquire lock
601                 $mm_tmp->atfork_parent;
602         }
603 }
604
605 sub reindex {
606         my ($self, $regen) = @_;
607         my $ibx = $self->{-inbox};
608         my $pfx = "$ibx->{mainrepo}/git";
609         my $max_git;
610         my $latest = git_dir_latest($self, \$max_git);
611         return unless defined $latest;
612         my $head = $ibx->{ref_head} || 'refs/heads/master';
613         $self->idx_init; # acquire lock
614         my $x40 = qr/[a-f0-9]{40}/;
615         my $mm_tmp = $self->{skel}->{mm}->tmp_clone;
616         if (!$regen) {
617                 my (undef, $max) = $mm_tmp->minmax;
618                 unless (defined $max) {
619                         $regen = 1;
620                         warn
621 "empty msgmap.sqlite3, regenerating article numbers\n";
622                 }
623         }
624         my $tip; # latest commit out of all git repos
625         if ($regen) {
626                 my $regen_max = 0;
627                 for (my $cur = $max_git; $cur >= 0; $cur--) {
628                         die "already reindexing!\n" if $self->{reindex_pipe};
629                         my $git = PublicInbox::Git->new("$pfx/$cur.git");
630                         -d $git->{git_dir} or next; # missing parts are fine
631                         chomp($tip = $git->qx('rev-parse', $head)) unless $tip;
632                         my $h = $cur == $max_git ? $tip : $head;
633                         my @count = ('rev-list', '--count', $h, '--', 'm');
634                         $regen_max += $git->qx(@count);
635                 }
636                 die "No messages found in $pfx/*.git, bug?\n" unless $regen_max;
637                 $regen = \$regen_max;
638         }
639         my $D = {};
640         my @cmd = qw(log --raw -r --pretty=tformat:%h
641                         --no-notes --no-color --no-abbrev);
642
643         # if we are regenerating, we must not use a newer tip commit than what
644         # the regeneration counter used:
645         $tip ||= $head;
646
647         # work backwards through history
648         for (my $cur = $max_git; $cur >= 0; $cur--) {
649                 die "already reindexing!\n" if delete $self->{reindex_pipe};
650                 my $cmt;
651                 my $git_dir = "$pfx/$cur.git";
652                 -d $git_dir or next; # missing parts are fine
653                 my $git = PublicInbox::Git->new($git_dir);
654                 my $h = $cur == $max_git ? $tip : $head;
655                 my $fh = $self->{reindex_pipe} = $git->popen(@cmd, $h);
656                 while (<$fh>) {
657                         if (/\A$x40$/o) {
658                                 chomp($cmt = $_);
659                         } elsif (/\A:\d{6} 100644 $x40 ($x40) [AM]\tm$/o) {
660                                 $self->reindex_oid($mm_tmp, $D, $git, $1,
661                                                 $regen);
662                         } elsif (m!\A:\d{6} 100644 $x40 ($x40) [AM]\t_/D$!o) {
663                                 $self->mark_deleted($D, $git, $1);
664                         }
665                 }
666                 delete $self->{reindex_pipe};
667         }
668         my $gaps;
669         if ($regen && $$regen != 0) {
670                 warn "W: leftover article number ($$regen)\n";
671                 $gaps = 1;
672         }
673         my ($min, $max) = $mm_tmp->minmax;
674         if (defined $max) {
675                 warn "W: leftover article numbers at $min..$max\n";
676                 $gaps = 1;
677         }
678         warn "W: were old git partitions deleted?\n" if $gaps;
679         my @d = sort keys %$D;
680         if (@d) {
681                 warn "BUG: ", scalar(@d)," unseen deleted messages marked\n";
682                 foreach (@d) {
683                         my ($mid, undef) = split(/\0/, $_, 2);
684                         warn "<$mid>\n";
685                 }
686         }
687 }
688
689 1;