]> git.ipfire.org Git - thirdparty/public-inbox.git/log
thirdparty/public-inbox.git
2 years agosearch: add comments wrt codesearch, reduce ops
Eric Wong [Fri, 9 Jun 2023 10:31:06 +0000 (10:31 +0000)] 
search: add comments wrt codesearch, reduce ops

Add some comments about various usages of xdb_shards_flat and
mset since the addition of CodeSearch (and other search things)
subclassing it may become confusing.

Since we're in the area, we can also avoid an extra hash
lookups/initializations and reduce Perl ops in various places.

2 years agot/lei.t: quiet newline warning on older Perls
Eric Wong [Thu, 8 Jun 2023 18:26:08 +0000 (18:26 +0000)] 
t/lei.t: quiet newline warning on older Perls

Perl < 5.22 warned on newlines in the middle of a string instead
of just the end.  Workaround it by disabling all warnings on older
Perls while running File::Path::mkpath.

2 years agoxapcmd: rely on File::Temp cleanup for temporary dir
Eric Wong [Thu, 8 Jun 2023 18:04:54 +0000 (18:04 +0000)] 
xapcmd: rely on File::Temp cleanup for temporary dir

remove_tree from File::Path 2.09 (from Perl 5.16.3 on CentOS 7.x)
doesn't seem to work properly on File::Temp objects.   Since
File::Temp->newdir sets CLEANUP=>1 by default anyways, we'll
just rely on that to perform cleanup instead of doing it ourselves.

2 years agowww: more restrictive query string parsing
Eric Wong [Wed, 31 May 2023 22:10:01 +0000 (22:10 +0000)] 
www: more restrictive query string parsing

Only allow single-character query keys to prevent clients from
wasting memory in Perl's hash tables.  We'll also perform the
utf8::decode and tr/+/ / calls once on the whole query string at
once to reduce op calls.

This also avoids creating an empty hash in the common case
when the QUERY_STRING is empty and instead relies on
auto-vivification of Perl.

2 years agosearchview: clarify that only pct% links are same page
Eric Wong [Wed, 31 May 2023 09:14:45 +0000 (09:14 +0000)] 
searchview: clarify that only pct% links are same page

Non-matching messages in the skeleton aren't rendered on
the same page.

2 years agosearchview: fix 80-column violation for "above" link
Eric Wong [Wed, 31 May 2023 09:14:44 +0000 (09:14 +0000)] 
searchview: fix 80-column violation for "above" link

I think just noting "options" is enough and the mbox download
buttons are visible enough at the top of the search results
pages.

2 years agocindex: fix --no-scan no-op non-termination
Eric Wong [Tue, 9 May 2023 09:15:30 +0000 (09:15 +0000)] 
cindex: fix --no-scan no-op non-termination

We must account for the shards_active() recursing upon itself
when outside DS->event_loop.  This is tricky, unfortunately, but
--no-scan isn't a common mode of operation.  Noticed while
developing the monster --associate functionality to
automatically create bidirectional associations of
inboxes/extindices to coderepos.

2 years agocindex: fix --no-scan --prune
Eric Wong [Mon, 8 May 2023 16:58:14 +0000 (16:58 +0000)] 
cindex: fix --no-scan --prune

We must define $GIT_TODO to be non-undef when using --no-scan
for prune-only invocations to run.  I'm leaning towards making
--no-scan a publicly-documented switch for -cindex; but I'm
less certain about documenting it for -index and -extindex...

2 years agoisearch: support 64-bit article numbers for SQLite query
Eric Wong [Sat, 6 May 2023 22:40:03 +0000 (22:40 +0000)] 
isearch: support 64-bit article numbers for SQLite query

While IMAP UIDs are specified as 32-bit in RFC 3501, there's no
reason we can't support 64-bit article numbers on our end when
the time comes.  Neither NNTP nor POP3 have the 32-bit
limitation, even, so it's not inconceivable that IMAP will drop
that limitation at some point, too.

2 years agoxcpdb: support cindex upgrades and resharding
Eric Wong [Thu, 4 May 2023 11:06:42 +0000 (11:06 +0000)] 
xcpdb: support cindex upgrades and resharding

xcpdb is necessary for upgrading Xapian backends (e.g. glass to
honey), thus codesearch indices (cindex) must be supported.
Resharding is also useful if CPU count is altered on system
upgrades or downgrades.

cindex Xapian sharding is completely different than anything
else we do, so the resharding operation must be a special case
based on existing cindex sharding rules.

2 years agocompact+xcpdb: ux: include basename(*dir) in progress
Eric Wong [Thu, 4 May 2023 11:06:41 +0000 (11:06 +0000)] 
compact+xcpdb: ux: include basename(*dir) in progress

This is helpful if compacting multiple
inboxes/extindices/cindices sequentially from the CLI.

2 years agocindex: --prune + --exclude= drops repo information
Eric Wong [Wed, 3 May 2023 11:42:15 +0000 (11:42 +0000)] 
cindex: --prune + --exclude= drops repo information

--exclude= alone only prevents a coderepo from being indexed in
a particular invocation, but --prune will purge all traces of it
to ensure --update doesn't pick it up again w/o --exclude=
(unless --project-list= includes it).

2 years agoipc: get rid of lock support
Eric Wong [Wed, 3 May 2023 06:33:25 +0000 (06:33 +0000)] 
ipc: get rid of lock support

SOCK_SEQPACKET is used whenever we care about parallel writes to
a socket, so there's no need to mess with locks in userspace
code.

2 years agocompact: support codesearch indices
Eric Wong [Wed, 3 May 2023 03:11:14 +0000 (03:11 +0000)] 
compact: support codesearch indices

This is much easier to support than xcpdb since it's 1:1 and
doesn't follow a different sharding scheme than the inboxes and
extindices.

2 years agoadmin: hoist out resolve_any_idxdir from resolve_{inboxdir,eidxdir}
Eric Wong [Wed, 3 May 2023 03:11:13 +0000 (03:11 +0000)] 
admin: hoist out resolve_any_idxdir from resolve_{inboxdir,eidxdir}

This bit of common code will be handy for the upcoming
resolve_cidxdir, too.

2 years agodaemon: improve handling of Git->async_abort
Eric Wong [Mon, 1 May 2023 23:29:35 +0000 (23:29 +0000)] 
daemon: improve handling of Git->async_abort

The $oid arg for Git->cat_async is defined on async_abort using
the original request, so use undefined $type to distinguish that
case in caller-supplied callbacks.  async_abort isn't common, of
course, but sometimes git subprocesses can die unexpectedly.

2 years agosolver_git: don't spew to daemon err on git apply failure
Eric Wong [Sat, 29 Apr 2023 20:02:14 +0000 (20:02 +0000)] 
solver_git: don't spew to daemon err on git apply failure

Too many patches don't apply (due to coderepos being a PITA to
associate) and interested admins can check for 404s to diagnose
them, anyways.  This reduces the noise in syslog/stderr for
public-facing daemons.

2 years agot/lei-import-nntp: dump $lei_err on failure
Eric Wong [Sat, 29 Apr 2023 07:18:53 +0000 (07:18 +0000)] 
t/lei-import-nntp: dump $lei_err on failure

I hit an error on the backwards range import test and can't
reproduce it, perhaps dumping $lei_err can help diagnose it
in the future.

2 years agogit: make check_async callbacks identical to cat_async
Eric Wong [Fri, 28 Apr 2023 21:07:30 +0000 (21:07 +0000)] 
git: make check_async callbacks identical to cat_async

This simplifies Git->cat_async_step and fixes Git->async_abort,
the latter of which was passing arguments improperly for the
--batch-check (or `info') case at the cost of making the few
check_async callers handle an extra argument.

The extra (PublicInbox::Git) $self argument for check_async
callbacks is now gone, as avoiding the temporary cyclic
reference doesn't seem worthwhile since the temporary cyclic
reference appears in the ->cat_async code paths, too.

2 years agocontent_digest_dbg: handle empty inputs
Eric Wong [Fri, 28 Apr 2023 09:43:27 +0000 (09:43 +0000)] 
content_digest_dbg: handle empty inputs

It's possible that we hit messages or attachments with empty
bodies, so avoid doing a regexp match on an uninitialized variable.

2 years agot/gzip_filter: enhance diagnostics on missing SIGPIPE
Eric Wong [Fri, 28 Apr 2023 01:08:19 +0000 (01:08 +0000)] 
t/gzip_filter: enhance diagnostics on missing SIGPIPE

I encountered this SIGPIPE test not working as intended on
FreeBSD 12.4 once (out of hundreds of runs); but can't reproduce
it...

2 years agot/watch_maildir: eliminate extra LF from cat-file requests
Eric Wong [Thu, 27 Apr 2023 22:32:21 +0000 (22:32 +0000)] 
t/watch_maildir: eliminate extra LF from cat-file requests

This allows us to eliminate the workaround of respawning
`git cat-file', too :x

2 years agoINSTALL: fix FreeBSD pkg name typos
Siva Mahadevan [Thu, 27 Apr 2023 20:16:54 +0000 (16:16 -0400)] 
INSTALL: fix FreeBSD pkg name typos

Tested on FreeBSD 13.2-RELEASE.

2 years agoxcpdb: preserve indexlevel for extindex
Eric Wong [Wed, 26 Apr 2023 00:49:29 +0000 (00:49 +0000)] 
xcpdb: preserve indexlevel for extindex

This likely fixes indexlevel preservation for some v2 on some
systems, too, since (apparently) we need to sort shards
numerically to get Xapian metadata working properly on a
combined (multi-shard) Xapian DB.

2 years agoemergency: make error messages more consistent
Eric Wong [Tue, 25 Apr 2023 11:02:58 +0000 (11:02 +0000)] 
emergency: make error messages more consistent

Showing "failed" is needless if we already know the program
is die-ing.  We'll prefix "BUG:" to bug messages, "W:" to
non-fatal warnings to be consistent with our newer code such
as lei.

2 years agosearchidx: reduce short-lived variables for TermGenerator
Eric Wong [Tue, 25 Apr 2023 11:02:57 +0000 (11:02 +0000)] 
searchidx: reduce short-lived variables for TermGenerator

We can avoid needless refcount traffic in some cases.

2 years agosearchidxshard: use BUG error messages more consistently
Eric Wong [Tue, 25 Apr 2023 11:02:56 +0000 (11:02 +0000)] 
searchidxshard: use BUG error messages more consistently

We'll also drop the "\n" for die() to make diagnostics easier.
There's no known bugs in this area, just consistency
improvements and LoC reduction.

2 years agocindex: simplify store_repo
Eric Wong [Tue, 25 Apr 2023 11:02:55 +0000 (11:02 +0000)] 
cindex: simplify store_repo

It's easier to just create a new Xapian::Document and
replace it rather than to load and edit it.  I don't
know if there's any performance difference one way or
the other, but fewer branches helps with maintainability
and smaller optree size to lower memory use and startup
speed.

2 years agocindex: simplify tmpfile management for indexing
Eric Wong [Tue, 25 Apr 2023 11:02:54 +0000 (11:02 +0000)] 
cindex: simplify tmpfile management for indexing

I considered making this a pipe, but we must avoid spawning
`git log --stdin --no-walk=unsorted' for the no-op case since that
still emits a commit if stdin is empty.  So just get rid of an
unnecessary loop and do lseek(2) inside workers for parallelism

2 years agocindex: drop unneeded module use
Eric Wong [Tue, 25 Apr 2023 11:02:53 +0000 (11:02 +0000)] 
cindex: drop unneeded module use

I initially thought I'd use the PublicInbox::Eml module and rely
on --pretty=mboxrd; but eventually decided against it since
it wasn't saving any code.

2 years agocontent_digest_dbg: improve display of To:/Cc: diffs
Eric Wong [Tue, 25 Apr 2023 10:50:52 +0000 (10:50 +0000)] 
content_digest_dbg: improve display of To:/Cc: diffs

To: and Cc: headers can be long and differences in long lines
are easier to view when broken apart.  Just split by /,/ since
Data::Dumper will delimit with "," anyways.

2 years agomail_diff: show headers differences in WWW /$MSGID/d/ view
Eric Wong [Tue, 25 Apr 2023 10:50:51 +0000 (10:50 +0000)] 
mail_diff: show headers differences in WWW /$MSGID/d/ view

Some messages only differ in the To/Cc headers because some
MTAs seem to normalize them.  I was getting confused when I
saw some /d/ endpoints with no visible differences

2 years agomail_diff: match ContentHash EOL and EOM behavior more closely
Eric Wong [Tue, 25 Apr 2023 10:50:50 +0000 (10:50 +0000)] 
mail_diff: match ContentHash EOL and EOM behavior more closely

ContentHash currently doesn't convert CRCRLF to LF.  Perhaps it
should, but for now, have diff behavior match the actual
comparison behavior used for dedupe and omit all trailing
whitespace for diff.

2 years agomid+contenthash: eliminate needless local variable captures
Eric Wong [Tue, 25 Apr 2023 10:50:49 +0000 (10:50 +0000)] 
mid+contenthash: eliminate needless local variable captures

It's possible in theory that Perl could be smarter and free
memory a tad sooner this way.  Regardless, fewer lines of code
is easier-to-navigate/read and can save optree size and reduce
parsing times.

2 years agocindex: rewrite prune (again) for speed
Eric Wong [Sat, 22 Apr 2023 10:33:42 +0000 (10:33 +0000)] 
cindex: rewrite prune (again) for speed

With my partial git.kernel.org mirror, this brings a full prune
down from ~75 minutes to under 5 minutes using git 2.19+.  This
speedup even applies to users on slow storage (rotational HDD).

First off, xapian-delve(1) is nearly 10x faster for dumping
boolean terms by prefix than the equivalent Perl code with
Xapian bindings.  This performance difference is critical since
we need to check over 5 million commits for pruning a partial
git.kernel.org mirror.

We can use sed(1) and sort(1) to massage delve output into
something suitable for the first comm(1) input.

For the second comm(1) input, the output of `git cat-file
--batch-check --batch-all-objects' against all indexed git repos
with awk(1) filtering provides the necessary output for
generating a list of indexed-but-no-longer accessible commits.

sed(1) and awk(1) are POSIX standard tools which can be roughly
2x faster than equivalent Perl for simple filters, while
sort(1) is designed to handle larger-than-memory datasets
efficiently (unlike the `sort' perlop).

With slow storage and git <2.19, the switch to --batch-all-objects
actually results in a performance regression since having git
perform sorting results in worse disk locality than the previous
sequential iteration by Xapian docid.  git 2.19+ users with
`--unordered' support benefits from improved storage locality;
and speedups from storage locality dwarfs the extra overhead of
an extra external sort(1) invocation.

Even with consumer-grade SATA-II SSDs, the combo of --unordered
and sort(1) provides a noticeable speedup since SSD latency
remains a factor for --batch-all-objects.

git <2.19 users must upgrade git to get acceptable performance
on slow storage and giant indexes, but git 2.19 was released
nearly 5 years ago so it's probably a reasonable requirement for
performance.

The only remaining downside of this change for all users
the extra temporary disk space for sort(1) and comm(1);
but the speedup provided with git 2.19+ is well worth it.

2 years agocindex: fix prune to not wipe out the entire index
Eric Wong [Fri, 21 Apr 2023 11:52:03 +0000 (11:52 +0000)] 
cindex: fix prune to not wipe out the entire index

Oops :x  I noticed this while I was working on a major optimization
for prune...

2 years agolei_mail_sync: prepare to support SHA-256
Eric Wong [Thu, 20 Apr 2023 10:23:02 +0000 (10:23 +0000)] 
lei_mail_sync: prepare to support SHA-256

I'm not sure how combining SHA-1 and SHA-256 in a single git
repo will work, eventually.   But this is an obvious place to do
the right thing if we ever see a 64-byte hex string (unless git
adds support for another hash which uses 64-byte hex string
representations, which would break many assumptions elsewhere,
too...).

2 years agocindex: limit parallelism of extensions.objectFormat check
Eric Wong [Thu, 20 Apr 2023 00:53:30 +0000 (00:53 +0000)] 
cindex: limit parallelism of extensions.objectFormat check

We can't safely spawn all `git config' processes of every
indexed git directory at once due to system resource limits
(RLIMIT_NPROC, RLIMIT_NOFILE). So queue them up and limit
parallelism that way.

2 years agocindex: support sha256 coderepos alongside sha1
Eric Wong [Wed, 19 Apr 2023 21:54:48 +0000 (21:54 +0000)] 
cindex: support sha256 coderepos alongside sha1

This special support is only needed for --prune at the moment
since the indexing side works on a per-repo basis.  There's no
automated tests, yet, but it seems to work well on my sha256
projects when sharing a cindex with sha1 projects.

2 years agowww_coderepo: rescan cgit project-list for new coderepos
Eric Wong [Tue, 18 Apr 2023 18:39:14 +0000 (18:39 +0000)] 
www_coderepo: rescan cgit project-list for new coderepos

Coderepo changes are probably more common than inbox changes, so
it probably makes sense to rescan and look for new coderepos on
404s, especially since we serve mirrored manifest.js.gz as-is.

I noticed my git.kernel.org mirror was serving manifest.js.gz
pointing to irretrievable repositories.  This should stop that.

We'll also drop the underscore ('_') and use `coderepo'
everywhere to be consistent with our documentation.

We may serve new inboxes in a similar way down the line, too;
but this change only affects coderepos for now since we can
guarantee the inbox manifest.js.gz never contains irretrievable
inboxes as it's dynamically generated.

2 years agolistener: support multi-accept like nginx
Eric Wong [Wed, 12 Apr 2023 10:17:42 +0000 (10:17 +0000)] 
listener: support multi-accept like nginx

While accepting a single connection at-a-time is likely best for
multi-worker and/or load-balanced deployments; accepting
multiple connections at once should be less bad on overloaded
single-worker systems.

We can't automatically pick the best value here since worker
counts are dynamic via SIGTTIN/SIGTTOU.  Process managers
(e.g. systemd) can also spawn multiple instances sharing a
single listener with no knowledge sharing between listeners.

2 years agolei_mail_sync: cleanup stale/dangling fids if possible
Eric Wong [Wed, 12 Apr 2023 06:19:10 +0000 (06:19 +0000)] 
lei_mail_sync: cleanup stale/dangling fids if possible

I'm not sure how it happens or if/when it was fixed, but my
earliest lei installations have hit some
"E: fid=$fid for $oidhex unknown" messages on `lei import'
invocations.

This really should've enabled the foreign keys pragma to begin
with; but we'll probably start using that in the future.  For
now, at least rely on a transaction to keep things consistent
in SQLite.

2 years agogit: parallelize manifest_entry
Eric Wong [Wed, 12 Apr 2023 00:13:02 +0000 (00:13 +0000)] 
git: parallelize manifest_entry

This saves a few milliseconds per-epoch without incurring
any dependencies on the event loop.  It can be parallelized
further, of course, but it may not be worth it for -extindex
users since it's already cached.

2 years agowww_coderepo: drop unused $EACH_REF variable
Eric Wong [Wed, 12 Apr 2023 00:13:01 +0000 (00:13 +0000)] 
www_coderepo: drop unused $EACH_REF variable

It's unused since commit cbe2548c91859dfb
(www_coderepo: use OnDestroy to render summary view, 2023-04-09)

2 years agogit: rename version() to git_version()
Eric Wong [Wed, 12 Apr 2023 00:13:00 +0000 (00:13 +0000)] 
git: rename version() to git_version()

In case it gets confused with Inbox->version or similar.

2 years agogzip_filter: use carp in ->bail for failure checks
Eric Wong [Wed, 12 Apr 2023 00:12:59 +0000 (00:12 +0000)] 
gzip_filter: use carp in ->bail for failure checks

carp is more useful since it shows the perspective of the caller
and can be made to show a full backtrace with
PERL5OPT=-MCarp=verbose

2 years agogit: cat_async_step: reduce batch-command info checks
Eric Wong [Wed, 12 Apr 2023 00:12:58 +0000 (00:12 +0000)] 
git: cat_async_step: reduce batch-command info checks

This improves readability for me.  Instead of checking for `info '
requests of `--batch-command' in multiple places of every
common branch, do it once per-call and stash its result.

We'll also avoid storing `$bc' for now since the only other
check is in a cold path.

2 years agogit: fix cat_async_retry
Eric Wong [Tue, 11 Apr 2023 11:23:50 +0000 (11:23 +0000)] 
git: fix cat_async_retry

Retrying requests on alternates changing was causing inflight
requests to get lost due to {inflight} getting clobbered by
batch_prepare.

Unfortunately, reproducing this is difficult without mocking
->alternates_changed.

SearchIdx now avoids calling ->batch_prepare directly and
relies on more common API functions.

Fixes: 65db62eb006f ("git: use --batch-command in git 2.36+ to save processes")
2 years agowww_coderepo: use OnDestroy to render summary view
Eric Wong [Sun, 9 Apr 2023 22:30:13 +0000 (22:30 +0000)] 
www_coderepo: use OnDestroy to render summary view

This lets us get rid of a /bin/sh process and allows us us to
rely on Qspawn to parallelize git commands.

Special treatment of the OnDestroy object is necessary to keep
its scope limited for MockHTTP.  Neither the generic `plackup'
HTTP server and nor our -httpd/-netd needed this scope
limitation.  As a result, summary() is now called inside an
anonymous sub to keep the memory overhead of the anonymous sub
itself as small as possible.  Avoiding anonymous subs entirely
would be preferable for memory savings, but it's necessary for
PSGI.

2 years agot/nntpd.t: avoid `used only once' warning
Eric Wong [Sat, 8 Apr 2023 20:19:28 +0000 (20:19 +0000)] 
t/nntpd.t: avoid `used only once' warning

We can't use cross-package `our' variables without `use'-ing the
package, first.

2 years agov2writable: drop experimental DEBUG_DIFF support
Eric Wong [Sat, 8 Apr 2023 09:23:44 +0000 (09:23 +0000)] 
v2writable: drop experimental DEBUG_DIFF support

I haven't used it in 5 years, and I doubt anybody else has,
either.  In any case, we have both `lei mail-diff' and diff
support in the WWW UI, now, so more convenient options are
available.

2 years agoviewvcs: avoid uninitialized var on unusable filenames
Eric Wong [Sat, 8 Apr 2023 20:08:36 +0000 (20:08 +0000)] 
viewvcs: avoid uninitialized var on unusable filenames

This happens if somebody uses a bogus filename like `.' for the
`b=' parameter (e.g. GET `$REPO/$OID/?b=.').

2 years agot/sigfd: avoid multiple Sigfd instances
Eric Wong [Fri, 7 Apr 2023 22:53:36 +0000 (22:53 +0000)] 
t/sigfd: avoid multiple Sigfd instances

This may fix sporadic test failures I've seen under FreeBSD 12.x
when using kqueue with EVFILT_SIGNAL to emulate Linux signalfd.

2 years agoconfig: describe order dependency in cgitrc parsing
Eric Wong [Thu, 6 Apr 2023 21:02:03 +0000 (21:02 +0000)] 
config: describe order dependency in cgitrc parsing

I just had to do a double-take here and look back at cgit.c
to see the ordering dependency wasn't a bug I introduced,
but mimicking what cgit does.

2 years agoswitch git version comparisons to vstrings, too
Eric Wong [Fri, 7 Apr 2023 12:40:53 +0000 (12:40 +0000)] 
switch git version comparisons to vstrings, too

There's too many require_git callsites in t/*.t to change,
but we can make the rest of the code more readable and reuse
PublicInbox::Git::version() in our test suite, too.

2 years agosearchidx: use vstring to improve readability
Eric Wong [Fri, 7 Apr 2023 12:40:52 +0000 (12:40 +0000)] 
searchidx: use vstring to improve readability

Perl has native `vstring' encoding for vector (or version)
strings, make use of it instead of relying on difficult-to-read
hex versions and integer shifts.

2 years agoumask: rely on the OnDestroy-based call where applicable
Eric Wong [Fri, 7 Apr 2023 12:40:51 +0000 (12:40 +0000)] 
umask: rely on the OnDestroy-based call where applicable

This lets us get rid of some awkwardness around the old API
and single-use subroutines while saving us some LoC.

2 years agoumask: hoist out of InboxWritable
Eric Wong [Fri, 7 Apr 2023 12:40:50 +0000 (12:40 +0000)] 
umask: hoist out of InboxWritable

Since CodeSearchIdx doesn't deal with inboxes, it makes sense
to split it out from inbox-specific code and start moving
towards using OnDestroy to restore the umask at the end of
scope and reducing extra functions.

2 years agocindex: preserve indexlevel across invocations
Eric Wong [Fri, 7 Apr 2023 12:40:49 +0000 (12:40 +0000)] 
cindex: preserve indexlevel across invocations

This matches the behavior of mail indexers and ensures `medium'
indices don't grow unexpectedly to be come `full' indices.

2 years agocindex: improve progress display
Eric Wong [Fri, 7 Apr 2023 12:40:48 +0000 (12:40 +0000)] 
cindex: improve progress display

Instead of displaying the total number of changes across all
repos next to the repo path ("$GIT_DIR: $TOTAL commits"), we'll
only show the number of changes made in that repo.

We'll also note when a prune is complete on a shard, since
prunes may often be expensive no-ops.

2 years agowatch: close inotify FD on ->quit
Eric Wong [Thu, 6 Apr 2023 12:39:53 +0000 (12:39 +0000)] 
watch: close inotify FD on ->quit

For simplicity, we quit and recreate an entire watch instance
on SIGHUP.  However, inotify (and signalfd) FDs are tied to
the DS event loop and stay pinned to existence that way.
Thus we explicitly close the FD in Watch->quit to prevent
leakage on SIGHUP.

2 years agowatch: use detect_indexlevel for unconfigured inboxes
Eric Wong [Thu, 6 Apr 2023 12:39:52 +0000 (12:39 +0000)] 
watch: use detect_indexlevel for unconfigured inboxes

I favor leaving the publicinbox.<name>.indexlevel parameter
out of config files to make it easier to alter and reduce
sources of truth.  It worked well in most cases, but
public-inbox-watch also needs to detect the indexlevel.

Moving the sub to InboxWritable (from Admin) probably makes
sense since it's a per-inbox attribute and allows -watch
to reuse it.

2 years agocindex: reset DS internals on cidx_run completion
Eric Wong [Wed, 5 Apr 2023 11:26:58 +0000 (11:26 +0000)] 
cindex: reset DS internals on cidx_run completion

We may be invoking cidx_run multiple times per-process,
so ensure it can setup signalfd/EVFILT_SIGNAL across them.

2 years agocindex: workaround for FreeBSD missing SIGCHLD
Eric Wong [Wed, 5 Apr 2023 11:26:57 +0000 (11:26 +0000)] 
cindex: workaround for FreeBSD missing SIGCHLD

This likely affects all other *BSDs with kevent, as well;
since SIGCHLD is special w.r.t. EVFILT_SIGNAL

2 years agocindex: enter event loop once per run
Eric Wong [Wed, 5 Apr 2023 11:26:56 +0000 (11:26 +0000)] 
cindex: enter event loop once per run

This avoids needing to alter the sigmask for systems without
signalfd or EVFILT_SIGNAL.  This will also make it easier to
workaround FreeBSD (and likely *BSD) signal behavior in the
next commit.

2 years agocindex: share PktOp across indexing workers
Eric Wong [Wed, 5 Apr 2023 11:26:55 +0000 (11:26 +0000)] 
cindex: share PktOp across indexing workers

Using fewer sockets simplifies completion checks, too.

2 years agocindex: share PktOp socket across prune workers
Eric Wong [Wed, 5 Apr 2023 11:26:54 +0000 (11:26 +0000)] 
cindex: share PktOp socket across prune workers

We can allocate fewer sockets and memory this way.

2 years agocindex: do prune work while waiting for `git log -p'
Eric Wong [Wed, 5 Apr 2023 11:26:53 +0000 (11:26 +0000)] 
cindex: do prune work while waiting for `git log -p'

`git log -p' can several seconds to generate its initial output.
SMP systems can be processing prunes during this delay, so let
DS do a one-shot notification for us while prune is running.  On
Linux, we'll also use the biggest pipe possible so git can do
more CPU-intensive work to generate diffs while our Perl
processes are indexing and likely hitting I/O wait.

2 years agoipc: support awaitpid in WQ workers
Eric Wong [Wed, 5 Apr 2023 11:26:52 +0000 (11:26 +0000)] 
ipc: support awaitpid in WQ workers

Using signalfd is necessary to get reliable signal wakeups w/o
polling on fixed intervals.  This change will make it possible
to use awaitpid in cidx shard workers so they can perform prune
work while waiting on the initial output of `git log -p'.

2 years agowww: support POST /$INBOX/$MSGID/?x=m&q=
Eric Wong [Thu, 30 Mar 2023 11:29:51 +0000 (11:29 +0000)] 
www: support POST /$INBOX/$MSGID/?x=m&q=

This allows filtering the contents of any existing thread using
a search query.  It uses the existing THREADID column in Xapian
so we can internally add a Xapian OP_FILTER to the results.

This new functionality is orthogonal to the existing `t=1'
parameter which gives mairix-style thread expansion.  It doesn't
make sense to use `t=1' with this functionality, but it's not
disallowed, either.

The indentation change in Over->next_by_mid is to ensure
DBI->prepare_cached can share across both ->next_by_mid
and ->mid2tid.

I also noticed the existing regex for `POST /$INBOX/?x=m&q=' was
allowing extra characters.  With an added \z, it's now as strict
was originally intended and AFAIK nothing was generating invalid
URLs for it

Reported-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Link: https://public-inbox.org/meta/aaniyhk7wfm4e6m5mbukcrhevzoc6ftctyrfwvmz4fkykwwtlj@mverfng6ytas/T/
2 years agocindex: interleave prune with indexing
Eric Wong [Wed, 29 Mar 2023 20:32:59 +0000 (20:32 +0000)] 
cindex: interleave prune with indexing

We need to ensure we don't block indexing for too long while
pruning, since pruning coderepos seems more frequent and
necessary than inbox repos due to the prevalence of force
pushes with branches like `seen' (formerly `pu') in git.git.

Implement this via ->event_step and requeue mechanisms of DS so
we periodically flush our work and let indexing resume.

I originally wanted to implement this as a dedicated group
of workers, but the XS Search::Xapian bug[1] workaround
to handle uncaught C++ exceptions was expensive and complex
compared to the evented mechanism.

[1] https://lists.xapian.org/pipermail/xapian-discuss/2023-March/009967.html
   <20230327114604.M803690@dcvr>

2 years agocindex: leave SIGTSTP and SIGCONT unblocked
Eric Wong [Tue, 28 Mar 2023 02:59:04 +0000 (02:59 +0000)] 
cindex: leave SIGTSTP and SIGCONT unblocked

This makes it easier to pause and restart long-running indexing
jobs which use our event loop.

2 years agocindex: always break out of event loop on $DO_QUIT
Eric Wong [Tue, 28 Mar 2023 02:59:02 +0000 (02:59 +0000)] 
cindex: always break out of event loop on $DO_QUIT

Shard workers may not die soon enough (or get stuck), just let
the parent die earlier since it doesn't need to commit anything.

2 years agocindex: simplify some internal data structures
Eric Wong [Tue, 28 Mar 2023 02:59:01 +0000 (02:59 +0000)] 
cindex: simplify some internal data structures

We'll rely more on local-ized `our' globals rather than
hashref fields.  The former is more resistant to typos
and can be checked at compile-time earlier via `perl -c'.

The {-internal} field is also renamed to {-cidx_internal}
in case to reduce confusion within a large code base.

2 years agot/lei-refresh-mail-sync: improve test reliability
Eric Wong [Tue, 28 Mar 2023 10:53:58 +0000 (10:53 +0000)] 
t/lei-refresh-mail-sync: improve test reliability

Lack of signalfd/EVFILT_SIGNAL means we need to kill a
process repeatedly to ensure it wakes up.

2 years agoinotify: wrap with informative error message
Eric Wong [Tue, 28 Mar 2023 11:12:36 +0000 (11:12 +0000)] 
inotify: wrap with informative error message

As encountered by Louis DeLosSantos, Linux inotify is capped by
a lesser-known limit than the standard RLIMIT_NOFILE (`ulimit -n`)
value.  Give the user a hint about the fs.inotify.max_user_instances
sysctl knob on EMFILE, since EMFILE alone may mislead users into
thinking they've hit the (typically higher) RLIMIT_NOFILE limit.

I can test this on my system using:

  perl -I lib -MPublicInbox::Inotify -E \
   'my @x = map { PublicInbox::Inotify->new } (1..128)'

But I hesitate to include it in the test suite since triggering
the limit can cause unrelated processes to fail.

Link: https://public-inbox.org/meta/CAE6jdTo8iQfNM9Yuk0Dwi-ARMxmQxX-onL8buXcQ9Ze3r0hKrg@mail.gmail.com/
Reported-by: Louis DeLosSantos <louis.delos@gmail.com>
2 years agogit: check for --version errors
Eric Wong [Sun, 26 Mar 2023 23:48:03 +0000 (23:48 +0000)] 
git: check for --version errors

While unlikely, `git --version' may fail, so we must check for
errors and by reaping the process ASAP via tied close().

2 years agowatch: do not recreate signalfd on SIGHUP
Eric Wong [Sun, 26 Mar 2023 10:52:46 +0000 (10:52 +0000)] 
watch: do not recreate signalfd on SIGHUP

The normal method by which PublicInbox::DS::event_loop sets up
signals once needs some coercing to work with -watch.
Otherwise, we'll end up wasting FDs every time somebody reloads
-watch via SIGHUP.

2 years agowatch: avoid Mail::IMAPClient errors when disconnected
Eric Wong [Sun, 26 Mar 2023 10:52:45 +0000 (10:52 +0000)] 
watch: avoid Mail::IMAPClient errors when disconnected

No point in issuing LOGOUT commands and causing Mail::IMAPClient
to spew a giant backtrace when we're unconnected.

2 years agolei_mirror: fix sh syntax error in "make help" target
Eric Wong [Sun, 26 Mar 2023 08:21:32 +0000 (08:21 +0000)] 
lei_mirror: fix sh syntax error in "make help" target

Oops :x

Fixes: 836faf5093df ("lei_mirror: add `index' target to generated Makefile")
2 years agoMerge branch 'cindex'
Eric Wong [Sun, 26 Mar 2023 09:35:43 +0000 (09:35 +0000)] 
Merge branch 'cindex'

* cindex: (29 commits)
  cindex: --prune checkpoints to avoid OOM
  cindex: ignore SIGPIPE
  cindex: respect existing permissions
  cindex: squelch incompatible options
  cindex: implement reindex
  cindex: add support for --prune
  cindex: filter out non-existent git directories
  spawn: show failing directory for chdir failures
  cindex: improve granularity of quit checks
  cindex: attempt to give oldest commits lowest docids
  cindex: truncate or drop body for over-sized commits
  cindex: check for checkpoint before giant messages
  cindex: implement --max-size=SIZE
  sigfd: pass signal name rather than number to callback
  cindex: handle graceful shutdown by default
  cindex: drop `unchanged' progress message
  cindex: show shard number in progress message
  cindex: implement --exclude= like -clone
  ds: @post_loop_do replaces SetPostLoopCallback
  cindex: use DS and workqueues for parallelism
  ...

2 years agolei: improve bash completion involving colons
Eric Wong [Thu, 23 Mar 2023 21:45:45 +0000 (21:45 +0000)] 
lei: improve bash completion involving colons

This fixes completions of labels (`+L:' for `lei import' and
`L:' for `lei q') so they can appear anywhere in the
command-line.

I mainly wanted this for `lei import $URL +L:label', but
this also fixes `lei forget-external' completions for URLs
(which involve colons).

2 years agolei_store: avoid redundant work on no-op worker spawn
Eric Wong [Sat, 25 Mar 2023 11:11:05 +0000 (11:11 +0000)] 
lei_store: avoid redundant work on no-op worker spawn

While ->wq_workers_start is idempotent, the pipe creation for
PublicInbox::LeiStoreErr was not and required several extra
syscalls and FD allocations.  Check the correct field required
for SOCK_SEQPACKET workers rather than pipe-based workers.

Fixes: cbc2890cb89b81cb ("lei/store: use SOCK_SEQPACKET rather than pipe")
2 years agocindex: --prune checkpoints to avoid OOM
Eric Wong [Fri, 24 Mar 2023 10:40:22 +0000 (10:40 +0000)] 
cindex: --prune checkpoints to avoid OOM

Having many ->delete_document calls in a transaction still
causes Xapian to eat up a large amount of memory and OOM on my
system.

I may reimplement --prune to avoid blocking ongoing updates, but
this is a simple fix for swapping and OOMs for now.

2 years agocindex: ignore SIGPIPE
Eric Wong [Tue, 21 Mar 2023 23:07:43 +0000 (23:07 +0000)] 
cindex: ignore SIGPIPE

We check for all socket write errors anyways, and I don't expect
stderr output to be significant enough to matter.

2 years agocindex: respect existing permissions
Eric Wong [Tue, 21 Mar 2023 23:07:42 +0000 (23:07 +0000)] 
cindex: respect existing permissions

For internal ($GIT_DIR/public-inbox-cindex) Xapian DBs, we can
rely on core.sharedRepository.  For external ones, we'll just
rely on existing permissions if the directory already exists.

2 years agocindex: squelch incompatible options
Eric Wong [Tue, 21 Mar 2023 23:07:41 +0000 (23:07 +0000)] 
cindex: squelch incompatible options

Some options don't make sense when used together.

2 years agocindex: implement reindex
Eric Wong [Tue, 21 Mar 2023 23:07:40 +0000 (23:07 +0000)] 
cindex: implement reindex

This allows changing --indexlevel at the moment and will allow
us to fix some yet-to-be-discovered bugs or backwards-compatible
improvements in the future.

2 years agocindex: add support for --prune
Eric Wong [Tue, 21 Mar 2023 23:07:39 +0000 (23:07 +0000)] 
cindex: add support for --prune

This gets rid of both inaccessible commits AND repositories.
It will only unindex commits which are pruned in git, first,
so repos with auto GC disabled will need GC to prune them.

2 years agocindex: filter out non-existent git directories
Eric Wong [Tue, 21 Mar 2023 23:07:38 +0000 (23:07 +0000)] 
cindex: filter out non-existent git directories

We'll just warn them about our non-existent prune support,
for now, and implement --prune in the next commit.

2 years agospawn: show failing directory for chdir failures
Eric Wong [Tue, 21 Mar 2023 23:07:37 +0000 (23:07 +0000)] 
spawn: show failing directory for chdir failures

Our use of `git rev-parse --git-dir' depends on our (v)fork+exec
wrapper doing chdir, so the error message is required to avoid
user confusion.  I'm still avoiding `git -C $DIR' for now since
ancient versions of git did not support it.

2 years agocindex: improve granularity of quit checks
Eric Wong [Tue, 21 Mar 2023 23:07:36 +0000 (23:07 +0000)] 
cindex: improve granularity of quit checks

This fixes shutdown handling when shard_index() isn't running
and ensures we can shut down the process more quickly.

2 years agocindex: attempt to give oldest commits lowest docids
Eric Wong [Tue, 21 Mar 2023 23:07:35 +0000 (23:07 +0000)] 
cindex: attempt to give oldest commits lowest docids

Monotonically increasing docids may help us avoid sorting output
for the web and CLI, since recent commits are generally the most
desired search results.

`git log --reverse' incurs no extra overhead in this case, since
`--stdin' will mean git buffers the commit list in memory before
attempting to emit anything.

2 years agocindex: truncate or drop body for over-sized commits
Eric Wong [Tue, 21 Mar 2023 23:07:34 +0000 (23:07 +0000)] 
cindex: truncate or drop body for over-sized commits

We need to get at least the commit OID indexed to
avoid redundant work.

2 years agocindex: check for checkpoint before giant messages
Eric Wong [Tue, 21 Mar 2023 23:07:33 +0000 (23:07 +0000)] 
cindex: check for checkpoint before giant messages

Giant messages may put us far over the batch limit if we're
close to it.

2 years agocindex: implement --max-size=SIZE
Eric Wong [Tue, 21 Mar 2023 23:07:32 +0000 (23:07 +0000)] 
cindex: implement --max-size=SIZE

This matches existing behavior of -index and -extindex, and
will hopefully allow me to avoid OOM problems by skipping
problematic commits.

2 years agosigfd: pass signal name rather than number to callback
Eric Wong [Tue, 21 Mar 2023 23:07:31 +0000 (23:07 +0000)] 
sigfd: pass signal name rather than number to callback

This is consistent with normal Perl %SIG handlers, and allows
-cindex signal handlers to be implemented consistently across
platforms.

2 years agocindex: handle graceful shutdown by default
Eric Wong [Tue, 21 Mar 2023 23:07:30 +0000 (23:07 +0000)] 
cindex: handle graceful shutdown by default

While individual Xapian shards are consistent due to the use of
Xapian transactions, the data across shards still needs to be
in a consistent state for our search to work.

2 years agocindex: drop `unchanged' progress message
Eric Wong [Tue, 21 Mar 2023 23:07:29 +0000 (23:07 +0000)] 
cindex: drop `unchanged' progress message

It's too noisy, and a similar message isn't emitted by -clone.

2 years agocindex: show shard number in progress message
Eric Wong [Tue, 21 Mar 2023 23:07:28 +0000 (23:07 +0000)] 
cindex: show shard number in progress message

Otherwise it may be confusing to see the `$nr' value walk
backwards if some shards are indexing at a slower pace.