]> Sergey Matveev's repositories - public-inbox.git/log
public-inbox.git
2 years agowww: move mirror instructions to /text/
Eric Wong [Sat, 28 Aug 2021 11:50:06 +0000 (11:50 +0000)]
www: move mirror instructions to /text/

This makes the mirroring and code retrieval instructions less
obstructive.  Relying on WwwText means we only use our Linkify
module to make hrefs of full URLs; making relative and shortened
hrefs off-limits; hopefully this isn't too much of a problem.

coderepo information remains duplicated on every page since
(IMHO) coderepos are an important feature; but nobody besides me
has ever bothered to configure coderepos, so I suppose it's
fine...

Suggested-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Link: https://public-inbox.org/meta/20210826132747.6gxuwnhftyf7c6hp@nitro.local/
2 years agowww: avoid potential auto-vivification on ibx->{url}
Eric Wong [Fri, 27 Aug 2021 22:03:02 +0000 (22:03 +0000)]
www: avoid potential auto-vivification on ibx->{url}

This may fix problems with the "all" link disappearing.

Link: https://public-inbox.org/meta/CAMwyc-Tw=v5yT1U1U66GSwwTK8OJXv8_YDu-=oXbZO3tHSnYWw@mail.gmail.com/
2 years agowww_listing: fix odd "locate inbox" cases
Eric Wong [Fri, 27 Aug 2021 12:08:45 +0000 (12:08 +0000)]
www_listing: fix odd "locate inbox" cases

Searching inboxes with an empty query no longer gives 500 errors
due to Xapian.  Also, improve the error message when no inboxes
match, since saying no inboxes exist yet is wrong.

2 years agowww_listing: show ->ALL at top of HTML listing
Eric Wong [Fri, 27 Aug 2021 12:08:44 +0000 (12:08 +0000)]
www_listing: show ->ALL at top of HTML listing

It's a special case and we can show it in the HTML display
without affecting manifest.js.gz generation.

2 years agomove ->ids_after from mm to over
Eric Wong [Thu, 26 Aug 2021 12:33:38 +0000 (12:33 +0000)]
move ->ids_after from mm to over

Since we favor ->over in WWW and IMAP, move this method to
->over to reduce open files in common cases.

This fixes the /$EXTINDEX_NAME/all.mbox.gz endpoint for extindex
entries (which may get expensive...).

2 years agowww_text: add coderepo config support for extindex
Eric Wong [Thu, 26 Aug 2021 12:33:37 +0000 (12:33 +0000)]
www_text: add coderepo config support for extindex

At least manually configured coderepos "just work"
for extindex, though it probably could be automatic
and inherited from the publicinbox configs.

2 years agoconfig: do not parse altid for extindex
Eric Wong [Thu, 26 Aug 2021 12:33:36 +0000 (12:33 +0000)]
config: do not parse altid for extindex

There's currently no support for altid with extindex, and
there's likely no legacy precedent for using altid like there is
with single public-inboxes.

2 years agowww_text: fix example config snippet for extindex
Eric Wong [Thu, 26 Aug 2021 12:33:35 +0000 (12:33 +0000)]
www_text: fix example config snippet for extindex

extindex doesn't use the same config stuff as normal
"publicinbox" entries, so we'll need a separate function
for them.

2 years agowww: avoid incorrect instructions for extindex
Eric Wong [Thu, 26 Aug 2021 12:33:34 +0000 (12:33 +0000)]
www: avoid incorrect instructions for extindex

There's no way to clone an extindex, since there's no git
storage associated with them.  So attempt to link to the
HTML listing of public-inboxes, instead.

2 years agowww_stream: sh-friendly .onion URLs wrapping
Eric Wong [Thu, 26 Aug 2021 12:33:33 +0000 (12:33 +0000)]
www_stream: sh-friendly .onion URLs wrapping

The long v3 .onion URL was causing havoc on small mobile
displays, so extract "hostname" into a variable which can
still used as a Bourne shell snippet.

While we're at it, include "torsocks" in the git command used
for .onion URLs since that's the (near)-universal wrapper for
Tor-ifying things (like git) which are dynamically linked to
libc.

Cc: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Link: https://public-inbox.org/meta/20210816163654.c6gfzuezhji4l6s7@nitro.local/
2 years agods: use bytes::substr and bytes::length module-wide for now
Eric Wong [Thu, 26 Aug 2021 12:33:32 +0000 (12:33 +0000)]
ds: use bytes::substr and bytes::length module-wide for now

The use of substr within IO::Handle->write may not be correct if
we have wide characters, so handle it ourselves.

bytes.pm usage is probably better fixed in PublicInbox::NNTP,
but the effort required is higher, so we'll just keep bytes in
DS for now.

2 years agoget rid of unnecessary bytes::length usage
Eric Wong [Thu, 26 Aug 2021 12:33:31 +0000 (12:33 +0000)]
get rid of unnecessary bytes::length usage

The only place where we could return wide characters with -httpd
was the raw $INBOX_DIR/description text, which is now converted
to octets.

All daemon (HTTP/NNTP/IMAP) sockets are opened in binary mode,
so length() and bytes::length() are equivalent on reads.  For
socket writes, any non-octet data would warn about wide characters
and we are strict in warnings with test_httpd.

All gzipped buffers are also octets, as is PublicInbox::Eml->body,
and anything from PerlIO objects ("git cat-file --batch" output,
filesystems), so bytes::length was unnecessary in all those places.

2 years agowwwlisting: support global CSS in HTML view
Eric Wong [Wed, 18 Aug 2021 11:41:02 +0000 (11:41 +0000)]
wwwlisting: support global CSS in HTML view

Since CSS can be overridden by a static webserver on a per-inbox
basis, we need a similar pattern to deal with the instance-wide
WwwListing HTML.  "/+/" probably won't conflict with any current
nor future public inbox names.

I don't think it'll cause problems with common linkifiers or URL
extractors, either (and it's unlikely anybody would want to
share URLs of just the CSS in a plain text(-like) format).

2 years agolei_mail_sync: remove warning message from caller
Eric Wong [Wed, 25 Aug 2021 08:40:40 +0000 (08:40 +0000)]
lei_mail_sync: remove warning message from caller

We can afford to be liberal in what messages we accept
internally, since LeiToMail uses a trailing slash internally.

2 years agolei up: improve --all=local stderr output
Eric Wong [Wed, 25 Aug 2021 08:40:39 +0000 (08:40 +0000)]
lei up: improve --all=local stderr output

The "# $NR written to $DEST ($total matches)" messages are
arguably the most useful output of "lei up --all=local",
but they get intermixed with progress messages from various
workers.  Queue up these finalization messages and only spit
them out on ->DESTROY.

2 years agoimap+nntp: die loudly if ->mm or ->over disappear
Eric Wong [Tue, 24 Aug 2021 22:49:24 +0000 (22:49 +0000)]
imap+nntp: die loudly if ->mm or ->over disappear

While the WWW front-end can gracefully handle ->mm and ->over
disappearing (in most cases), IMAP+NNTP front-ends are completely
dependent on these and failed mysteriously when they go missing
after startup.

These will hopefully make issues like what Konstantin
encountered more obvious:

Link: https://public-inbox.org/meta/20210824204855.ejspej4z7r2rpu63@nitro.local/
2 years agolei: non-blocking lei/store->done in lei-daemon
Eric Wong [Tue, 24 Aug 2021 13:06:39 +0000 (13:06 +0000)]
lei: non-blocking lei/store->done in lei-daemon

This allows client sockets to wait for "done" commits to
lei/store while the daemon reacts asynchronously.  The goal
of this change is to keep the script/lei client alive until
lei/store commits changes to the filesystem, but without
blocking the lei-daemon event loop.  It depends on Perl
refcounting to close the socket.

This change also highlighted our over-use of "done" requests to
lei/store processes, which is now corrected so we only issue it
on collective socket EOF rather than upon reaping every single
worker.

This also fixes "lei forget-mail-sync" when it is the initial
command.

This took several iterations and much debugging to arrive at the
current implementation:

1. The initial iteration of this change utilized socket passing
   from lei-daemon to lei/store, which necessitated switching
   from faster pipes to slower Unix sockets.

2. The second iteration switched to registering notification sockets
   independently of "done" requests, but that could lead to early
   wakeups when "done" was requested by other workers.  This
   appeared to work most of the time, but suffered races under
   high load which were difficult to track down.

Finally, this iteration passes the stringified socket GLOB ref
to lei/store which is echoed back to lei-daemon upon completion
of that particular "done" request.

2 years agolei: add missing LeiWatch lazy-load
Eric Wong [Tue, 24 Aug 2021 13:04:06 +0000 (13:04 +0000)]
lei: add missing LeiWatch lazy-load

I'm not sure if this class will actually be needed, but
we need to load it while we're using it.

2 years agolei: implicitly watch all Maildirs it knows about
Eric Wong [Thu, 19 Aug 2021 09:49:34 +0000 (09:49 +0000)]
lei: implicitly watch all Maildirs it knows about

This allows MUA-made flag changes to Maildirs to be instantly
read and acknowledged for future search results.

In the future, it may be used to speed up --augment and
--import-before (the default) with with "lei q".

2 years agolei q: make --save the default
Eric Wong [Thu, 19 Aug 2021 01:36:38 +0000 (01:36 +0000)]
lei q: make --save the default

Since "lei up" is more often useful than not and incurs neglible
overhead; enable --save by default and allow --no-save to work.

This also fixes a long-standing when overwriting --output
destinations with saved searches:  dedupe data from previous
searches are reset and no longer influences the new (changed)
search, so results no longer go missing if two sequential
invocations of "lei q --save" point to the same --output.

2 years agolei forget-mail-sync: rely on lei/store process
Eric Wong [Tue, 17 Aug 2021 08:52:41 +0000 (08:52 +0000)]
lei forget-mail-sync: rely on lei/store process

As implied in commit 6ff03ba2be9247f1
("lei export-kw: do not write directly to mail_sync.sqlite3"),
modifying mail_sync.sqlite3 directly can lead to conflicts
and making everything go through lei/store is easier.

2 years agoipc: remove WQ_MAX_WORKERS
Eric Wong [Tue, 17 Aug 2021 08:52:40 +0000 (08:52 +0000)]
ipc: remove WQ_MAX_WORKERS

We no longer rely on IO::FDPass, so there's no longer a reason
to limit this internally.

2 years agolei: add ->lms shortcut for LeiMailSync
Eric Wong [Tue, 17 Aug 2021 08:52:39 +0000 (08:52 +0000)]
lei: add ->lms shortcut for LeiMailSync

We access this read-only in many places (and will in more),
so provide a shortcut to simplify callers.

2 years agoview: remove mbox.gz and Atom from topic view
Eric Wong [Mon, 16 Aug 2021 23:35:20 +0000 (23:35 +0000)]
view: remove mbox.gz and Atom from topic view

This declutters the topic view since these links seem rarely
used.  Atom and mbox.gz links probably make most sense when
users have read the HTML and decide the topic is worth following
or downloading.

Reported-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Link: https://public-inbox.org/meta/20210816154444.sj3ks2sikq3x2ywx@nitro.local/
2 years agouser_content: update + wrap lines for CSS change
Eric Wong [Mon, 16 Aug 2021 22:42:45 +0000 (22:42 +0000)]
user_content: update + wrap lines for CSS change

Fixes: 86df4acd140d61ab ("Duplicate base css definitions in stylesheets")
2 years agoDuplicate base css definitions in stylesheets
Konstantin Ryabitsev [Mon, 16 Aug 2021 14:50:15 +0000 (10:50 -0400)]
Duplicate base css definitions in stylesheets

All pages carry the following inlined css declaration:

    <style>pre{white-space:pre-wrap}*{font-size:100%;font-family:monospace}</style>

However, site security policies may deliberately prohibit execution of
inline content such as scripts and stylesheets as an extra layer of
protection against XSS vulnerabilities. For example, with the following
HTTP headers returned by the server, the inline styles above will be
ignored:

    Content-Security-Policy: default-src 'self'

This causes public-inbox content to be rendered poorly on mobile devices
due to the default <pre> behaviour. Duplicating this declaration into
the contrib stylesheets makes sure that these styles are applied even
with the strictest security policies in place.

Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
2 years agot/run.perl: fix "make check-run" on FreeBSD 11.x
Eric Wong [Mon, 16 Aug 2021 07:29:17 +0000 (07:29 +0000)]
t/run.perl: fix "make check-run" on FreeBSD 11.x

Persistent lei-daemon still leads to ECONNRESET client errors on
FreeBSD, and maxing out the kern.ipc.soacceptqueue sysctl (as
documented in the FreeBSD listen(2) manpage) doesn't seem to
help.

"make check-run" is still 4-5s faster than "make check" on my
FreeBSD VM even after this change, so it's still a worthwhile
improvement.

2 years agolei_search: avoid unconditional warning when no exception
Eric Wong [Mon, 16 Aug 2021 05:39:33 +0000 (05:39 +0000)]
lei_search: avoid unconditional warning when no exception

Oops, we shouldn't warn on "$@" unless "$@" is truthy.

Fixes: c7bcfe6cd6648ff0 ("lei: diagnostics for /Document \d+ not found/ errors")
2 years agowww: uninitialized vars due to extindex lacking address
Eric Wong [Mon, 16 Aug 2021 05:30:22 +0000 (05:30 +0000)]
www: uninitialized vars due to extindex lacking address

Some messages have From/To/Cc headers munged to be unparseable to
Email::Address::XS, the fallback is to use the default inbox address.
-extindex do not have an address on their own, so just fall back to
using 'unknown@example.com' for now.

An example of such a message:
https://yhbt.net/lore/all/20201002154535.28412-1-fw@strlen.de/

2 years agowww: avoid uninitialized vars from shadowed Message-IDs
Eric Wong [Sat, 14 Aug 2021 07:42:39 +0000 (07:42 +0000)]
www: avoid uninitialized vars from shadowed Message-IDs

For /all/ (extindex) and like, Message-ID reuse from client
errors or list-injected footers can cause threading weirdness.
Avoid auto-vivification in the mapping table and dereferencing
of unknown messages.

2 years agolei: hexdigest mocks account for unwanted headers
Eric Wong [Sat, 14 Aug 2021 00:29:44 +0000 (00:29 +0000)]
lei: hexdigest mocks account for unwanted headers

PublicInbox::Import never imports @UNWANTED_HEADERS, so ensure
our mock blob OIDs do the same.  This ought to prevent
duplicates if the PSGI mboxrd download starts setting
"X-Status: F" like "lei q -tt .."

2 years agolei <q|up>: wait on remote mboxrd imports synchronously
Eric Wong [Sat, 14 Aug 2021 00:29:43 +0000 (00:29 +0000)]
lei <q|up>: wait on remote mboxrd imports synchronously

This ought to avoid /Document \d+ not found/ errors from Xapian
when seeing a message for the first time by not attempting to
read keywords for totally unseen messages.

2 years agolei: diagnostics for /Document \d+ not found/ errors
Eric Wong [Sat, 14 Aug 2021 00:29:42 +0000 (00:29 +0000)]
lei: diagnostics for /Document \d+ not found/ errors

This may help diagnose "Exception: Document \d+ not found"
errors I'm seeing from "lei up" with HTTPS endpoints.

2 years agolei up: note errors if one output destination fails
Eric Wong [Thu, 12 Aug 2021 23:40:27 +0000 (23:40 +0000)]
lei up: note errors if one output destination fails

We can keep going if one (out of multiple) output destinations
fail, but the error needs to be communicated to the caller as an
exit code.

2 years agolei up: support multiple output folders w/o --all=local
Eric Wong [Thu, 12 Aug 2021 23:40:26 +0000 (23:40 +0000)]
lei up: support multiple output folders w/o --all=local

Being able to update 1 folder, or all (local) folders is
sometimes too limiting, so just allow updating any subset
of local folders.

2 years agolei: attempt to canonicalize away "/../" pathnames
Eric Wong [Wed, 11 Aug 2021 11:26:18 +0000 (11:26 +0000)]
lei: attempt to canonicalize away "/../" pathnames

As documented, File::Spec->canonpath does not canonicalize
"/../".  While we want to do our best to preserve symlinks in
pathnames, leaving "/../" can mislead our inotify|kqueue usage.

2 years agolei_saved_search: canonicalized relative save paths
Eric Wong [Wed, 11 Aug 2021 11:26:17 +0000 (11:26 +0000)]
lei_saved_search: canonicalized relative save paths

Storing relative paths with '..' in them can be expensive to
resolve when running 'lei up', so prefer storing canonicalized
absolute paths.  We only do this for paths with '..' in them,
though, since this can lose symlink info.

2 years agotreewide: use *nix-specific dirname regexps
Eric Wong [Wed, 11 Aug 2021 11:26:16 +0000 (11:26 +0000)]
treewide: use *nix-specific dirname regexps

None of our code elsewhere accounts for non-*nix pathnames and
it's not worth our time to start.  So stop wasting CPU cycles
giving the illusion that we'd care about non-*nix pathnames.

2 years agolei_xsearch: improve Xapian open failure messages
Eric Wong [Sun, 8 Aug 2021 20:07:47 +0000 (20:07 +0000)]
lei_xsearch: improve Xapian open failure messages

Displaying $! can help users diagnose resource limit problems
such as EMFILE/ENFILE/ENOMEM.  $@ is currently useful for XS
Search::Xapian and perhaps future versions of the Xapian.pm SWIG
bindings.

2 years agosearchidx: die on Xapian load errors
Eric Wong [Sun, 8 Aug 2021 01:14:17 +0000 (01:14 +0000)]
searchidx: die on Xapian load errors

Xapian bindings may not be installed or be out-of-date w.r.t. the
Perl version, improve the visibility of errors in those cases.
Cleanup and drop some redundant checks while we're at it.

Cc: "Toke Høiland-Jørgensen" <toke@toke.dk>
Link: https://public-inbox.org/meta/87k0ky5mbd.fsf@toke.dk/
2 years agotests: fix test failures when Xapian is missing
Eric Wong [Sun, 8 Aug 2021 01:14:16 +0000 (01:14 +0000)]
tests: fix test failures when Xapian is missing

We still support usage without Xapian, so ensure our tests
work when Xapian bindings are missing

2 years agohttpd: set psgi.url_scheme to 'https' for TLS listeners
Eric Wong [Sun, 8 Aug 2021 01:03:50 +0000 (01:03 +0000)]
httpd: set psgi.url_scheme to 'https' for TLS listeners

For users using the native TLS functionality of -httpd (instead
of using nginx + Plack::Middleware::ReverseProxy),
psgi.url_scheme=http was wrong and would lead to improper
redirects.

2 years agoli2wrap: avoid double-close on Linux::Inotify2 <2.3
Eric Wong [Fri, 6 Aug 2021 00:29:52 +0000 (00:29 +0000)]
li2wrap: avoid double-close on Linux::Inotify2 <2.3

LI2Wrap was not working as expected due to the missing bless
to override ->DESTROY.  This bug showed up in an message check in
t/lei-q-remote-import.t

Fixes: 7fc6e30aeab9925b ("lei: close inotify FD in forked child")
2 years agolei export-kw: workaround race in updating Maildir locations
Eric Wong [Thu, 5 Aug 2021 02:33:40 +0000 (02:33 +0000)]
lei export-kw: workaround race in updating Maildir locations

Inotify updates may simultaneously remove or update the location
of a message, so ensure we at least have knowledge of the new
location if the old one cannot be updated.

2 years agoextindex: fix boost with partial runs
Eric Wong [Wed, 4 Aug 2021 10:02:48 +0000 (10:02 +0000)]
extindex: fix boost with partial runs

Boost relies on knowledge of all inboxes in a given config file
to work properly.  So while we support indexing a subset of
inboxes, we must still account for boost in inboxes we're not
indexing.  So split internal inbox groups into "known" and
"active", where previously we only cared for inboxes which were
being actively indexed.

Furthermore, boost checks need to be applied when a
message arrives in different inboxes across multiple
invocations.

Reported-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Link: https://public-inbox.org/meta/20210802204058.vscbxs5q7xyolyu2@nitro.local/
2 years agoextindex: do not over-account for cross-posted messages
Eric Wong [Wed, 4 Aug 2021 10:02:47 +0000 (10:02 +0000)]
extindex: do not over-account for cross-posted messages

Cross-posted messages don't result in massive writes to the
Xapian DBs like a completely unseen message would, so stop
accounting for their size.  This ought to improve performance
for heavily cross-posted setups, but --commit-interval still
has effect.

2 years agolei: close inotify FD in forked child
Eric Wong [Thu, 29 Jul 2021 10:01:31 +0000 (10:01 +0000)]
lei: close inotify FD in forked child

Linux::Inotify2 2.3+ includes an ->fh method to give us the
ability to safely close an FD without hitting EBADF (and
automatically use FD_CLOEXEC).

We'll still need a new wrapper class (LI2Wrap) to handle it for
users of old versions, though.

Link: http://lists.schmorp.de/pipermail/perl/2021q3/thread.html
2 years agoextindex: -xcpdb and -compact support
Eric Wong [Fri, 30 Jul 2021 12:18:55 +0000 (12:18 +0000)]
extindex: -xcpdb and -compact support

Since extindex uses Xapian shards in a similar way to
v2 inboxes, we'll support -xcpdb (reshard+upgrade) and
-compact all the same to give admins tuning+upgrade
options.

2 years agoadmin: index_inbox: drop unnecessary check
Eric Wong [Fri, 30 Jul 2021 12:18:54 +0000 (12:18 +0000)]
admin: index_inbox: drop unnecessary check

No callers pass an unblessed pathname to index_inbox,
only Inbox object refs.

2 years agolistener: maximize listen(2) backlog
Eric Wong [Wed, 28 Jul 2021 00:37:19 +0000 (00:37 +0000)]
listener: maximize listen(2) backlog

This helps avoid errors from script/lei dying on ECONNRESET
when a single lei-daemon is serving all tests when run via
"make check-run".

Instead of using some arbitrary limit, use INT_MAX and let
the kernel clamp it (both Linux and FreeBSD do).

There's no need to call listen() in LEI.pm, either, since
Listener->new takes care of it.

2 years agolei: die on ECONNRESET
Eric Wong [Wed, 28 Jul 2021 00:37:18 +0000 (00:37 +0000)]
lei: die on ECONNRESET

ECONNRESET should be rare on a private local socket, and if
we hit it, it's because we're hitting the listen() limit.

2 years agotreewide: s/sequential_shard/sequential-shard/g
Eric Wong [Tue, 27 Jul 2021 10:44:29 +0000 (10:44 +0000)]
treewide: s/sequential_shard/sequential-shard/g

The underscore variant was never documented and maintaining
the difference between the command-line and internal hash
is not worth it.

2 years agoextindex: support --jobs/-j properly on creation for shard count
Eric Wong [Sun, 25 Jul 2021 12:44:23 +0000 (12:44 +0000)]
extindex: support --jobs/-j properly on creation for shard count

This wasn't wired up properly, but Xapian appears to suffer from
I/O amplification problems as DB shards get larger:

  https://lists.xapian.org/pipermail/xapian-discuss/2019-February/009727.html
  <23640.32170.703368.841021@y.dockes.com>

Of course, we shouldn't have too many shards, either; because
performance problems with too many shards was the entire reason
extindex was created:

  https://lists.xapian.org/pipermail/xapian-discuss/2020-August/009823.html
  <20200826064728.GA32239@dcvr>

2 years agodoc: lei-{p2q,rediff}: note implicit --stdin
Eric Wong [Sun, 25 Jul 2021 12:03:33 +0000 (12:03 +0000)]
doc: lei-{p2q,rediff}: note implicit --stdin

lei actually uses implicit --stdin everywhere, but I thing
these patch-related commands are the most common use of them.

2 years agot/lei-watch.t: improve test reliability
Eric Wong [Sun, 25 Jul 2021 11:15:06 +0000 (11:15 +0000)]
t/lei-watch.t: improve test reliability

On single CPU (and overloaded SMP) systems, we can't rely on
inotify in lei-daemon firing before a "lei note-event done"
client hits it.  So force in a single tick() to ensure the
scheduler can yield to lei-daemon and see the inotify wakeup
before "lei note-event done" to commit the write.

2 years agoinit: support git <2.30 for "-c KEY=VALUE" args
Eric Wong [Sun, 25 Jul 2021 10:40:17 +0000 (10:40 +0000)]
init: support git <2.30 for "-c KEY=VALUE" args

It turns out `--fixed-value' is a relatively new git-config(1)
feature in git 2.30+ (December 2020).  So use the quotemeta
perlop for now since it seems compatible-enough for POSIX ERE
used by git.

2 years agolei_mail_sync: locations_for API uses oidbin for comparisons
Eric Wong [Sun, 25 Jul 2021 00:43:32 +0000 (00:43 +0000)]
lei_mail_sync: locations_for API uses oidbin for comparisons

Favor oidbin use internally to reduce internal memory traffic.

2 years agolei_inspect: fix typo
Eric Wong [Sun, 25 Jul 2021 00:43:31 +0000 (00:43 +0000)]
lei_inspect: fix typo

Not sure how this wasn't caught, earlier...

2 years agolei_search: favor binary OID comparisons
Eric Wong [Sun, 25 Jul 2021 00:43:30 +0000 (00:43 +0000)]
lei_search: favor binary OID comparisons

Reduce memory traffic and code, too.

2 years agoextsearchidx: favor binary comparison in common case
Eric Wong [Sun, 25 Jul 2021 00:43:29 +0000 (00:43 +0000)]
extsearchidx: favor binary comparison in common case

We'll use 20-byte SHA-1 comparisons instead of 40-byte
hex representations for a minor reduction in memory
traffic.

2 years agoextsearchidx: use more appropriate max for dedupe
Eric Wong [Sun, 25 Jul 2021 00:11:03 +0000 (00:11 +0000)]
extsearchidx: use more appropriate max for dedupe

The over.msgid table may contain ghost Message-IDs and also
Message-IDs of deleted spam messages, so over->max isn't a
good aproproximation of dedupe progress.

2 years agoextindex: improve comment around git->async_wait_all
Eric Wong [Sun, 25 Jul 2021 00:11:02 +0000 (00:11 +0000)]
extindex: improve comment around git->async_wait_all

I found myself tempted to remove this, but it appears impossible
due to odd messages which have multiple Message-IDs.

2 years agoextindex: support --dedupe[=MSGID]
Eric Wong [Sun, 25 Jul 2021 00:11:01 +0000 (00:11 +0000)]
extindex: support --dedupe[=MSGID]

Sometimes I just want to dedupe a single Message-ID to test
something, and this lets me do it.

This patch appears to do what its supposed to.  But it also
appears to be finding duplicates that were previously missed.
That's a good thing, but I wish I understood what seems to be
fixed :x

I'm not sure why the previous ExtSearchIdx.pm (blob 357312b8)
was causing messages to be missed, even, and why this patch
seems to fix it...  And it's not infinite looping, either.

Anyways, before this patch, "-extindex --dedupe" was taking ~5
min to no-op every message (after the initial full --dedupe run
which took over a day to run).  No-op --dedupes now take just
under 2 hours to scan every single cross-posted message for a
no-op dedupe.  The initial dedupe took nearly 44 hours on my
system for <https://yhbt.net/lore/all/> due to SATA-2 TLC SSD
latency on 3 gigantic Xapian shards.

Running --dedupe with this change seems to prevent
/BUG\?.*?not deduplicated properly/ stderr messages from being
triggered by View.pm.  Current versions of -extindex do not
seem susceptible to introducing duplicates.

2 years agolei rm-watch: new command to support removing watches
Eric Wong [Fri, 23 Jul 2021 10:56:12 +0000 (10:56 +0000)]
lei rm-watch: new command to support removing watches

Pretty trivial since it just invokes "git-config".  It's mainly
intended to make shell completion easier.

2 years agolei: avoid SQLite COUNT() for dedupe
Eric Wong [Fri, 23 Jul 2021 10:56:11 +0000 (10:56 +0000)]
lei: avoid SQLite COUNT() for dedupe

SQLite COUNT() is a slow operation that does a full table scan
with no conditions.  There's no need for it, since lei dedupe
only needs to know if it's empty or not to decide between
new/ and cur/ for Maildir outputs.

2 years agot/lei*: check error messages on failures
Eric Wong [Fri, 23 Jul 2021 10:56:10 +0000 (10:56 +0000)]
t/lei*: check error messages on failures

I just hit an unreproducible failure in t/lei-p2q.t and
lacked $lei_err information to diagnose it.  Hopefully
this helps track down odd failures in the future.

2 years agot/solver_git: use like() to improve error reporting
Eric Wong [Thu, 22 Jul 2021 08:37:36 +0000 (08:37 +0000)]
t/solver_git: use like() to improve error reporting

I hit a test failure here, but haven't been able to reproduce
it...

2 years agolei: auto-refresh watches in config, cancel missing
Eric Wong [Wed, 21 Jul 2021 14:07:06 +0000 (14:07 +0000)]
lei: auto-refresh watches in config, cancel missing

This makes behavior less surprising on restarts as we no longer
lose state on restarts, so there's no need to manually run "lei
add-watch" to re-enable watches.  This also allows us to
transparently handle changes if somebody edits the lei config
file directly or via git-config(1).

2 years agolei: start implementing inotify Maildir support
Eric Wong [Mon, 19 Jul 2021 08:59:35 +0000 (08:59 +0000)]
lei: start implementing inotify Maildir support

This allows lei to automatically note keyword (message flag)
changes made to a Maildir and propagate it into lei/store:

lei add-watch --state=tag-ro /path/to/Maildir

This doesn't persist across restarts, yet.  In the future,
it will be applied automatically to "lei q" output Maildirs
by default (with an option to disable it).

State values of tag-rw, index-<ro|rw>, import-<ro|rw> will all
be supported for Maildir.

This represents a fairly major internal change that's fairly
intrusive, but the whole daemon-oriented design was to
facilitate being able to automatically monitor (and propagate)
Maildir/IMAP flag changes.

2 years agoinit: allow arbitrary key-values via -c KEY=VALUE
Eric Wong [Wed, 21 Jul 2021 14:05:50 +0000 (14:05 +0000)]
init: allow arbitrary key-values via -c KEY=VALUE

This won't blindly append identical key=values, but
allows specifying multiple, different key=value pairs
as long as the values are different.

2 years agoextsearch: support publicinbox.*.boost parameter
Eric Wong [Wed, 21 Jul 2021 14:05:49 +0000 (14:05 +0000)]
extsearch: support publicinbox.*.boost parameter

This behaves identically the lei external "boost" parameter in
prioritizing raw messages for extindex.

Relying exclusively on the config file order doesn't work well
for mirrors since it's impossible to guarantee config file
ordering via grokmirror hooks.

Config file ordering remains the default if boost is
unconfigured, or in case of ties.

Note: I chose the name "boost" rather than "priority" or "rank"
since I always get confused by whether higher or lower numbers
take precedence when it comes to kernel scheduling.  "weight" is
also a part of Xapian API terminology, which we currently do not
expose to configuration (but may in the future).

2 years agohttpd: fix SIGHUP by invalidating cache on reload
Eric Wong [Tue, 20 Jul 2021 08:58:58 +0000 (08:58 +0000)]
httpd: fix SIGHUP by invalidating cache on reload

Since we require separate PublicInbox::HTTPD instances for each
listen socket address (in order to support {SERVER_<NAME|PORT>}
for PSGI env), the old cache needed to be invalidated on rare
app refreshes.

SIGHUP has always been broken in -httpd (but not -imapd or
-nntpd) due to this cache.

Update the daemon documentation and 5.10.1-ize some bits while
we're in the area.

2 years agoconfig: s/_one_val/get_1/ for public use
Eric Wong [Tue, 13 Jul 2021 11:06:13 +0000 (11:06 +0000)]
config: s/_one_val/get_1/ for public use

We'll be using this in lei for watch configs.

2 years agoextindex: dedupe: reduce SQLite contention and dirty data
Eric Wong [Thu, 8 Jul 2021 08:25:19 +0000 (08:25 +0000)]
extindex: dedupe: reduce SQLite contention and dirty data

Complex queries causes SQLite to block readers for longer than
their retry period.  For dedupe, it was also preventing us from
making good use of checkpoints due to the query time.

With many deduplications, checkpoints are necessary to maintain
system health due to having too much data piled up.

2 years agoextsearchidx: ignore Eml warnings across the board
Eric Wong [Wed, 7 Jul 2021 23:24:55 +0000 (23:24 +0000)]
extsearchidx: ignore Eml warnings across the board

There's nothing we can do about misformatted emails and headers
we get from untrusted sources.  They're too noisy and those
messages already exist in public-inboxes, anyways, so just
keep things quiet so we can spot real problems more easily.

2 years agoextindex: --gc: avoid SQLite lock conflict on shard cleanup
Eric Wong [Tue, 6 Jul 2021 12:42:03 +0000 (12:42 +0000)]
extindex: --gc: avoid SQLite lock conflict on shard cleanup

Xapian shard cleanup only requires read-only access to
over.sqlite3, so avoid opening it with read-write access since
create_tables will hit lock conflicts on "INSERT OR IGNORE"
statements.

2 years agoextindex: implement --dedupe to fix old extindices
Eric Wong [Tue, 6 Jul 2021 12:42:02 +0000 (12:42 +0000)]
extindex: implement --dedupe to fix old extindices

This is intended to fix older indices that had deduplication
bugs for matching content.  It'll also make dealing with
future changes to ContentHash easier since that's never
guaranteed stable.

It also supports --dry-run to print changes only without
making them.

2 years agoeml: relax warn_ignore regexps for current Email::Address::XS
Eric Wong [Tue, 6 Jul 2021 12:42:01 +0000 (12:42 +0000)]
eml: relax warn_ignore regexps for current Email::Address::XS

These seem needed with the data I'm currently working on, but I
haven't changed my version of Email::Address::XS since my last
Debian stable upgrade (to buster).

2 years agolei: drop workers on EOF from clients
Eric Wong [Sun, 4 Jul 2021 19:35:54 +0000 (19:35 +0000)]
lei: drop workers on EOF from clients

Sometimes a user will be bored waiting for a command to finish,
so ensure we drop disconnect workers in this case.

2 years agolei import: increase flags search batch size, display progress
Eric Wong [Fri, 2 Jul 2021 21:02:23 +0000 (21:02 +0000)]
lei import: increase flags search batch size, display progress

IMAP flag-only synchronization doesn't fetch entire messages,
so we can safely bump the batch size iff a user specified one
for full messages to 10000 times that.

Since I sometimes wonder why nothing happens for several seconds
after starting "lei import $URL", we'll also show some progress
during the flag synchronization phase.

2 years agolei inspect: help+completion for --dir option
Eric Wong [Fri, 2 Jul 2021 20:42:24 +0000 (20:42 +0000)]
lei inspect: help+completion for --dir option

It's the most generic name I could find for it since it can
mean so many things...

2 years agoextsearchidx: extra assertions for deduplication flow
Eric Wong [Fri, 2 Jul 2021 20:42:09 +0000 (20:42 +0000)]
extsearchidx: extra assertions for deduplication flow

I haven't found any bugs from this (still looking for missed
deduplication bugs), and it's a bit shorter and more likely to
catch future bugs.  Clean up an unnecessary ->{mid} array copy
while we're at it, too.

2 years agolei inspect: support "mid:" (and "m:") prefix
Eric Wong [Thu, 1 Jul 2021 11:31:33 +0000 (11:31 +0000)]
lei inspect: support "mid:" (and "m:") prefix

Using this to track down deduplication failures in -extindex...

2 years agolei inspect: support automatic pager in output
Eric Wong [Thu, 1 Jul 2021 11:31:32 +0000 (11:31 +0000)]
lei inspect: support automatic pager in output

All commands which output non-trivial amounts of data to
the terminal should support this.

2 years agoextsearchidx: lock before writing multi-pack-index
Eric Wong [Wed, 30 Jun 2021 22:00:20 +0000 (22:00 +0000)]
extsearchidx: lock before writing multi-pack-index

This avoids errors from git in case -extindex gets invoked in
parallel.

2 years agoextsearchidx: symlink .rev and .bitmap files into ALL.git
Eric Wong [Wed, 30 Jun 2021 19:14:48 +0000 (19:14 +0000)]
extsearchidx: symlink .rev and .bitmap files into ALL.git

It's possible for these to exist and git can (or may eventually)
take advantage of them to speed up functionality which affects
us.

2 years agosearchidx: default BATCH_BYTES to 8MB on 64-bit systems
Eric Wong [Wed, 30 Jun 2021 17:58:54 +0000 (17:58 +0000)]
searchidx: default BATCH_BYTES to 8MB on 64-bit systems

This default seems closer to reasonable on 64-bit systems which
are the norm these days.  32-bit systems gain 48K so it's an
even 1 MB, but we need to keep 32-bit systems from using too
much since there's still some ancient systems out there with
small inboxes.

2 years agowww: fix manifest.js.gz for default publicInbox.grokManifest
Eric Wong [Mon, 28 Jun 2021 21:59:06 +0000 (21:59 +0000)]
www: fix manifest.js.gz for default publicInbox.grokManifest

ManifestJsGz->response was not invoking the new "url_filter"
method properly.  Furthermore, fix url_filter for returning 404
responses.

Reported-by: Kyle Meyer <kyle@kyleam.com>
Link: https://public-inbox.org/meta/87fsx3128a.fsf@kyleam.com/
Fixes: 520be116e8a686cb ("www_listing: start updating for pagination + search")
2 years agoextindex: maintain pack symlinks and use "git multi-pack-index"
Eric Wong [Fri, 25 Jun 2021 01:06:39 +0000 (01:06 +0000)]
extindex: maintain pack symlinks and use "git multi-pack-index"

This is a fair amount of complexity, but it speeds up
"git cat-file --batch" startup by 3-4% with 50K packfiles
with a hot kernel cache.

This appears extremely sensitive to RAM available to
the kernel page cache with my SATA 2 SSD.  Faster storage
and more RAM can bring loading pack.

2.60s vs 2.69s were the best cases on my workstation with and
without the multi-pack-index, however times could be all over
the place (even in the minutes) with more activity on my
workstation.

Getting sub-minute times requires a git patch to speed up
alt_odb_usable():
  <https://lore.kernel.org/20210624005806.12079-1-e@80x24.org/>
Otherwise, prepare to wait several minutes.

2 years agowww_listing: fix manifest.js.gz generation with extindex "all"
Eric Wong [Thu, 24 Jun 2021 12:59:09 +0000 (12:59 +0000)]
www_listing: fix manifest.js.gz generation with extindex "all"

WwwListing and ManifestJsGz may be too different nowadays to
be worth the code sharing between them.

Update some comments and note we still needs better tests :x

Fixes: 520be116e8a686cb ("www_listing: start updating for pagination + search")
2 years agov2writable: avoid spawning "git hash-object"
Eric Wong [Thu, 24 Jun 2021 08:41:56 +0000 (08:41 +0000)]
v2writable: avoid spawning "git hash-object"

We have git_sha() nowadays that's used everywhere, so avoid
process spawning overhead for "git hash-object".

2 years agodoc: tuning: add a note about Linux sys.vm.max_map_count
Eric Wong [Thu, 24 Jun 2021 08:32:05 +0000 (08:32 +0000)]
doc: tuning: add a note about Linux sys.vm.max_map_count

git tends to die when mmap(2) fails on this limit, so let
users know about it.  Perhaps git could gracefully fallback.

2 years agofavor git(1) rather than libgit2 for ExtSearch
Eric Wong [Thu, 24 Jun 2021 05:50:04 +0000 (05:50 +0000)]
favor git(1) rather than libgit2 for ExtSearch

While both git and libgit2 take around 16 minutes to load 100K
alternates there's already a proposed patch to make git faster:

  <https://lore.kernel.org/git/20210624005806.12079-1-e@80x24.org/>

It's also easier to patch and install git locally since the
git.git build system defaults to prefix=$HOME and dealing with
dynamic linking with libgit2 is more difficult for end users
relying on Inline::C.

libgit2 remains in use for the non-ALL.git case, but maybe it's
not necessary (libgit2 is significantly slower than git in
Debian 10 due to SHA-1 collision checking).

2 years agowww: do not warn on blank query parameters
Eric Wong [Wed, 23 Jun 2021 11:14:22 +0000 (07:14 -0400)]
www: do not warn on blank query parameters

Sometimes users (or bots) may lead queries with '&' and
trigger uninitialized variable warnings, just ignore them
and give consumers a $ctx->{qp}->{''} entry.

While we're in the area, pass a regexp rather than scalar string
to the `split' perlop to prevent Perl from recompiling the
regexp on every call.

2 years agowww_listing: start updating for pagination + search
Eric Wong [Wed, 23 Jun 2021 11:14:21 +0000 (07:14 -0400)]
www_listing: start updating for pagination + search

When dealing with thousands of inboxes, displaying all of
them on a single page isn't going to work.  So steal some
pagination and search results code from the message search
to generate some basic HTML output that looks good in w3m.

2 years agosearch: make xap_terms easier-to-use and use it more
Eric Wong [Wed, 23 Jun 2021 11:14:20 +0000 (07:14 -0400)]
search: make xap_terms easier-to-use and use it more

This allows us to simplify callers throughout, and exceptions are
can no longer be silently hidden.  MiscSearch now uses xap_terms
for looking up eidx_key terms for a code reduction.

We also simplify LeiStore->_msg_kw for runtime use by moving the
MsetIterator handling into t/lei_store.t test case.

2 years agot/hl_mod: accept "make" or "makefile" for Makefile
Alyssa Ross [Tue, 22 Jun 2021 12:09:20 +0000 (12:09 +0000)]
t/hl_mod: accept "make" or "makefile" for Makefile

Version 4.0 of highlight has renamed the "make" language to
"makefile".  So just check the string starts with "make", to handle
both 3.x and 4.x.

I tested that public-inbox does actually work with highlight 4 -- it
can highlight my Makefile fine. :)

2 years agolei: use open() perlop for -C (chdir)
Eric Wong [Tue, 22 Jun 2021 10:04:36 +0000 (10:04 +0000)]
lei: use open() perlop for -C (chdir)

This is for consistency with the open() at initial accept, in
case we hit a code path which expects Perl directory handles
rather than "file handles".  Both work with the chdir() perlop
(fchdir(2), in our case).

2 years agolei import: help + completion for --new-only
Eric Wong [Sun, 20 Jun 2021 08:39:47 +0000 (08:39 +0000)]
lei import: help + completion for --new-only

I've found it's very helpful for large IMAP folders.

2 years agolei sucks: don't warn or error out on missing dependencies
Eric Wong [Sun, 20 Jun 2021 04:33:19 +0000 (04:33 +0000)]
lei sucks: don't warn or error out on missing dependencies

%INC can hold undef.  This can be hit on a Linux machine missing
Linux::Inotify2.  Loading PublicInbox::KQNotify is attempted and
PublicInbox/KQNotify.pm always exists, causing the `undef' entry
in %INC when it fails to load IO::KQueue.

$ perl -MData::Dumper -I lib \
-E 'eval { require PublicInbox::KQNotify }; say Dumper(\%INC)'