1 # Copyright (C) all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 # WQ worker for dealing with parallel Maildir reads;
5 # this does NOT use the {shard_info} field of LeiToMail
6 # (and we may remove {shard_info})
8 package PublicInbox::LeiPmdir;
11 use parent qw(PublicInbox::IPC);
14 my ($cls, $lei, $ipt) = @_;
15 my $self = bless { -wq_ident => 'lei Maildir worker' }, $cls;
16 my $jobs = $lei->{opt}->{jobs} // '';
17 $jobs =~ /\A[0-9]+,([0-9]+)\z/ and $jobs = $1;
18 my $nproc = $jobs || do {
19 # barely tested with >=4 CPUs, though I suspect I/O latency
20 # of SATA SSD storage will make >=4 processes unnecessary,
21 # here. NVMe users may wish to use '-j'
22 my $n = $self->detect_nproc;
25 my ($op_c, $ops) = $lei->workers_start($self, $nproc,
26 undef, { ipt => $ipt }); # LeiInput subclass
27 $op_c->{ops} = $ops; # for PktOp->event_step
28 $self->{lei_sock} = $lei->{sock}; # keep client for pmd_done_wait
32 sub ipc_atfork_child {
34 my $ipt = $self->{ipt} // die 'BUG: no self->{ipt}';
35 my $lei = $ipt->{lei} = $self->{lei};
36 delete @$lei{qw(auth net)}; # no network access in this worker
37 $ipt->ipc_atfork_child; # calls _lei_atfork_child;
40 sub each_mdir_fn { # maildir_each_file callback
41 my ($f, $fl, $self, @args) = @_;
42 $self->wq_io_do('mdir_iter', [], $f, $fl, @args);
45 sub mdir_iter { # via wq_io_do
46 my ($self, $f, $fl, @args) = @_;
47 $self->{ipt}->pmdir_cb($f, $fl, @args);
50 sub _lei_wq_eof { # EOF callback for main lei daemon