Object cache

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

CodeWhat it owns
internal/storage/objectcache/ring.goRing: which instance serves a key, the load bound, and ejection. It knows nothing of the S3 SDK.
internal/storage/objectstore/s3/cacheroute.goThe 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.gocacheGet and cacheDelete, with their direct fallbacks
internal/gateway/cacheroute.goThe 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.

alt [cache answers] [proxy fails, or the body stalls] Acquire(bucket/key) instance (home, or the next under the load bound) GET, Range added after signing bytes direct ranged GET from the current offset the rest of the bytes Release(outcome) Reader Ring Cache instance Object storage

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:
internal/storage/objectcache/ring.go
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

ConditionWhat the reader does
No instance is eligible, or none is configuredReads 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 errorReads directly and charges the instance (error)
The instance answers with bytes other than those asked forReads directly and charges the instance (range)
Storage's own answer through a working proxy, such as not foundReturns 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 throughResumes 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:

internal/storage/objectstore/s3/cacheroute.go
// 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

BoundDefaultSet by
Ring positions per instance128Fixed
Load factor1.25; must be above 1--object-cache-load-factor
Failures before ejection3 in a rowFixed
Ejection cooldown30 sFixed
Connect budget1 s--object-cache-connect-budget
First-byte budget, and the mid-body stall5 s--object-cache-first-byte-budget
SignalWhat it shows
nova.objectcache.requestsRequests sent through the cache
nova.objectcache.fallbacksDirect reads, by cause
nova.objectcache.spillsClaims sent past a key's home instance by the load bound
nova.objectcache.ejections, nova.objectcache.ring.sizeEjections, and instances available
objectcache: cache instance ejected, objectcache: cache instance restoredEach 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.

See also

On this page