store

package
v0.45.2 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2026 License: MIT Imports: 36 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

Index

Constants

View Source
const (
	DefaultPrefetchTreeEntries       = DefaultTreeEntries / 4
	DefaultPrefetchBlobBytes   int64 = 1 << 30
	PrefetchBlobMax                  = 64 << 10
	PrefetchRuns                     = 2
	TreePrefetchRuns                 = 1
	PrefetchWorkers                  = 4
)
View Source
const (

	// SegmentBytes is the size after which a segment is sealed.
	SegmentBytes = 64 << 20
	// SegmentBlobMax is the largest blob that a segment holds.
	SegmentBlobMax = 256 << 10
)
View Source
const DefaultTreeEntries = 2 << 20

DefaultTreeEntries is the entries that a tree cache holds: about 200 MiB.

View Source
const OpHeadsBudget = 2 * time.Second

OpHeadsBudget bounds one store call, because the shim waits on it while jj holds its op-heads lock.

Variables

View Source
var ErrGrantRefused = errors.New(volattr.GrantRefused)

ErrGrantRefused is the store answer 403 to a grant: the store holds no read of the repo for the grant, and no retry of the call passes.

View Source
var ErrNoBlobStream = errors.New("vfs: the store has no blob stream")

ErrNoBlobStream is the answer of a store that has no blob stream route, as an older service.

View Source
var ErrPackTooLarge = errors.New("vfs: the store refuses the pack as too large")

ErrPackTooLarge is the store refusing a pack for its size, or for the work that verifying it takes.

SharedTrees is the tree cache of a daemon. A tree and a commit are named by their hash, so every workspace of the node, whatever its repository, can use the same decoded tree.

Functions

func CopyBlob added in v0.29.0

func CopyBlob(ctx context.Context, st Store, s gitpack.SHA, size int64, w io.Writer) error

CopyBlob streams the blob s of size bytes, or of the size that the store gives when size is negative, from st to w through the buffers of one copy and the hash that checks it, and holds nothing of the blob in memory. It fails unless the stream has the size and the hash of the name, and w has then received bytes that the caller must discard on an error.

func EncodeTree

func EncodeTree(es []Entry) []byte

EncodeTree serializes entries in git order.

func EvictTo added in v0.40.0

func EvictTo(max int64, dir string)

EvictTo removes the least recently used sealed segments of the process until Tier2Bytes is at most max, and then the oldest files of blobs. A segment or a file that an open blob uses stays readable until the blob is closed, because the open file keeps it.

func HoldNodeCache added in v0.40.0

func HoldNodeCache(dir string) (release func(), err error)

HoldNodeCache makes the process the owner of the node cache directory dir for as long as it runs, and fails when another process owns it. The caches of the process on dir share the hold.

func Maintain added in v0.40.0

func Maintain(ctx context.Context, o MaintainOptions)

func RemoveStrayTemps added in v0.22.0

func RemoveStrayTemps(dir string)

RemoveStrayTemps removes the temporary files in dir that are older than this process: a dead writer left them.

func SeedCacheSize added in v0.22.0

func SeedCacheSize(dir string)

SeedCacheSize adds the size of the files that an earlier process left in dir to Tier2Bytes. A file that this process wrote is already in the figure.

func SeedTier2Bytes

func SeedTier2Bytes(n int64)

SeedTier2Bytes adds the size of the cache directory at startup to Tier2Bytes.

func Tier2Bytes

func Tier2Bytes() int64

Tier2Bytes is the number of blob bytes that this process wrote to the node cache, plus the size of the cache that SeedTier2Bytes found at startup.

func Tier2Evictions added in v0.40.0

func Tier2Evictions() int64

Tier2Evictions is the number of segments and files that this process evicted from the node cache.

Types

type BlobFile added in v0.40.0

type BlobFile struct {
	F      *os.File
	Off, N int64
	// contains filtered or unexported fields
}

BlobFile is an open blob of the node cache: N bytes at Off of F. The caller reads F and calls Close when it is done, and never closes F itself.

func (BlobFile) Close added in v0.40.0

func (b BlobFile) Close()

type BlobPrefetch added in v0.42.0

type BlobPrefetch struct {
	Blobs    int
	Bytes    int64
	Held     int
	Complete bool
}

type BlobPutter added in v0.30.0

type BlobPutter interface {
	PutBlob(ctx context.Context, sha gitpack.SHA, size int64, r io.Reader) error
}

BlobPutter is an optional method of Store: it stores a blob over gitpack.MaxObjectBytes from a stream.

type BlobStreamBatcher added in v0.40.0

type BlobStreamBatcher interface {
	StreamBlobs(ctx context.Context, shas []gitpack.SHA, fn func(sha gitpack.SHA, data []byte) error) error
}

BlobStreamBatcher is an optional method of Store: it reads the blobs of a batch as a stream and calls fn with each blob as it arrives, which holds one blob and sends no base64. A store that has no stream answers ErrNoBlobStream.

type BlobStreamer added in v0.29.0

type BlobStreamer interface {
	OpenBlob(ctx context.Context, sha gitpack.SHA) (int64, io.ReadCloser, error)
}

BlobStreamer is an optional method of Store: it reads a blob of any size as a stream, which the cache needs for a blob over gitpack.MaxObjectBytes, as Blobs refuses one.

type Cache

type Cache struct {
	Store       Store
	Dir         string
	BulkEntries int
	PrefetchN   int
	PrefetchB   int64
	// WriteWorkers is the number of files that a batch writes at the same time.
	WriteWorkers int
	// Pipeline is the number of batches that a miss reads in the background after its own, in the order of the read-ahead.
	Pipeline int

	// Trees holds the decoded trees. A cache has its own, and the caches of one daemon share SharedTrees.
	Trees *TreeCache

	BlobHits, BlobMisses, TreeMisses, TreeHits atomic.Int64
	// Tel carries the correlation attributes of the spans of this cache.
	Tel tel.Telemetry
	// contains filtered or unexported fields
}

Cache is tier 1 (decoded trees in memory) and tier 2 (blobs on node-local disk).

func NewCache

func NewCache(st Store, dir string) *Cache

func (*Cache) AddTree

func (c *Cache) AddTree(t *Tree)

AddTree puts a decoded tree in the memory tier.

func (*Cache) Adopt added in v0.30.0

func (c *Cache) Adopt(tmp *os.File, s gitpack.SHA, size int64) error

Adopt moves the spool file tmp, which holds the blob s, to its place in the node cache.

func (*Cache) Blob

func (c *Cache) Blob(ctx context.Context, e Entry, next func(yield func(Entry) bool)) (string, error)

Blob returns the path of the blob of e in the node cache, fetching it (plus read-ahead) if absent or if its file does not have the size of its tree entry. next yields read-ahead candidates after e; it may be nil.

func (*Cache) BlobPath

func (c *Cache) BlobPath(s gitpack.SHA) string

BlobPath is the path of the blob in the node cache, whether or not it exists.

func (*Cache) CachedTree

func (c *Cache) CachedTree(sha gitpack.SHA) *Tree

CachedTree returns a tree only when it is already in memory.

func (*Cache) Close added in v0.40.0

func (c *Cache) Close() error

Close gives up the segments of the cache. The last cache of the process on a directory seals its segment and closes the files when their last open blob is closed.

func (*Cache) File added in v0.30.0

func (c *Cache) File(ctx context.Context, s gitpack.SHA) (*os.File, error)

File returns the file of the blob s in the node cache, fetching it first when the cache lacks it, by a stream when the store has one. A caller that needs the bytes of a blob by name, and has no tree entry, uses it.

func (*Cache) HasBlob

func (c *Cache) HasBlob(s gitpack.SHA) bool

HasBlob reports whether the blob is in the node cache.

func (*Cache) Open added in v0.40.0

func (c *Cache) Open(ctx context.Context, e Entry, next func(yield func(Entry) bool)) (BlobFile, error)

Open is Blob that returns the open blob. A blob that a segment holds is served from the segment file, and every other blob from its own file.

func (*Cache) OpenHeld added in v0.40.0

func (c *Cache) OpenHeld(s gitpack.SHA) (BlobFile, bool)

OpenHeld opens the blob that the cache holds, and reports false for a blob that it lacks. It fetches nothing.

func (*Cache) PrefetchBlobs added in v0.42.0

func (c *Cache) PrefetchBlobs(ctx context.Context, root gitpack.SHA, maxEntries int, maxBytes int64) (BlobPrefetch, error)

func (*Cache) PrefetchTrees added in v0.42.0

func (c *Cache) PrefetchTrees(ctx context.Context, root gitpack.SHA, maxEntries int) (TreePrefetch, error)

func (*Cache) ReadBlob

func (c *Cache) ReadBlob(ctx context.Context, e Entry) ([]byte, error)

ReadBlob returns blob bytes from the node cache. It is the one reader that holds a blob in memory whole, so it refuses an entry over gitpack.MaxObjectBytes before it asks the cache, which another workspace may have filled with such a blob by its name.

func (*Cache) Spool added in v0.30.0

func (c *Cache) Spool() (*os.File, error)

Spool creates the locked temporary file of an upload that the caller then streams into and hands to Adopt.

func (*Cache) Tree

func (c *Cache) Tree(ctx context.Context, sha gitpack.SHA) (*Tree, error)

func (*Cache) TreeLimit added in v0.42.0

func (c *Cache) TreeLimit(ctx context.Context, sha gitpack.SHA, bulk int) (*Tree, error)

func (*Cache) UseSegments added in v0.40.0

func (c *Cache) UseSegments() error

UseSegments makes the cache keep the blobs of at most SegmentBlobMax bytes in append-only segment files in the directory seg of the cache, and not one file each. A caller that wants a file for such a blob gets one that the cache makes from the segment.

type Entry

type Entry struct {
	Name string
	Mode uint32
	SHA  gitpack.SHA
	Size int64
}

func (Entry) IsDir

func (e Entry) IsDir() bool

func (Entry) IsExec

func (e Entry) IsExec() bool
func (e Entry) IsGitlink() bool
func (e Entry) IsSymlink() bool

type HTTPStore

type HTTPStore struct {
	BaseURL string
	// Grant returns the bearer grant of each call. A caller whose mount outlives one grant returns a fresh one.
	// A grant that fails fails the call.
	Grant  client.GrantFunc
	Client *http.Client
	// Tel carries the correlation attributes and the logger of the spans and records the client writes.
	Tel tel.Telemetry
	// contains filtered or unexported fields
}

HTTPStore reads and writes the version control store through client.Client and adds the spans of the daemon.

func (*HTTPStore) Blobs

func (s *HTTPStore) Blobs(ctx context.Context, shas []gitpack.SHA) ([][]byte, error)

func (*HTTPStore) Calls

func (s *HTTPStore) Calls() int64

Calls is the number of store requests made so far.

func (*HTTPStore) Commit

func (s *HTTPStore) Commit(ctx context.Context, sha gitpack.SHA) (gitpack.SHA, time.Time, error)

func (*HTTPStore) DeleteRef

func (s *HTTPStore) DeleteRef(ctx context.Context, name string, expect int64) error

func (*HTTPStore) GetOp

func (s *HTTPStore) GetOp(ctx context.Context, kind, id string) ([]byte, error)

func (*HTTPStore) Has

func (s *HTTPStore) Has(ctx context.Context, shas []gitpack.SHA) ([]bool, error)

Has reports which of shas the store holds.

func (*HTTPStore) ImportPack

func (s *HTTPStore) ImportPack(ctx context.Context, idx, pack []byte) error

ImportPack uploads one pack and its v2 index. The pack ID is the SHA-256 of the pack.

func (*HTTPStore) Layer added in v0.40.0

func (s *HTTPStore) Layer(ctx context.Context, key string) (layerrow.Row, error)

func (*HTTPStore) LayersByBase added in v0.44.0

func (s *HTTPStore) LayersByBase(ctx context.Context, base string) ([]layerrow.Row, error)

LayersByBase returns the rows with the base key, most recently used first.

func (*HTTPStore) Object

func (s *HTTPStore) Object(ctx context.Context, sha gitpack.SHA) (gitpack.Type, []byte, error)

Object reads one object of any type.

func (*HTTPStore) OpHeads

func (s *HTTPStore) OpHeads(ctx context.Context) (api.OpHeads, error)

OpHeads reads the op heads. A workspace that has none yet is generation 0 and no heads.

func (*HTTPStore) OpenBlob added in v0.29.0

func (s *HTTPStore) OpenBlob(ctx context.Context, sha gitpack.SHA) (int64, io.ReadCloser, error)

OpenBlob returns the size and a reader of the blob sha, of any size. The span ends when the body starts.

func (*HTTPStore) PutBlob added in v0.29.0

func (s *HTTPStore) PutBlob(ctx context.Context, sha gitpack.SHA, size int64, r io.Reader) error

PutBlob stores one blob over the in-memory limit of the store, of size bytes that it streams from r.

func (*HTTPStore) PutLayer added in v0.40.0

func (s *HTTPStore) PutLayer(ctx context.Context, key, base, tree string, files, bytes int64) (layerrow.Row, error)

func (*HTTPStore) PutObjects

func (s *HTTPStore) PutObjects(ctx context.Context, objs []gitpack.Object) error

PutObjects uploads objs in requests of at most maxPutBytes and maxPutObjects. One snapshot is one request unless it is larger.

func (*HTTPStore) PutOp

func (s *HTTPStore) PutOp(ctx context.Context, kind, id string, data []byte) error

func (*HTTPStore) PutWorkspace

func (s *HTTPStore) PutWorkspace(ctx context.Context, op, commit string, generation int64) error

func (*HTTPStore) Ref

func (s *HTTPStore) Ref(ctx context.Context, name string) (api.Ref, error)

func (*HTTPStore) Refs

func (s *HTTPStore) Refs(ctx context.Context) ([]api.Ref, error)

func (*HTTPStore) StreamBlobs added in v0.40.0

func (s *HTTPStore) StreamBlobs(ctx context.Context, shas []gitpack.SHA, fn func(sha gitpack.SHA, data []byte) error) error

StreamBlobs reads the blobs of shas through the blob stream and calls fn with each blob as it arrives. A store that does not have the route answers ErrNoBlobStream: an older service answers 405 to a POST on this path, which its route of a blob matches with other methods, and an unknown path 404 with the text of the status, while every other not found has its own text.

func (*HTTPStore) SwapOpHeads

func (s *HTTPStore) SwapOpHeads(ctx context.Context, expect int64, heads []string) (api.OpHeads, error)

func (*HTTPStore) SwapRef

func (s *HTTPStore) SwapRef(ctx context.Context, name string, expect int64, commit string) (api.Ref, error)

func (*HTTPStore) TreeBulk

func (s *HTTPStore) TreeBulk(ctx context.Context, sha gitpack.SHA, maxEntries int) ([]*Tree, error)

type HasStore

type HasStore interface {
	Has(ctx context.Context, shas []gitpack.SHA) ([]bool, error)
}

HasStore reports which objects the store holds, without reading them.

type MaintainOptions added in v0.40.0

type MaintainOptions struct {
	Every    time.Duration
	MaxBytes int64
	// Dir is the node cache directory that eviction measures.
	Dir string
	// EvictAfter, when set, holds the eviction back until it is closed: the size of the cache is known only after the
	// scan of the start.
	EvictAfter <-chan struct{}
}

MaintainOptions: a MaxBytes of 0 evicts nothing.

type OpHeadsStore

type OpHeadsStore interface {
	OpHeads(ctx context.Context) (api.OpHeads, error)
	SwapOpHeads(ctx context.Context, expect int64, heads []string) (api.OpHeads, error)
}

OpHeadsStore reads and swaps the op heads of the workspace that the grant names.

type OpObjectStore

type OpObjectStore interface {
	PutOp(ctx context.Context, kind, id string, data []byte) error
	GetOp(ctx context.Context, kind, id string) ([]byte, error)
}

OpObjectStore keeps the operations and views of the op log of the workspace that the grant names.

type RefStore

type RefStore interface {
	Refs(ctx context.Context) ([]api.Ref, error)
	Ref(ctx context.Context, name string) (api.Ref, error)
	SwapRef(ctx context.Context, name string, expect int64, commit string) (api.Ref, error)
	DeleteRef(ctx context.Context, name string, expect int64) error
}

RefStore reads and swaps the refs of the native repo that the grant names. A lost swap is client.ErrGenerationConflict, and client.CurrentRef returns the stored ref.

type SegHandle added in v0.40.0

type SegHandle struct {
	F      *os.File
	Off, N int64
	// contains filtered or unexported fields
}

SegHandle is an open blob of a segment: the bytes at Off, N long, of F. The file belongs to the store, so a caller reads it and never closes it, and calls Close when it is done.

func (SegHandle) Close added in v0.40.0

func (h SegHandle) Close()

type Store

type Store interface {
	Commit(ctx context.Context, sha gitpack.SHA) (tree gitpack.SHA, when time.Time, err error)
	// TreeBulk returns the tree and its subtrees breadth first until maxEntries entries, with blob sizes.
	TreeBulk(ctx context.Context, sha gitpack.SHA, maxEntries int) ([]*Tree, error)
	Blobs(ctx context.Context, shas []gitpack.SHA) ([][]byte, error)
	PutObjects(ctx context.Context, objs []gitpack.Object) error
	Object(ctx context.Context, sha gitpack.SHA) (gitpack.Type, []byte, error)
}

Store is what the daemon needs from the version control store. One method is one remote call.

type Tree

type Tree struct {
	SHA     gitpack.SHA
	Entries []Entry
	// contains filtered or unexported fields
}

func NewTree

func NewTree(sha gitpack.SHA, es []Entry) *Tree

func (*Tree) Lookup

func (t *Tree) Lookup(name string) (Entry, bool)

type TreeCache added in v0.40.0

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

TreeCache holds decoded trees and the tree of each commit that was asked for, in two generations of at most max/2 entries each, except one tree that is larger: a tree that nothing used since the last rotation goes when the next rotation comes.

func NewTreeCache added in v0.40.0

func NewTreeCache(max int) *TreeCache

func (*TreeCache) Commit added in v0.40.0

func (c *TreeCache) Commit(ctx context.Context, st Store, sha gitpack.SHA) (gitpack.SHA, time.Time, error)

type TreePrefetch added in v0.42.0

type TreePrefetch struct {
	Trees, Entries int
	Calls          int
	Complete       bool
}

type WorkspaceStore

type WorkspaceStore interface {
	PutWorkspace(ctx context.Context, op, commit string, generation int64) error
}

WorkspaceStore records the head operation and mount commit, ordered by the op-heads generation of the swap.

Jump to

Keyboard shortcuts

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