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 package PublicInbox::SearchIdxPart;
6 use base qw(PublicInbox::SearchIdx);
9 my ($class, $v2writable, $part, $threader) = @_;
10 my $self = $class->SUPER::new($v2writable->{-inbox}, 1, $part);
11 $self->{threader} = $threader;
13 pipe($r, $w) or die "pipe failed: $!\n";
15 defined $pid or die "fork failed: $!\n";
17 foreach my $other (@{$v2writable->{idx_parts}}) {
18 my $other_w = $other->{w} or next;
19 close $other_w or die "close other failed: $!\n";
23 eval { partition_worker_loop($self, $r) };
24 die "worker $part died: $@\n" if $@;
25 die "unexpected MM $self->{mm}" if $self->{mm};
34 sub partition_worker_loop ($$) {
36 my $xdb = $self->_xdb_acquire;
37 $xdb->begin_transaction;
39 while (my $line = $r->getline) {
40 if ($line eq "commit\n") {
41 $xdb->commit_transaction if $txn;
43 } elsif ($line eq "close\n") {
47 my ($len, $artnum, $object_id) = split(/ /, $line);
48 $xdb ||= $self->_xdb_acquire;
50 $xdb->begin_transaction;
53 my $n = read($r, my $msg, $len) or die "read: $!\n";
54 $n == $len or die "short read: $n != $len\n";
55 my $mime = PublicInbox::MIME->new(\$msg);
56 $self->index_blob($mime, $len, $artnum, $object_id);
59 warn "$$ still in transaction\n" if $txn;
60 warn "$$ xdb active\n" if $xdb;
63 # called by V2Writable
65 my ($self, $len, $msgref, $artnum, $object_id) = @_;
66 print { $self->{w} } "$len $artnum $object_id\n", $$msgref or die
67 "failed to write partition $!\n";