Documentation
¶
Overview ¶
Package packmeta stores the small bit of data Packhorse needs to serve a cached pack as a packfile-uri without reading the whole pack back. It keeps the pack checksum, the object format, and the response sections that come before the packfile.
The data lives in two places. An in-memory LRU is the fast per-pod copy. Object storage is the shared copy that every pod can read, so one pod can reuse a pack another pod cached. A read looks in memory first and then in object storage. A write saves to both.
Index ¶
Constants ¶
const Version = 1
Version is the schema version of a stored Meta. Bump it when the stored shape changes so a reader can skip data from a version it does not understand.
Variables ¶
var ErrNotFound = errors.New("object not found")
ErrNotFound is what an ObjectStore returns when a key has no object. The store uses it to treat a missing object as a miss, which keeps packmeta free of any object-storage SDK.
Functions ¶
This section is empty.
Types ¶
type Meta ¶
type Meta struct {
Version int `json:"version"`
PackHash string `json:"pack_hash"`
ObjectFormat string `json:"object_format"`
HeaderSections []pktlineeditor.Section `json:"header_sections"`
}
Meta describes a pack that is cached in object storage. It holds what a hit needs to build a packfile-uri response without reading the pack back.
type ObjectStore ¶
type ObjectStore interface {
// ReadObject returns the whole object for a key as bytes. It returns ErrNotFound
// when the key has no object.
ReadObject(ctx context.Context, key string) ([]byte, error)
// WriteObject saves data as the whole object for a key and replaces any object
// already stored there.
WriteObject(ctx context.Context, key string, data []byte) error
}
ObjectStore is the part of object storage the metadata store uses.
type Store ¶
type Store interface {
// Get returns the metadata for a key. It looks in memory first and then in
// object storage, and copies an object-storage hit back into memory. A key with
// no metadata returns (nil, false, nil).
Get(ctx context.Context, key string) (*Meta, bool, error)
// Put saves the metadata in memory and in object storage.
Put(ctx context.Context, key string, meta *Meta) error
// Evict removes a key from memory. Object storage keeps its copy and is cleaned
// up by its own lifecycle rules.
Evict(key string)
}
Store maps a cache key to the metadata for its cached pack.
func NewStore ¶
func NewStore(objects ObjectStore, capacity int) Store
NewStore makes a two-tier Store backed by objects, with an in-memory tier that holds at most capacity entries.