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";
24 # F_SETPIPE_SZ = 1031 on Linux; increasing the pipe size here
25 # speeds V2Writable batch imports across 8 cores by nearly 20%
26 fcntl($r, 1031, 1048576) if $^O eq 'linux';
28 eval { partition_worker_loop($self, $r) };
29 die "worker $part died: $@\n" if $@;
30 die "unexpected MM $self->{mm}" if $self->{mm};
39 sub partition_worker_loop ($$) {
41 my $xdb = $self->_xdb_acquire;
42 $xdb->begin_transaction;
44 while (my $line = $r->getline) {
45 if ($line eq "commit\n") {
46 $xdb->commit_transaction if $txn;
48 } elsif ($line eq "close\n") {
52 my ($len, $artnum, $object_id) = split(/ /, $line);
53 $xdb ||= $self->_xdb_acquire;
55 $xdb->begin_transaction;
58 my $n = read($r, my $msg, $len) or die "read: $!\n";
59 $n == $len or die "short read: $n != $len\n";
60 my $mime = PublicInbox::MIME->new(\$msg);
61 $self->index_blob($mime, $len, $artnum, $object_id);
64 warn "$$ still in transaction\n" if $txn;
65 warn "$$ xdb active\n" if $xdb;
68 # called by V2Writable
70 my ($self, $len, $msgref, $artnum, $object_id) = @_;
72 print $w "$len $artnum $object_id\n", $$msgref or die
73 "failed to write partition $!\n";
74 $w->flush or die "failed to flush: $!\n";