]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/SearchIdxPart.pm
Merge remote-tracking branch 'origin/danga-bundle'
[public-inbox.git] / lib / PublicInbox / SearchIdxPart.pm
index e5766a825ed511af4518d77fc556a3711efb65de..51d81a0a21560ef73cac1776f5176f8a29df16e0 100644 (file)
@@ -1,5 +1,8 @@
 # Copyright (C) 2018 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+
+# used to interface with a single Xapian partition in V2 repos.
+# See L<public-inbox-v2-format(5)> for more info on how we partition Xapian
 package PublicInbox::SearchIdxPart;
 use strict;
 use warnings;
@@ -11,7 +14,6 @@ sub new {
        # create the DB before forking:
        $self->_xdb_acquire;
        $self->_xdb_release;
-       $self->{over} = $v2writable->{over};
        $self->spawn_worker($v2writable, $part) if $v2writable->{parallel};
        $self;
 }
@@ -25,7 +27,7 @@ sub spawn_worker {
        my $pid = fork;
        defined $pid or die "fork failed: $!\n";
        if ($pid == 0) {
-               $v2writable->atfork_child;
+               my $bnote = $v2writable->atfork_child;
                $v2writable = undef;
                close $w or die "failed to close: $!";
 
@@ -33,7 +35,7 @@ sub spawn_worker {
                # speeds V2Writable batch imports across 8 cores by nearly 20%
                fcntl($r, 1031, 1048576) if $^O eq 'linux';
 
-               eval { partition_worker_loop($self, $r, $part) };
+               eval { partition_worker_loop($self, $r, $part, $bnote) };
                die "worker $part died: $@\n" if $@;
                die "unexpected MM $self->{mm}" if $self->{mm};
                exit;
@@ -43,19 +45,27 @@ sub spawn_worker {
        close $r or die "failed to close: $!";
 }
 
-sub partition_worker_loop ($$$) {
-       my ($self, $r, $part) = @_;
+sub partition_worker_loop ($$$$) {
+       my ($self, $r, $part, $bnote) = @_;
        $0 = "pi-v2-partition[$part]";
+       my $current_info = '';
+       my $warn_cb = $SIG{__WARN__} || sub { print STDERR @_ };
+       local $SIG{__WARN__} = sub {
+               chomp $current_info;
+               $warn_cb->("[$part] $current_info: ", @_);
+       };
        $self->begin_txn_lazy;
        while (my $line = $r->getline) {
+               $current_info = $line;
                if ($line eq "commit\n") {
                        $self->commit_txn_lazy;
                } elsif ($line eq "close\n") {
                        $self->_xdb_release;
                } elsif ($line eq "barrier\n") {
                        $self->commit_txn_lazy;
-                       print { $self->{over}->{w} } "barrier $part\n" or
-                                       die "write failed to overview $!\n";
+                       # no need to lock < 512 bytes is atomic under POSIX
+                       print $bnote "barrier $part\n" or
+                                       die "write failed for barrier $!\n";
                } elsif ($line =~ /\AD ([a-f0-9]{40,}) (.+)\n\z/s) {
                        my ($oid, $mid) = ($1, $2);
                        $self->begin_txn_lazy;