Skip to content

experimental/air: warm snapshot cache for the plain_tar path - #6572

Open
ben-hansen-db wants to merge 4 commits into
air-plain-tar-pgzipfrom
air-warm-snapshot-cache-v2
Open

experimental/air: warm snapshot cache for the plain_tar path#6572
ben-hansen-db wants to merge 4 commits into
air-plain-tar-pgzipfrom
air-warm-snapshot-cache-v2

Conversation

@ben-hansen-db

@ben-hansen-db ben-hansen-db commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Stacked on #6571 (parallel gzip). Adds a local warm cache for the air run plain_tar snapshot path (dirty working tree / no git ref), so a repeated submission re-reads and re-tars only the files that changed.

  • Keyed by (repo path, config path, include_paths)$TMPDIR/databricks/.air/<sha256>/, holding a warm tar + a manifest.json of each file's size, mtime, and byte-range in the tar.
  • On the next run: stat the current file set; unchanged members are copied verbatim from the warm tar (no disk re-read), only changed/new files are re-read, deletions drop out. Change detection is size+mtime — the same fingerprint DABs file-sync uses.
  • --no-cache bypasses it and re-packs from scratch (also parallel-gzip, from the parent PR).
  • Engages only above 64 MiB (below that a plain re-pack is cheap). Compresses at DefaultCompression, matching the parent PR.

When does the cache actually help?

Honestly: parallel gzip (#6571) is the dominant win in the common warm-page-cache case. The cache's own contribution shows up in two situations:

  • Cold page cache (first run after checkout/reboot, CI, or working set > RAM): scattered small-file reads were 6,464 ms for research (84 MB) vs 14 ms to read the warm tar sequentially — parallel gzip can't touch that.
  • Large monorepos (whole universe, ~4 GB / 534k files) that can't stay in page cache: a warm hit packaged in ~6.6 s vs ~20 s cold.

Pack-phase decomposition at the shipped level (research+js+spark, 476 MB, warm page cache; enumerate ~634 ms is common to every path):

pack phase time
no cache, serial gz6 (old) 7,940 ms
no cache, parallel gz6 (#6571) 752 ms
cache hit, parallel gz6 413 ms

Parallel gzip removes ~90% of the pack cost by itself; the warm-tar reuse trims a further ~340 ms warm, and far more when the page cache is cold.

Correctness (addressed after Isaac Review)

Two MAJOR review findings are fixed in this PR:

  • Concurrent same-key rebuilds no longer race a shared snapshot.tar.tmp + non-atomic manifest write.
  • A crash mid-rebuild can no longer leave a manifest whose byte offsets describe a different tar layout (which would have silently corrupted a later verbatim-reuse rebuild).

Each build writes a uniquely named snapshot.<id>.tar that is never overwritten, and installs the manifest atomically (unique temp + rename) only after its tar is durable. So a manifest and the tar it indexes are always a consistent pair — concurrent rebuilds are last-writer-wins on the manifest rather than interleaving, and no lock is needed. Superseded/orphaned tars are cleaned up best-effort. Covered by a rotation test.

Known follow-ups (not in this PR)

  • No eviction of stale cache directories across keys — each distinct repo/config/include-set leaves a dir under $TMPDIR (within a key, superseded tars are already cleaned up).
  • The list phase (git ls-files + lstat of all index entries) is the next bottleneck for large trees.
  • plain_tar upload isn't content-addressed, so an unchanged tree still re-uploads.

This pull request and its description were written by Isaac.

@eng-dev-ecosystem-bot

eng-dev-ecosystem-bot commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator

Integration test report

Commit: ed64774

Run: 34372303743

Env 🔄​flaky 💚​RECOVERED ✅​pass 🙈​skip Time
💚​ aws linux 1 275 16 11:53
💚​ aws windows 1 277 14 9:09
💚​ azure linux 1 274 16 13:56
🔄​ azure windows 2 1 274 14 12:35
💚​ gcp linux 1 275 16 11:29
💚​ gcp windows 1 277 14 9:35
Test Name aws linux aws windows azure linux azure windows gcp linux gcp windows
💚​ TestAccept 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R
🔄​ TestFsCpFileToDirFileNotOverwritten ✅​p ✅​p ✅​p 🔄​f ✅​p ✅​p
🔄​ TestFsCpFileToDirFileNotOverwritten/uc-volumes_to_uc-volumes ✅​p ✅​p ✅​p 🔄​f ✅​p ✅​p
Top 22 slowest tests (at least 2 minutes):
duration env testname
7:38 aws windows TestAccept
7:23 azure windows TestAccept
6:53 gcp windows TestAccept
4:06 azure linux TestAccept
4:04 gcp windows TestFilerWorkspaceFilesExtensionsRead
3:58 aws linux TestAccept
3:55 gcp linux TestAccept
3:21 azure windows TestFilerWorkspaceFilesExtensionsReadDir
3:17 gcp windows TestExportDir
3:11 gcp windows TestSyncIncrementalFileSync
3:06 azure linux TestFilerWorkspaceFilesExtensionsReadDir
3:02 azure windows TestFilerRecursiveDelete/workspace_files_extensions
3:00 azure windows TestFilerRecursiveDelete/workspace_files
2:48 aws windows TestFilerWorkspaceFilesExtensionsRead
2:38 gcp linux TestFilerRecursiveDelete/workspace_files
2:24 gcp linux TestFilerWorkspaceFilesExtensionsDelete
2:23 aws linux TestFilerRecursiveDelete/workspace_files
2:20 azure linux TestFilerRecursiveDelete/workspace_files
2:14 azure linux TestSyncIncrementalFileSync
2:10 azure linux TestFilerRecursiveDelete/workspace_files_extensions
2:10 azure windows TestFilerReadWrite/workspace_files_extensions
2:02 aws linux TestFilerReadWrite/workspace_files_extensions

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Approval status: pending

/acceptance/experimental/air/ - needs approval

Files: acceptance/experimental/air/config-help/output.txt
Suggested: @riddhibhagwat-db
Also eligible: @vinchenzo-db, @apeforest, @bfontain, @lu-wang-dl, @panchalhp-db, @maggiewang-db, @pardis-beikzadeh-db

/experimental/air/ - needs approval

7 files changed
Suggested: @riddhibhagwat-db
Also eligible: @vinchenzo-db, @apeforest, @bfontain, @lu-wang-dl, @panchalhp-db, @maggiewang-db, @pardis-beikzadeh-db

Any maintainer (@andrewnester, @anton-107, @denik, @pietern, @shreyas-goenka, @simonfaltum, @renaudhartert-db, @janniklasrose, @lennartkats-db, @rugpanov, @rclarey) can approve all areas.
See OWNERS for ownership rules.

ben-hansen-db and others added 4 commits September 8, 2026 23:08
Stacked on the parallel-gzip change. Add a local warm cache for the plain_tar
snapshot path, keyed by (repo, config, include_paths) under
$TMPDIR/databricks/.air/<key>: an uncompressed snapshot.tar plus a manifest of
each file's size+mtime and byte range. Later runs stat the file set, copy
unchanged members verbatim from the warm tar, and re-read only changed files
before gzipping the upload. --no-cache bypasses it and re-packs from scratch
(now also parallel-gzip, from the parent PR). The cache engages only above 64 MiB.

The cache's payoff is largest when the working set does not fit the OS page
cache: cold, scattered small-file reads cost seconds (6.5 s for research, 84 MB)
versus ~ms to read the warm tar sequentially. When the tree is already warm in
RAM, parallel gzip accounts for most of the gain and the cache adds little.

Co-authored-by: Isaac <no-reply@databricks.com>
Match the parent PR: DefaultCompression rather than BestSpeed in newGzFile, so
the cached tarball is re-gzipped at the same level as the --no-cache path and the
upload stays small. Parallel compression makes the higher level nearly free.

Co-authored-by: Isaac <no-reply@databricks.com>
The new --no-cache flag on `air run` adds a line to its --help output, which the
experimental/air/config-help acceptance test pins. Regenerate the golden.

Co-authored-by: Isaac <no-reply@databricks.com>
Isaac Review flagged two MAJOR correctness bugs in the warm cache:
- Concurrent `air run` on the same cache key wrote the same snapshot.tar.tmp and
  raced the rename plus a non-atomic manifest write, interleaving into a corrupt
  tar/manifest pair.
- rebuildWarmSnapshot renamed the new tar into place before saving the manifest,
  so a crash between the two left a manifest whose byte offsets described a
  different tar layout -- silently corrupting a later verbatim-reuse rebuild.

Fix both by binding the manifest to a per-build, uniquely named tar
(snapshot.<id>.tar) that is never overwritten, and installing the manifest
atomically (unique temp + rename) only after its tar is durable. A manifest and
the tar it indexes are therefore always a consistent pair: there is no window
where offsets describe a mismatched tar, and concurrent rebuilds are
last-writer-wins on the manifest rather than interleaving, so no lock is needed.
Superseded and orphaned tars are cleaned up best-effort. Adds a rotation test.

Co-authored-by: Isaac <no-reply@databricks.com>
@ben-hansen-db
ben-hansen-db force-pushed the air-warm-snapshot-cache-v2 branch from 710e750 to ed64774 Compare September 9, 2026 15:44
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