]> Sergey Matveev's repositories - public-inbox.git/log
public-inbox.git
3 years agogrok-pull.post_update_hook: favor --sequential-shard for HDD
Eric Wong [Thu, 13 Aug 2020 08:04:04 +0000 (08:04 +0000)]
grok-pull.post_update_hook: favor --sequential-shard for HDD

--sequential-shard offers better performance on HDD than -j0
since the on-disk active set can be kept small (with -j $HIGH_NUM).
--batch-size can also be helpful for systems with much RAM.

3 years agoindex|compact|xcpdb: support --all switch
Eric Wong [Thu, 13 Aug 2020 08:04:37 +0000 (08:04 +0000)]
index|compact|xcpdb: support --all switch

For -index, this is a convenient way to quickly index all
inboxes after a grok-pull.  Might as well support it for
rarely used commands like -compact and -xcpdb, too.

3 years agov2writable: remove IdxStack import
Eric Wong [Wed, 12 Aug 2020 09:17:19 +0000 (09:17 +0000)]
v2writable: remove IdxStack import

We use IdxStack via log2stack() from SearchIdx, now.

3 years agoxcpdb: wire up new index options and --help
Eric Wong [Wed, 12 Aug 2020 09:17:18 +0000 (09:17 +0000)]
xcpdb: wire up new index options and --help

--sequential-shard also disables the copy parallelism (--jobs),
so it can be useful for systems unable to handle parallel random
I/O but still want many shards.

There was a missing "use strict", too, which is fixed.

3 years agoadmin: don't warn when --jobs exceeds shards
Eric Wong [Wed, 12 Aug 2020 09:17:17 +0000 (09:17 +0000)]
admin: don't warn when --jobs exceeds shards

Established tools like make(1), prove(1) and xargs(1) don't warn
when the desired parallelism level can't be met, either.

3 years agoxapcmd: reduce CPU idling when shards exceeds job count
Eric Wong [Wed, 12 Aug 2020 09:17:16 +0000 (09:17 +0000)]
xapcmd: reduce CPU idling when shards exceeds job count

In case there's unbalanced shards AND we're limiting parallelism
while using many shards, spawn the next task in the queue ASAP
once a task is done, instead of waiting for all tasks to finish
before spawning the next batch.

Unbalanced shards probably isn't a big issue for most users;
however many smaller shards with few jobs can be useful for HDD
users to reduce the effect of random writes.

3 years agoxcpdb: support --no-fsync from CLI
Eric Wong [Wed, 12 Aug 2020 09:17:15 +0000 (09:17 +0000)]
xcpdb: support --no-fsync from CLI

This was omitted in 8b1950055d51d436 :x

Fixes: 8b1950055d51d436 ("index+xcpdb: rename `--no-sync' to `--no-fsync'")
3 years agoxapcmd: simplify sub reference
Eric Wong [Wed, 12 Aug 2020 09:17:14 +0000 (09:17 +0000)]
xapcmd: simplify sub reference

We don't need to fully-qualify when referring to subs in
the same namespace, nor do we need make a SCALAR ref only
to dereference it

(Yes, still learning Perl :x)

3 years agoconvert: set No_COW on copied SQLite files
Eric Wong [Mon, 10 Aug 2020 02:12:05 +0000 (02:12 +0000)]
convert: set No_COW on copied SQLite files

We'll use our existing logic and use sqlite_backup_from_file,
which appeared in 1.39 (along with sqlite_backup_to_file).

3 years agoconvert: check ARGV more correctly
Eric Wong [Mon, 10 Aug 2020 02:12:04 +0000 (02:12 +0000)]
convert: check ARGV more correctly

Instead of silently ignoring excessive args, don't let a user
specify an extra directory.  Furthermore, we'll support the odd
case where BOFH wants to name an $INBOX_DIR to be `0' :P

3 years agoconvert: speed up --help
Eric Wong [Mon, 10 Aug 2020 02:12:03 +0000 (02:12 +0000)]
convert: speed up --help

Lazy-loading dependencies speeds up --help by several hundred
milliseconds and is a huge step towards user-friendliness.

3 years agoconvert: support new -index options
Eric Wong [Mon, 10 Aug 2020 02:12:02 +0000 (02:12 +0000)]
convert: support new -index options

Converting v1 inboxes from v2 can be a painful experience
on HDD.  Some of the new options in the CLI or config
file make it less painful.

3 years agosearchidx: use singular `$opt' for consistency with v2
Eric Wong [Mon, 10 Aug 2020 02:12:01 +0000 (02:12 +0000)]
searchidx: use singular `$opt' for consistency with v2

The rest of our indexing code uses `$opt' instead of `$opts'.

3 years agoindex: cleanup internal variables
Eric Wong [Mon, 10 Aug 2020 02:12:00 +0000 (02:12 +0000)]
index: cleanup internal variables

Move away from hard-to-read alllowercase naming and favor
snake_case or separated-by-dashes.

We'll keep `--indexlevel' as-is for now, since it's been around
for several releases; but we'll support `--index-level' in the
CLI and update our documentation in a few months.

We'll also clarify that publicInbox.indexMaxSize is only
intended for -index, and not -watch or -mda.

3 years agoadmin: use a generic variable name
Eric Wong [Mon, 10 Aug 2020 02:11:59 +0000 (02:11 +0000)]
admin: use a generic variable name

We parse other options, too, not just --max-size

3 years agoavoid File::Temp::tempfile in more places
Eric Wong [Mon, 10 Aug 2020 02:11:58 +0000 (02:11 +0000)]
avoid File::Temp::tempfile in more places

We can use open(..., undef) natively in Perl in t/import.t

In places where we need a pathname, the File::Temp OO API
gives us auto-unlinking for free.

3 years agomsgmap: tmp_clone: simplify + meaningful filename
Eric Wong [Mon, 10 Aug 2020 02:11:57 +0000 (02:11 +0000)]
msgmap: tmp_clone: simplify + meaningful filename

Trying to use the newer ->sqlite_backup_to_dbh method doesn't
seem worth it, as we'll have to support DBD::SQLite <= 1.60
another decade or more.

Dumping 'msgmap-XXXXXXX' into $INBOX_DIR can appear a bit
confusing to users, so give it a "mm_tmp-$PID-XXXXXXXX" name
to emphasize it's a temporary file tied to a given PID.

We also don't want to penalize read-only daemons with
loading File::Temp, so do it lazily.

3 years agoindex+xcpdb: improve SIG{INT,TERM,HUP,PIPE} behavior
Eric Wong [Mon, 10 Aug 2020 02:11:56 +0000 (02:11 +0000)]
index+xcpdb: improve SIG{INT,TERM,HUP,PIPE} behavior

-index now invokes ->DESTROY like xcpdb does, which is necessary
to cleanup $INBOX_DIR/msgmap-XXXXXXX files.  We'll also exit
with the expected values for various signals by adding 128
as described in <https://www.tldp.org/LDP/abs/html/exitcodes.html>

-xcpdb now terminates worker processes and xapian-compact(1)
invocations when prematurely killed, too.

3 years agodoc: add some notes around -xcpdb / -edit / -purge
Eric Wong [Mon, 10 Aug 2020 02:11:55 +0000 (02:11 +0000)]
doc: add some notes around -xcpdb / -edit / -purge

These rarely-used commands have some caveats that needed
expanding on.

3 years agodoc: index: more notes about latest changes
Eric Wong [Mon, 10 Aug 2020 02:11:54 +0000 (02:11 +0000)]
doc: index: more notes about latest changes

With LKML on an HDD, a giant --batch-size of 500m ends up being
pretty useful.  I was able to index LKML in ~16 hours on a
system that had other activity on it.  The big downside was it
was eating up over 5g of RAM :x.

We'll also fix up a duplicated indexBatchSize section, fix
formatting around global vs per-inbox indexSequentialShard,
and ensure section 5 manpages are linked correctly.

3 years agoindex: --sequential-shard works incrementally
Eric Wong [Mon, 10 Aug 2020 02:11:53 +0000 (02:11 +0000)]
index: --sequential-shard works incrementally

We should never reindex all data in Xapian unless --reindex is
specified on the command-line.  This means users who put
publicInbox.indexSequentialShard in their config file won't have
to put up with a full reindex at every invocation, only when
they specify --reindex.

We'll also cleanup the progress output to not emit non-sensical
ranges where the starting number is higher than the end.

3 years agoindex: require --reindex when using --xapian-only
Eric Wong [Mon, 10 Aug 2020 02:11:52 +0000 (02:11 +0000)]
index: require --reindex when using --xapian-only

This to avoid user error of a currently undocumented switch;
since --xapian-only always goes through the full history at
the moment.

3 years agofavor `getconf _NPROCESSORS_ONLN` over GNU nproc
Eric Wong [Sat, 8 Aug 2020 11:24:05 +0000 (11:24 +0000)]
favor `getconf _NPROCESSORS_ONLN` over GNU nproc

getconf(1) itself is POSIX, while `_NPROCESSORS_ONLN' is not.
However, FreeBSD (tested 11.4 and 12.1) and glibc (tested CentOS
7.x and Debian 10.x) both support `getconf _NPROCESSORS_ONLN'.

GNU coreutils (and thus `nproc' or `gnproc') are not installed
by default on the *BSDs, so we'll try the option most likely
to exist on both glibc and *BSDs out-of-the-box.

3 years agodir_idle: require Perl 5.22+ for kqueue
Eric Wong [Sat, 8 Aug 2020 04:59:49 +0000 (04:59 +0000)]
dir_idle: require Perl 5.22+ for kqueue

IO::KQueue requires us to use fileno(DIRHANDLE) for setting up
kqueue watches.  This use of fileno() is only supported since
Perl 5.22, so BSD users on older Perl will have to fall back to
old polling.

This affects users of -watch, currently; but will affect other
read-only Xapian users soon.

3 years agosupport setting No_COW on Perl <5.22
Eric Wong [Sat, 8 Aug 2020 04:59:48 +0000 (04:59 +0000)]
support setting No_COW on Perl <5.22

fileno(DIRHANDLE) only works on Perl 5.22+, so we need to use
dirfd(3) ourselves from Inline::C (or rely on chattr(1) being
installed).

While we're at it, rename `set_nodatacow' to `nodatacow_fd'
for consistency with `nodatacow_dir'.

3 years agoindex: add built-in --help / -?
Eric Wong [Fri, 7 Aug 2020 10:52:18 +0000 (10:52 +0000)]
index: add built-in --help / -?

Eventually, commonly-used commands run by the user will all
support --help / -? for user-friendliness.   The changes from
up-front `use' to lazy `require' speed up `--help' by 3x or so.

3 years agosearchidx: use Perl truthiness to detect XAPIAN_FLUSH_THRESHOLD
Eric Wong [Fri, 7 Aug 2020 10:52:17 +0000 (10:52 +0000)]
searchidx: use Perl truthiness to detect XAPIAN_FLUSH_THRESHOLD

XAPIAN_FLUSH_THRESHOLD is a C string in the environment, so
users may be tempted to assign an empty string in in their
shell, e.g. `XAPIAN_FLUSH_THRESHOLD= <command>' instead of using
`unset' POSIX shell built-in.

With either a value of "0" or "" (empty string), Xapian will
fall back to its default (10000 documents), which causes grief
for memory-starved users.

3 years agoindex: max out XAPIAN_FLUSH_THRESHOLD if using --batch-size
Eric Wong [Fri, 7 Aug 2020 10:52:16 +0000 (10:52 +0000)]
index: max out XAPIAN_FLUSH_THRESHOLD if using --batch-size

If XAPIAN_FLUSH_THRESHOLD is unset, Xapian will default to
10000.  That limits the effectiveness of users specifying
extremely large values of --batch-size.

While we're at it, localize the changes to globals since -index
may be eval-ed in tests (and perhaps production code in the
future).

3 years agoindex: --compact respects --sequential-shard
Eric Wong [Fri, 7 Aug 2020 10:52:15 +0000 (10:52 +0000)]
index: --compact respects --sequential-shard

Since the --compact switch works on Xapian shards,
it makes sense that --sequential-shard affects our
usage of xapian-compact(1).

3 years agov2writable: fix batch size accounting
Eric Wong [Fri, 7 Aug 2020 10:52:14 +0000 (10:52 +0000)]
v2writable: fix batch size accounting

We need to account for whether shard parallelization is
enabled or not, since users of parallelization are expected
to have more RAM.

3 years agoindex+xcpdb: rename `--no-sync' to `--no-fsync'
Eric Wong [Fri, 7 Aug 2020 01:14:06 +0000 (01:14 +0000)]
index+xcpdb: rename `--no-sync' to `--no-fsync'

We'll continue supporting `--no-sync' even if its yet-to-make it
it into a release, but the term `sync' is overloaded in our
codebase which may be confusing to new hackers and users.

None of our our code nor dependencies issue the sync(2) syscall,
either, only fsync(2) and fdatasync(2).

3 years agoindex: support --xapian-only switch
Eric Wong [Fri, 7 Aug 2020 01:14:05 +0000 (01:14 +0000)]
index: support --xapian-only switch

This is useful for speeding up indexing runs when only Xapian
rules change but SQLite indexing doesn't change.  This mostly
implies `--reindex', but does NOT pick up new messages (because
SQLite indexing needs to occur for that).

I'm leaving this undocumented in the manpage for now since it's
mainly to speed up development and testing.  Users upgrading to
1.6.0 will be advised to `--reindex --rethread', anyways, due to
the threading improvements since 1.1.0-pre1.

It may make sense to document for 1.7+ when there's Xapian-only
indexing changes, though.

3 years agoindex: v2: --sequential-shard option
Eric Wong [Fri, 7 Aug 2020 01:14:04 +0000 (01:14 +0000)]
index: v2: --sequential-shard option

This gives better page cache utilization for Xapian indexing on
slow storage by improving locality for random I/O activity on
the Xapian DB.

Instead of doing a single-pass to index both SQLite and Xapian;
this indexes them separately.  The first pass is identical to
indexlevel=basic: it indexes both over.sqlite3 and msgmap.sqlite3.

Subsequent passes only operate on a single Xapian shard for
documents belonging to that shard.  Given enough shards, each
individual shard can be made small enough to fit into the kernel
page cache and avoid HDD seeks for read activity.

Doing rough tests with a busy system with a 7200 RPM HDD with ext4,
full indexing of LKML (9 epochs) goes from ~80 hours (-j0) to
~30 hours (-j8) with 16GB RAM with 7 shards configured and fsync(2)
disabled (--no-sync) and `--batch-size=10m'.

3 years agov2writable: fix rethread cleanup
Eric Wong [Fri, 7 Aug 2020 01:14:03 +0000 (01:14 +0000)]
v2writable: fix rethread cleanup

We need to drop old ghosts properly while inside the
transaction, otherwise it becomes a no-op.  This isn't a big
deal, as it only results in a few dangling DB rows and a
small amount of wasted space.

3 years agoxapcmd: drop outdated comment
Eric Wong [Fri, 7 Aug 2020 01:14:02 +0000 (01:14 +0000)]
xapcmd: drop outdated comment

We replaced Xtmpdir with File::Temp->newdir in
commit 2a3e3a0469f54f6a4f80bf04614e5ddd794a6c5e
("xapcmd: replace Xtmpdirs with File::Temp->newdir")
but forgot to remove the outdated comment.

3 years agoxapcmd: remove redundant searchidx require
Eric Wong [Fri, 7 Aug 2020 01:14:01 +0000 (01:14 +0000)]
xapcmd: remove redundant searchidx require

We already "use" it starting with commit
cd8dd7b08fddc7c2b5f218c3fcaa5dca5f9ad945
("search: support SWIG-generated Xapian.pm"),
so there's no need to require it redundantly.

3 years agoxapcmd: quietly no-op on indexlevel=basic
Eric Wong [Fri, 7 Aug 2020 01:14:00 +0000 (01:14 +0000)]
xapcmd: quietly no-op on indexlevel=basic

I find myself mindlessly adding "-c" to public-inbox-index,
and other users may do the same.  Instead of erroring out,
we'll just silently ignore it, for now and allow
public-inbox-compact to work on SQLite-only inboxes.

We'll only check for xapian-compact if search exists, since
it won't be needed in case we support SQLite VACUUM.

3 years agosyscall: support sparc64 (and maybe other big-endian systems)
Eric Wong [Fri, 7 Aug 2020 10:15:04 +0000 (10:15 +0000)]
syscall: support sparc64 (and maybe other big-endian systems)

Thanks to the GCC compile farm project, we can wire up syscalls
for sparc64 and set system-specific SFD_* constants properly.

I've FINALLY figured out how to use POSIX::SigSet to generate
a usable buffer for the syscall perlfunc.  This is required
for endian-neutral behavior and relevant to sparc64, at least.

There's no need for signalfd-related stuff to be constants,
either.  signalfd initialization is never a hot path and a stub
subroutine for constants uses several KB of memory in the
interpreter.

We'll drop the needless SEEK_CUR import while we're importing
O_NONBLOCK, too.

3 years agoimap: search support BODY key
Eric Wong [Thu, 6 Aug 2020 21:43:46 +0000 (21:43 +0000)]
imap: search support BODY key

This is specified in RFC 3501 but was accidentally omitted :x
I probably got it confused with TEXT, so add a comment about
TEXT being "everything" in the message.

3 years agowww: avoid warnings on YYYYMMDD-only t= query parameter
Eric Wong [Fri, 7 Aug 2020 10:42:52 +0000 (10:42 +0000)]
www: avoid warnings on YYYYMMDD-only t= query parameter

While we always generate YYYYMMDDhhmmss query parameters
ourselves, the regexps in paginate_recent allow YYYYMMDD-only
(no hhmmss) timestamps, so don't trigger Time::Local::timegm
warnings about empty numeric comparisons on empty strings when a
client starts making up their own URLs.

3 years agomsgmap: tmp_clone: use MEMORY journal upon reconnect
Eric Wong [Thu, 6 Aug 2020 10:37:10 +0000 (10:37 +0000)]
msgmap: tmp_clone: use MEMORY journal upon reconnect

Since reindexing releases the DB handle every indexBatchSize bytes,
we need to ensure we keep the journal in-memory when reopening
the DB since this is throwaway data.

3 years agot/epoll: adjust for u64_mod_8 case
Eric Wong [Thu, 6 Aug 2020 09:28:22 +0000 (02:28 -0700)]
t/epoll: adjust for u64_mod_8 case

epoll_wait_mod8 places a dummy element into the [2] slot of the
nested array, which caused is_deeply to fail.

Tested on aarch64.

3 years agowatch: quiet some warnings on spam mailboxes
Eric Wong [Sun, 2 Aug 2020 11:22:07 +0000 (11:22 +0000)]
watch: quiet some warnings on spam mailboxes

Email::Address::XS and PublicInbox::MsgTime both emit warnings
which are likely to trigger from spam messages.  Since this can
be configured to remove spam, just filter out those warnings to
avoid cluttering up stderr with useless information.

3 years agot/indexlevels-mirror-v1: localize ENV change
Eric Wong [Sun, 2 Aug 2020 07:55:23 +0000 (07:55 +0000)]
t/indexlevels-mirror-v1: localize ENV change

We don't want ENV changes propagated to other tests
when using t/run.perl via "make check-run"

3 years agot/nntpd: do not fork on indexing, test v2
Eric Wong [Sun, 2 Aug 2020 03:09:37 +0000 (03:09 +0000)]
t/nntpd: do not fork on indexing, test v2

No need to waste resources when doing minimal work.  With
PI_TEST_VERSION=2, this fixes a test failure where
Net::NNTP::DESTROY was getting called in the shard process.

We'll also get rid of an unnecessary use_ok under v2, too.

3 years agoremove unnecessary ->header_obj calls
Eric Wong [Sat, 1 Aug 2020 08:12:27 +0000 (08:12 +0000)]
remove unnecessary ->header_obj calls

We used ->header_obj in the past as an optimization with
Email::MIME.  That optimization is no longer necessary
with PublicInbox::Eml.

This doesn't make any functional difference even if we were to
go back to Email::MIME.  However, it reduces the amount of code
we have and slightly reduces allocations with PublicInbox::Eml.

3 years agosearchidx: remove v1-only msg_mime sub
Eric Wong [Sat, 1 Aug 2020 08:12:26 +0000 (08:12 +0000)]
searchidx: remove v1-only msg_mime sub

We can rely on the newer mids() sub directly and use faster
numeric comparisons for Msgmap unindexing in v1.

3 years agoinboxwritable: rename mime_from_path to eml_from_path
Eric Wong [Sat, 1 Aug 2020 08:12:25 +0000 (08:12 +0000)]
inboxwritable: rename mime_from_path to eml_from_path

This is more accurate given we use PublicInbox::Eml instead
of Email::MIME/PublicInbox::MIME, nowadays.

3 years agoinboxwritable: mime_from_path: reduce `$/' scope and returns
Eric Wong [Sat, 1 Aug 2020 08:12:24 +0000 (08:12 +0000)]
inboxwritable: mime_from_path: reduce `$/' scope and returns

We don't want `local $/' affecting Eml->new, and we can
use implicit returns which may be faster on older Perl.

3 years agonntp: fix STAT command
Eric Wong [Sat, 1 Aug 2020 20:16:58 +0000 (20:16 +0000)]
nntp: fix STAT command

The return value of art_lookup changed but this command wasn't
updated since it wasn't tested.

Fixes: 0e6ceff37fc38f28 ("nntp: support slow blob retrievals")
3 years agoimprove error handling on import fork / lock failures
Eric Wong [Fri, 31 Jul 2020 21:36:18 +0000 (21:36 +0000)]
improve error handling on import fork / lock failures

v?fork failures seems to be the cause of locks not getting
released in -watch.  Ensure lock release doesn't get skipped
in ->done for both v1 and v2 inboxes.  We also need to do
everything we can to ensure DB handles, pipes and processes
get released even in the face of failure.

While we're at it, make failures around `git update-server-info'
non-fatal, since smart HTTP seems more popular anyways.

v2 changes:
- spawn: show failing command
- ensure waitpid is synchronous for inotify events
- teardown all fast-import processes on exception,
  not just the failing one
- beef up lock_release error handling
- release lock on fast-import spawn failure

3 years agowww: rework async_* to use method table
Eric Wong [Thu, 30 Jul 2020 23:43:50 +0000 (23:43 +0000)]
www: rework async_* to use method table

Although the ->async_next method does not take $self as
a receiver, but rather a PublicInbox::HTTP object, we may
still retrieve it to be called with the HTTP object via
UNIVERSAL->can.

3 years agolock: show failure path
Eric Wong [Thu, 30 Jul 2020 08:05:33 +0000 (08:05 +0000)]
lock: show failure path

This ought to be useful for diagnosing bugs in -watch.

3 years agomsgmap: disable CoW for tmp_clone, too
Eric Wong [Wed, 29 Jul 2020 21:25:43 +0000 (21:25 +0000)]
msgmap: disable CoW for tmp_clone, too

The temporary clone starts as large as the full msgmap
and deletes will write to it randomly.  So ensure it
doesn't get fragmented and slower as time goes on.

3 years agowwwlisting: fix grep call for match=domain filtering
Kyle Meyer [Thu, 30 Jul 2020 05:30:55 +0000 (01:30 -0400)]
wwwlisting: fix grep call for match=domain filtering

The grep call in list_match_domain_i returns true for all inboxes,
even ones without a URL that matches the regular expression, because
the qr value passed to grep is not surrounded by slashes.  Add them.

Fixes: 1988d730c0088e8b (config: support multi-value inbox.*.*url)
3 years agoemergency: create full path to PI_EMERGENCY
Eric Wong [Wed, 29 Jul 2020 08:43:09 +0000 (08:43 +0000)]
emergency: create full path to PI_EMERGENCY

It's possible for ~/.public-inbox/ to not exist if PI_CONFIG
points to an alternate location.  Only noticed from the previous
patch fixing t/init.t behavior.

3 years agot/init: fix test when ~/.public-inbox/ does not exist
Eric Wong [Wed, 29 Jul 2020 08:43:08 +0000 (08:43 +0000)]
t/init: fix test when ~/.public-inbox/ does not exist

We'll just set the documented PI_EMERGENCY env to
a writable location.

3 years agot/imap_searchqp: fix test dependencies
Eric Wong [Wed, 29 Jul 2020 08:43:07 +0000 (08:43 +0000)]
t/imap_searchqp: fix test dependencies

The query parser test pulls in all of the IMAP stuff, so it
has the same dependencies.

3 years agoxapcmd: -xcpdb and -compact disable CoW, too
Eric Wong [Wed, 29 Jul 2020 11:20:00 +0000 (11:20 +0000)]
xapcmd: -xcpdb and -compact disable CoW, too

This gives an opportunity for users already suffering from CoW
fragmentation to at least get the Xapian DBs off CoW.  Aside
from over.sqlite3 in v1, the SQLite DBs remain untouched; though
VACUUM support may come in the future.

3 years agosearchidx: disable CoW for SQLite and Xapian under btrfs
Eric Wong [Tue, 28 Jul 2020 22:21:58 +0000 (22:21 +0000)]
searchidx: disable CoW for SQLite and Xapian under btrfs

SQLite and Xapian files are written randomly, thus they become
fragmented under btrfs with copy-on-write.  This leads to
noticeable performance problems (and probably ENOSPC) as these
files get big.

lore/git (v2, <1GB) indexes around 20% faster with this on an
ancient SSD.  lore/lkml seems to be taking forever and I'll
probably cancel it to save wear on my SSD.

Unfortunately, disabling CoW also means disabling checksumming
(and compression), so we'll be careful to only set the No_COW
attribute on regeneratable data.  We want to keep CoW (and
checksums+compression) on git storage because current ref
storage is neither checksummed nor compressed, and git streams
pack output.

3 years agov2writable: use {inboxdir} for msgmap->tmp_clone
Eric Wong [Tue, 28 Jul 2020 22:11:32 +0000 (22:11 +0000)]
v2writable: use {inboxdir} for msgmap->tmp_clone

Otherwise, a user is more likely to remove the msgmap-XXXXXXXX
SQLite file from $TMPDIR and cause SQLite to error out.

3 years agov2writable: support async git blob retrievals
Eric Wong [Sat, 25 Jul 2020 21:12:21 +0000 (21:12 +0000)]
v2writable: support async git blob retrievals

This seems to speed up --reindex on smallish v2 inboxes by about
30% on both HDD and SSD.  lore/git (~1GB) on an SSD even gives a
30% improvement with 3 shards.  I'm only seeing a ~4% speedup on
LKML with a SATA SSD (which is difficult to repeat because it
takes around 4 hours).

Testing LKML on an HDD will take much more time...

3 years agoexamples/grok-pull.post_update_hook: fix description URL
Eric Wong [Tue, 28 Jul 2020 10:31:14 +0000 (10:31 +0000)]
examples/grok-pull.post_update_hook: fix description URL

I finally noticed descriptions weren't showing up in my mirrors :x

3 years agoxt/imapd-mbsync-oimapd: fix noop due to case sensitivity
Eric Wong [Sun, 26 Jul 2020 06:57:31 +0000 (06:57 +0000)]
xt/imapd-mbsync-oimapd: fix noop due to case sensitivity

mbsync was not retrieving anything since it was looking for
"inbox" when we need to return "INBOX" as a special case
for IMAP.

Fixes: 8af34015e9aa94e5 (imap: LIST shows "INBOX" in all caps)
3 years agoimap: introduce and use Git->async_prefetch
Eric Wong [Sun, 26 Jul 2020 06:57:30 +0000 (06:57 +0000)]
imap: introduce and use Git->async_prefetch

We can keep the git process more active by sending another
request to it while fetch_run_ops() is running.  This
parallelization speeds up mutt's initial FETCH for headers by
around ~35%(!).

3 years agot/init.t: don't modify ~/.public-inbox/
Eric Wong [Sun, 26 Jul 2020 09:03:15 +0000 (09:03 +0000)]
t/init.t: don't modify ~/.public-inbox/

Tests for failures should not leave junk temporary files lying
around in a users' ~/.public-inbox/.

On a side note, I'm not sure if PI_DIR is or was ever
necessary.  It's never been documented, so perhaps
using $HOME for this is better...

3 years agoindex: --compact respects --jobs
Eric Wong [Sun, 26 Jul 2020 09:31:10 +0000 (09:31 +0000)]
index: --compact respects --jobs

And -compact supports --jobs=0 like -index to disable parallel
execution.  Running three xapian-compact processes in parallel
on a USB 2.0 HDD is pretty painful.

3 years agooveridx: fix compatibility with current versions
Eric Wong [Sun, 26 Jul 2020 19:43:06 +0000 (19:43 +0000)]
overidx: fix compatibility with current versions

We still need to use SQL_BLOB to ensure existing versions of
public-inbox can read over.sqlite3 because they're still using
{sqlite_unicode}.  This partially reverts commit
e9fc1290ead44e06d20ff58e0a6acb5306d4fbe2.

Fixes: e9fc1290ead44e06 ("over: unset sqlite_unicode attribute")
3 years agov2writable: {unindexed} belongs in $sync state
Eric Wong [Fri, 24 Jul 2020 05:56:06 +0000 (05:56 +0000)]
v2writable: {unindexed} belongs in $sync state

There's no reason for {unindexed} to persist beyond
an ->index_sync call.

3 years agosearchidx: $batch_cb => v1_checkpoint
Eric Wong [Fri, 24 Jul 2020 05:56:05 +0000 (05:56 +0000)]
searchidx: $batch_cb => v1_checkpoint

Another closure gone, and we may be able to share more
code with v2 in upcoming commits.

3 years agosearchidx: support async git check
Eric Wong [Fri, 24 Jul 2020 05:56:04 +0000 (05:56 +0000)]
searchidx: support async git check

This allows v1 indexing to run while the `cat-file --batch-check'
process is waiting on high-latency storage.

3 years agov2writable: share log2stack code with v1
Eric Wong [Fri, 24 Jul 2020 05:56:03 +0000 (05:56 +0000)]
v2writable: share log2stack code with v1

Another step in making v1 and v2 more similar.

3 years agoindex+xcpdb: support --no-sync flag
Eric Wong [Fri, 24 Jul 2020 05:56:02 +0000 (05:56 +0000)]
index+xcpdb: support --no-sync flag

This allows us to speed up indexing operations to SQLite
and Xapian.

Unfortunately, it doesn't affect operations using
`xapian-compact' and the compactor API, since that doesn't seem
to support Xapian::DB_NO_SYNC, yet.

3 years agosearchidx: make v1 indexing closer to v2
Eric Wong [Fri, 24 Jul 2020 05:56:01 +0000 (05:56 +0000)]
searchidx: make v1 indexing closer to v2

We'll switch to using IdxStack here to ensure we get repeatable
results and ascending THREADIDs according to git chronology.
This means we'll need a two-pass reindex to index existing
messages before indexing new messages.

Since we no longer have a long-lived git-log process, we don't
have to worry about old Xapian referencing the git-log pipe
w/o FD_CLOEXEC, either.

3 years agosearchidx: rename _xdb_{acquire,release} => idx_
Eric Wong [Fri, 24 Jul 2020 05:56:00 +0000 (05:56 +0000)]
searchidx: rename _xdb_{acquire,release} => idx_

The "xdb" prefix was inaccurate since it's used by
indexlevel=basic, which is Xapian-free.  The '_' (underscore)
prefix was also wrong for a method which is called across
package boundaries.

3 years agoxapcmd: set {from} properly for v1 inboxes
Eric Wong [Fri, 24 Jul 2020 05:55:59 +0000 (05:55 +0000)]
xapcmd: set {from} properly for v1 inboxes

This was a bug, but I'm not sure where it matters, yet, but it
may matter in the future.

3 years agov2writable: clarify "epoch" comment
Eric Wong [Fri, 24 Jul 2020 05:55:58 +0000 (05:55 +0000)]
v2writable: clarify "epoch" comment

3 years agov2writable: get rid of {reindex_pipe} field
Eric Wong [Fri, 24 Jul 2020 05:55:57 +0000 (05:55 +0000)]
v2writable: get rid of {reindex_pipe} field

Since normal per-epoch indexing no longer holds a "git log"
process open, we don't need to worry about not sharing the
pipe with forked shards when we restart the indexer.

While we're in the area, better describe what `unindex' does,
since it's a rarely-used but necessary code path.

3 years agov2writable: use read-only PublicInbox::Git for cat_file
Eric Wong [Fri, 24 Jul 2020 05:55:56 +0000 (05:55 +0000)]
v2writable: use read-only PublicInbox::Git for cat_file

We can reduce the number of parameters we pass around on stack
and make our read-write and read-only code paths more uniform.

3 years agosearch: avoid copying {inboxdir}
Eric Wong [Fri, 24 Jul 2020 05:55:55 +0000 (05:55 +0000)]
search: avoid copying {inboxdir}

Instead, storing {xdir} will allow us to avoid string
concatenation in the read-only path and save us a little
hash entry space.

3 years agouse consistent {ibx} field for writable code paths
Eric Wong [Fri, 24 Jul 2020 05:55:54 +0000 (05:55 +0000)]
use consistent {ibx} field for writable code paths

This is a step which makes our use of abbreviations more
consistent when referring to PublicInbox::Inbox objects.
We'll also be reducing the number of redundant fields
in SearchIdx and V2Writable code paths to make the
object graph easier-to-follow.

3 years agov2writable: drop "EPOCH.git indexing $RANGE" progress
Eric Wong [Fri, 24 Jul 2020 05:55:53 +0000 (05:55 +0000)]
v2writable: drop "EPOCH.git indexing $RANGE" progress

It'll be one continuous range with IdxStack.

3 years agov2writable: allow >= 40 byte git object IDs
Eric Wong [Fri, 24 Jul 2020 05:55:52 +0000 (05:55 +0000)]
v2writable: allow >= 40 byte git object IDs

Another step in slowly updating our code to support SHA-256 or
whatever other hash algorithms git may support in the future.

3 years agov2writable: move {autime} and {cotime} into $sync state
Eric Wong [Fri, 24 Jul 2020 05:55:51 +0000 (05:55 +0000)]
v2writable: move {autime} and {cotime} into $sync state

The V2Writable object may be long-lived, so it makes more
sense to put the {autime} and {cotime} fields into the
shorter-lived index_sync state.

3 years agov2writable: index_sync: reduce fill_alternates calls
Eric Wong [Fri, 24 Jul 2020 05:55:50 +0000 (05:55 +0000)]
v2writable: index_sync: reduce fill_alternates calls

Instead of doing fill_alternates for every epoch we're indexing,
just do it once at the start of index_sync invocation.  This
will set us up for using a single "git cat-file" process for
indexing multiple epochs.

3 years agov2writable: introduce idx_stack
Eric Wong [Fri, 24 Jul 2020 05:55:49 +0000 (05:55 +0000)]
v2writable: introduce idx_stack

This avoids pinning a potentially large chunk of memory from
`git-log --reverse' into RAM (or triggering less predictable
swap behavior).  Instead it uses a contiguous temporary file
with a fixed-size record for every blob we'll need to index.

3 years agov2: index forwards (via `git log --reverse')
Eric Wong [Fri, 24 Jul 2020 05:55:48 +0000 (05:55 +0000)]
v2: index forwards (via `git log --reverse')

Since we'll need to expose THREADID to JMAP and IMAP users,
index all messages in the order they were committed to ensure
our `tid' (thread ID) column ascends in mirrors the same way
they do in the source inbox.

This drastically simplifies our code but increases memory
usage of `git-log'.  The next commit will bring memory use
back down at the expense of $TMPDIR usage.

3 years agoindex: support --rethread switch to fix old indices
Eric Wong [Fri, 24 Jul 2020 05:55:47 +0000 (05:55 +0000)]
index: support --rethread switch to fix old indices

Older versions of public-inbox < 1.3.0 had subtly
different semantics around threading in some corner
cases.  This switch (when combined with --reindex)
allows us to fix them by regenerating associations.

3 years agomsgmap: fix atfork_* callbacks
Eric Wong [Sat, 18 Jul 2020 06:36:32 +0000 (06:36 +0000)]
msgmap: fix atfork_* callbacks

Noticed while reindexing a largish v2 inbox in parallel on an
SSD which required checkpointing and respawning shard workers.

Fixes: f06e84220e5566e7 ("over+msgmap: do not store filename after DBI->connect")
3 years agov2writable: git_hash_raw: avoid $TMPDIR write
Eric Wong [Fri, 17 Jul 2020 07:25:07 +0000 (07:25 +0000)]
v2writable: git_hash_raw: avoid $TMPDIR write

We can rely on FD_CLOEXEC being set by default (since Perl 5.6+)
on pipes to avoid FS/page-cache traffic, here.  We also know
"git hash-object" won't output anything until it's consumed all
of its standard input; so there's no danger of a deadlock even
in the the unlikely case git uses a hash that can't fit into
PIPE_BUF :P

3 years agosearch: simplify unindexing
Eric Wong [Fri, 17 Jul 2020 06:31:55 +0000 (06:31 +0000)]
search: simplify unindexing

Since over.sqlite3 seems here to stay, we no longer need to do
Message-ID lookups against Xapian and can simply rely on the
docid <=> NNTP article number equivalancy SCHEMA_VERSION=15
gave us.

This rids us of the closure-using batch_do sub in the v1
code path and vastly simplifies both v1 and v2 unindexing.

3 years agosearchidx: use v5.10.1, parent.pm, drop warnings
Eric Wong [Fri, 17 Jul 2020 06:31:54 +0000 (06:31 +0000)]
searchidx: use v5.10.1, parent.pm, drop warnings

Prefer "parent" to "base" since the former is lighter and part
of Perl 5.10+.  We'll also rely on warnings from "-w" globally
(or not) instead of via "use".

3 years agooveridx: favor non-OO sub dispatch for internal subs
Eric Wong [Fri, 17 Jul 2020 06:31:53 +0000 (06:31 +0000)]
overidx: favor non-OO sub dispatch for internal subs

OO method dispatch was 10-15% slower when I was implementing the
NNTP server.  It also serves as a helpful reminder to the reader
at the callsite as to whether a sub is likely in the same
package as the caller or not.

3 years agooveridx: each_by_mid: pass self and args to callbacks
Eric Wong [Fri, 17 Jul 2020 06:31:52 +0000 (06:31 +0000)]
overidx: each_by_mid: pass self and args to callbacks

This saves runtime allocations and reduces the likelyhood of
memory leaks either from cycles or buggy old Perl versions.

3 years agowith_umask: pass args to callback
Eric Wong [Fri, 17 Jul 2020 06:31:51 +0000 (06:31 +0000)]
with_umask: pass args to callback

While it makes the code flow slightly less well in some places,
it saves us runtime allocations and indentation.

3 years agoimport: use common capitalization for filtering headers
Eric Wong [Fri, 17 Jul 2020 06:31:50 +0000 (06:31 +0000)]
import: use common capitalization for filtering headers

In case this ends up in the same process as Mbox::msg_hdr,
it can reduce memory use by sharing the cache key in
PublicInbox::Eml::re_memo

3 years agodrop binmode usage
Eric Wong [Fri, 17 Jul 2020 06:31:49 +0000 (06:31 +0000)]
drop binmode usage

We only support Unix-like platforms where binmode (":raw") is
the default anyways, and v5.10 semantics means it won't do
unicode_strings (unlike v5.12).  So save some lines of code.

3 years agov2: use v5.10.1, parent.pm, drop warnings
Eric Wong [Fri, 17 Jul 2020 06:31:48 +0000 (06:31 +0000)]
v2: use v5.10.1, parent.pm, drop warnings

The "5.010_001" form was for Perl 5.6, which I doubt anybody
would attempt; so favor "v5.10.1" as it is more readable to
humans.  Prefer "parent" to "base" since the former is lighter.
We'll also rely on warnings from "-w" globally (or not) instead
of via "use".

We'll also update "use" statements to reflect what's actually
used by V2Writable.

3 years agot/import: quiet warning, clobber variable
Eric Wong [Thu, 16 Jul 2020 21:54:24 +0000 (21:54 +0000)]
t/import: quiet warning, clobber variable

The eval in key2sub via t/run.perl ("make check-run") won't
trigger the warning, but running "prove -bvw t/import.t"
directly, does.  In any case, ensure the contents of this
variable doesn't linger across runs.

3 years agodoc: add some recommendations around slow HDDs
Eric Wong [Fri, 17 Jul 2020 03:57:24 +0000 (03:57 +0000)]
doc: add some recommendations around slow HDDs

grok-pull is still painful with serialization on an old USB 2.0
HDD, but at least it can finish with flock(1) and disabling
parallelization.  While parallel "git fetch" doesn't seem so
bad, slow seeks are exacerbated by parallel reads in Xapian.
That means some updates can take days instead of hours.  The
same updates take only seconds or minutes on an SSD.