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