Repository navigation
engine: run containerd's metadata on an in-memory store - #15036
Merged
Merged
Conversation
grouville
self-requested a review
November 2, 2026 21:43
grouville
approved these changes
Nov 2, 2026
containerd's metadata database and the overlay snapshotter's store both run on go.etcd.io/bbolt. The engine runs them without fsync, so bolt's cost is its page work: rereading and rewriting B+tree pages, copying them for every write transaction, and holding a single write lock while it does. This package is a store with the subset of bbolt's API that containerd and the engine use, built for speed instead of durability. Each bucket is a persistent treap. A write transaction copies only the path to what it changes and publishes the new root with one atomic store, so readers take no lock and see the state as of their start, as in bbolt. Read transactions share one handle per bucket version; a key and its value are one allocation. Nothing is durable while it runs. Close writes the whole store to its file (a temporary file renamed over it, with a checksum), and Open reads it back and marks the file in use, so a file whose process never closed it, or a damaged one, is refused at the next Open. Signed-off-by: Erik Sipsma <[email protected]>
containerd's metadata database, the overlay snapshotter's store and the engine's own bolt code reach bolt only through go.etcd.io/bbolt, so one replace moves them all onto the in-memory store. No containerd fork is needed. On a cold first build of dagger's CLI the engine spends about half as long in containerd's snapshot and lease calls, uses about 3 CPU-s less, allocates about 0.7 GiB and 6 M objects less, and the build finishes 0.2-0.4 s sooner. Edits and unchanged rebuilds don't change. The store is saved when the engine stops gracefully and loaded when it starts. After a crash or kill its file is still marked in use, so it is refused, and the engine resets its local cache, as it does today when a bolt database fails to open. The overlay snapshotter opens its store on first use, so the engine now opens it at start (making its directory first), to send a refused file through that same reset. The store's own tests run in CI with the other nested modules, and it is linted like them. Signed-off-by: Erik Sipsma <[email protected]>
The engine opens the snapshotter's store at start, so a database its last engine never closed resets the local cache. Only overlayfs uses that handle. The native snapshotter opens its own store on the same file, and found it marked in use by the engine's handle, so every snapshot operation failed. After choosing the snapshotter, the engine now closes its handle unless the snapshotter is overlayfs. The check at start still happens first, so a crashed file still resets the local cache. A graceful stop now closes the snapshotter, which closes the store it uses, overlayfs the engine's and native its own, so native's store is saved too. The new test runs an engine on the native snapshotter: a build, a clean restart that keeps the cache, and a kill whose next start resets it. Signed-off-by: Erik Sipsma <[email protected]>
The engine never supported fuse-overlayfs in practice. It only picked it when overlayfs was unavailable and fuse-overlayfs happened to be. An engine without overlayfs now uses the native snapshotter, as it already did where fuse-overlayfs was missing. A config that names fuse-overlayfs gets the engine's error for an unknown snapshotter, and the engine doesn't start. The export path's and layercopy's special cases for fuse-overlayfs mounts go with it, and so does the module. Signed-off-by: Erik Sipsma <[email protected]>
…containerd's metadata tests internal/fastbolt is its own Go module, so the package-test shard, which lists the root module's packages, never ran its tests, and nothing else in CI did. The new testFastbolt check runs: - its own tests with the race detector, including a save that fills a small filesystem: the save fails, leaves no partial file, and the next open refuses the file instead of reading part of a save; - a differential test that drives it and the real bbolt through the same random operations and requires the same data after every transaction, and a concurrent-reader test with the race detector; - containerd's own core/metadata and core/snapshots/storage tests at the engine's containerd version, on the store, the metadata tests also with the race detector at 1, 4 and 16 CPUs. Signed-off-by: Erik Sipsma <[email protected]>
A start that failed for a reason a local cache reset can't fix, such as an unknown snapshotter name, returned without closing the metadata stores it had opened. With the in-memory store they stay marked in use, so the next start, with the config fixed, reset an otherwise clean local cache. Such a failure now closes the local cache state the way the reset path does, so the unchanged stores are saved clean. The new test starts an engine, fails a start with an unknown snapshotter, then requires the next start to keep the first engine's cache. Signed-off-by: Erik Sipsma <[email protected]>
The differential test's go.mod replaces realbolt with ./realbolt, which the testFastbolt check fills with a copy of the real bbolt. Without the directory, the Go scanners that read every module in the workspace, such as golangci-lint's, fail on the replace. A placeholder module there keeps them working, and the check replaces it whole. Signed-off-by: Erik Sipsma <[email protected]>
…shotter The graceful stop now closes the snapshotter, which closes the store it uses. A server stopped before it had a snapshotter, as the graceful stop tests build one, has none, and the stop dereferenced it. Without a snapshotter, the stop closes the engine's store directly, as it did before. Signed-off-by: Erik Sipsma <[email protected]>
sipsma
force-pushed
the
sipsma/containerd-metadata-in-memory
branch
from
November 2, 2026 21:51
1ee2f99 to
a832069
Compare
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.
This is #14965's change, unchanged, now on its own PR on today's main. #14965 was folded into #15007, the engine performance batch, and closed. It's split back out because replacing containerd's metadata store needs validation and review of its own.
containerd's metadata database and the overlay snapshotter's store run on bbolt. The engine already runs both without fsync, so what bolt costs is its page work: decoding and rewriting B+tree pages, copying them for each write transaction, and holding one write lock while it does. Every snapshot prepare, view and commit, and every lease change, pays it.
This replaces bbolt, for containerd and for the engine's own bolt code, with
internal/fastbolt: a store with the part of bbolt's API they use, built for speed instead of durability. Onego.modreplace swaps it in; containerd isn't forked.What it does for users
Measured on a cold first build of dagger's CLI with the dagger/go module, on c8gd.4xlarge machines, each round running the engine with and without the store on one machine, 12 rounds:
How it works
Bucket.Tx()returns nil on a bucket opened in a read transaction. Nothing in containerd or the engine calls it.How it persists and recovers
Closewrites the whole store to its file, as a temporary file renamed over it, with a checksum. The engine already closes both databases at the end of its graceful stop.Openloads the file and marks it in use untilClose. A missing or empty file starts an empty store, as bbolt does.Openrefuses it, and the engine resets its local cache through the path it takes today when a bolt database fails to open. A crash already resets the local cache today, through the dagql cache's unclean-shutdown check, so this adds no reset. A damaged nonempty file is refused the same way. This covers the engine process crashing or being killed, not the host: like the rest of the engine's state, the store isn't synced to disk, so a host crash or power loss can leave an older or empty file, which the next start accepts.Also in this PR
fuse-overlayfsnow gets the engine's unknown-snapshotter error and the engine doesn't start.On a fresh engine taking in the remote cache's results
Measured by Remote Cache's work on cheap installs (Nov 1), one profiled run per arm: a fresh engine installing dagger/dagger's test-base results from the remote cache. These are times summed across concurrent operations, not wall time, and there is no wall-time pair.
With the store in place, containerd's metadata database is still the largest lock in a fresh engine's first 15 s: 9.8–12.1 s of contention summed, from two serialized transactions per fetched blob (two diagnostic profiles, Nov 1). So the store cuts the time spent in metadata work, but its single writer still serializes it.
Validation
Run for this PR, on spot machines:
test-split/test-fastbolt, passes. CI never ran the store's own tests before, since it's a separate Go module. The check runs:core/metadataandcore/snapshots/storagetests on the store, at the engine's containerd version, the metadata tests also with the race detector at 1, 4 and 16 CPUs.overlayfskeeping the store open, a concurrency test that could pass without reading, and the failed-start gap, all fixed here, and no concurrency defects in the store.Earlier validation (from #14965)
internal/fastbolt's own tests: persistence round trips, refusal of unclean and damaged files, several handles to one bucket across writes, shared read handles. They pass under the race detector, and they're added to CI's lists of nested modules to test and lint.core/metadata(also under the race detector) andcore/snapshots/storagetest suites, run on the store.Not validated yet