Skip to content

test: tracing captures and WAL flush counts that hold up under load - #2149

Merged
aaj3f merged 9 commits into
mainfrom
test/span-capture-reliable
Oct 26, 2026
Merged

aaj3f merged 9 commits into
mainfrom
test/span-capture-reliable

Conversation

@aaj3f

@aaj3f aaj3f commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Tests that capture tracing events through a thread-local default subscriber (the fast-path routing stamps MustFire / MustNotFire, the overlay_translate spans, the batched-join lane event, and a few in-crate captures) could intermittently see nothing under parallel load. A presence assertion then failed, which is the flake we've been re-running past (jsonld_join_takes_batched_subject_probe_like_sparql, empty_cross_ledger_restrictions_under_default_allow_keep_fast_paths and others). The quieter half is an absence assertion (MustNotFire) that passed vacuously the same way.

The cause is in tracing-core's callsite interest cache. While only one dispatcher is registered, which a single thread-local capture often is, a callsite's first hit computes its interest from the hitting thread's default alone. When a sibling test's thread with no subscriber hits it first, the callsite is cached as never interesting, and the capturing thread's subscriber never sees that event.

The fix is fluree_test_support::scoped_default (and with_scoped_default). Once per process, it registers two dispatchers that are nobody's default, answer every callsite with Interest::sometimes() and enable nothing. With two always registered, the single-dispatcher shortcut never applies, and no callsite can be cached as never, so each event reaches whichever subscriber is the current thread's default. Two, not one, so that the gap between one test's capture and the next can't fall back to the shortcut. The floor dispatchers receive no events.

  • span_capture::init_test_tracing / init_info_only_tracing go through it, which covers the routing stamps in about fifty api test files. The in-crate captures (fluree-db-api's lib.rs, import.rs and bm25_worker.rs, fluree-graph-turtle's splitter, fluree-db-binary-index's dict reader, fluree-db-indexer's GC collector events) and the server's telemetry captures do too. init_test_tracing's narrower fix from 32336d21c (a second NoSubscriber dispatcher plus a rebuild) folds into the helper rather than living beside it.
  • Three tests that had hand-rolled a rebuild_interest_cache() workaround drop it. A rebuild only repairs callsites already registered, so it never fully closed the gap.
  • harness_coverage::scoped_subscribers_use_the_floor fails, naming file:line, on a direct subscriber::set_default( / with_default(, or a builder's .set_default(), in a workspace member's src/ or tests/. It's a narrow scan (a used bare name isn't caught), and its doc says so.
  • docs/contributing/tests.md: the "instrumentation tests keep their own binary" rule becomes "install through the helper".

Global installs (the CLI, MCP serve, server telemetry, a few try_init probe layers in tests, benches) are left as they are; a global default doesn't have this race.

Proof.

  • a_callsite_registered_first_on_another_thread_reaches_the_capture reproduces the mechanism deterministically: another thread with no subscriber hits a fresh callsite first, then the capturing thread hits it. With the floor removed (a bare set_default) it fails left: 0, right: 1; with it, it passes.
  • Under the same load, before and after: grp_query went from 7 failing runs in 60 to 0 in 60, and the policy cross-ledger repro from 18 in 120 to 0 in 120, with no measurable time cost.
  • The guard fails naming span_capture.rs when that file is changed back to tracing::subscriber::set_default.

WAL flush counts

it_wal::a_transaction_costs_one_flush failed the same way under load, counting 15 flushes (and in other runs 2) where it expects 1. fsyncs_issued() counts every flush of the root's log, and the log's background thread flushes on its own schedule: it flushes an append left waiting for 50 ms, and it closes a segment once it's a second old and retires it, flushing every file the segment covered. None of those is the transaction's, but whenever a loaded run's window met one, the test counted it. Nextest's process per test doesn't help here, since it's timing inside one test.

The fix is a test hook, FileStorage::pause_wal_background_for_test, which stops the background thread and waits out a pass already under way, so the count is the transaction's own. Every test that counts a window of flushes on a live log uses it now: the two in it_wal, and two in fluree-db-core's wal_tests (a_commit_costs_one_flush, owners_keep_separate_logs_and_flush_every_write) that had the same exposure. With a 1.2 s delay injected into the window, the three that expect exactly one flush failed before (15, 14 and 9) and pass with the hook; concurrent_ledgers_share_a_flush asserts fewer flushes than commits, which the thread's flushes could only push the wrong way. Under load, 36 runs of the it_wal binary, 12 at a time, went from 14 failures to 0.

The hook only exists for tests. It compiles in fluree-db-core's own tests and under a new, non-default test-hooks feature, which fluree-db-api turns on from its dev-dependencies (the way it already turns on residency). A normal build of the API or the server resolves fluree-db-core without it, so the background thread there is the same code as on main.

No production behavior change.

aaj3f added 3 commits October 20, 2026 06:20
A test that asserts on tracing output installs its subscriber as its own
thread's default. Each callsite's interest is cached process-wide, and
tracing-core computes a new callsite's interest from the registering
thread's default alone while at most one dispatcher is registered, which
a test capture often is. So a sibling test whose thread had no subscriber
could hit a callsite first and cache it as never interesting, and the
capture missed it: captures came back empty intermittently, failing
presence assertions and passing absence ones vacuously.

fluree_test_support::scoped_default and with_scoped_default first
register, once per process, two dispatchers that are never a default and
answer every callsite with sometimes. With two alive the one-dispatcher
path is never taken and no combined interest is never, so each event
reaches the capture's own enabled check. span_capture's init functions,
the in-crate unit tests and the server's capture tests install through
them, and three tests drop the cache rebuilds they had added as a partial
workaround.

harness_coverage gains scoped_subscribers_use_the_floor, which fails on
a direct set_default or with_default anywhere in the workspace's src and
tests. A test in fluree-test-support pins the mechanism: a callsite first
hit on another thread reaches the capture.
The rule that tests asserting on instrumentation keep their own binary
existed because a thread-local capture was unreliable next to parallel
siblings. Captures installed through fluree_test_support::scoped_default
are reliable there, so the rule now says to install through it, which
harness_coverage checks. The standalone tests' headers say why they have
a binary of their own and that they no longer need one; the one hazard a
thread-local capture keeps, events emitted on other threads, stays noted.
@aaj3f
aaj3f requested a review from bplatz October 20, 2026 21:18
aaj3f added 3 commits October 20, 2026 17:22
fsyncs_issued counts every flush of the root's log, the background
thread's included: it flushes an append left waiting, and closes a
segment a second old and retires it, flushing every file the segment
covered. A test that counts one commit's flushes therefore counted the
thread's too whenever the commit ran late enough to meet one, which a
loaded machine makes likely (a_transaction_costs_one_flush saw 15 for 1).
The tests that count a window of flushes on a live log now pause the
thread for it, with a test hook that waits out a pass already under way.
Two are in fluree-db-core's own suite, two in it_wal.
pause_wal_background_for_test, and the state behind it, compile only in
fluree-db-core's own tests and under a new test-hooks feature, which
fluree-db-api enables from its dev-dependencies. A production build has
the background thread exactly as before.
@aaj3f aaj3f changed the title test: a thread-local tracing capture sees every event it should test: tracing captures and WAL flush counts that hold up under load Oct 21, 2026
@aaj3f

aaj3f commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

Folded in one more of the same class: it_wal::a_transaction_costs_one_flush (and three sibling flush-count tests) counted the WAL background thread's own flushes when a loaded run's window caught one. c0b2e80e9 adds a test-only FileStorage::pause_wal_background_for_test behind a new non-default test-hooks feature, which fluree-db-api turns on from its dev-dependencies only, so a normal build of the API or server compiles fluree-db-core without it. The description has a new "WAL flush counts" section, and the title now covers both.

@bplatz bplatz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving. The interest-floor reasoning matches how tracing-core works, the WAL pause covers the background thread's only entry point, and test-hooks stays out of production builds under resolver 2.

One nit inline. Also, the branch is 64 commits behind main. It merges cleanly and main has no new direct installs, so the guard stays green, but an update from main would get CI on the current base. @aaj3f please go through the feedback before merging.

"subscriber::set_default(",
"subscriber::with_default(",
"dispatcher::set_default(",
"dispatcher::with_default(",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: the method form from tracing-subscriber (fmt().with_test_writer().set_default(), via SubscriberInitExt) slips past this. Nothing uses it today, but it's the likeliest way a new test bypasses the floor. Add .set_default() here, or list it in the doc's blind spots.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, that's the likeliest way in. The scan now looks for .set_default() too (61eb42f8d), and the doc names the method form. the_floor_guard_names_each_direct_install builds a throwaway workspace with a function-form install in src/, a fmt().with_test_writer().set_default() in src/, a dispatcher::with_default in tests/ and a commented-out call. It checks that all three are named by file:line and the comment isn't. the_floor_guard_passes_installs_through_the_helper checks that a scoped_default install passes. Take .set_default() back out of the list and the first fails on m/src/lib.rs:2. Nothing in the workspace uses the method form today, so the guard stays green.

aaj3f added 3 commits October 26, 2026 13:10
…iable

# Conflicts:
#	fluree-db-api/tests/support/span_capture.rs
Main added a thread-local capture of the collector's info events, installed
with subscriber::set_default; it now goes through scoped_default like every
other capture, so the floor guard stays green.
fmt().with_test_writer().set_default(), through SubscriberInitExt, installs
a thread-local default as subscriber::set_default does, and the guard did
not look for it. It does now, and two tests pin what it names: every direct
form, in src/ and tests/, by file:line, and not a commented-out call.
@aaj3f

aaj3f commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for going through this so carefully. I merged main (2582ad837), and two things came along with it that are worth a word.

Your 32336d21c had landed a narrower fix for the same race in init_test_tracing (a NoSubscriber second dispatcher plus a rebuild). The floor here covers that and every other capture, so I folded it into scoped_default instead of keeping two mechanisms side by side. init_test_tracing and init_info_only_tracing both go through the helper, and the it_sparql_lists change from that commit stays as it was.

Main had also picked up one new direct install since your review: c39369d66 added a thread-local capture of the GC collector's info events in fluree-db-indexer with subscriber::set_default, and the guard flagged it. It goes through scoped_default now (489c9e6af, with fluree-test-support as a dev-dependency of the indexer). Put the direct install back and harness_coverage fails, naming collector.rs.

@aaj3f
aaj3f merged commit 42bb964 into main Oct 26, 2026
19 checks passed
@aaj3f
aaj3f deleted the test/span-capture-reliable branch October 26, 2026 20:42
bplatz added a commit that referenced this pull request Oct 31, 2026
Brings #2217 (SPARQL reads list members as values; CONSTRUCT writes lists),
#2218 (schema writes judged by modify policy), #2208, #2169, #2168, #2153,
#2149 and #2148 into next.

Resolutions:
- Nameservice: branch_records is the one branch listing (strict, retracted
  branches kept for GC) on every backend, resolved through next's bindings;
  Fluree::list_branches filters retracted ones. The lifecycle conformance
  suite reads live branches through a helper. DynamoDB's narrow listing is
  wired into its trait impl.
- JSON-LD adapter: main's graph scoping (Walk, Scope, node_graph, selectors)
  with next's triple terms, @annotation, @reifies, blank-label and number
  datatype handling. to_graph_events writes a JSON-LD named graph under its
  @id and refuses a graph selector. main's f:reifiesGraph anchor is dropped:
  next writes an annotation as an rdf:reifies link in its graph.
  emit_quad_list_item takes (graph, index).
- Bulk import: an annotation's link is written to the graph its slots name,
  and a triple-term statement in a named graph is spooled under that graph
  (both landed in the default graph); emit_quad_reified_triple is
  implemented. resolve_object_value keeps main's vector refusals and next's
  term-table path.
- Ledger manager: a store that fails to load fails the load or keeps the
  reloaded ledger's state (main), over next's load_decoding_root and
  activation swap rule.
- Novelty keeps main's KeptEffects without the retired arena's reifies
  capture. The pool's resolve_events_at and compaction's split_lifecycles
  follow fluree_db_core::same_t.
- Retired annotation arena files stay deleted.
- Tests from main adapted to next: one Fluree per storage directory, async
  genesis_ledger, storage-namespace content stores, u32 graph ids, a store
  broken by hiding a dictionary branch (next has no disk cache), a refused
  import leaving no ledger. next's tests that pinned bulk import refusing
  @graph and SPARQL's RDF list view now check what main changed them to.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants