Progress reporting: a debug trace and a test framework

Started by Manuabout 2 months ago3 messageshackers
Jump to latest
#1Manu
manuelreyesbravo@gmail.com

The two patches attached add a debug trace and a test framework for
progress reporting. They were first posted in [1]/messages/by-id/179018818545.3031865.5809261654654798774@gmail.com; they get their own
thread now, as Michael suggested.

0001 adds PROGRESS_DEBUG. With it defined, every change to a backend's
progress state is logged at LOG_SERVER_ONLY, so a test can read back the
exact sequence of reports a command makes, without needing concurrency or
injection points. It is compiled out by default: with it undefined the
object code of backend_progress.c is unchanged (the same instruction
stream, only the line numbers baked into existing elog calls shift), and
the test below skips, so "make check" and "meson test" are not any slower.

0002 adds the test module test_progress. It replays each backend's trace
and checks the rules that hold for every command -- values continue from
the last one logged, counters do not decrease or only go back to 0, done
counters stay within their totals, phases take defined values, and a
command writes only its own parameters -- and then the exact succession of
phases for each command. It also checks every parameter of
commands/progress.h against a description, on any build, so a new or
renumbered parameter has to be described before the test passes.

These checks have already been useful: the trace is what found the three
blips fixed in 3be29d9346d, and the description check flagged, while
rebasing, that 1378aa13430 had added PROGRESS_VACUUM_CURRENT_INDEX_RELID
without describing it.

Run on master, the framework also flags two harmless blips that no view
exposes: when one command builds or vacuums several indexes in a row
(REPACK, VACUUM FULL, VACUUM in several cycles), the index-build tuple
counter and the dead-item counters step straight to the next round's
value instead of first going back to 0. The test sets these aside as
known-accepted (listed in @ACCEPTED, the dead-item one under a TODO) so
the suite is green; they are harmless and I have left the behavior as it
is. Resetting the counters in every build and cycle removes them and
makes the dead-item counters match their documented "collected since the
last cycle" meaning; I can post that as a small optional follow-up if it
is wanted.

[1]: /messages/by-id/179018818545.3031865.5809261654654798774@gmail.com

Attachments:

t254082_1
v5-0001-Add-PROGRESS_DEBUG-to-test-the-whole-sequence-of-.patchtext/x-patchDownload+1511-1
v5-0002-Check-the-documented-progress-phases-against-the-.patchtext/x-patchDownload+370-15
#2Manu
manuelreyesbravo@gmail.com
In reply to: Manu (#1)
Re: Progress reporting: a debug trace and a test framework

Hi,

Using v5 I found two problems with it: with PROGRESS_DEBUG compiled
in, a check-world wrote 1.8 GB of server logs (master: 70 MB), and,
reverting each progress fix committed this year, it caught only four
of the ten. v6, attached and rebased on master, fixes both: 135 MB,
the extra 65 MB being test_progress's own trace, and nine of the ten.

Changes since v5: a trace_progress developer option; a check that a
command has ended when its process goes idle; each parameter checked
by value or listed with the reason; commands failing part of the way;
and the whole succession of each counter and phase checked, in more
scenarios: parallel builds, CREATE INDEX CONCURRENTLY waiting for
writers and snapshots, REPACK (CONCURRENTLY) applying changes, VACUUM
in failsafe mode, autovacuum.

The trace is written only where it is read: trace_progress turns it
on, as trace_syncscan does for TRACE_SYNCSCAN, and test_progress sets
it for its nodes. Álvaro, you thought a compile option was enough; it
still is what puts the code in, and trace_progress only keeps the
trace out of every other test's log. Without PROGRESS_DEBUG the
object code has the same instructions as master's, and meson test
takes as long: 84.9 s against 84.2 s, median of five paired rounds, a
difference within the noise. With the option it takes 7 s more,
test_progress's scenarios (10 s alone).

The checks new since v5 catch 99ea4a55270, 4dd037286e0, cedd2cec7d5,
422e54e3092 and 55f0a13e96b. I wrote them knowing those fixes, so
they show the fixes would hold, not that they would have been found.
To see what it finds beyond those, I mutated every progress call of
the backend blindly: 572 mutants. Of a sample of 150 fixed
beforehand, today's tests catch 10. test_progress now catches 548 of
the 572, but the new checks were written against them; the number
that counts is a reserve of 301 more mutants, of other kinds, sealed
before and not looked at until the end: it catches 285 (94.7%). Of
the 16 left, 4 are gaps a check could close; they and the rest are
listed with the reason in nocfbot-mutation-benchmark.txt, and the
numbers are in measurements.txt.

The sweep of check-world with the trace on also found one that is
still on master: WaitForOlderSnapshots() leaves the PROGRESS_WAITFOR_*
values set when it returns, which WaitForLockersMultiple() resets, so
REINDEX CONCURRENTLY's wait for readers shows lockers_done 2 with
lockers_total 1 (repro-waitfor.sh.txt, on any build). It also flags
ANALYZE of a file_fdw table, whose COPY report takes over ANALYZE's;
Antonin's sub-command patch (CF 6958) is about that.

One detail the benchmark showed: PROGRESS_DATACHECKSUMS_PHASE_ENABLING
is 0, the value every parameter starts with, so neither the trace nor
the view can tell when that phase is set.

Regards,
Manu

Attachments:

t254082_2
v6-0001-Add-PROGRESS_DEBUG-to-test-the-whole-sequence-of-.patchtext/x-patchDownload+3270-1
v6-0002-Check-the-documented-progress-phases-against-the-.patchtext/x-patchDownload+295-2
measurements.txttext/plainDownload
nocfbot-mutation-benchmark.txttext/plainDownload
repro-waitfor.sh.txttext/plainDownload
#3Manu
manuelreyesbravo@gmail.com
In reply to: Manu (#2)
Re: Progress reporting: a debug trace and a test framework

Hi,

v7, attached, is rebased on master, where the previous version no
longer passes: 51ae21aa313 added two setup phases to REPACK
(CONCURRENTLY), and with PROGRESS_DEBUG, 001 failed on both REPACK
(CONCURRENTLY) phase subtests. That is the kind of change the test
is there to catch.

001 now expects the two phases. The first, "enabling logical
decoding", is optional: it has nothing to do when effective_wal_level
is already logical, and the backend may wake up after it is over. In
20 runs of 001 with the CPUs kept busy, 8 of the 40 REPACK
(CONCURRENTLY) runs reported it and 32 did not, and all 20 runs
passed. Nothing else changed.

check-world passes without PROGRESS_DEBUG, with it, and with it plus
trace_progress on in every test server.

Regards,
Manu

Attachments:

t254082_3
v7-0001-Add-PROGRESS_DEBUG-to-test-the-whole-sequence-of-.patchtext/x-patchDownload+3283-1
v7-0002-Check-the-documented-progress-phases-against-the-.patchtext/x-patchDownload+295-2