rangecache

package
v0.27.0-rc.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 19, 2026 License: Apache-2.0 Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package rangecache stores byte ranges of blobs the node has already fetched.

The containerd content store is all-or-nothing: a blob is either committed whole or absent, so a peer cannot serve any part of a 1 GiB layer until it holds all of it. Under Artifact Streaming that makes a cold image unserveable between peers - every node reads a few KiB of OverlayBD index and every one of those reads has to go to origin. This cache holds the ranges a node actually fetched so they can be answered locally and served to peers long before any layer is complete.

Index

Constants

This section is empty.

Variables

View Source
var ErrFull = errors.New("rangecache: full")

ErrFull means a new blob was not admitted. Put leaves its reader untouched.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache is a disk-backed store of partial blob content. It is intentionally non-durable: entries are discarded on restart rather than revalidated, because a stale range served as authoritative would corrupt an image.

func New

func New(dir string, maxBytes int64) (*Cache, error)

New prepares an empty cache rooted at dir. Any previous contents are removed: the interval index lives in memory, so leftover files cannot be trusted.

func (*Cache) Close

func (c *Cache) Close() error

Close releases the open files.

func (*Cache) Coverage added in v0.26.0

func (c *Cache) Coverage(d digest.Digest, prefix int64) (available, total int64)

Coverage counts unique cached bytes unioned with an in-flight ingest's contiguous prefix. Overlapping ranges and repeated reads count only once.

func (*Cache) Digests

func (c *Cache) Digests() []digest.Digest

Digests lists blobs with at least one cached range.

func (*Cache) Full

func (c *Cache) Full() bool

Full reports whether the cache stopped admitting new blobs.

func (*Cache) Has

func (c *Cache) Has(d digest.Digest, requested httprange.Range) bool

Has reports whether the full interval is already cached.

func (*Cache) HasAny

func (c *Cache) HasAny(d digest.Digest) bool

HasAny reports whether any range of d is cached, which is enough to make this node a useful provider for it.

func (*Cache) OpenRange

func (c *Cache) OpenRange(_ context.Context, d digest.Digest, requested httprange.Range) (io.ReadCloser, int64, error)

OpenRange satisfies streaming.LocalRangeStore. It returns ifaces.ErrNotFound unless the whole requested interval is cached, so a partial hit never produces a short body.

func (*Cache) Put

func (c *Cache) Put(d digest.Digest, total, start int64, r io.Reader) (int64, error)

Put stores data read from r at start. total is the blob's full size, used for Content-Range on later reads. Put reports the number of bytes stored; a truncated read still records what landed. ErrFull means no bytes were read or stored, so the caller can serve r without caching.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL