rangecache

package
v0.25.0 Latest Latest
Warning

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

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

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) 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