Object cache
How nodes and the Gateway route object reads through a shared cache tier and fall back to storage.
The object cache is a tier of caching proxies in front of object storage. Nodes, auditors, and the Gateway send ranged reads through it, so many readers of the same object cost one download. Every cache request has a direct ranged GET as its fallback, and a failure at any point, even halfway through a body, continues on that direct path. A cache problem can slow a read, but it does not fail it. The one exception is an instance that refuses because it is at its own concurrency limit: the caller gets a retryable throttle, as it would from object storage.
Where it lives
| Code | What it owns |
|---|---|
internal/storage/objectcache/ring.go | Ring: which instance serves a key, the load bound, and ejection. It knows nothing of the S3 SDK. |
internal/storage/objectstore/s3/cacheroute.go | The cache-routed S3 client: the proxy hook, the connect and first-byte budgets, and the Range header added after signing |
internal/storage/objectstore/s3/s3.go | cacheGet and cacheDelete, with their direct fallbacks |
internal/gateway/cacheroute.go | The same route for the Gateway's fetches of presigned URLs |
deploy/docker/objectcache/ | The instance configuration the compose stack runs |
One process builds one Ring and shares it across every store that routes through the cache, so the load bound and ejections cover all its readers.
Routing
The ring key is the bucket and the object key, <bucket>/<key>, so every process routes an object the same way.
- Key affinity. Each instance takes 128 positions on a hash ring, hashed from its URL, so the order of the instance list does not matter. A key belongs to the first instance at or after its position. Every process sends the same key to the same instance, so the instance can merge concurrent downloads of it.
- Bounded load. Each claim counts as one in-flight request on its instance until the body is closed. An instance at the ceiling is passed over for the next instance in ring order, which spreads a hot object across several instances. The ceiling counts only instances that are not ejected:
ceiling := int(math.Ceil(r.loadFactor * float64(eligibleLoad+1) / float64(eligible)))- Ejection. Three failures in a row eject an instance for 30 seconds. After the cooldown, the next request tests it again. The failure count is not reset by the cooldown, so one more failure ejects it again at once.
What happens on each outcome
| Condition | What the reader does |
|---|---|
| No instance is eligible, or none is configured | Reads directly; counted as fallback cause ejected |
The connection takes longer than --object-cache-connect-budget (1s) | Reads directly and charges the instance (connect) |
The response headers take longer than --object-cache-first-byte-budget (5s) | Reads directly and charges the instance (first_byte). The default sits above direct S3's p99, so slow storage is not taken for a sick instance. |
| Any other proxy-layer error | Reads directly and charges the instance (error) |
| The instance answers with bytes other than those asked for | Reads directly and charges the instance (range) |
| Storage's own answer through a working proxy, such as not found | Returns that answer and charges nothing. A direct retry would get the same answer. |
The instance refuses at its own concurrency limit (a SlowDown without S3's request ID) | Returns it as ErrCacheOverloaded, a kind of ErrThrottled, and charges nothing. Clients see a retryable UNAVAILABLE, or 503 over HTTP, and auditor budgets back off with cause cache. |
| The body fails or stalls partway through | Resumes once, directly, from the current offset. The caller never sees the switch (midstream or stall). |
A body counts as stalled when it sends nothing for the first-byte budget. The Gateway reads each range whole into memory, so on the same failure it fetches the whole range again directly instead of resuming.
Deletes go through the cache
When a cache route is set, a single-key delete travels through the key's instance, so cached bytes are dropped with the object. A delete that fails at the proxy layer is sent directly; the instance's time-to-live covers the missed invalidation. Writes and listings never use the cache.
Batch deletes (DeleteBatch) always go directly. The auditor uses them for its slot trims and for the confirmed reaps of stream objects. Sending each key of a batch through the cache would turn one request into up to 1,000. Nothing reads those keys once their references are gone, and no key is written twice, so their cached pages simply expire.
The auditor's own storage client, and every client of a node that only audits, route only deletes (Reads: false). The auditor can share its slot reads through its own fetch cache, and one auditor copies a given ledger. Through the shared cache those reads would help no other reader and would push out the readers' hot pages.
Request signing and network access
A cache instance widens small reads to whole cache pages. It can change the Range header only when that header is outside the request's signature, because it has no credentials to sign again. Nodes and auditors add Range after SigV4 signing, which SigV4 allows:
// unsignedRange is the cache-route middleware: it attaches the Range
// header after the Signing step, so the header is never in
// SignedHeaders and the cache may rewrite it.
func unsignedRange() middleware.FinalizeMiddleware {
// ... in the finalize step, after signing:
if info, ok := ctx.Value(cacheRouteKey{}).(*cacheRouteInfo); ok && info.rangeValue != "" {
if req, ok := in.Request.(*smithyhttp.Request); ok {
req.Header.Set("Range", info.rangeValue)
}
}
// ...
}A presigned URL from a read plan signs neither the scheme nor Range, so the Gateway can route it through the cache too.
Cache traffic is plain HTTP inside the cluster, so the instance can read and widen it. A cache hit does not ask object storage to check the caller again. Keep the cache reachable only from inside the cluster, away from tenant and public networks.
Concurrency
The ring is one mutex over its instance table, in-flight counts, and failure counts. A claim lasts for the whole transfer, so the load bound sees a long streaming read as load. Release runs exactly once per claim; a second call does nothing.
Bounds and signals
| Bound | Default | Set by |
|---|---|---|
| Ring positions per instance | 128 | Fixed |
| Load factor | 1.25; must be above 1 | --object-cache-load-factor |
| Failures before ejection | 3 in a row | Fixed |
| Ejection cooldown | 30 s | Fixed |
| Connect budget | 1 s | --object-cache-connect-budget |
| First-byte budget, and the mid-body stall | 5 s | --object-cache-first-byte-budget |
| Signal | What it shows |
|---|---|
nova.objectcache.requests | Requests sent through the cache |
nova.objectcache.fallbacks | Direct reads, by cause |
nova.objectcache.spills | Claims sent past a key's home instance by the load bound |
nova.objectcache.ejections, nova.objectcache.ring.size | Ejections, and instances available |
objectcache: cache instance ejected, objectcache: cache instance restored | Each ejection, with its cause, and each return |
Tests
internal/storage/objectcache:TestRingPicksDeterministicallyAcrossInstanceOrder,TestRingSpillsHotKeyAtBoundedLoadAndReturnsOnRelease,TestRingEjectsAfterConsecutiveFailuresThenReprobesHalfOpen,TestRingReturnsErrNoRouteWhenAllInstancesEjected.internal/storage/objectstore/s3:TestCacheRoutedGetIsProxyFormWithRangeOutsideSignature,TestCacheRouteResumesDirectWhenBodyDiesMidStream,TestCacheRouteResumesDirectWhenBodyStallsMidStream,TestCacheRouteTreatsAPIErrorsAsAnswersNotFailures,TestCacheRefusalIsTheCachesOwnPushback,TestCacheRouteDeleteTravelsProxyWhateverReadsSetting,TestCacheRouteNeverRoutesWritesOrList,TestS3ConformanceCacheRouteDead.