]> Sergey Matveev's repositories - public-inbox.git/log
public-inbox.git
2 years agolei inspect: add atfork hook
Eric Wong [Tue, 19 Oct 2021 09:33:44 +0000 (09:33 +0000)]
lei inspect: add atfork hook

This is necessary for in case an inspect command is run
in a parallel with other commands.

2 years agodoc: lei: describe lei-daemon-kill and upgrades
Eric Wong [Tue, 19 Oct 2021 09:33:43 +0000 (09:33 +0000)]
doc: lei: describe lei-daemon-kill and upgrades

While we're at it, start dropping copyright years
since it seems acceptable to not have them:

  https://www.linuxfoundation.org/blog/copyright-notices-in-open-source-software-projects/

Copyright years are also a noisy to update every year (maybe,
just maybe, we'll make it to 2022...)

2 years agolei: remove unused ->busy time arg
Eric Wong [Tue, 19 Oct 2021 09:33:42 +0000 (09:33 +0000)]
lei: remove unused ->busy time arg

Our graceful shutdown doesn't time out clients.

2 years agolei up: support --exclude=, --no-(external|remote|local)
Eric Wong [Tue, 19 Oct 2021 09:33:41 +0000 (09:33 +0000)]
lei up: support --exclude=, --no-(external|remote|local)

These can be used to temporarily disable  using certain
externals in case of temporary network failure or mount point
unavailability.

2 years agolei: conditionally add "\n" to error messages
Eric Wong [Tue, 19 Oct 2021 09:33:40 +0000 (09:33 +0000)]
lei: conditionally add "\n" to error messages

Some error messages already include "\n" (w/ file+line info),
so don't add another one.  (`warn' will automatically add its
caller location unless there's a final "\n").

2 years agolei up: propagate redispatch_all failure via exit code
Eric Wong [Tue, 19 Oct 2021 09:33:39 +0000 (09:33 +0000)]
lei up: propagate redispatch_all failure via exit code

We can still continue with some local externals, maybe;
but the error needs to be propagated to the calling process
for scripting purposes.

2 years agolei: use die for external and query handling
Eric Wong [Tue, 19 Oct 2021 09:33:38 +0000 (09:33 +0000)]
lei: use die for external and query handling

This allows "lei up" to continue processing unrelated externals
if on output fails.

2 years agolei up: prefix `remote' and `local' with `o_'
Eric Wong [Tue, 19 Oct 2021 09:33:37 +0000 (09:33 +0000)]
lei up: prefix `remote' and `local' with `o_'

This will help distinguish between mail outputs and external
public-inboxes.

2 years agotest_common: lazy-require AutoReap
Eric Wong [Tue, 19 Oct 2021 09:33:36 +0000 (09:33 +0000)]
test_common: lazy-require AutoReap

This might speed up non-daemon-using tests.

2 years agoMakefile.PL: drop generated lib/PublicInbox.pm in blib/
Ævar Arnfjörð Bjarmason [Tue, 19 Oct 2021 11:13:52 +0000 (13:13 +0200)]
Makefile.PL: drop generated lib/PublicInbox.pm in blib/

Running "make test" on this project doesn't pass unless you've got an
existing PublicInbox.pm in your @INC, presumably nobody's set this up
on a fresh machine in a while.

This Makefile.PL trickery seems to do it, I've validated this with
this ad-hoc test of committing blib/ and Makefile to the repository:

    git clean -dxf; perl Makefile.PL && make -j8 all && git add -f blib Makefile.PL Makefile && git commit -m"now"

Running that in interactive rebase before/after shows that only the
PublicInbox.pm file was added to blib/lib/. We use $(INST_LIB) instead
of a hardcoded 'blib/lib' now, but it's what ExtUtils::MakeMaker
recommends, so it's probably for the better.

As far as I can tell this broke with 1fae720d (build: generate
PublicInbox.pm with $VERSION, 2021-04-01), but I have not tested
that. See also 1fae720d (build: generate PublicInbox.pm with $VERSION,
2021-04-01) which made the PublicInbox.pm a generated file.

2 years agov2: mirrors don't clobber msgs w/ reused Message-IDs
Eric Wong [Mon, 18 Oct 2021 05:09:05 +0000 (05:09 +0000)]
v2: mirrors don't clobber msgs w/ reused Message-IDs

For odd messages with reused Message-IDs, the second message
showing up in a mirror (via git-fetch + -index) should never
clobber an entry with a different blob in over.

This is noticeable only if the messages arrive in-between
indexing runs.

Fixes: 4441a38481ed ("v2: index forwards (via `git log --reverse')")
2 years agoextindex: show mismatches for messages deleted from inbox
Eric Wong [Mon, 18 Oct 2021 05:09:04 +0000 (05:09 +0000)]
extindex: show mismatches for messages deleted from inbox

There seems to be a bug in v2 inbox reindexing somewhere...

2 years agoextindex: better locations for {quit} checks
Eric Wong [Sun, 17 Oct 2021 09:52:50 +0000 (22:52 -1100)]
extindex: better locations for {quit} checks

Check for graceful termination at every message since it's
a fairly inexpensive check.

2 years agoextindex: guard against false mismatch unrefs
Eric Wong [Sun, 17 Oct 2021 09:52:49 +0000 (22:52 -1100)]
extindex: guard against false mismatch unrefs

I'm not sure if this is a bug or not (or it could be
an old bug in the v2 indexing code).

2 years agoextindex: retry sync_inbox before reindex
Eric Wong [Sun, 17 Oct 2021 09:52:48 +0000 (22:52 -1100)]
extindex: retry sync_inbox before reindex

Ensure the num highwater mark of the target inbox is stable
before using it.  Otherwise we may end up repeating work
done to index a message.

2 years agoextindex: use localtime to display lock time
Eric Wong [Sun, 17 Oct 2021 09:52:47 +0000 (22:52 -1100)]
extindex: use localtime to display lock time

Since this is intended for use on the command-line,
include TZ offset in time and try to shorten the
message a bit so it wraps less on a terminal.

2 years agomsgmap: do not cache num_highwater
Eric Wong [Sat, 16 Oct 2021 19:11:33 +0000 (19:11 +0000)]
msgmap: do not cache num_highwater

Caching the value doesn't seem necessary from a performance
perspective, and it adds a caveat for read-only users which
may lead to bugs in future code.

2 years agoeml: fix leak workaround
Eric Wong [Sat, 16 Oct 2021 23:23:01 +0000 (23:23 +0000)]
eml: fix leak workaround

Our previous workaround didn't actually work around the leak in
<https://rt.cpan.org/Public/Bug/Display.html?id=139622> since
croak()-via-Perl was still invoked before the SV reference
count could be decremented.

Put in a proper workaround which saves warnings onto a temporary
variable and only croak after ->decode or ->encode returns; not
inside those methods.

2 years agoMANIFEST: regenerate with: git ls-files >MANIFEST
Eric Wong [Sat, 16 Oct 2021 17:04:59 +0000 (17:04 +0000)]
MANIFEST: regenerate with: git ls-files >MANIFEST

2 years agolei sockets: favor level-triggered epoll for fairness
Eric Wong [Sat, 16 Oct 2021 09:29:53 +0000 (09:29 +0000)]
lei sockets: favor level-triggered epoll for fairness

Sigfd->event_step needs priority over script/lei clients,
LeiSelfSocket, and everything else.

2 years agoinput_pipe: do not loop in ->event_step for fairness
Eric Wong [Sat, 16 Oct 2021 09:29:52 +0000 (09:29 +0000)]
input_pipe: do not loop in ->event_step for fairness

Sigfd->event_step needs priority over InputPipe (and everything
else).  We keep Edge Triggering here but use ->requeue instead
of looping inside event_step.  This was necessary because
InputPipe can be used with regular files which can't be
monitored with epoll.

We'll also rid of the vestigial lei-oneshot support while we're
at it.

2 years agopkt_op: favor level-triggered epoll for fairness
Eric Wong [Sat, 16 Oct 2021 09:29:51 +0000 (09:29 +0000)]
pkt_op: favor level-triggered epoll for fairness

Sigfd->event_step needs priority over PktOp (and everything else).
We'll also add ECONNRESET checking, here, since it could see
bidirectional use in the future.

This is unlikely to have any sort of performance difference
since this is only for small, occasional packets, but the code
reduction is nice.

2 years agowqworker: favor level-triggered epoll for fairness
Eric Wong [Sat, 16 Oct 2021 09:29:50 +0000 (09:29 +0000)]
wqworker: favor level-triggered epoll for fairness

Sigfd->event_step needs priority over WQWorkers (and everything
else).  Do that by running once per event_loop iteration rather
than looping inside event_step.  This lowers throughput since it
requires more syscalls, but that's the price of fairness.

2 years agot/lei*: set EDITOR for dumb terminals
Eric Wong [Sat, 16 Oct 2021 07:54:03 +0000 (07:54 +0000)]
t/lei*: set EDITOR for dumb terminals

Running tests over a non-interactive ssh session fails,
otherwise.

2 years agodoc: lei: add manpages for remaining commands
Kyle Meyer [Sat, 16 Oct 2021 05:39:44 +0000 (01:39 -0400)]
doc: lei: add manpages for remaining commands

At this point all of the current lei commands, aside from -help and
-sucks, should be covered.

2 years agodoc: lei: restore alphabetical order to some listings
Kyle Meyer [Sat, 16 Oct 2021 05:39:43 +0000 (01:39 -0400)]
doc: lei: restore alphabetical order to some listings

Most the lei-related entries in txt2pre and Makefile.PL are in
alphabetical order.  Reorder the few that aren't.

While at it, reflow the Makefile.PL entries in preparation for the
entries that will be added in the next commit.

2 years agoextindex: avoid triggering a buggy unref
Eric Wong [Sat, 16 Oct 2021 01:41:34 +0000 (01:41 +0000)]
extindex: avoid triggering a buggy unref

We can't attempt to unref messages beyond the highwater mark of
an inbox.  This bugfix was found by commit c485036d0b1ce7ed
(extindex: guard against buggy unrefs, 2021-10-14), which
actually did its intended job and guarded against a buggy unref.

2 years agohttpd/async: switch to level-triggered epoll
Eric Wong [Sat, 16 Oct 2021 01:01:03 +0000 (01:01 +0000)]
httpd/async: switch to level-triggered epoll

We'll save ourselves some code here and let the kernel do more
work, instead.

2 years agoinbox + search: use 5.10.1 and do some golfing
Eric Wong [Sat, 16 Oct 2021 01:01:02 +0000 (01:01 +0000)]
inbox + search: use 5.10.1 and do some golfing

Some yak-shaving while I try to track down other bugs...

2 years agolei_to_mail: quiet down abort messages
Eric Wong [Sat, 16 Oct 2021 01:01:01 +0000 (01:01 +0000)]
lei_to_mail: quiet down abort messages

We don't need to flood the terminal with "W: $oid is  (!= blob)\n"
messages when somebody nukes a git cat-file process from under
us.

2 years agolei_overview: die rather than lei->fail
Eric Wong [Sat, 16 Oct 2021 01:01:00 +0000 (01:01 +0000)]
lei_overview: die rather than lei->fail

This will make our code more flexible in case it gets used in
non-lei things.

2 years agoextindex: prune invalid alternate entries on --gc
Eric Wong [Sat, 16 Oct 2021 01:00:59 +0000 (01:00 +0000)]
extindex: prune invalid alternate entries on --gc

Seeing the same warning over and over again gets annoying.

2 years agolei: more eval guards for die on failure
Eric Wong [Sat, 16 Oct 2021 01:00:58 +0000 (01:00 +0000)]
lei: more eval guards for die on failure

Relying on $lei->fail is unsustainable since there'll always
be parts of our code and dependencies which can trigger die()
and break the event loop.

2 years agolei: always keep cwd fd {3} for ->fchdir
Eric Wong [Sat, 16 Oct 2021 01:00:57 +0000 (01:00 +0000)]
lei: always keep cwd fd {3} for ->fchdir

The extra FD shouldn't cause noticeable overhead in short-lived
workers, and it lets us simplify lei->rel2abs.  Get rid of a
2-argument form of open() while we're at it, since it's been
considered for warning+deprecation by Perl for safety reasons.

2 years agolei: golf PATH2CFG cleanup
Eric Wong [Sat, 16 Oct 2021 01:00:56 +0000 (01:00 +0000)]
lei: golf PATH2CFG cleanup

More code means more bugs.

2 years agohttpd: move pipeline logic into event_step
Eric Wong [Sat, 16 Oct 2021 01:00:55 +0000 (01:00 +0000)]
httpd: move pipeline logic into event_step

Most of the HTTP server code was written for Danga::Socket and
not fully-transitioned to take advantage of PublicInbox::DS.
This change brings it up-to-date with the style of pipeline
handling used for -imapd and -nntpd.

2 years agoimapd+nntpd: drop timer-based expiration
Eric Wong [Sat, 16 Oct 2021 01:00:54 +0000 (01:00 +0000)]
imapd+nntpd: drop timer-based expiration

It's needlessly complex and O(n), so it doesn't scale well to a
high number of clients nor is it easy-to-scale with the data
structures available to us in pure Perl.

In any case, I see no evidence of either -imapd nor -nntpd
experiencing high connection loads on public-facing sites.
-httpd has never had its own timer-based expiration, either.

Fwiw, public-inbox.org itself has been running a public-facing
HTTP/HTTPS server with no userspace idle client expiration for
the past 8 years or with no ill effect.  Clients can come and go
as they wish, and SO_KEEPALIVE takes care of truly broken
connections if they're gone for ~2 hours.

Internet connections drop all time, so it should be harmless to
drop connections w/o warning since both NNTP and IMAP protocols
have well-defined semantics for determining if a message was
truncated (as does HTTP/1.1+).

2 years agodir_idle: do not add watches in ->new
Eric Wong [Sat, 16 Oct 2021 01:00:53 +0000 (01:00 +0000)]
dir_idle: do not add watches in ->new

There's no savings in having two ways to add watches to an
inotify nor kqueue descriptor.

2 years agosmsg: add ->oidbin method
Eric Wong [Sat, 16 Oct 2021 01:00:52 +0000 (01:00 +0000)]
smsg: add ->oidbin method

This makes some of our code less noisy by reducing the
amount of pack('H*', ...) use.

2 years agolei q: guard query_done against die()
Eric Wong [Fri, 15 Oct 2021 15:52:57 +0000 (15:52 +0000)]
lei q: guard query_done against die()

v2w->wq_do('done') may die on I/O errors, and likely other
places.  Just guard the entire block with an eval and ->fail
as appropriate.

2 years agolei forget-search: support multiple args
Eric Wong [Fri, 15 Oct 2021 14:02:15 +0000 (14:02 +0000)]
lei forget-search: support multiple args

I've been testing a lot of searches which I don't want to keep
around, so make it easy to remove a bunch at once.  We'll behave
like rm(1) and keep going in the face of failure.

2 years agolei note-event: fix explicit flush reliability
Eric Wong [Fri, 15 Oct 2021 13:30:56 +0000 (13:30 +0000)]
lei note-event: fix explicit flush reliability

We need to send the socket over to lei/store and wait for the
kernel to drop the socket refcount down to zero before
script/lei can exit.

This is not a new bug and only caused very sporadic test
failures.  I only noticed it while simplifying IPC stuff.

2 years agolei + ipc: simplify process reaping
Eric Wong [Fri, 15 Oct 2021 13:30:55 +0000 (13:30 +0000)]
lei + ipc: simplify process reaping

Simplify our APIs and force dwaitpid() to work in async mode for
all lei workers.  This avoids having lingering zombies for
parallel searches if one worker finishes soon before another.

The old distinction between "old" and "new" workers was
needlessly complex, error-prone, and embarrasingly bad.

We also never handled v2:// writers properly before on
Ctrl-C/Ctrl-Z (SIGINT/SIGTSTP), so add them to @WQ_KEYS
to ensure they get handled by $lei when appropropriate.

2 years agolei forget-search: fix for symlink-ed paths
Eric Wong [Fri, 15 Oct 2021 13:30:54 +0000 (13:30 +0000)]
lei forget-search: fix for symlink-ed paths

If lei up and edit-search work on something, so should forget-search.

2 years agolei q: avoid kw lookup failure on remote mboxrd
Eric Wong [Fri, 15 Oct 2021 09:52:53 +0000 (09:52 +0000)]
lei q: avoid kw lookup failure on remote mboxrd

When importing several sources in parallel via http(s) mboxrd,
we need to be able to get keywords of uncommitted documents
directly from shard workers.  Otherwise, Xapian DocNotFound
errors happen because the read-only LeiSearch won't see
documents from uncomitted transactions.  Keep in mind that it's
possible the keywords can be changed on-the-fly even for
uncommitted documents because of inotify watches from LeiNoteEvent.

2 years agowww: various help text updates
Eric Wong [Fri, 15 Oct 2021 07:30:01 +0000 (07:30 +0000)]
www: various help text updates

`dt:' documentation is redundant with `d:' approxidate support;
so drop `dt:' since mairix uses `d:'.  We'll also document
`rt:' since there are legit messages from senders with broken
clocks.

Reduce indentation level of help texts to be in 2-space
increments to using too much horizontal space.

We'll always place IMAP ahead of NNTP since it's alphabetical
and there's likely more IMAP clients out there.

Add "--ng NEWSGROUP" to -init instructions if configured.

There's also some minor wording changes throughout.

2 years agolei up --all: send signals to workers, receive errors
Eric Wong [Thu, 14 Oct 2021 13:16:09 +0000 (13:16 +0000)]
lei up --all: send signals to workers, receive errors

The redispatch mechanism wasn't routing signals and messages
between redispatched workers and script/lei properly.  We now
rely on PktOp to do bidirectional message forwarding and
carefully avoiding circular references by using PktOp.

2 years agolei up: actually rely on DESTROY for --alllll
Eric Wong [Thu, 14 Oct 2021 13:16:08 +0000 (13:16 +0000)]
lei up: actually rely on DESTROY for --alllll

We need to use DESTROY here to ensure we wait for workers, too;
not just the initial dispatch.

Fixes: cafbd77b3c82167d ("lei up: avoid excessively parallel --all")
2 years agolei: TSTP affects all curl and related subprocesses
Eric Wong [Thu, 14 Oct 2021 13:16:07 +0000 (13:16 +0000)]
lei: TSTP affects all curl and related subprocesses

By relying more on pgroups for remaining remaining processes,
this lets us pause all curl+tail subprocesses with a single
kill(2) to avoid cluttering stderr.

We won't bother pausing the pigz/gzip/bzip2/xz compressor
process not cat-file processes, though, since those don't write
to the terminal and they idle soon after the workers react to
SIGSTOP.

AutoReap is hoisted out from TestCommon.pm.  CLONE_SKIP
is gone since we won't be using Perl threads any time
soon (they're discouraged by the maintainers of Perl).

2 years agogit: cat-file --batch are their own pgrp
Eric Wong [Thu, 14 Oct 2021 13:16:06 +0000 (13:16 +0000)]
git: cat-file --batch are their own pgrp

We want these long-lived processes to die naturally when their
parent dies.  Hopefully this improves graceful shutdown for
-extindex because I'm interrupting a lot of reindexing...

2 years agogit: ->fail invokes current callback
Eric Wong [Thu, 14 Oct 2021 13:16:05 +0000 (13:16 +0000)]
git: ->fail invokes current callback

While we try to invoke all pending callbacks to force error
handling, the current callback wasn't getting invoked on
invoked on async_abort if my_read/my_readline failed.

2 years agogit: async_err shows retried requests properly
Eric Wong [Thu, 14 Oct 2021 13:16:04 +0000 (13:16 +0000)]
git: async_err shows retried requests properly

We make $req a reference upon retrying, but
"SCALAR(...)" in error messages isn't helpful, so
dereference the scalar ref.

2 years agolei: use send() perlop for signals
Eric Wong [Thu, 14 Oct 2021 13:16:03 +0000 (13:16 +0000)]
lei: use send() perlop for signals

This may save us a small bit of startup time since there's
fewer args and opcodes should be smaller.

2 years agolei: give workers their own process group
Eric Wong [Thu, 14 Oct 2021 04:32:55 +0000 (04:32 +0000)]
lei: give workers their own process group

This lets users Ctrl-Z from their terminal to pause an entire
git-clone process hierarchy.

2 years agolei: -d (--dir) and -O (only) shortcuts
Eric Wong [Thu, 14 Oct 2021 09:54:54 +0000 (09:54 +0000)]
lei: -d (--dir) and -O (only) shortcuts

`-d' seems like a non-brainer for --dir with inspect.

I find myself using `--only' a bit, too, and `-O' seems like
a reasonable shortcut for it.

2 years agolei add-external --mirror: respect client umask
Eric Wong [Thu, 14 Oct 2021 04:32:54 +0000 (04:32 +0000)]
lei add-external --mirror: respect client umask

While lei is intended for non-public mail and runs umask(077)
by default, externals are one area which can safely defer to
the user's umask.

Instead of sending it unconditionally with every command, only
have lei-daemon request it when necessary.

2 years agoclone+fetch: respect umask for all downloaded files
Eric Wong [Thu, 14 Oct 2021 04:32:53 +0000 (04:32 +0000)]
clone+fetch: respect umask for all downloaded files

Since public inboxes are usually intended to be public,
the File::Temp default permission of 0600 is wrong.
Just respect the user's umask in this case as git-clone
does.

This doesn't work for "lei add-external --mirror", yet;
but it will...

2 years agolei inspect: account for non-extindex inboxes
Eric Wong [Thu, 14 Oct 2021 03:12:25 +0000 (03:12 +0000)]
lei inspect: account for non-extindex inboxes

Inbox->xdb does not exist, but this code path was apparently
never tested :x  I noticed this on basic v2 inbox, but it could
happen with any v1/v2 inbox.  Move ->num2docid into Search
so it's less awkward to use.

2 years agoextindex: guard against buggy unrefs
Eric Wong [Thu, 14 Oct 2021 06:06:29 +0000 (06:06 +0000)]
extindex: guard against buggy unrefs

I noticed some unref messages which shouldn't have been
happening, but they were.  Which is troubling.  So add
a guard around an unref path until we can get to the bottom
of this.

2 years agofetch: support --try-remote/-T for alternate remote names
Eric Wong [Wed, 13 Oct 2021 11:06:21 +0000 (11:06 +0000)]
fetch: support --try-remote/-T for alternate remote names

This allows -fetch to work out-of-the-box on using the
grokmirror 2.x default of "_grokmirror".

2 years agot/nntpd-tls: change diag() to like() assertion
Eric Wong [Wed, 13 Oct 2021 10:16:11 +0000 (10:16 +0000)]
t/nntpd-tls: change diag() to like() assertion

This test wasn't finished when I initially wrote it :x

2 years agot/git: avoid "once" warning for async_warn
Eric Wong [Wed, 13 Oct 2021 10:16:10 +0000 (10:16 +0000)]
t/git: avoid "once" warning for async_warn

No point in testing use_ok when we have no outside dependencies
nor exports in this case.

2 years agot/lei-mirror: avoid reading ~/.public-inbox/config in test
Eric Wong [Wed, 13 Oct 2021 10:16:09 +0000 (10:16 +0000)]
t/lei-mirror: avoid reading ~/.public-inbox/config in test

Oops, we shouldn't attempt to read a users' actual HOME when
running -index, since mine has a bunch of invalid entries in
there.

2 years agoeml: avoid Encode 2.87..3.12 leak
Eric Wong [Wed, 13 Oct 2021 10:16:08 +0000 (10:16 +0000)]
eml: avoid Encode 2.87..3.12 leak

Encode::FB_CROAK leaks memory in old versions of Encode:
<https://rt.cpan.org/Public/Bug/Display.html?id=139622>

Since I expect there's still many users on old systems and old
Perls, we can use "$SIG{__WARN__} = \&croak" here with
Encode::FB_WARN to emulate Encode::FB_CROAK behavior.

2 years agot/www_listing: require opt-in for grokmirror tests
Eric Wong [Wed, 13 Oct 2021 10:16:07 +0000 (10:16 +0000)]
t/www_listing: require opt-in for grokmirror tests

grokmirror 2.x seems to idle in several places for 5s at-a-time,
causing t/www_listing.t to take longer than "make check-run" on
a 4-core system when run without grokmirror.  So make it
optional but add some test knobs to allow tailing the log
output so I can see what's going on.

2 years agotest_common: hoist out tail_f sub
Eric Wong [Wed, 13 Oct 2021 10:16:06 +0000 (10:16 +0000)]
test_common: hoist out tail_f sub

We'll be reusing this in more places.  While we're at it, allow
it to tail all run_script() users, including lei() in TestCommon.

2 years agoxt/perf-msgview: drop unnecessary use_ok
Eric Wong [Wed, 13 Oct 2021 10:16:05 +0000 (10:16 +0000)]
xt/perf-msgview: drop unnecessary use_ok

require_mods covers it, and we're not testing Plack itself.

2 years agowww: preload: load ExtSearch via ->ALL
Eric Wong [Wed, 13 Oct 2021 07:00:38 +0000 (07:00 +0000)]
www: preload: load ExtSearch via ->ALL

This ought to give us more CoW savings and fragmentation
avoidance in -httpd.

2 years agoextindex: set {current_info} in eidxq processing
Eric Wong [Wed, 13 Oct 2021 07:00:37 +0000 (07:00 +0000)]
extindex: set {current_info} in eidxq processing

This gives context as to where warnings are coming from.

2 years agotreewide: use warn() or carp() instead of env->{psgi.errors}
Eric Wong [Wed, 13 Oct 2021 07:00:36 +0000 (07:00 +0000)]
treewide: use warn() or carp() instead of env->{psgi.errors}

Large chunks of our codebase and 3rd-party dependencies do not
use ->{psgi.errors}, so trying to standardize on it was a
fruitless endeavor.  Since warn() and carp() are standard
mechanism within Perl, just use that instead and simplify a
bunch of existing code.

2 years agolei: use standard warn() in more places
Eric Wong [Wed, 13 Oct 2021 07:00:35 +0000 (07:00 +0000)]
lei: use standard warn() in more places

warn() is easier to augment with context information, and
frankly unavoidable in the presence of 3rd-party libraries
we don't control.

2 years agoextindex: show OID on bad blob failure
Eric Wong [Wed, 13 Oct 2021 07:00:34 +0000 (07:00 +0000)]
extindex: show OID on bad blob failure

AFAIK I've never hit these messages, but I might be glad
if I ever do.

2 years agodaemon: set $SIG{__WARN__} properly
Eric Wong [Wed, 13 Oct 2021 02:48:59 +0000 (02:48 +0000)]
daemon: set $SIG{__WARN__} properly

Eml->warn_ignore_cb itself returns a callback, so creating a
reference to it was wrong when assigning it to $SIG{__WARN__};

Fixes: 176cd51f9aa81b74 ("daemon: quiet down Eml-related warnings")
2 years agolei up --all: show output for warnings
Eric Wong [Tue, 12 Oct 2021 22:45:00 +0000 (22:45 +0000)]
lei up --all: show output for warnings

This helps users make sense of which saved searches some
warnings were coming from.

Since I often create and discard externals, some warnings
from saved searches were confusing to me without output context:

  "`$FOO' is unknown"
  "$FOO not indexed by Xapian"

2 years agodoc: relnotes: note some recent improvements
Eric Wong [Tue, 12 Oct 2021 22:44:59 +0000 (22:44 +0000)]
doc: relnotes: note some recent improvements

2 years agoindex: optimize after all SQLite DB commits
Eric Wong [Tue, 12 Oct 2021 22:44:58 +0000 (22:44 +0000)]
index: optimize after all SQLite DB commits

This covers v1 inboxes, as well.  We also guard the execution
since "PRAGMA optimize" was only introduced in SQLite 3.18.0
(2017-03-30)

2 years agolei/store: use remove_doc to save some LoC
Eric Wong [Tue, 12 Oct 2021 22:44:57 +0000 (22:44 +0000)]
lei/store: use remove_doc to save some LoC

2 years agoextindex: flush pending reindex before unref
Eric Wong [Tue, 12 Oct 2021 22:44:56 +0000 (22:44 +0000)]
extindex: flush pending reindex before unref

This prevents unnecessary message renumbering and I/O.

Without this change, there is a small window for long-running
WWW streaming requests to miss a message that was unref-ed
before reindexing.  If we expose an "All Mail" mailbox via
IMAP/JMAP, this will save client traffic.

2 years agowww: _/text/config/raw Last-Modified: is mm->created_at
Eric Wong [Tue, 12 Oct 2021 11:47:05 +0000 (11:47 +0000)]
www: _/text/config/raw Last-Modified: is mm->created_at

This allows IMAP mirrors to keep UIDVALIDITY synchronized (and
"LIST ACTIVE.TIMES" in NNTP).  "lei add-external --mirror" will
automatically set it, as will the combination of
public-inbox-clone + public-inbox-index.

This avoids the need for extra endpoints or config entries,
at least...

2 years agomsgmap: ->new_file to supports $ibx arg, drop ->new
Eric Wong [Tue, 12 Oct 2021 11:47:04 +0000 (11:47 +0000)]
msgmap: ->new_file to supports $ibx arg, drop ->new

The original Msgmap->new API was v1-specific and not necessary.
The ->new_file API now supports an $ibx object being passed to
it, simplify -no_fsync use.  It will also make an upcoming
change easier...

2 years agodaemon: unconditionally close Xapian shards on cleanup
Eric Wong [Tue, 12 Oct 2021 11:47:03 +0000 (11:47 +0000)]
daemon: unconditionally close Xapian shards on cleanup

The cost of opening a Xapian DB (even with shards) isn't high,
so save some FDs and just close it.  We hit Xapian far less than
over.sqlite3 and we discard the MSet ASAP even when streaming
large responses.

This simplifies our code a bit and hopefully helps reduce
fragmentation by increasing mortality of late allocations.

2 years agomsgmap: share most of check_inodes w/ over
Eric Wong [Tue, 12 Oct 2021 11:47:02 +0000 (11:47 +0000)]
msgmap: share most of check_inodes w/ over

We still need to account for msgmap being open all the time
and not having separate read-only vs. read-write packages.

2 years agomsgmap: use DBI->prepare_cached
Eric Wong [Tue, 12 Oct 2021 11:47:01 +0000 (11:47 +0000)]
msgmap: use DBI->prepare_cached

msgmap is not performance-critical enough to justify doing our
own prepared statement caching.  Just rely on the functionality
of DBI here so future changes will be easier.

There's also minor style changes to avoid dirtying refcount
cache lines bumping by repeating hash lookups rather than attempting
to store them as locals.

2 years agonntp: use defined-OR from Perl 5.10 for msgid check
Eric Wong [Tue, 12 Oct 2021 11:47:00 +0000 (11:47 +0000)]
nntp: use defined-OR from Perl 5.10 for msgid check

"<0>" could be a valid Message-ID, maybe...

2 years agosearch: delete QueryParser along with DB handle
Eric Wong [Tue, 12 Oct 2021 11:46:59 +0000 (11:46 +0000)]
search: delete QueryParser along with DB handle

Xapian::QueryParser is attached to the Xapian::Database,
so holding onto the QueryParser was preventing us from
releasing DB handles if a query was performed.

2 years agodaemon: quiet down Eml-related warnings
Eric Wong [Tue, 12 Oct 2021 11:46:58 +0000 (11:46 +0000)]
daemon: quiet down Eml-related warnings

Email::Address::XS is quite noisy and there's nothing we can
really do about messages we're serving from read-only daemons.

2 years agodaemon: use v5.10.1, disable local warnings
Eric Wong [Tue, 12 Oct 2021 11:46:57 +0000 (11:46 +0000)]
daemon: use v5.10.1, disable local warnings

We're moving towards relying on "perl -w" for warnings and
v5.12 for strict.

2 years agoisearch: do not access Extsearch->{over} directly
Eric Wong [Tue, 12 Oct 2021 08:40:01 +0000 (08:40 +0000)]
isearch: do not access Extsearch->{over} directly

It may not exist due to periodic cleanup to avoid excessive FD use.

2 years agoextindex: avoid invalid blobs after unref
Eric Wong [Mon, 11 Oct 2021 08:06:20 +0000 (08:06 +0000)]
extindex: avoid invalid blobs after unref

When unref-ing a blob from xref3, make sure the "preferred"
smsg->{blob} doesn't point to the blob we just unrefed.  This
is necessary because we periodically checkpoint our extindex
process to allow -watch and -mda processes to run.

This also gets rid of a lot of redundant code for ->remove_xref3,
since it's all handled in ExtSearchIdx, now.

2 years agoextindex: more consistent doc removal
Eric Wong [Mon, 11 Oct 2021 08:06:19 +0000 (08:06 +0000)]
extindex: more consistent doc removal

We need to ensure a message is consistently removed from eidxq,
over and Xapian in all cases.  Removing from eidxq saves users
from some noisy error messages.

2 years agoextindex: share unref logic in more places
Eric Wong [Mon, 11 Oct 2021 08:06:18 +0000 (08:06 +0000)]
extindex: share unref logic in more places

We can use the same logic for --gc and --reindex and
'd' log entries

They're similar enough and the actual need to unref should
be fairly rare.  We could go a lot faster if we didn't show
progress for --gc and --reindex, actually.

2 years agoextindex: rename var: active => active_shards
Eric Wong [Mon, 11 Oct 2021 08:06:17 +0000 (08:06 +0000)]
extindex: rename var: active => active_shards

We also have the idea of active inboxes, too, so "active shards"
ought to make the purpose of the data structure more obvious.

2 years agosqlite: PRAGMA optimize on close
Eric Wong [Mon, 11 Oct 2021 08:06:16 +0000 (08:06 +0000)]
sqlite: PRAGMA optimize on close

As recommended by SQLite documentation[1]:

  To achieve the best long-term query performance without the need
  to do a detailed engineering analysis of the application schema
  and SQL, it is recommended that applications run "PRAGMA optimize"
  (with no arguments) just before closing each database connection.

Hopefully that works for our use cases and can make things
faster for us.

[1] https://www.sqlite.org/pragma.html#pragma_optimize

2 years agoextindex: speed up --reindex --fast
Eric Wong [Mon, 11 Oct 2021 08:06:15 +0000 (08:06 +0000)]
extindex: speed up --reindex --fast

This required some tweaking of xref3 indices in over.sqlite3,
but the end result is it brings no-op "--reindex --fast --all"
checks down to roughly 20 minutes (from 30-40 minutes) on
lore/all.

This is faster because a bunch of small SQLite queries are still
slower en-mass than a bunch of perlops.  Despite the lack of IPC
overhead, crossing .so boundaries and repeating lookups over
btrees is still slower than doing the same with Perl hash tables.

2 years agodoc: lei-refresh-mail-sync: drop repeated word
Kyle Meyer [Mon, 11 Oct 2021 04:53:59 +0000 (00:53 -0400)]
doc: lei-refresh-mail-sync: drop repeated word

2 years agoextindex: sync each inbox before checking for missed messages
Eric Wong [Sun, 10 Oct 2021 14:25:18 +0000 (14:25 +0000)]
extindex: sync each inbox before checking for missed messages

Otherwise, it gets too noisy and we repeat some work
when we do an actual sync, since the last_commit info
will be out-of-date.

2 years agolei/store: keep ".err-XXXX" in stderr tmpfile
Eric Wong [Sun, 10 Oct 2021 14:25:17 +0000 (14:25 +0000)]
lei/store: keep ".err-XXXX" in stderr tmpfile

This is slighly more meaningful since the file is already
in ~/.local/share/lei/store, so "lei_store" was redundant
(and the "XXXX" are random characters replaced by File::Temp)

2 years agoextindex: --gc doesn't touch ghost entries
Eric Wong [Sun, 10 Oct 2021 14:25:16 +0000 (14:25 +0000)]
extindex: --gc doesn't touch ghost entries

We were deleting ghost entries, this was usually harmless since
other messages could fill-in-the-blanks, but could cause
misthreading in odd cases where a big chunk of a thread is
missing and the latest messages only referenced ghosts.

We'll also save some cycles when scanning Xapian shards since
docids won't be <= 0.

2 years agoextindex: minor cost reductions
Eric Wong [Sun, 10 Oct 2021 14:25:15 +0000 (14:25 +0000)]
extindex: minor cost reductions

Don't bother decoding the 20-byte SHA-1 to a 40-byte hex value
since we don't read it, anyways.  We can also use the on-stack
ibx->eidx_key value instead of dispatching the method again.

2 years agoextindex: speed up Xapian cleanup in --gc
Eric Wong [Sun, 10 Oct 2021 14:25:14 +0000 (14:25 +0000)]
extindex: speed up Xapian cleanup in --gc

Avoiding repeated SQL statements brings --gc down to 2-3 minutes
from around 10.  We'll also add some checkpoints around over and
xref3 cleanups.