]> Sergey Matveev's repositories - public-inbox.git/log
public-inbox.git
2 years agoset nodatacow on more SQLite files
Eric Wong [Sun, 10 Oct 2021 14:25:13 +0000 (14:25 +0000)]
set nodatacow on more SQLite files

We'll set nodatacow when detecting existing but empty
files, and also their directories in more cases (for
auxiliary -wal, -journal, -shm files).  Hopefully
this keeps performance reasonable on CoW FSes.

2 years agoadmin: add '# ' prefix for progress messages
Eric Wong [Sun, 10 Oct 2021 14:25:12 +0000 (14:25 +0000)]
admin: add '# ' prefix for progress messages

It's more consistent with TAP output and hopefully puts
users at ease in case they don't understand the meaning
of a message.

2 years agolei_to_mail: show --output on augment progress failure
Eric Wong [Sun, 10 Oct 2021 14:25:11 +0000 (14:25 +0000)]
lei_to_mail: show --output on augment progress failure

Just in case it fails when there's many parallel invocations.

2 years agoextindex: support --reindex --fast
Eric Wong [Sat, 9 Oct 2021 12:04:41 +0000 (05:04 -0700)]
extindex: support --reindex --fast

This mode only checks history for missed/stale messages
and doesn't attempt to reindex messages which are already
indexed.

2 years agoview: save memory by dropping smsg->{from_name} on use
Eric Wong [Sat, 9 Oct 2021 12:03:36 +0000 (12:03 +0000)]
view: save memory by dropping smsg->{from_name} on use

We'll also save a few LoC when generating it.  $smsg objects can
linger a while when rendering large threads, so saving a few
bytes here can add up to several hundred KB saved.

I noticed this while chasing the ref cycle leak in commit
b28e74c9dc0a (www: fix ref cycle from threading w/ extindex, 2021-10-03).
While there's no longer a leak, releasing memory earlier can
allow it to be reused sooner and reduce both memory traffic and
memory pressure.

2 years agohttp: avoid Perl target cache for psgi.input
Eric Wong [Sat, 9 Oct 2021 12:03:35 +0000 (12:03 +0000)]
http: avoid Perl target cache for psgi.input

By using syswrite to populate env->{psgi.input}.  The substr()
call IO::Handle->write will trigger Perl's target/scratchpad and
result in a permanent allocation.  Since this is a cold path,
that allocation is pointless, and syswrite() can already write a
substring.

Allowing Perl to cache a large allocation in a cold path only
result in fragmentation and wasted RAM.

write(2) on a regular file won't result in short writes
unless the FS quotas or free space limits are hit, or the buffer
is close to overflowing (e.g. the 0x7ffff000-byte Linux limit).
Since our HTTP server will never buffer that much in RAM,
there's no need to retry syswrite nor rely on the retrying
implicit in IO::Handle->write and the "print" perlop.

2 years agoview: discard Eml->{bdy} when done using
Eric Wong [Sat, 9 Oct 2021 12:03:34 +0000 (12:03 +0000)]
view: discard Eml->{bdy} when done using

We can release the raw body buffer once we've obtained a copy of
the decoded buffer.  This reduces memory pressure ahead of some
expensive diff processing.

2 years agosolver_git: shorten scalar lifetimes
Eric Wong [Sat, 9 Oct 2021 12:03:33 +0000 (12:03 +0000)]
solver_git: shorten scalar lifetimes

Some of these scalar buffers may be large patches, so try
to keep them as short-lived as possible to reduce memory
pressure.

2 years agonet_reader: hoist out _imap_fetch_bodies
Eric Wong [Fri, 8 Oct 2021 22:00:19 +0000 (22:00 +0000)]
net_reader: hoist out _imap_fetch_bodies

We'll be supporting pipelining in a future commit, since
Tor is too slow and increasing batch size can use too much
memory.

2 years agogit: fatalize async callback errors by default
Eric Wong [Fri, 8 Oct 2021 10:20:04 +0000 (10:20 +0000)]
git: fatalize async callback errors by default

This should help us catch BUG: errors (and then some) in
-extindex and other read-write code paths.  Only read-only
daemons should warn on async callback failures, since those
aren't capable of causing data loss.

2 years agogit: async_abort includes --batch-check requests
Eric Wong [Fri, 8 Oct 2021 10:20:03 +0000 (10:20 +0000)]
git: async_abort includes --batch-check requests

We need to abort both check-only and cat requests when
aborting, since we'll be aborting more aggressively
in in read-write paths.

2 years agogit: use async_wait_all everywhere
Eric Wong [Fri, 8 Oct 2021 10:20:02 +0000 (10:20 +0000)]
git: use async_wait_all everywhere

Some code paths may use maximum size checks, so ensure
any checks are waited on, too.

2 years agooveridx: each_by_mid: account for messages being deleted
Eric Wong [Thu, 7 Oct 2021 08:29:32 +0000 (08:29 +0000)]
overidx: each_by_mid: account for messages being deleted

This may fix some extindex problems and should get rid of
the "Can't bless non-reference value" errors.

2 years agods: tmpio: avoid Perl target cache
Eric Wong [Wed, 6 Oct 2021 11:50:42 +0000 (11:50 +0000)]
ds: tmpio: avoid Perl target cache

The use of `substr' here an argument to `print' was causing Perl
to internally cache its target buffer.  Since `syswrite()'
already offers a buffer offset arg and length limits, just use
`syswrite' directly.  We were using autoflush anyways, so the
lack of buffering was of no concern performance-wise.

The target buffer could get to roughly ~10MB under some loads,
but it was usually a cold path and using memory which cannot be
released nor reused in other places.

note: IO::Handle::write uses `substr' internally, too;
so nothing would be gained using IO::Handle:write.

2 years agomsg_iter: split_quotes adds trailing "\n"
Eric Wong [Wed, 6 Oct 2021 11:19:36 +0000 (11:19 +0000)]
msg_iter: split_quotes adds trailing "\n"

The regexp in split_quotes relies on the presence of a
final "\n", so add it wherever we need to instead of
making it the responsibility of every caller.

This probably doesn't matter in practice since every
email seems to have a "\n" as the final byte (due to
the way SMTP works), but maybe there's some odd ones
that'll get imported via lei.

2 years agooveridx: subject_path: allow non-ASCII char in subject matches
Eric Wong [Wed, 6 Oct 2021 10:12:21 +0000 (10:12 +0000)]
overidx: subject_path: allow non-ASCII char in subject matches

This should bring us closer to the "Base subject" definition in
IMAP ORDEREDSUBJECT (RFC 5256 2.1).  Larger changes may cause
some breakage (until --reindex).  But for now, a reindex will
prevents the non-ASCII subjects from being normalized to the
same fuzzy "thread" in the thread view.

2 years agoextindex: --gc checkpoints
Eric Wong [Wed, 6 Oct 2021 09:44:50 +0000 (09:44 +0000)]
extindex: --gc checkpoints

We need to ensure -extindex --gc runs don't prevent other
work from happening in the meantime.  I actually caused
my -extindex to OOM due to the lack of checkpoints :x

We'll also hoist out the shard scanning into its own sub
in preparation for lei/store usage.

2 years agoxt/perf-msgview: modernize, support TEST_BLOB
Eric Wong [Wed, 6 Oct 2021 09:42:18 +0000 (09:42 +0000)]
xt/perf-msgview: modernize, support TEST_BLOB

This helped me quickly reproduce a bug in Encode[1] and
will help me determine performance implications of workarounds
for the aforementioned bug.

[1] https://rt.cpan.org/Public/Bug/Display.html?id=139622

2 years agoindex: --reindex w/ --{since,until,before,after}
Eric Wong [Tue, 5 Oct 2021 09:40:17 +0000 (09:40 +0000)]
index: --reindex w/ --{since,until,before,after}

This lets administrators reindex specific time ranges
according to git "approxidate" formats.  These arguments
are passed directly to underlying git-log(1) invocations
and may still reach into old epochs.

Since these options rely on git committer dates (which we infer
from the most recent Received: header), they are not guaranteed
to be strictly tied to git history and it's possible to
over/under-reindex some messages.  It's probably not a major
problem in practice, though; reindexing a few extra messages
is generally harmless aside from some extra device wear.

Since this currently relies on git-log, these options do not
affect -extindex, yet.

2 years agoextsearchidx: favor 20-byte OID comparison
Eric Wong [Mon, 4 Oct 2021 11:12:34 +0000 (00:12 -1100)]
extsearchidx: favor 20-byte OID comparison

As with most of our internal-only code, favor smaller
comparisons to reduce memory traffic.

2 years agooveridx: update comment for new sub name
Eric Wong [Mon, 4 Oct 2021 11:11:43 +0000 (11:11 +0000)]
overidx: update comment for new sub name

`shard_remove_eidx_info' was made unnecessary with commit
82b805db3ad9 (searchidxshard: IPC conversion, part 2, 2021-01-03)
and we now call `remove_eidx_info' directly.

2 years ago{dir,inbox}idle: use level-triggered epoll
Eric Wong [Mon, 4 Oct 2021 08:26:33 +0000 (08:26 +0000)]
{dir,inbox}idle: use level-triggered epoll

Both read(2) on inotify and kevent(2) return a finite amount of
events.  Let the kernel notify us again in cases where we'd
need to retry instead of looping ourselves.  This can prevent
missed/delayed notifications while still ensuring fairness in
busy event loops.

2 years agohl_mod: don't memoize highlight::codeGenerator objects
Eric Wong [Mon, 4 Oct 2021 06:10:21 +0000 (06:10 +0000)]
hl_mod: don't memoize highlight::codeGenerator objects

Making them immortal doesn't seem worth it, since doing immortal
allocations after process startup leads to fragmentation.  While
the allocations made by highlight are small, those small
allocations can break up contiguous regions and prevent
consolidation by the malloc implementation.

Since instantiating code generators doesn't seem too expensive,
just use and delete them ASAP.

2 years agowww: fix ref cycle from threading w/ extindex
Eric Wong [Mon, 4 Oct 2021 00:07:17 +0000 (19:07 -0500)]
www: fix ref cycle from threading w/ extindex

Unlike v1 inboxes (which don't accept duplicate Message-IDs at
all), and v2 inboxes (which generate a new Message-ID for
duplicates), extindex must accept duplicate Message-IDs as-is.

This was fine for storage, but prevented the reference-cycle
mechanism of our message threading display algorithm from working
reliably.  It could no longer delete the ->{parent} field from
clobbered entries in the %id_table.

So we now take into account reused Message-IDs and never clobber
entries in %id_table.  Instead, we mark reused Message-IDs as
"imposters" and special-case them by injecting them as children
after all other threading is complete.

This cycle was noticed using a pre-release of Devel::Mwrap::PSGI:
  https://80x24.org/mwrap-perl.git

2 years agot/thread-cycle: make Email::Simple optional
Eric Wong [Mon, 4 Oct 2021 00:07:16 +0000 (19:07 -0500)]
t/thread-cycle: make Email::Simple optional

We only use it if Mail::Thread is available, and often it's not.

2 years agoextsearchidx: emit diagnostics for missing blobs
Eric Wong [Sat, 2 Oct 2021 11:18:35 +0000 (11:18 +0000)]
extsearchidx: emit diagnostics for missing blobs

I'm not sure why they weren't emitted, earlier.

2 years agocontent_hash: normalize whitespace before hashing addresses
Eric Wong [Sat, 2 Oct 2021 11:18:34 +0000 (11:18 +0000)]
content_hash: normalize whitespace before hashing addresses

This should prevent some false duplicates.  I noticed this
while implementing "lei mail-diff", and only noticed it when
I implemented the ContentDigestDbg wrapper for mail-diff.

2 years agolei mail-diff: diagnostic command to diff mail contents
Eric Wong [Sat, 2 Oct 2021 11:18:33 +0000 (11:18 +0000)]
lei mail-diff: diagnostic command to diff mail contents

This is useful in finding the cause of deduplication bugs,
and possibly the cause of missing threads reported by
Konstantin in <20211001130527.z7eivotlgqbgetzz@meerkat.local>

usage:

  u=https://yhbt.net/lore/all/87czop5j33.fsf@tynnyri.adurom.net/raw
  lei mail-diff $u

2 years agoextsearchidx: attach_config: set {ibx_map} value to $ibx
Eric Wong [Sat, 2 Oct 2021 11:18:32 +0000 (11:18 +0000)]
extsearchidx: attach_config: set {ibx_map} value to $ibx

It doesn't seem to matter, actually, but this matches the
behavior of attach_inbox and the comment in ->new.

2 years agolei inspect: fix "mid:" prefix, expand to Xapian
Eric Wong [Sat, 2 Oct 2021 08:16:22 +0000 (08:16 +0000)]
lei inspect: fix "mid:" prefix, expand to Xapian

This fixes inspect for uninitialized instances, and adds Xapian
("xdoc") output if available.

Reported-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Message-ID: <20211001204943.l4yl6xvc45c5eapz@meerkat.local>

2 years agolei inspect: integerize "bytes" and "lines" fields
Eric Wong [Sat, 2 Oct 2021 08:16:21 +0000 (08:16 +0000)]
lei inspect: integerize "bytes" and "lines" fields

These are always numeric, but none of the Perl code cares;
we want to prevent JSON from quoting them.

2 years agoextsearchidx: do not process eidxq w/o config
Eric Wong [Fri, 1 Oct 2021 21:44:18 +0000 (21:44 +0000)]
extsearchidx: do not process eidxq w/o config

When indexing a single inbox, do not attempt reindexing code
paths without a full config, otherwise ordering comparisons
won't work.

2 years agodoc: lei-daemon: new manpage
Eric Wong [Fri, 1 Oct 2021 09:54:45 +0000 (09:54 +0000)]
doc: lei-daemon: new manpage

In case users see "lei-daemon" in ps(1) or syslog and wonder.

Helped-by: Kyle Meyer <kyle@kyleam.com>
2 years agods: inline set_cloexec
Eric Wong [Fri, 1 Oct 2021 09:54:44 +0000 (09:54 +0000)]
ds: inline set_cloexec

I'm thinking we can drop support for Linux <2.6.27 soonish and
just use EPOLL_CLOEXEC.  Perl without signalfd (or
EVFILT_SIGNAL) is miserable, actually.

2 years agoinbox: keep DB handles if git processes are live
Eric Wong [Fri, 1 Oct 2021 09:54:43 +0000 (09:54 +0000)]
inbox: keep DB handles if git processes are live

Having git processes outlive DB handles is likely to hurt
from a fragmentation perspective if the DB handle needs to
be recreated immediately due to a git->cat_async callback.
So only unref DB handles when we're sure there's no live
git users left, otherwise check the inodes.

We'll also avoid needless localization checks in git->cleanup
and make the return value more obvious since the pid fields are
unconditionally deleted nowadays.

2 years agoinbox: inline and eliminate git_cleanup
Eric Wong [Fri, 1 Oct 2021 09:54:42 +0000 (09:54 +0000)]
inbox: inline and eliminate git_cleanup

It was probably incorrect to use from max_git_epoch, and it's
small enough to inline into do_cleanup.  We'll also eliminate
the unnecessary deletion of {-altid_map} while we're in the
area, since we no longer cache/memoize that.

Fixes: 7e5cea05f061e757 ("inbox: rewrite cleanup to be more aggressive")
2 years agods: simplify signalfd use
Eric Wong [Fri, 1 Oct 2021 09:54:41 +0000 (09:54 +0000)]
ds: simplify signalfd use

Since signalfd is often combined with our event loop, give it a
convenient API and reduce the code duplication required to use it.

EventLoop is replaced with ::event_loop to allow consistent
parameter passing and avoid needlessly passing the package name
on stack.

We also avoid exporting SFD_NONBLOCK since it's the only flag we
support.  There's no sense in having the memory overhead of a
constant function when it's in cold code.

2 years agoipc: run Net::SSLeay::randomize
Eric Wong [Fri, 1 Oct 2021 09:54:40 +0000 (09:54 +0000)]
ipc: run Net::SSLeay::randomize

Currently we don't use OpenSSL from child processes of parents
which use OpenSSL, but we may in the future.  So ensure OpenSSL
initializes its PRNG after these forks to avoid one security
pitfall down the line.

2 years agodaemon: make SO_ACCEPTFILTER a shared variable
Eric Wong [Fri, 1 Oct 2021 09:54:39 +0000 (09:54 +0000)]
daemon: make SO_ACCEPTFILTER a shared variable

Constant subroutines use more memory and there's no need to
optimize it for inlining since it's only used at startup.

2 years agolistener: switch to level-triggered epoll
Eric Wong [Fri, 1 Oct 2021 09:54:38 +0000 (09:54 +0000)]
listener: switch to level-triggered epoll

On second thought, the ->requeue + accept retry code path isn't
worth the userspace complexity and overhead.  Level-triggered
epoll has always annoyed me since it takes an inefficient code
path in the kernel; but taking our less-efficient code path in
Perl seems even worse.  We also need to take load distribution
into account for multi-worker systems.

2 years agodoc: lei-security: some more updates
Eric Wong [Fri, 1 Oct 2021 09:54:37 +0000 (09:54 +0000)]
doc: lei-security: some more updates

Virtual users will probably be used for read-write IMAP/JMAP
support.  The potential for various kernel/hardware bugs and
attacks also needs to be highlighted.

2 years agosearch_view: various navigation tweaks
Eric Wong [Fri, 1 Oct 2021 02:10:27 +0000 (02:10 +0000)]
search_view: various navigation tweaks

This improves the "&x=t" navigation between the thread overview
(skeleton) section at the bottom and jumping back to the top for
the mbox download form.  The "--links below ..." text ought to
be helpful for users unfamiliar with the /$MSGID/T/ and /$MSGID/t/
views.

2 years agogit: shorten --git-dir= in CLI with chdir in spawn
Eric Wong [Wed, 29 Sep 2021 21:25:20 +0000 (21:25 +0000)]
git: shorten --git-dir= in CLI with chdir in spawn

Long pathnames are difficult to read and distinguish in ps(1)
output.  Deep paths can also slow down pathname resolution
when dealing with loose objects, so we put "cat-file --batch"
deeper into the directory tree.

Since v2 processes are in the form of $INBOXDIR/all.git, keep
the basename of $INBOXDIR in --git-dir= so it's easy to
distinguish between processes just by looking at ps(1).

While "git -C" also exists, it's only present in git 1.8.5+.
We also need to keep in mind the "directory" pointed to by
--git-dir= need not be a directory (nor a symlink pointing
to one).

This reduces pathname resolution overhead for v1 and v2 inbox
git processes, but unfortunately not for extindex since that
needs to store alternates as absolute paths.

2 years agods: drop ::later support
Eric Wong [Wed, 29 Sep 2021 12:40:47 +0000 (07:40 -0500)]
ds: drop ::later support

add_uniq_timer seems sufficient, and we'll drop the last
user of ::later (IMAP) and switch to unique timers.

2 years agods: simplify idle time expiry, slightly
Eric Wong [Wed, 29 Sep 2021 12:40:46 +0000 (07:40 -0500)]
ds: simplify idle time expiry, slightly

While it doesn't look like $EXPMAP can be populated in
non-obvious ways via ->DESTROY, it still makes sense to keep it
close to some of our other code around cleanup to reduce
the likelyhood of subtle bugs in case semantics change..

2 years agot/solver_git: fix test to work with git <2.29
Eric Wong [Wed, 29 Sep 2021 03:02:54 +0000 (03:02 +0000)]
t/solver_git: fix test to work with git <2.29

'git diff --abbrev=40' did not abbreviate /^index / lines of
diff output with git <2.29, and 40 will be insufficient for
SHA-256.  --full-index has been around since 2005, so it's safe
to rely on.

Tested git version 2.20.0 (Debian buster).

Fixes: 751df49e7db8ba77 ("lei rediff: add --drq and --dequote-only")
2 years agoinbox: do not vivify {-repo_objs} during cleanup
Eric Wong [Wed, 29 Sep 2021 00:14:28 +0000 (00:14 +0000)]
inbox: do not vivify {-repo_objs} during cleanup

This caused config->repo_objs to not fill in {-repo_objs}
properly before starting solver.

Reported-by: Kyle Meyer <kyle@kyleam.com>
Link: https://public-inbox.org/meta/87o88cqobd.fsf@kyleam.com/
Fixes: 63d7b8ceee55a34 ("daemons: revamp periodic cleanup task")
2 years agoinbox: drop memoization/preload, cleanup expires caches
Eric Wong [Tue, 28 Sep 2021 23:11:06 +0000 (23:11 +0000)]
inbox: drop memoization/preload, cleanup expires caches

cloneurl, description, and base_url are no longer memoized.  The
non-$env form of base_url is rare in WWW, and is fast enough to
not require memoization.

cloneurl and description are now expired during cleanup,
allowing admins to change these files without restarting
(or SIGHUP).

-altid_map is no longer cached nor memoized at all, since the
endpoint(s) which hit it seem rarely accessed.

nntp_url and imap_url are now cached (instead of memoized) in
case an inbox is unvisited for a long time.  They remain cached
since the truthiness check gets called in every per-inbox HTML
page, which can potentially be expensive.

2 years agoinbox: rewrite cleanup to be more aggressive
Eric Wong [Tue, 28 Sep 2021 23:11:05 +0000 (23:11 +0000)]
inbox: rewrite cleanup to be more aggressive

Avoid relying on a giant cleanup hash and instead use the new
DS->add_uniq_timer API to amortize the pause times associated
with having to cleanup many inboxes.  We can also use smaller
intervals for this, as well.

We now discard SQLite DB handles at cleanup.  Each of these can
use several megabytes of memory, which adds up with
hundreds/thousands of inboxes.  Since per-inbox access intervals
are unpredictable and opening an SQLite handle is relatively
inexpensive, release memory more aggressively to avoid the heap
having to hit swap.

2 years agowww: do not bump {over} refcnt on long responses
Eric Wong [Tue, 28 Sep 2021 23:11:04 +0000 (23:11 +0000)]
www: do not bump {over} refcnt on long responses

SQLite files may be replaced or removed by admins while
generating a large threads or mailbox responses.  Ensure we
don't hold onto DBI handles and associated file descriptors
past their cleanup.

2 years agowww+httpd: lower priority of large mbox downloads
Eric Wong [Tue, 28 Sep 2021 07:53:49 +0000 (07:53 +0000)]
www+httpd: lower priority of large mbox downloads

While each git blob request is treated fairly w.r.t other git
blob requests, responses triggering thousands of git blob
requests can still noticeably increase latency for
less-expensive responses.

Move large mbox results and the nasty all.mbox endpoint to
a low priority queue which only fires once per-event loop
iteration.  This reduces the response time of short HTTP
responses while many gigantic mboxes are being downloaded
simultaneously, but still maximizes use of available I/O
when there's no inexpensive HTTP responses happening.

This only affects PublicInbox::WWW users who use
public-inbox-httpd, not generic PSGI servers.

2 years agodoc: lei-rediff: grammar fixes for --drq and --dequote-only
Kyle Meyer [Mon, 27 Sep 2021 23:53:56 +0000 (19:53 -0400)]
doc: lei-rediff: grammar fixes for --drq and --dequote-only

2 years agolei completion: workaround old Perl bug
Eric Wong [Mon, 27 Sep 2021 21:05:45 +0000 (16:05 -0500)]
lei completion: workaround old Perl bug

While `$argv[-1]' is `undef' on an empty @argv, using `$argv[-1]'
as a subroutine argument would fail incorrectly with:

    Modification of non-creatable array value attempted, subscript -1 at ...

...even though we'd never attempt to modify @_ itself in the
subroutines being called.  Work around the bug (tested on
5.16.3) by passing `undef' explicitly when `$argv[-1]' is
already `undef'.

Reported-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Link: https://public-inbox.org/meta/20210927124056.kj5okiefvs4ztk27@meerkat.local/
2 years agot/lei-index: IMAP and NNTP dependencies are optional
Eric Wong [Mon, 27 Sep 2021 21:05:44 +0000 (16:05 -0500)]
t/lei-index: IMAP and NNTP dependencies are optional

"lei index" support for IMAP and NNTP is incomplete, so there's
no point in requiring them.

Reported-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Link: https://public-inbox.org/meta/20210927124056.kj5okiefvs4ztk27@meerkat.local/
2 years agofetch: support running as root
Eric Wong [Mon, 27 Sep 2021 21:05:43 +0000 (16:05 -0500)]
fetch: support running as root

The "-w" perlop always succeeds as root, so we need to check
st_mode for writability bits to detect directories we shouldn't
write to.

Reported-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Link: https://public-inbox.org/meta/20210927124056.kj5okiefvs4ztk27@meerkat.local/
2 years agot/cmd_ipc: allow extra errors and add diagnostics
Eric Wong [Mon, 27 Sep 2021 18:35:36 +0000 (13:35 -0500)]
t/cmd_ipc: allow extra errors and add diagnostics

Apparently, sendmsg can fail in less common ways when
network buffers are gigantic.  Add some diagnostics for
future failures, as well.

Reported-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Link: https://public-inbox.org/meta/20210927124056.kj5okiefvs4ztk27@meerkat.local/
2 years agoxt/net_writer_imap: env knobs for compress/debug/proxy
Eric Wong [Mon, 27 Sep 2021 09:23:15 +0000 (02:23 -0700)]
xt/net_writer_imap: env knobs for compress/debug/proxy

It can be useful to test with some of these, but we can't enable
them universally for all servers (and debug + compress is gross)

2 years agoconfig: get_1: use full parameter name
Eric Wong [Mon, 27 Sep 2021 07:53:07 +0000 (02:53 -0500)]
config: get_1: use full parameter name

Instead of passing the prefix section and key separately, pass
them together as is commonly done with git-config(1) usage as
well as our ->get_all API.  This inconsistency in the get_1 API
is a needless footgun and confused me a bit while working on
"lei up" the other week.

2 years agolei rediff: add --drq and --dequote-only
Eric Wong [Mon, 27 Sep 2021 04:59:31 +0000 (04:59 +0000)]
lei rediff: add --drq and --dequote-only

More switches which can be useful for users who pipe from text
editors.  --drq can be helpful while writing patch review email
replies, and perhaps --dequote-only, too.

2 years agolei rediff: quiet warnings from Import and Eml
Eric Wong [Mon, 27 Sep 2021 04:59:30 +0000 (04:59 +0000)]
lei rediff: quiet warnings from Import and Eml

lei rediff is expected to see partial patch fragments and such,
so silence warnings when something isn't exactly a valid email
message.

2 years agonet_reader: drop support for IgnoreSizeErrors option
Eric Wong [Sun, 26 Sep 2021 21:25:47 +0000 (21:25 +0000)]
net_reader: drop support for IgnoreSizeErrors option

Only the ->message_string method of Mail::IMAPClient uses it,
and we have no intention of using ->message_string outside
of tests.

2 years agolei: ensure refresh_watches isn't called from workers
Eric Wong [Sun, 26 Sep 2021 05:38:19 +0000 (22:38 -0700)]
lei: ensure refresh_watches isn't called from workers

Only the top-level lei-daemon will do inotify/kevent.

2 years agot/run.perl: less confusing error reporting
Eric Wong [Sun, 26 Sep 2021 01:42:38 +0000 (01:42 +0000)]
t/run.perl: less confusing error reporting

The $sigchld handler was reporting the last test (successful or
not) for a given PID in case a worker dies prematurely.
Instead, redisplay all failed test in $run_log to ensure the
report only shows failed tests, and not the last started (and
possibly successful) one.

2 years agoinbox: cloneurl: avoid undef to hash table value
Eric Wong [Sun, 26 Sep 2021 01:42:29 +0000 (01:42 +0000)]
inbox: cloneurl: avoid undef to hash table value

This saves us some memory for the hash slot in the common case
the `cloneurl' file doesn't exist.

2 years agolei -f reply: fix Cc: header combining
Eric Wong [Sun, 26 Sep 2021 01:42:06 +0000 (01:42 +0000)]
lei -f reply: fix Cc: header combining

When combining lines from To: and Cc: headers, ", " needs to be
used to separate them.

2 years agowww_listing: support /all/ search as a 302 redirect
Eric Wong [Sun, 26 Sep 2021 01:30:47 +0000 (01:30 +0000)]
www_listing: support /all/ search as a 302 redirect

This allows users to search /all/ from the top-level WwwListing
without extra manual steps, although there's still extra network
roundtrips incurred.

No vertical whitespace is added, and there's no clumsy radio
buttons nor menus to deal with.  Users only have to use a
different <input type=submit /> button.  I forgot how to do this
until I realized we already do something similar with multiple
submit buttons for threaded vs non-threaded mboxrd.gz downloads.

Link: https://public-inbox.org/meta/20210827120845.29682-1-e@80x24.org/
2 years agolei note-event: ignore kw_changed exceptions
Eric Wong [Sun, 26 Sep 2021 00:02:32 +0000 (00:02 +0000)]
lei note-event: ignore kw_changed exceptions

The note-event worker may see changes before a Xapian shard
commit happens, meaning keyword lookups fail as a result.
Just emit the request to the lei/store worker since it's a
fairly cheap operation at this point.

We'll try harder to look for kw changes, too, since
deduplication changes may lead to multiple docids being
resolved for a single message.

2 years agosearch: avoid setting undef hashtable entries
Eric Wong [Sat, 25 Sep 2021 22:16:45 +0000 (22:16 +0000)]
search: avoid setting undef hashtable entries

`undef' entries still take up a slot in the hash table, and
cause the `exists' check to false-positive in ->cleanup_shards.
This should fully fix the (innocuous) messages introduced in
commit 63d7b8ce (daemons: revamp periodic cleanup task, 2021-09-23)

2 years agoextmsg: search_partial: use ->isrch if available
Eric Wong [Sat, 25 Sep 2021 22:16:44 +0000 (22:16 +0000)]
extmsg: search_partial: use ->isrch if available

This allows us to avoid creating ibx->{search}->{xdb} at this
spot by using an `undef' value.  This is a step towards
eliminating the innocuous "/path/to/inboxdir/xap15 has no shards"
messages introduced in commit 63d7b8ce (daemons: revamp
periodic cleanup task, 2021-09-23)

2 years agolei ls-external: split into separate file
Eric Wong [Sat, 25 Sep 2021 08:49:45 +0000 (08:49 +0000)]
lei ls-external: split into separate file

This was written before we had auto-loading and rarely used.

2 years agolei add-external: split into separate file
Eric Wong [Sat, 25 Sep 2021 08:49:44 +0000 (08:49 +0000)]
lei add-external: split into separate file

Also was written before we had auto-loading and rarely used.

2 years agolei forget-external: split into separate file
Eric Wong [Sat, 25 Sep 2021 08:49:43 +0000 (08:49 +0000)]
lei forget-external: split into separate file

This was written before we had auto-loading, and forget-external
should be a rarely-used command that's not worth loading at
startup.  Do some golfing while we're in the area, too.

2 years agodoc: lei-rm: remove unnecessary -F values
Eric Wong [Sat, 25 Sep 2021 07:08:38 +0000 (07:08 +0000)]
doc: lei-rm: remove unnecessary -F values

-F is really only useful for distinguishing between mbox
variants and single message/rfc822 files.  URLs and
directory-based formats can be auto-detected easily enough.

2 years agolei: make pkt_op easier-to-use and understand
Eric Wong [Sat, 25 Sep 2021 06:17:54 +0000 (06:17 +0000)]
lei: make pkt_op easier-to-use and understand

Since switching to SOCK_SEQUENTIAL, we no longer have to use
fixed-width records to guarantee atomic reads.  Thus we can
maintain more human-readable/searchable PktOp opcodes.

Furthermore, we can infer the subroutine name in many cases
to avoid repeating ourselves by specifying a command-name
twice (e.g. $ops->{CMD} => [ \&CMD, $obj ]; can now simply be
written as: $ops->{CMD} => [ $obj ]  if CMD is a method of
$obj.

2 years agolei2mail: augment_inprogress: guard against closed FDs
Eric Wong [Sat, 25 Sep 2021 05:49:45 +0000 (05:49 +0000)]
lei2mail: augment_inprogress: guard against closed FDs

I'm not sure what caused it, but $err was undef and caused print
to fail, leading to an event loop error.  Guard the timer with
an eval and assume warn() can't trigger an event loop failure.

2 years agolei: restore old sigmask before daemon exit
Eric Wong [Sat, 25 Sep 2021 05:49:44 +0000 (05:49 +0000)]
lei: restore old sigmask before daemon exit

If the event loop fails, we want blocking waitpid (wait4) calls
to be interruptible with SIGTERM via "kill $PID" rather than
SIGKILL.  Though a failing event loop is something we should
avoid...

2 years agolei up: show timezone offset with localtime
Eric Wong [Sat, 25 Sep 2021 05:49:43 +0000 (05:49 +0000)]
lei up: show timezone offset with localtime

Sometimes a user (e.g. me) isn't really sure what timezone
they're in...

2 years agodoc: lei: manpages for export-kw and refresh-mail-sync
Eric Wong [Fri, 24 Sep 2021 12:51:09 +0000 (12:51 +0000)]
doc: lei: manpages for export-kw and refresh-mail-sync

Something is better than nothing.

2 years agodoc: lei-index: remove --stdin, reword -F
Eric Wong [Fri, 24 Sep 2021 12:51:08 +0000 (12:51 +0000)]
doc: lei-index: remove --stdin, reword -F

lei-index really only works for Maildir, at the moment.

2 years agodoc: lei-overview: implicit stdin, correct Inline::C notes
Eric Wong [Fri, 24 Sep 2021 12:51:07 +0000 (12:51 +0000)]
doc: lei-overview: implicit stdin, correct Inline::C notes

Implicit stdin based on standard input being a pipe or regular
file is here to stay, so save users the trouble of typing '-'
or '--stdin'.

Inline::C is required as of commit 1d6e1f9a6a66 (lei: require
Socket::MsgHdr or Inline::C, drop oneshot, 2021-05-26); but
Socket::MsgHdr still gives a noticeable improvement in bash
completion speed.

Also, spell-out "MESSAGE-ID" since "MID" is actually not a
common abbreviation ("MSGID" is used by RFC 3977 and several
other RFCs, I recall).

2 years agodoc: lei blob+rediff+p2q: add notes about git directory
Eric Wong [Fri, 24 Sep 2021 12:51:06 +0000 (12:51 +0000)]
doc: lei blob+rediff+p2q: add notes about git directory

Try to clarify these commands are intended to be useful for
git-using (usually software) projects (and not the bare git
repos we use internally).

We'll also document some commonly useful git-diff switches
in the lei-rediff man page to highlight the usefulness
of the command.

2 years agot/v2mirror: check dependencies for legacy test
Eric Wong [Sat, 25 Sep 2021 03:21:01 +0000 (03:21 +0000)]
t/v2mirror: check dependencies for legacy test

We still need Email::MIME to test against old revisions.
We'll also depend on the revision just prior to the
manifest.js.gz introduction to avoid loading Danga::Socket,
since it was getting loaded even with `plackup'.

Finally, we'll disable Inline::C usage with old Spawn.pm
since our old code included alloca.h, which is not
portable to FreeBSD.

2 years agofetch: support v2 w/o manifest on old WWW
Eric Wong [Fri, 24 Sep 2021 10:56:45 +0000 (10:56 +0000)]
fetch: support v2 w/o manifest on old WWW

There may still be pre-manifest.js.gz versions of
PublicInbox::WWW running and serving v2 inboxes.

While -clone and "add-external --mirror" were working, -fetch
was failing due to 301 redirect to $INBOX_URL/manifest.js.gz/
and not the expected 404.  Update the code to deal with a JSON
decode error (from the 301) and ensure v2 epochs detection is
correct (and not using a shadowed variable).

2 years agoclone|fetch|--mirror: cull manifest in partial mirrors
Eric Wong [Fri, 24 Sep 2021 10:56:44 +0000 (10:56 +0000)]
clone|fetch|--mirror: cull manifest in partial mirrors

This makes it easier for users to enable fetching on a
previously read-only epoch.  Prior to this change, users were
required to delete manifest.js.gz in addition to adding the
writable bit.  Now, they just have to "chmod +w $EPOCH_DIR".

2 years agoclone|--mirror: fix and test against pre-manifest WWW
Eric Wong [Fri, 24 Sep 2021 10:56:43 +0000 (10:56 +0000)]
clone|--mirror: fix and test against pre-manifest WWW

There may still be pre-manifest.js.gz versions of PublicInbox::WWW.
running and serving v2 inboxes.

Since $INBOX_URL/manifest.js.gz was not understood, it was
assumed to be a Message-ID and 301-ed to
"$INBOX_URL/manifest.js.gz/" with a trailing slash, so our 404
checks were invalid.  Update our fallbacks to deal with 301
by catching JSON decoding errors to trigger HTML scraping.

For HTML parsing, be sure to not be fooled by potential
user-generated content and only scan the part after the last
<hr>.

We also need to avoid propagating $? from curl unnecessarily
when we can continue safely.

Finally, update v2mirror.t with tests to use PublicInbox::WWW
from our "v1.1.0-pre1" tag to ensure these code paths get tested

2 years agofetch: fix skipping with multi-epoch inboxes
Eric Wong [Fri, 24 Sep 2021 10:56:42 +0000 (10:56 +0000)]
fetch: fix skipping with multi-epoch inboxes

We need to check every epoch for writability, so don't
break out of the loop when we find a URL.

2 years agoclone|--mirror: support --epoch=RANGE for partial clones
Eric Wong [Fri, 24 Sep 2021 10:56:41 +0000 (10:56 +0000)]
clone|--mirror: support --epoch=RANGE for partial clones

Partial (v2) clones should be useful addition for users wanting
to conserve storage while having fast access to recent messages.

Continuing work started in 876e74283ff3 (fetch: ignore
non-writable epoch dirs, 2021-09-17), this creates bare,
read-only epoch git repos.  These git repos have the remotes
pre-configured, but does not fetch any objects.

The goal is to allow users to set the writable bit on a
previously-skipped epoch and start fetching it.

Shell completion support may not be necessary given how short
the epoch ranges are, here.

Cc: Luis Chamberlain <mcgrof@kernel.org>
Link: https://public-inbox.org/meta/20210917002204.GA13112@dcvr/T/#u
2 years agolei_xsearch: use localtime for user message
Eric Wong [Thu, 23 Sep 2021 10:37:42 +0000 (10:37 +0000)]
lei_xsearch: use localtime for user message

It's probably least confusing for user-facing messages to
display times in the user's configured timezone.  I considered
appending "UTC" to the message and sticking with gmtime(), too,
but this output isn't intended to be web-cache friendly nor
expect users from across multiple timezones to view the same
output.

2 years agolei: common --all[=remote|local] help message
Eric Wong [Thu, 23 Sep 2021 10:36:22 +0000 (10:36 +0000)]
lei: common --all[=remote|local] help message

It helps to be consistent and reduce the learning curve, here.

2 years agoxcpdb: avoid race when shards are added
Eric Wong [Thu, 23 Sep 2021 05:53:03 +0000 (05:53 +0000)]
xcpdb: avoid race when shards are added

It's possible for the rename() sequence to cause read-only
daemons using ->xdb_shards_flat to load an incomplete set of
contiguous shards and get invalid docids for search results.

With this change, we favor the case where search is momentarily
unavailable rather than giving wrong results during the small
window where Xapcmd->commit_changes runs.

2 years agoxcpdb: -R$SHARDS creates new shards with correct perms
Eric Wong [Thu, 23 Sep 2021 05:53:02 +0000 (05:53 +0000)]
xcpdb: -R$SHARDS creates new shards with correct perms

"Correct" meaning the permissions match that of the parent
xap15 or ei15 directory.

2 years agotest_common: reset umask on non-forking run_script
Eric Wong [Thu, 23 Sep 2021 05:53:01 +0000 (05:53 +0000)]
test_common: reset umask on non-forking run_script

public-inbox-init sets umask for git <2.1.0, so our fork+exec
replacement needs to restore the original umask of the "parent".

2 years agodaemons: revamp periodic cleanup task
Eric Wong [Thu, 23 Sep 2021 00:46:25 +0000 (00:46 +0000)]
daemons: revamp periodic cleanup task

Neither Inboxes nor ExtSearch objects were retrying correctly
when there are live git processes, but the inboxes were getting
rescanned for search or other reasons.  Ensure the scan retries
eventually if there's live processes.

We also need to update the cleanup task to detect Xapian shard
count changes, since Xapian ->reopen is enough to detect any
other Xapian changes.  Otherwise, we just issue an inexpensive
->reopen call and let Xapian check whether there's anything
worth reopening.

This also lets us eliminate the Devel::Peek dependency.

2 years agogcf2 + extsearch: check for unlinked files on Linux
Eric Wong [Wed, 22 Sep 2021 09:45:17 +0000 (09:45 +0000)]
gcf2 + extsearch: check for unlinked files on Linux

Check for unlinked mmap-ed files via /proc/$PID/maps every 60s
or so.

ExtSearch (extindex) is compatible-enough with Inbox objects to
be wired into the old per-inbox code, but the startup cost is
projected to be much higher down the line when there's >30K
inboxes, so we scan /proc/$PID/maps for deleted files before
unlinking.  With old Inbox objects, it was (and is) simpler to
just kill processes w/o checking due to the low startup cost
(and non-portability of checking).

Reported-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Link: https://public-inbox.org/meta/20210921144754.gulkneuulzo27qbw@meerkat.local/
2 years agolei: drop redundant WQ EOF callbacks
Eric Wong [Wed, 22 Sep 2021 02:24:35 +0000 (02:24 +0000)]
lei: drop redundant WQ EOF callbacks

Redundant code is noise and therefore confusing :<

2 years agolei up: avoid excessively parallel --all
Eric Wong [Wed, 22 Sep 2021 02:24:34 +0000 (02:24 +0000)]
lei up: avoid excessively parallel --all

We shouldn't dispatch all outputs right away since they
can be expensive CPU-wise.  Instead, rely on DESTROY to
trigger further redispatches.

This also fixes a circular reference bug for the single-output
case that could lead to a leftover script/lei after MUA exit.

I'm not sure how --jobs/-j should work when the actual xsearch
and lei2mail has it's own parallelism ("--jobs=$X,$M"), but
it's better than having thousands of subtasks running.

Fixes: b34a267efff7b831 ("lei up: fix --mua with single output")
2 years agoinbox: do not waste hash slot on httpbackend_limiter
Eric Wong [Wed, 22 Sep 2021 02:24:33 +0000 (02:24 +0000)]
inbox: do not waste hash slot on httpbackend_limiter

A few dozen bytes saved here can add up when we have thousands
of inboxes.  It also makes Data::Dumper debug output a bit cleaner.

2 years agolei: dclose: do not close unnecessarily
Eric Wong [Wed, 22 Sep 2021 02:24:32 +0000 (02:24 +0000)]
lei: dclose: do not close unnecessarily

The bit about reap_compress is no longer true since
LeiXSearch->query_done triggers it, instead.  I only noticed
this while working on "lei up".

2 years agoscript/lei: describe purpose of sleep loop
Eric Wong [Wed, 22 Sep 2021 02:24:31 +0000 (02:24 +0000)]
script/lei: describe purpose of sleep loop

It looks dumb, but I'm not about to take a runtime penalty to
use signalfd|EVFILT_SIGNAL, here, either.

2 years agotreewide: fix %SIG localization, harder
Eric Wong [Wed, 22 Sep 2021 02:24:30 +0000 (02:24 +0000)]
treewide: fix %SIG localization, harder

This fixes the occasional t/lei-sigpipe.t infinite loop
under "make check-run".

Link: http://nntp.perl.org/group/perl.perl5.porters/258784
  <CAHhgV8hPbcmkzWizp6Vijw921M5BOXixj4+zTh3nRS9vRBYk8w@mail.gmail.com>
Followup-to: b552bb9150775fe4 ("daemon+watch: fix localization of %SIG for non-signalfd users")