use warnings;
use Fcntl qw(:flock :DEFAULT);
use PublicInbox::SearchIdxPart;
-use PublicInbox::SearchIdxThread;
+use PublicInbox::SearchIdxSkeleton;
use PublicInbox::MIME;
use PublicInbox::Git;
use PublicInbox::Import;
-use Email::MIME::ContentType;
-$Email::MIME::ContentType::STRICT_PARAMS = 0;
# an estimate of the post-packed size to the raw uncompressed size
my $PACKING_FACTOR = 0.4;
my ($len, $msgref) = @{$im->{last_object}};
$self->idx_init;
- my $num = $self->{all}->index_mm($mime);
+ my $num = $self->{skel}->index_mm($mime, 1);
my $nparts = $self->{partitions};
my $part = $num % $nparts;
my $idx = $self->idx_part($part);
$self->{idx_parts}->[$part];
}
+# idempotent
sub idx_init {
my ($self) = @_;
return if $self->{idx_parts};
- # first time initialization:
- my $all = $self->{all} =
- PublicInbox::SearchIdxThread->new($self->{-inbox});
+
+ # first time initialization, first we create the skeleton pipe:
+ my $skel = $self->{skel} = PublicInbox::SearchIdxSkeleton->new($self);
# need to create all parts before initializing msgmap FD
my $max = $self->{partitions} - 1;
my $idx = $self->{idx_parts} = [];
for my $i (0..$max) {
- push @$idx, PublicInbox::SearchIdxPart->new($self, $i, $all);
+ push @$idx, PublicInbox::SearchIdxPart->new($self, $i, $skel);
}
- $all->_msgmap_init->{dbh}->begin_work;
+
+ # Now that all subprocesses are up, we can open the FD for SQLite:
+ $skel->_msgmap_init->{dbh}->begin_work;
}
sub remove {
sub searchidx_checkpoint {
my ($self, $more) = @_;
- # order matters, we can only close {all} after all partitions
- # are done because the partitions also write to {all}
-
+ # order matters, we can only close {skel} after all partitions
+ # are done because the partitions also write to {skel}
if (my $parts = $self->{idx_parts}) {
foreach my $idx (@$parts) {
- $idx->remote_commit;
+ $idx->remote_commit; # propagates commit to skel
$idx->remote_close unless $more;
}
delete $self->{idx_parts} unless $more;
}
- if (my $all = $self->{all}) {
- $all->{mm}->{dbh}->commit;
+ if (my $skel = $self->{skel}) {
+ my $dbh = $skel->{mm}->{dbh};
+ $dbh->commit;
if ($more) {
- $all->{mm}->{dbh}->begin_work;
+ $dbh->begin_work;
+ } else {
+ $skel->remote_commit; # XXX should be unnecessary...
+ $skel->remote_close;
+ delete $self->{skel};
}
- $all->remote_commit;
- $all->remote_close unless $more;
- delete $self->{all} unless $more;
}
$self->{transact_bytes} = 0;
}
undef # TODO
}
+sub atfork_child {
+ my ($self) = @_;
+ if (my $parts = $self->{idx_parts}) {
+ $_->atfork_child foreach @$parts;
+ }
+ if (my $im = $self->{im}) {
+ $im->atfork_child;
+ }
+}
+
1;