experimental/air: warm snapshot cache for the plain_tar path - #6572
Open
ben-hansen-db wants to merge 4 commits into
Open
experimental/air: warm snapshot cache for the plain_tar path#6572ben-hansen-db wants to merge 4 commits into
ben-hansen-db wants to merge 4 commits into
Conversation
Collaborator
Integration test reportCommit: fc3da1b
Top 1 slowest tests (at least 2 minutes):
|
ben-hansen-db
marked this pull request as ready for review
September 8, 2026 17:42
ben-hansen-db
force-pushed
the
air-plain-tar-pgzip
branch
from
September 8, 2026 21:52
b732496 to
8155ccf
Compare
ben-hansen-db
force-pushed
the
air-warm-snapshot-cache-v2
branch
2 times, most recently
from
September 9, 2026 23:27
ed64774 to
b77d56d
Compare
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. 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 for a large folder 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
force-pushed
the
air-warm-snapshot-cache-v2
branch
from
September 10, 2026 21:34
b77d56d to
fc3da1b
Compare
vinchenzo-db
approved these changes
Sep 14, 2026
vinchenzo-db
left a comment
Contributor
There was a problem hiding this comment.
Claude says:
No-change hit can hard-fail under a concurrent same-key rebuild (minor, correctness)
snapshot_cache.go, the hit path:
if old != nil && old.DirName == dirName && fileExists(oldTarPath) && !snapshotChanged(files, old) {
return gzipFile(oldTarPath, outputTarball)
}
There's a TOCTOU between fileExists(oldTarPath) and gzipFile's os.Open. If a concurrent same-key rebuild finishes and its cleanupOldTars removes oldTarPath in that window (on Linux, where os.Remove of an unopened file succeeds), gzipFile returns "failed to open warm tar" and the whole air run submit errors out instead of just re-packing. The rebuild path already degrades gracefully when the old tar is gone (old = nil); the hit path doesn't. Cheap fix: if gzipFile fails to open the warm tar, fall through to rebuildWarmSnapshot rather than propagating. Rare (needs two simultaneous submits of the same repo+config+includes), so minor — but the failure mode is a user-visible error on a path that's supposed to be a pure optimization.
everything else lgtm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a local warm cache for the
air runplain_tar snapshot path (dirty working tree / no git ref), so a repeated submission re-reads and re-tars only the files that changed.(repo path, config path, include_paths)→$TMPDIR/databricks/.air/<sha256>/, holding a warm tar + amanifest.jsonof each file's size, mtime, and byte-range in the tar.--no-cachebypasses it and re-packs from scratch.Relationship to #6571
Builds on #6571 (parallel gzip + Go-native tar packer), now merged into
main. The two are orthogonal: #6571 speeds up the from-scratch pack; this PR avoids re-reading unchanged files. The--no-cachefall-back path calls the merged Go/pgzip packer, so both paths are parallel.When does the cache help?
On a warm page cache the win is smaller — parallel gzip (#6571) is the dominant factor there — but the cache still trims the pack by reusing unchanged bytes:
Correctness
Two MAJOR review findings (from an earlier review pass) are addressed:
snapshot.tar.tmp+ non-atomic manifest write.Each build writes a uniquely named
snapshot.<id>.tarthat is never overwritten, and installs the manifest atomically (unique temp + rename) only after its tar is durable. 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)
$TMPDIR(within a key, superseded tars are already cleaned up).This pull request and its description were written by Isaac.