]> Sergey Matveev's repositories - public-inbox.git/log
public-inbox.git
3 years agoTODO: add item for dealing with base-85 binary patches
Eric Wong [Sun, 31 Jan 2021 09:20:52 +0000 (09:20 +0000)]
TODO: add item for dealing with base-85 binary patches

False-positives from search results are no fun

3 years agocontent_hash: skip Sender for cross posted messages
Eric Wong [Sat, 30 Jan 2021 05:41:09 +0000 (23:41 -0600)]
content_hash: skip Sender for cross posted messages

This regression was introduced long ago and matches behavior
originally specified in the comments.  It makes a noticeable
improvement with search results using -extindex ("all") and
lei results with multiple inboxes.

Update some style bits at the top of the test case while
we're at it.

Fixes: f0ef0a56a8957d6f ("v2: improve deduplication checks")
3 years agoshared_kv: simplify PID+object guard for cleanup
Eric Wong [Fri, 29 Jan 2021 07:43:00 +0000 (12:43 +0500)]
shared_kv: simplify PID+object guard for cleanup

We don't need another hash slot when we can encode the object ID
and PID owner into the field name itself.

3 years agoipc: move on_destroy scope to inside the eval
Eric Wong [Fri, 29 Jan 2021 07:42:59 +0000 (12:42 +0500)]
ipc: move on_destroy scope to inside the eval

It saves us a line of code

3 years agogit: synchronous cat_file may return type and OID
Eric Wong [Fri, 29 Jan 2021 07:42:58 +0000 (12:42 +0500)]
git: synchronous cat_file may return type and OID

Instead of forcing callers to set a variable to write into,
we'll just rely on wantarray.

3 years agolei: less error-prone FD mapping
Eric Wong [Fri, 29 Jan 2021 07:42:57 +0000 (12:42 +0500)]
lei: less error-prone FD mapping

Keeping track of non-standard FDs gets tricky, so make it easier
by relying on st_dev/st_ino mapping in the transmitted objects.

We'll keep using numbers for the standard FDs since we need to
be able to easily redirect them in the producer (main daemon)
process for (gzip|bzip2|xz) if writing to a compressed mbox.

3 years agoipc: more consistent behavior between worker types
Eric Wong [Fri, 29 Jan 2021 07:42:56 +0000 (12:42 +0500)]
ipc: more consistent behavior between worker types

Localize signals inside the respective worker loops
in case there's circular references.

We'll also rely on OnDestroy to trigger exits from the
ipc_worker_loop like we do with wq_worker_loop.  And
also add some more developer documentation to help future
developers.

The default signals remain different, for now.
Cleanup some unnecessary "use" statements while we're
loading OnDestroy.

3 years agolei_xsearch: drop repeated "Xapian" in error message
Eric Wong [Fri, 29 Jan 2021 07:42:55 +0000 (12:42 +0500)]
lei_xsearch: drop repeated "Xapian" in error message

Copy+paste error :x

3 years agoipc: wq: support passing fields to workers
Eric Wong [Fri, 29 Jan 2021 07:42:54 +0000 (12:42 +0500)]
ipc: wq: support passing fields to workers

This will be useful for pre-sharing certain file handles.

3 years agolei: dclose: fix typo
Eric Wong [Wed, 27 Jan 2021 09:42:30 +0000 (03:42 -0600)]
lei: dclose: fix typo

Oops :x

3 years agov2writable: nproc: use sysconf() on Linux and FreeBSD
Eric Wong [Wed, 27 Jan 2021 09:42:29 +0000 (03:42 -0600)]
v2writable: nproc: use sysconf() on Linux and FreeBSD

No need to fork a process on platforms I use daily, at least.

3 years agolei_overview: clear redundant ovv_buf definition
Eric Wong [Wed, 27 Jan 2021 09:42:28 +0000 (03:42 -0600)]
lei_overview: clear redundant ovv_buf definition

Declaring "my $buf" inside that `if' branch was useless, so
we've been declaring it per-callback when {l2m} isn't in use.

3 years agolei: complete option switch args
Eric Wong [Wed, 27 Jan 2021 09:42:27 +0000 (03:42 -0600)]
lei: complete option switch args

And add tests for existing completion cases

3 years agogcf2: rely on Perl 5.10 to avoid needless ++
Eric Wong [Wed, 27 Jan 2021 09:42:26 +0000 (03:42 -0600)]
gcf2: rely on Perl 5.10 to avoid needless ++

And note the PublicInbox::Spawn side effect of setting
PERL_INLINE_DIRECTORY.

3 years agolei: set PWD correctly for path expansion
Eric Wong [Wed, 27 Jan 2021 09:42:25 +0000 (03:42 -0600)]
lei: set PWD correctly for path expansion

While commit d1b9582872d1824f166a038dcf32b6ae8c6dc735
("lei: pass FD to CWD via cmsg, use fchdir on server")
ensured things work properly to get the daemon in the
right directory, it forgot to deal with places where
we expand relative paths based on the current working
directory.

3 years agolei: fix comment regarding client payload
Eric Wong [Wed, 27 Jan 2021 09:42:24 +0000 (03:42 -0600)]
lei: fix comment regarding client payload

The client PID is no longer sent to the daemon.

3 years agolei: drop "git" command forwarding
Eric Wong [Wed, 27 Jan 2021 09:42:23 +0000 (03:42 -0600)]
lei: drop "git" command forwarding

It was intended as a proof-of-concept and no longer needed.

3 years agoeml: favor index() over regexp match
Eric Wong [Wed, 27 Jan 2021 09:42:22 +0000 (03:42 -0600)]
eml: favor index() over regexp match

Where applicable, index() is faster than entering the regexp
engine and we favor it in several other places, as well.

3 years agouse defined-or in a few more places
Eric Wong [Mon, 25 Jan 2021 06:41:58 +0000 (22:41 -0800)]
use defined-or in a few more places

Mainly around fork() calls, but some nearby places as well.

3 years agospawn: split() on regexp, not a literal string
Eric Wong [Mon, 25 Jan 2021 06:41:57 +0000 (22:41 -0800)]
spawn: split() on regexp, not a literal string

It doesn't appear Perl (as of 5.32.x) has any internal
optimization for splitting on a single-byte, so give it
a regexp instead of letting it compile and discard a
new one every single time.

3 years agomiscidx: switch to lazy transactions
Eric Wong [Mon, 25 Jan 2021 06:41:56 +0000 (22:41 -0800)]
miscidx: switch to lazy transactions

This fixes a sporadic failure on a 1/2 core VM where
"git cat-file --batch" hasn't started up by the time
$cleanup->() destroys the ALL.git directory in t/lei.t
(but not t/lei-oneshot.t).

This happens because dwaitpid() runs inside the event loop
asynchronously and we were able to return to the client before
the cat-file process could even start.

I could not reproduce this failure on my usual 4-core
workstation via "schedtool -a 0x1" to force the entire
test to use a single core.

Lazy transactions matches OverIdx and SearchIdx behavior, and
I've verified this lets us avoid problems with old Xapian
versions (on CentOS 7.x) which failed to set FD_CLOEXEC.

3 years agodoc: start working on public-inbox-extindex(1) manpage
Eric Wong [Mon, 25 Jan 2021 04:53:46 +0000 (19:53 -0900)]
doc: start working on public-inbox-extindex(1) manpage

It's barely started, but I started writing this weeks ago, but
I'm still unsure about some behavioral/usability things and
hoping work on lei(1) can flush them out.

3 years agobuild: check with lexgrog(1) if available
Eric Wong [Mon, 25 Jan 2021 04:53:45 +0000 (19:53 -0900)]
build: check with lexgrog(1) if available

This will make life easier for Debian package maintainers
running lintian.

cf. commit 1350f5ab09f72c75ac2cd6c88f6a2b9e198fef55
    ("public-inbox-v[12]-format.pod: make lexgrog happy")

3 years agodoc: extindex-format: make lexgrog happy
Eric Wong [Mon, 25 Jan 2021 04:53:44 +0000 (19:53 -0900)]
doc: extindex-format: make lexgrog happy

Based on commit 1350f5ab09f72c75ac2cd6c88f6a2b9e198fef55
("public-inbox-v[12]-format.pod: make lexgrog happy")

3 years agolei: use Time::HiRes stat for nanosecond resolution
Eric Wong [Mon, 25 Jan 2021 06:41:55 +0000 (22:41 -0800)]
lei: use Time::HiRes stat for nanosecond resolution

The default stat() lacks subsecond granularity and may
lead to config updates being ignored.

3 years agolei q: continue remote search if torsocks(1) is missing
Eric Wong [Mon, 25 Jan 2021 01:18:57 +0000 (17:18 -0800)]
lei q: continue remote search if torsocks(1) is missing

torsocks is just one of many ways to get curl to use Tor,
so we'll continue if we can't find torsocks in our PATH
and assume the user has a proxy configured via curlrc,
the command-line, environment variable, or even firewall
rules.

3 years agolei q: reject remotes early if curl(1) is missing
Eric Wong [Mon, 25 Jan 2021 01:18:56 +0000 (17:18 -0800)]
lei q: reject remotes early if curl(1) is missing

This ought to provide a better user experience for
users if they attempt to use remote externals but
don't have curl installed.

We can avoid repeating PATH search in every worker here, too.

3 years agolei q: demangle and quiet curl output
Eric Wong [Mon, 25 Jan 2021 01:18:55 +0000 (17:18 -0800)]
lei q: demangle and quiet curl output

curl(1) writes to stderr one byte-at-a-time (presumably for the
progress bar).  This ends up being unreadable on my terminal
when parallel processes are trying to write error messages.

So instead, we'll capture the output to a file and run
'tail -f' on it if --verbose is enabled.

Since HTTP 404s from non-existent results are a common response,
we'll ignore them and stay silent, matching behavior of local
searches.

3 years agolei q: drop "oid" output format
Eric Wong [Mon, 25 Jan 2021 01:18:54 +0000 (17:18 -0800)]
lei q: drop "oid" output format

The default deduplication command-line arguments would be
non-sensical for such an option and probably confusing.  It
doesn't seem worth the code to support OID-only output when it's
easy enough to use one of the JSON formats to extract the same
info.

We also don't have OIDs if using remotes, and the
to-be-implemented memoization will be optional.

3 years agolei: reinstate JSON smsg output deduplication
Eric Wong [Mon, 25 Jan 2021 01:18:53 +0000 (17:18 -0800)]
lei: reinstate JSON smsg output deduplication

This was accidentally clobbered completely in
("lei q: fix JSON overview with remote externals").
There are now more tests to prevent future regressions.

3 years agodoc: re-add missing 1.6 release notes
Eric Wong [Mon, 25 Jan 2021 19:56:21 +0000 (19:56 +0000)]
doc: re-add missing 1.6 release notes

I missed these during the merge :x

3 years agodoc: README + INSTALL: update with -imapd info
Eric Wong [Mon, 25 Jan 2021 19:18:32 +0000 (19:18 +0000)]
doc: README + INSTALL: update with -imapd info

I forgot to update these when releasing 1.6 :x

3 years agosmsg: parse_references: micro-optimization
Eric Wong [Sun, 24 Jan 2021 11:46:55 +0000 (04:46 -0700)]
smsg: parse_references: micro-optimization

With Perl 5.10+, we can rely on the defined-or-assignment (//=)
operator to avoid repeatedly rewriting an SV.

This may not provide a measurable difference here, but
it's more consistent with current style where things like
commit a05445fb400108e60ede7d377cf3b26a0392eb24
("config: config_fh_parse: micro-optimize") provide a measurable
improvement.

3 years agosmsg: make parse_references an object method
Eric Wong [Sun, 24 Jan 2021 11:46:54 +0000 (04:46 -0700)]
smsg: make parse_references an object method

Having parse_references in OverIdx was awkward and Smsg is
a better place for it.

3 years agolei q: fix JSON overview with remote externals
Eric Wong [Sun, 24 Jan 2021 11:46:53 +0000 (04:46 -0700)]
lei q: fix JSON overview with remote externals

We can't (and don't need to) repeatedly get the $each_smsg
callback for each URI since that clobbers {ovv_buf} before
it can be output.

I initially thought this was a dedupe-related bug and
moved the dedupe code into the $each_smsg callback to
minimize differences.  Nevertheless it's a nice code
reduction.

I also thought it was related to incomplete smsg info,
so {references} is now filled in correctly for dedupe.

3 years agolei_xsearch: use curl -d '' for nginx compatibility
Eric Wong [Sun, 24 Jan 2021 11:46:52 +0000 (04:46 -0700)]
lei_xsearch: use curl -d '' for nginx compatibility

It appears Content-Length and/or Content-Type headers are
required by nginx with POST requests.

varnish alone doesn't have this requirement and my (perhaps
lossy) reading of RFC 2616, 7230, 7231 didn't note this, either.

In any case, we must support nginx even if it's overly strict.

Reported-By: Kyle Meyer <kyle@kyleam.com>
Link: https://public-inbox.org/meta/87v9bmswkh.fsf@kyleam.com/
3 years agolei q: honor --no-local to force remote searches
Eric Wong [Sun, 24 Jan 2021 11:46:51 +0000 (04:46 -0700)]
lei q: honor --no-local to force remote searches

This can be useful for testing remote behavior, or for
augmenting local results.  It'll also be possible to explicitly
include/exclude externals via CLI switches (once names are
decided).

3 years agolei q: disable remote externals if locals exist
Eric Wong [Sun, 24 Jan 2021 11:46:50 +0000 (04:46 -0700)]
lei q: disable remote externals if locals exist

--remote should be explicitly enabled if local externals are
present, since users may be offline or on expensive + metered
Internet while traveling.

In the future, --remote will probably default to
caching/memoizing all messages it fetches to increase the
usefulness of --local.

3 years agoipc: get rid of wq_set_recv_modes
Eric Wong [Sun, 24 Jan 2021 11:46:49 +0000 (04:46 -0700)]
ipc: get rid of wq_set_recv_modes

Just open every FD as read/write.  Perl (or any non-broken
runtime) won't care and won't attempt to use F_SETFL to alter
file description flags; as attempting to change those would
lead to unpleasant side effects if the file description is
shared with another process.

3 years agoipc: wq supports arbitrarily large payloads
Eric Wong [Sun, 24 Jan 2021 11:46:48 +0000 (04:46 -0700)]
ipc: wq supports arbitrarily large payloads

This should not be needed, but somebody using lei could
theoretically create thousands of external URLs and
only have a handful of workers, which means the per-worker
URI list could be large.

3 years agolei q: limit concurrency to 4 remote connections
Eric Wong [Sun, 24 Jan 2021 11:46:47 +0000 (04:46 -0700)]
lei q: limit concurrency to 4 remote connections

Unfortunately, this isn't a per-host limit, yet; but
nevertheless reduces load on existing PublicInbox::WWW
instances, since requesting a mboxrd is one of the more
expensive operations.

3 years agotreewide: reseed RNG in child processes
Eric Wong [Fri, 22 Jan 2021 20:01:19 +0000 (20:01 +0000)]
treewide: reseed RNG in child processes

This prevents name conflicts leading to retries and slowdowns in
temporary file name generation.  No actual data corruption
resulted because all temporary files are opened with O_EXCL
anyways.

This may increase security for IMAP, NNTP, and HTTPS sessions
using TLS, but it's all public data anyways.

3 years agolei add-external: don't allow non-existent directories
Eric Wong [Sat, 23 Jan 2021 10:27:55 +0000 (10:27 +0000)]
lei add-external: don't allow non-existent directories

At least not yet, though we may support mirroring via git.

3 years agolei forget-external: don't show redundant "not found"
Eric Wong [Sat, 23 Jan 2021 10:27:54 +0000 (10:27 +0000)]
lei forget-external: don't show redundant "not found"

Pathname/URL canonicalization may not change the result at
all, so there's no point in trying (and failing) the same
form twice if pre and post-canonicalization are identical.

3 years agolei q: support a bunch of curl(1) options
Eric Wong [Sat, 23 Jan 2021 10:27:53 +0000 (10:27 +0000)]
lei q: support a bunch of curl(1) options

Some of these options will make sense when on weird networks
(behind firewalls, etc.)  Some of these options may not make
sense at all.

This allows users who prefer to use the SOCKS5 proxy support in
curl rather than torsocks(1), but we'll still support torsocks
by default since some Tor instances aren't on the default
127.0.0.1:9050.

3 years agolei forget-external: just show the location
Eric Wong [Sat, 23 Jan 2021 10:27:52 +0000 (10:27 +0000)]
lei forget-external: just show the location

No need to show the full key name since the user mainly
uses the location.

3 years agolei completion: handle URLs with port numbers
Eric Wong [Sat, 23 Jan 2021 10:27:51 +0000 (10:27 +0000)]
lei completion: handle URLs with port numbers

This improves the experience for developers running local
instances of PublicInbox::WWW without permissions to bind
port 80 or 443.

3 years agolei: default "-f $mfolder" args for common MUAs
Eric Wong [Sat, 23 Jan 2021 10:27:50 +0000 (10:27 +0000)]
lei: default "-f $mfolder" args for common MUAs

At least mail, mailx, mutt, and neomutt follow this convention.
Heirloom mailx doesn't support Maildir (our default), but GNU
mailutils mail/mailx does.

3 years agolei: oneshot: preserve stdout if writing mbox
Eric Wong [Sat, 23 Jan 2021 10:27:49 +0000 (10:27 +0000)]
lei: oneshot: preserve stdout if writing mbox

We still need stdout if launching an MUA.

3 years agolei_to_mail: drop cyclic reference if not using IPC
Eric Wong [Sat, 23 Jan 2021 10:27:48 +0000 (10:27 +0000)]
lei_to_mail: drop cyclic reference if not using IPC

This may fix another interrupt-related segfault I'm occasionally
seeing (but so far unable to reproduce).

3 years agolei: support remote externals
Eric Wong [Sat, 23 Jan 2021 10:27:47 +0000 (10:27 +0000)]
lei: support remote externals

Via curl(1), since that lets us easily use tor on a
per-connection basis via LD_PRELOAD (torsocks) or proxy.
We'll eventually support more curl options which can allow
users to get past firewalls and deal with other odd network
configurations.

3 years agolei: move external vivification to xsearch
Eric Wong [Sat, 23 Jan 2021 10:27:46 +0000 (10:27 +0000)]
lei: move external vivification to xsearch

This seems like a better place to put it given upcoming
URI support, which starts in this commit.

3 years agolei forget-external: bash completion support
Eric Wong [Thu, 21 Jan 2021 19:46:24 +0000 (19:46 +0000)]
lei forget-external: bash completion support

The tricky bit was getting around word splitting bash
does on URLs.  This may work with other shells, too.

3 years agolei: forget-external support with canonicalization
Eric Wong [Thu, 21 Jan 2021 19:46:23 +0000 (19:46 +0000)]
lei: forget-external support with canonicalization

For proper matching, we'll do a better job canonicalizing
URLs and path names for matching.  Of course, users may edit
the file outside of lei, so ensure we try both the canonicalized
and as-is form provided by the user.

I also don't think we'll need to store externals info in
MiscIdx; just the config file is fine.

3 years agolei: remove @TO_CLOSE_ATFORK_CHILD
Eric Wong [Thu, 21 Jan 2021 19:46:22 +0000 (19:46 +0000)]
lei: remove @TO_CLOSE_ATFORK_CHILD

..At least limit it to a single file handle.  The write end
EOFpipe can be limited in scope and auto-closed when $quit is
clobbered, leaving only the listener.  The listener is the only
handle that needs to be closed explicitly due to it being on the
stack in the Listener->event_step => accept_dispatch => lei_$FOO
code path.

Everything else gets clobbered by DS->Reset in children after
forking.

3 years agolei_xsearch: reduce reference paths to lxs
Eric Wong [Thu, 21 Jan 2021 19:46:21 +0000 (19:46 +0000)]
lei_xsearch: reduce reference paths to lxs

Having an extra reference to LeiXSearch from the OpPipe $done_op
map is unnecessary and makes the reference graph more complex
than it needs to be.  Just use $lei->{lxs} to simplify and
reduce the likelyhood of bugs.

3 years agolei: remove INT/QUIT/TERM handlers, fix daemon EOF
Eric Wong [Thu, 21 Jan 2021 19:46:20 +0000 (19:46 +0000)]
lei: remove INT/QUIT/TERM handlers, fix daemon EOF

The signal handlers on the client side were unnecessary,
all we need is to handle socket EOF properly in the daemon
by killing xsearch and l2m workers.

3 years agolei: oneshot: use client $io[2] for placeholder
Eric Wong [Thu, 21 Jan 2021 19:46:19 +0000 (19:46 +0000)]
lei: oneshot: use client $io[2] for placeholder

STDERR may actually get closed in ->ipc_atfork_child in
oneshot mode, so ensure we pass in a valid file handle
to avoid warnings ->wq_do.

3 years agolei_to_mail: avoid segfault on exit
Eric Wong [Thu, 21 Jan 2021 19:46:18 +0000 (19:46 +0000)]
lei_to_mail: avoid segfault on exit

Worker exit causes DESTROY ordering to become unpredictable and
leads to Perl segfaulting.  Instead, rely on OnDestroy and
explicit triggering after wq_worker_loop to ensure we finish
all outstanding git requests before worker exit.

3 years agolei: fix inadvertant FD sharing
Eric Wong [Thu, 21 Jan 2021 19:46:17 +0000 (19:46 +0000)]
lei: fix inadvertant FD sharing

$wq->{-ipc_atfork_child_close} neededed to be initialized properly.
And start setting $0 in workers to improve visibility.

3 years agolei: show {pct} and {oid} in From_ lines and filenames
Eric Wong [Thu, 21 Jan 2021 19:46:16 +0000 (19:46 +0000)]
lei: show {pct} and {oid} in From_ lines and filenames

From_ lines are shown when mbox* variants are output to stdout,
making {oid} and {pct} information visible without risking being
propagated to other importer processes if they were in
lei-specific X-* headers.

Maildirs already had OIDs in the filename, now they gain Xapian
{pct} in case anybody cares.

3 years agolei_xsearch: eliminate some unused, commented-out code
Eric Wong [Thu, 21 Jan 2021 19:46:15 +0000 (19:46 +0000)]
lei_xsearch: eliminate some unused, commented-out code

3 years agolei q: retrieve keywords for local, non-external messages
Eric Wong [Thu, 21 Jan 2021 19:46:14 +0000 (19:46 +0000)]
lei q: retrieve keywords for local, non-external messages

This isn't tested for now, so maybe it works.

3 years agolei_overview: rename {relevance} => {pct}
Eric Wong [Thu, 21 Jan 2021 19:46:13 +0000 (19:46 +0000)]
lei_overview: rename {relevance} => {pct}

The old name was too long compared to the rest of the field
names.  With the Xapian method being named ->get_percent,
"pct" is a well known abbreviation for "percent" and already
used internally by our wrapper.

..And cleanup some excess whitespace while we're in the area.

3 years agolei_to_mail: call PublicInbox::IPC::DESTROY
Eric Wong [Wed, 20 Jan 2021 05:04:49 +0000 (14:04 +0900)]
lei_to_mail: call PublicInbox::IPC::DESTROY

It doesn't seem to matter at the moment, but it should
save us from some surprises down the line.

3 years agolei_xsearch: keep l2m->{-wq_s1} while preparing query
Eric Wong [Wed, 20 Jan 2021 05:04:48 +0000 (14:04 +0900)]
lei_xsearch: keep l2m->{-wq_s1} while preparing query

This caused a performance regression which made parallel
lei2mail processes fail prematurely and fall back to
writing blobs in the lei_xsearch worker.

3 years agolei: dump and clear errors.log in daemon mode
Eric Wong [Wed, 20 Jan 2021 05:04:47 +0000 (14:04 +0900)]
lei: dump and clear errors.log in daemon mode

Inspired by "dmesg -c", this should help users report bugs
and avoids eating up $XDG_RUNTIME_DIR.

Once lei is ready for release, hopefully the need for this
should be few an far between, but shit happens.

3 years agolei q: cleanup store initialization
Eric Wong [Wed, 20 Jan 2021 05:04:46 +0000 (14:04 +0900)]
lei q: cleanup store initialization

Since we no longer leak an FD for over.sqlite3, we can
initialize and actually enable it by default as originally
intended.

3 years agooveridx: eidx_prep: fix leftover dbh reference
Eric Wong [Wed, 20 Jan 2021 05:04:45 +0000 (14:04 +0900)]
overidx: eidx_prep: fix leftover dbh reference

Leaving $dbh in another field was causing over.sqlite3 to
remain open after ->dbh_close.  Fix up some minor style
issues while we're at it.

3 years agolei: exit code in oneshot mode
Eric Wong [Wed, 20 Jan 2021 05:04:44 +0000 (14:04 +0900)]
lei: exit code in oneshot mode

waitpid() in DESTROY ends up setting $? for the exit status,
thus we must reap IPC children before calling CORE::exit.

This fixes t/lei-oneshot.t with TEST_RUN_MODE=0

3 years agolei: allow more mbox inode types
Eric Wong [Wed, 20 Jan 2021 05:04:43 +0000 (14:04 +0900)]
lei: allow more mbox inode types

We may attempt to write an mbox to any terminal, block, or
character device, not just regular files and FIFOs/pipes.
The only thing that is known to not work is a directory.

Sockets may be possible with some OSes (e.g. Plan 9) or
filesystems.  This fixes t/lei.t on FreeBSD 11.x

3 years agolei_overview: start implementing format detection
Eric Wong [Tue, 19 Jan 2021 09:34:35 +0000 (09:34 +0000)]
lei_overview: start implementing format detection

We'll need it for IMAP support, at least.  Proper mbox family
detection will be expensive, so deal with it later.

3 years agolei: test some likely errors due to misuse
Eric Wong [Tue, 19 Jan 2021 09:34:34 +0000 (09:34 +0000)]
lei: test some likely errors due to misuse

Because user errors happen...

3 years agot/lei: fix double-running of socket test with oneshot
Eric Wong [Tue, 19 Jan 2021 09:34:33 +0000 (09:34 +0000)]
t/lei: fix double-running of socket test with oneshot

We split out t/lei-oneshot.t and t/lei.t so it's easier
to isolate run-mode specific bugs and behavior and there's
no reason to rerun the socket daemon tests.

3 years agolei_overview: do not write if $lei->{1} is gone
Eric Wong [Tue, 19 Jan 2021 09:34:32 +0000 (09:34 +0000)]
lei_overview: do not write if $lei->{1} is gone

We'll invalidate the {1} (stdout) field on SIGPIPE,
so don't trigger a Perl warning by writing to it.

3 years agolei q: fix augment of compressed mailboxes
Eric Wong [Tue, 19 Jan 2021 09:34:31 +0000 (09:34 +0000)]
lei q: fix augment of compressed mailboxes

We need to delay writing out the mailbox until the compressor
process is up and running, so have startq wait a bit.  This
means we must create the pipe early and hand it off to the
workers before augmenting, despite spawning the
gzip/pigz/xz/bzip2 process after augment is complete.

3 years agolei: write daemon errors to the sock directory
Eric Wong [Tue, 19 Jan 2021 09:34:30 +0000 (09:34 +0000)]
lei: write daemon errors to the sock directory

Most everything should be captured by the __WARN__ handlers and
routed to syslog, but it appears Perl may write to stderr in
some emergency cases, as can libc or other libraries.  Just
point it to a small file that's cleared on reboot.

3 years agolei q: do not spawn MUA early
Eric Wong [Tue, 19 Jan 2021 09:34:29 +0000 (09:34 +0000)]
lei q: do not spawn MUA early

I'm not sure why, but mutt sometimes won't detect small
quickly.  We'll display a progress bar meter when writing
results, instead.

3 years agolei q: fix SIGPIPE handling from lei2mail workers
Eric Wong [Tue, 19 Jan 2021 09:34:28 +0000 (09:34 +0000)]
lei q: fix SIGPIPE handling from lei2mail workers

We need to properly propagate SIGPIPE to the top-level
lei-daemon process and avoid relying on auto-close,
since auto-close triggers Perl warnings when explicit
close() does not.

3 years agolei q: start ->mset while query_prepare runs
Eric Wong [Tue, 19 Jan 2021 09:34:27 +0000 (09:34 +0000)]
lei q: start ->mset while query_prepare runs

We don't need the result of query_prepare (for augmenting or
mass unlinking) until we're ready to deduplicate and write
results to the filesystem.  This ought to let us hide some of
the cost of Xapian searches on multi-device/core systems for
extremely expensive searches.

3 years agolei_to_mail: optimize for MUAs
Eric Wong [Mon, 18 Jan 2021 10:30:32 +0000 (04:30 -0600)]
lei_to_mail: optimize for MUAs

Instead of optimizing our own performance, this optimizes
our data to reduce work done by the MUA consumer.

Maildir and mbox destinations no longer support any notion of
the IMAP \Recent flag.  JMAP has no functioning \Recent
equivalent, and neither do we.

In practice, having MUAs (e.g. mutt) clear the \Recent flag when
committing changes to the mbox is expensive: it creates a
rename(2) storm with Maildir and overwrites the entire mbox.

For mboxcl2 (and mboxcl), we'll further optimize mutt behavior
by setting the Lines: header in addition to Content-Length.

With these changes, mutt exits instantaneously on mboxcl2,
mboxcl, and Maildirs generated by "lei q".

3 years agolei q: parallelize Maildir and mbox writing
Eric Wong [Mon, 18 Jan 2021 10:30:31 +0000 (04:30 -0600)]
lei q: parallelize Maildir and mbox writing

With 4 dedicated workers, this seems to provide a 100-120%
speedup on a 4 core machine when writing thousands of search
results to a Maildir or mbox.  This also sets us up for
high-latency IMAP destinations in the future.

This opens the door to more speedup opportunities such
as optimizing dedupe locking and other ways to reduce
contention.

This change is fairly complex and convoluted, unfortunately.
Further work may allow us to simplify it and even improve
performance.

3 years agolei q: add --mua-cmd switch
Eric Wong [Sun, 17 Jan 2021 08:52:27 +0000 (20:52 -1200)]
lei q: add --mua-cmd switch

It can be convenient to invoke an MUA as search results
are being written to it, as an eager person may want to
start seeing results ASAP.  This lets Maildir users
see results in the MUA as we are writing them.  Users
of IMAP will eventually be able to take advantage of
them, too.

Since we don't support mbox locking (yet?), we'll only invoke
the MUA after results are done for mbox formats.

3 years agolei: pager: pass correct env in oneshot mode
Eric Wong [Sat, 16 Jan 2021 11:36:24 +0000 (23:36 -1200)]
lei: pager: pass correct env in oneshot mode

We want new environment variables when spawning the
pager from oneshot (non-daemon) mode.

3 years agolei: q: results output to Maildir and mbox* working
Eric Wong [Sat, 16 Jan 2021 11:36:23 +0000 (23:36 -1200)]
lei: q: results output to Maildir and mbox* working

All the augment and deduplication stuff seems to be working
based on unit tests.  OpPipe is a nice general addition that
will probably make future state machines easier.

3 years agoipc: children don't kill on DESTROY, reduce FD sharing
Eric Wong [Sat, 16 Jan 2021 11:36:22 +0000 (23:36 -1200)]
ipc: children don't kill on DESTROY, reduce FD sharing

Children should not be blindly killing siblings on ->DESTROY
since they're typically shorter-lived than parents.  We'll
also be more careful about on-stack variables and now we
can rely exclusively on delete ops to close FDs.

We also need to fix our SIGPIPE handling for the oneshot case
while fixing a typo for delete, so we write "!" to the EOF pipe
to ensure the parent oneshot process exits on the first worker
that hits SIGPIPE, rather than waiting for the last worker to
hit SIGPIPE.

3 years agolei_to_mail: prepare for worker offload
Eric Wong [Sat, 16 Jan 2021 11:36:21 +0000 (23:36 -1200)]
lei_to_mail: prepare for worker offload

We'll be doing most of the work in forked off worker processes,
so ensure some of it is fork and serialization-friendly.

3 years agoextindex: fix w/ Xapian 1.2.21..1.2.24
Eric Wong [Sun, 17 Jan 2021 07:09:59 +0000 (07:09 +0000)]
extindex: fix w/ Xapian 1.2.21..1.2.24

Xapian v1.2.21..v1.2.24 failed to set the close-on-exec flag
on the flintlock FD, causing "git cat-file" processes to
hold onto the lock and prevent subsequent Xapian::WritableDatabase
from locking the DB.  So cleanup git processes after committing
the miscidx transaction.

3 years agot/shared_kv: workaround old File::Spec
Eric Wong [Sun, 17 Jan 2021 07:09:58 +0000 (07:09 +0000)]
t/shared_kv: workaround old File::Spec

The version of File::Spec shipped with Perl 5.16.3 memoizes the
value of File::Spec->tmpdir, causing changes to $ENV{TMPDIR}
after-the-fact to be ignored.

We'll only work around this in the test since it's innocuous and
unlikely to matter in real-world usage (and there's many places
where we'd have to workaround this in non-test code).

3 years agot/thread-index-gap: support older DBI
Eric Wong [Sun, 17 Jan 2021 07:09:57 +0000 (07:09 +0000)]
t/thread-index-gap: support older DBI

...by avoiding selectall_array in favor of selectall_arrayref.
Tested with DBI 1.627.

3 years agoinitialize scalar for `vec' perlop modification
Eric Wong [Sun, 17 Jan 2021 07:09:56 +0000 (07:09 +0000)]
initialize scalar for `vec' perlop modification

Older Perls (tested 5.16.3) would warn on uninitialized scalars while
newer (tested 5.28.1) do not.  Just initialize it to an empty string
since it'll be filled in by `vec'.

3 years agoaddress: pairs: enable pure Perl version
Eric Wong [Sun, 17 Jan 2021 07:09:55 +0000 (07:09 +0000)]
address: pairs: enable pure Perl version

Oops, this is needed for systems lacking Email::Address::XS

3 years agolei: pass FD to CWD via cmsg, use fchdir on server
Eric Wong [Thu, 14 Jan 2021 07:06:27 +0000 (19:06 -1200)]
lei: pass FD to CWD via cmsg, use fchdir on server

Perl chdir() automatically does fchdir(2) if given a file
or directory handle since 5.8.8/5.10.0, so we can safely
rely on it given our 5.10.1+ requirement.

This means we no longer have to waste several milliseconds
loading the Cwd.so and making stat() calls to ensure
ENV{PWD} is correct and usable in the server.  It also lets
us work in directories that are no longer accessible via
pathname.

3 years agolei: remove temporary var on open
Eric Wong [Thu, 14 Jan 2021 07:06:26 +0000 (19:06 -1200)]
lei: remove temporary var on open

We can place the IO/GLOB ref directly into $self, here.

3 years agoleixsearch: remove some commented out code
Eric Wong [Thu, 14 Jan 2021 07:06:25 +0000 (19:06 -1200)]
leixsearch: remove some commented out code

Dedupe is active, now, and we have $each_smsg->(...)

3 years agolei: q: lock stdout on overview output
Eric Wong [Thu, 14 Jan 2021 07:06:24 +0000 (19:06 -1200)]
lei: q: lock stdout on overview output

Most writes to stdout aren't atomic and we need locking to
prevent workers from interleaving and corrupting JSON output.
The one case stdout won't require locking is if it's pointed
to a regular file with O_APPEND; as POSIX O_APPEND semantics
guarantees atomicity.

3 years agolei_overview: rename "references" to "refs"
Eric Wong [Thu, 14 Jan 2021 07:06:23 +0000 (19:06 -1200)]
lei_overview: rename "references" to "refs"

"references" was too long of a name compared to the other field
names we output in the JSON.  While we currently don't have a
"refs:" search prefix for the "References:" header, we may in
the future.

3 years agosearch: rename "ts:" prefix to "rt:"
Eric Wong [Thu, 14 Jan 2021 07:06:22 +0000 (19:06 -1200)]
search: rename "ts:" prefix to "rt:"

Meaning "Received time", as it is the best description of the
value we use from the "Received:" header, if present.  JMAP
calls it "receivedAt", but "rt:" seems like a better
abbreviation being in line with "dt:" for the "Date" header.

"Timestamp" ("ts") was potentially ambiguous given the presence
of the "Date" header.

3 years agolei q: reinstate smsg dedupe
Eric Wong [Thu, 14 Jan 2021 07:06:21 +0000 (19:06 -1200)]
lei q: reinstate smsg dedupe

Now that dedupe is serialization and fork-safe, we can
wire it back up in our query results paths.

3 years agolei_dedupe+shared_kv: ensure round-tripping serialization
Eric Wong [Thu, 14 Jan 2021 07:06:20 +0000 (19:06 -1200)]
lei_dedupe+shared_kv: ensure round-tripping serialization

We'll be passing these objects via PublicInbox::IPC which uses
Storable (or Sereal), so ensure they're safe to use after
serialization.