user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
blob 23bccb4f0c962830f02172911830bfbd368b7437 1886 bytes (raw)
name: lib/PublicInbox/LeiPmdir.pm 	 # note: path name is non-authoritative(*)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
 
# Copyright (C) 2021 all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>

# WQ worker for dealing with parallel Maildir reads;
# this does NOT use the {shard_info} field of LeiToMail
# (and we may remove {shard_info})
# WQ key: {pmd}
package PublicInbox::LeiPmdir;
use strict;
use v5.10.1;
use parent qw(PublicInbox::IPC);

sub new {
	my ($cls, $lei, $ipt) = @_;
	my $self = bless { -wq_ident => 'lei Maildir worker' }, $cls;
	my $jobs = $lei->{opt}->{jobs} // '';
	$jobs =~ /\A[0-9]+,([0-9]+)\z/ and $jobs = $1;
	my $nproc = $jobs || do {
		# barely tested with >=4 CPUs, though I suspect I/O latency
		# of SATA SSD storage will make >=4 processes unnecessary,
		# here.  NVMe users may wish to use '-j'
		my $n = $self->detect_nproc;
		$n = $n > 4 ? 4 : $n;
	};
	my ($op_c, $ops) = $lei->workers_start($self, $nproc,
		undef, { ipt => $ipt }); # LeiInput subclass
	$op_c->{ops} = $ops; # for PktOp->event_step
	$self->{lei_sock} = $lei->{sock}; # keep client for pmd_done_wait
	$lei->{pmd} = $self;
}

sub ipc_atfork_child {
	my ($self) = @_;
	my $ipt = $self->{ipt} // die 'BUG: no self->{ipt}';
	my $lei = $ipt->{lei} = $self->{lei};
	delete @$lei{qw(auth net)}; # no network access in this worker
	$ipt->ipc_atfork_child; # calls _lei_atfork_child;
}

sub each_mdir_fn { # maildir_each_file callback
	my ($f, $fl, $self, @args) = @_;
	$self->wq_io_do('mdir_iter', [], $f, $fl, @args);
}

sub mdir_iter { # via wq_io_do
	my ($self, $f, $fl, @args) = @_;
	$self->{ipt}->pmdir_cb($f, $fl, @args);
}

sub pmd_done_wait {
	my ($arg, $pid) = @_;
	my ($self, $lei) = @$arg;
	$lei->can('wq_done_wait')->($arg, $pid);
}

sub _lei_wq_eof { # EOF callback for main lei daemon
	my ($lei) = @_;
	my $pmd = delete $lei->{pmd} or return $lei->fail;
	$lei->sto_done_request($pmd->{lei_sock});
	$pmd->wq_wait_old(\&pmd_done_wait, $lei);
}

1;

debug log:

solving 23bccb4f ...
found 23bccb4f in https://80x24.org/public-inbox.git

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).