Skip to content

fix(TC-2917): DuckDB cache cleanup without blocking other databases - #601

Draft
samgbafa wants to merge 2 commits into
skgbafa/tc-2917-part-lifecyclefrom
skgbafa/tc-2917-duckdb-fs-cleanup
Draft

samgbafa wants to merge 2 commits into
skgbafa/tc-2917-part-lifecyclefrom
skgbafa/tc-2917-duckdb-fs-cleanup

Conversation

@samgbafa

@samgbafa samgbafa commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #597 for TC-2917. Chunked artifact storage stays disabled by default.

DuckDB cache files are cleaned up without holding up other databases, and failures leave nothing behind:

  • When an actor closes or is idle-evicted, its main file, WAL and spill directory are renamed aside while its registration is still held, and deleted after the registration is released. Lookups of other databases no longer wait on file deletion. The cache paths are free before the registration disappears, so a replacement never hydrates onto files being deleted. If the process stops in between, the next hydration of that database removes the renamed files.
  • A spill directory left behind by a stopped process no longer blocks hydration or cache discard.
  • An import that fails at any step before its file is in place removes its staged file. An import that fails after that, including while saving, discards the imported file.
  • Shutting down an actor that has already exited (idle eviction at the same moment) counts as done rather than an internal error.

Validation:

  • The full DuckDB-enabled core suite passes, 1179/1179, on local throwaway PostgreSQL 18.6. Clippy with warnings denied passes for core and server (DuckDB features).
  • Lookups of other databases while an evicted actor's files are deleted, with the Persist DuckDB files through bounded artifact parts #591 review fixture (512 other keys, a leftover spill directory of 40,000 files plus 512 MiB): the worst single lookup took 0.73 ms, against 1.4-1.7 s in that review. The main file and the spill directory were gone when the registration vanished.
  • Mutations, each applied to a copy of this head with the DuckDB module tests run: registration protection for a replacement removed (MB), database-name validation removed (MD), refused import not discarded (ME), failed staging file kept (ME2), spill directory removed as a file, and shutdown of an exited actor returning an error are each caught by the new tests.
  • The cleanup order is carried by the types (review C2): renaming the files aside needs the held registration entry, releasing the registration consumes that entry, and only the released form can be deleted (it can only be built by the release step). Renaming after the release (MA) and deleting while the entry is held (MF2) no longer compile; both were checked against a copy of this head.

Remaining before enabling: DuckDB disk bounds (headroom and spill limit; follow-up stacked on this PR), existing-database conversion, and ceiling-load acceptance. This PR does not enable the feature.

Test-ruling: TC-2917. No existing test is edited. New tests, adopted from the #591 security review's probes:

  • traversal-shaped database names refused before any file or artifact access;
  • a substituted checkpoint part refused before open, with nothing left in the cache;
  • refused and invalid imports leaving no files;
  • an import that cannot be finalized leaving no staging file;
  • leftover spill directories not blocking hydration or discard;
  • a predecessor sparing its replacement's files;
  • cache paths freed before deregistration on idle eviction;
  • shutdown of an exited actor.

samgbafa pushed a commit that referenced this pull request Nov 13, 2026
Renaming aside needs the held registration, releasing it consumes the
entry, and only the released form can be deleted: reordering either
step no longer compiles (#601 review C2).
Evicted actors rename their cache files aside under the registration
and delete them after releasing it; leftover spill directories no longer
block hydration or discard; failed imports leave no staged or imported
file; shutting down an exited actor succeeds.
Renaming aside needs the held registration, releasing it consumes the
entry, and only the released form can be deleted: reordering either
step no longer compiles (#601 review C2).
@samgbafa
samgbafa force-pushed the skgbafa/tc-2917-part-lifecycle branch from 00d516f to c441b37 Compare November 14, 2026 01:41
@samgbafa
samgbafa force-pushed the skgbafa/tc-2917-duckdb-fs-cleanup branch from 80729de to 327b09c Compare November 14, 2026 01:41

This branch has not been deployed

No deployments
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.

1 participant