store

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 30 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 store keeps the git objects of a repository in packs and the operation objects of a workspace, in one object store. HTTP, grants and the SQL index are in other packages.

Index

Constants

View Source
const (
	// DefaultGrace is how long a retired file stays before it is deleted.
	DefaultGrace = time.Hour
	// CompactMaxBytes bounds the pack that one compaction writes.
	CompactMaxBytes = MaxPackBytes
	// MaxLayerObjects bounds the records of one layer file.
	MaxLayerObjects = 8 << 20
)
View Source
const (
	MaxOpBytes   = 8 << 20
	MaxPackBytes = 64 << 20
	MaxIdxBytes  = 8 << 20
	// MaxBlobBatchBytes bounds the blobs that one batch read returns.
	MaxBlobBatchBytes = 16 << 20
	// MaxBatch bounds the objects of one put.
	MaxBatch = 100000

	// MemoryBudget is the bytes that requests may hold while they work, apart from the bodies that are still being read.
	MemoryBudget = 512 << 20
)

Variables

View Source
var (
	ErrNotFound = errors.New("store: object not found")
	ErrInvalid  = errors.New("store: invalid object name or content")
	ErrTooLarge = errors.New("store: object too large")
)

Functions

func ValidWorkspaceID

func ValidWorkspaceID(id string) bool

ValidWorkspaceID reports whether id can name a workspace.

Types

type CacheStats added in v0.10.0

type CacheStats struct {
	Hits, Misses, Evictions int64
	OpenPacks, OpenBytes    int64
	IndexBytes              int64
	RangeReads, RangeBytes  int64
	IndexHits, IndexMisses  int64
	IndexEvictions          int64
	IndexResident           int64
}

CacheStats counts the open-pack cache, the layer cache and the bucket reads that fill them.

type Entry

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

type MaintStats added in v0.10.0

type MaintStats struct {
	CompactRuns, CompactBytes, CompactObjects int64
	MergeRuns, MergeObjects                   int64
	Deleted, Failures                         int64
	Repos, LayersMax, LayersSum               int64
}

MaintStats counts the work of Maintain, and the layers of the repos that it has seen.

type OpKind

type OpKind string
const (
	OpOperation OpKind = "operations"
	OpView      OpKind = "views"
)

type Option added in v0.10.0

type Option func(*Service)

Option tunes a Service.

func WithClock added in v0.10.0

func WithClock(c clock.Clock) Option

WithClock sets the clock that stamps retired files. It defaults to the real clock.

func WithGrace added in v0.10.0

func WithGrace(d time.Duration) Option

WithGrace sets how long a retired file stays before Maintain deletes it. A request that began within the grace reads a consistent set. A value of zero or less keeps DefaultGrace.

type PackIndex

type PackIndex interface {
	AddPack(ctx context.Context, repo, packID string, bytes int64) error
	Packs(ctx context.Context, repo string) ([]meta.Pack, error)
	RemovePack(ctx context.Context, repo, packID string) error
	RetireFiles(ctx context.Context, repo string, keys []string, at time.Time) error
	RetiredFiles(ctx context.Context, repo string) ([]meta.Retired, error)
	ForgetRetired(ctx context.Context, repo string, keys []string) error
	BeginDelete(ctx context.Context, repo string, keys []string, now, staleBefore, retiredBefore time.Time) ([]string, error)
	ClaimRetired(ctx context.Context, repo string, keys []string) (bool, error)
	Manifest(ctx context.Context, repo string) (meta.Manifest, error)
	SwapManifest(ctx context.Context, repo string, expect int64, body []byte) (int64, error)
}

PackIndex is the metadata that the store keeps about the packs of a repo: the packs, and the manifest of layers.

type Reader added in v0.6.0

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

Reader reads the objects of one repo against the pack list of the moment that Reader was called, so a request that reads many objects lists the packs once.

func (*Reader) Get added in v0.6.0

func (r *Reader) Get(ctx context.Context, sha gitpack.SHA) (gitpack.Type, []byte, error)

func (*Reader) GetSized added in v0.6.0

func (r *Reader) GetSized(ctx context.Context, sha gitpack.SHA, before func(size int64) error) (gitpack.Type, []byte, error)

GetSized is Get that calls before with the size of the object before it reads the object. An error of before stops the read.

func (*Reader) Has added in v0.6.0

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

Has reports for each sha whether the repo holds it, from the pack indexes only.

func (*Reader) Prefetch added in v0.11.0

func (r *Reader) Prefetch(ctx context.Context, shas []gitpack.SHA)

Prefetch reads the pack bytes that Get of shas will need, in few large ranges. It skips what it cannot place, and a failed read is left to the Get that needs it.

type Repo

type Repo struct{ Prefix, Path string }

Repo names a repository as <prefix>:<path>.

func ParseRepo

func ParseRepo(s string) (Repo, error)

ParseRepo reads the text form. It rejects a prefix or a path that the object keys cannot carry.

func (Repo) String

func (r Repo) String() string

type Service

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

Service stores the objects of every repo and workspace in one object store.

func New

func New(st bucket.Store, index PackIndex, opts ...Option) *Service

func (*Service) Blobs

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

func (*Service) CacheStats added in v0.10.0

func (s *Service) CacheStats() CacheStats

CacheStats returns the counters of the open-pack cache.

func (*Service) Commit

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

Commit returns the tree of a commit and its committer time.

func (*Service) Get

func (s *Service) Get(ctx context.Context, repo Repo, sha gitpack.SHA) (gitpack.Type, []byte, error)

func (*Service) GetOp

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

func (*Service) Has

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

Has reports for each sha whether a pack of the repo holds it. It reads the pack indexes only.

func (*Service) ImportPack

func (s *Service) ImportPack(ctx context.Context, repo Repo, id string, idx, pack []byte) error

ImportPack stores a pack and its v2 index under the SHA-256 of the pack.

func (*Service) MaintStats added in v0.10.0

func (s *Service) MaintStats() MaintStats

MaintStats returns the counters of Maintain.

func (*Service) Maintain added in v0.10.0

func (s *Service) Maintain(ctx context.Context, repo Repo) error

Maintain does one bounded pass over repo: it adds the packs that the manifest lacks, compacts packs, merges layers and deletes the retired files whose grace has passed. It repeats the compactions and the merges until no run is left or maintainBudget has passed, so a burst of writes does not outrun it. Every step ends in one compare and swap of the manifest, so a crash between steps loses nothing, and a repeat finishes the work. Each step holds the repository lock alone, so a tail merge of a write can run between steps. It is safe to run on many replicas, which only repeat work.

func (*Service) PutObjects

func (s *Service) PutObjects(ctx context.Context, repo Repo, objs []gitpack.Object) ([]gitpack.SHA, error)

PutObjects stores objects as one pack and returns their names in order.

func (*Service) PutOp

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

func (*Service) Reader added in v0.6.0

func (s *Service) Reader(ctx context.Context, repo Repo) (*Reader, error)

func (*Service) ReceivePack added in v0.6.0

func (s *Service) ReceivePack(ctx context.Context, repo Repo, pack []byte) error

ReceivePack stores the objects of a pushed pack as one pack of the repo. The pack may be thin: the service resolves the base of a ref delta from the repo, so the stored pack holds whole objects.

func (*Service) Reserve added in v0.5.0

func (s *Service) Reserve(ctx context.Context, bytes int64) (release func(), err error)

Reserve takes bytes of MemoryBudget, at most the whole budget, and waits while the budget is spent. The caller releases it.

func (*Service) TreeBulk

func (s *Service) TreeBulk(ctx context.Context, repo Repo, sha gitpack.SHA, maxEntries int, grow func(treeBytes int64) error) ([]Tree, error)

TreeBulk returns a tree and its subtrees breadth first, until the entries returned reach maxEntries. Blob entries carry their size. Before it reads a tree, it calls grow with the tree bytes of the trees read so far and this one, taken from the pack index.

func (*Service) Warm added in v0.8.0

func (s *Service) Warm(ctx context.Context, repos []Repo, parallel int) error

Warm loads the layers of repos, newest layer first, with at most parallel reads at a time. It stops loading when the layer cache first evicts, because a layer that it loads then only evicts another. It returns the first error.

type Stats

type Stats struct {
	Objects, Bytes, Layers, RangeReads, RangeBytes, MaxDepth, SlotWaitNanos atomic.Int64
}

Stats counts what one request read from the store. A handler puts one in the context with WithStats and reads it when the request ends. A nil *Stats counts nothing.

func StatsFrom

func StatsFrom(ctx context.Context) *Stats

StatsFrom returns the Stats of a request, or nil.

func WithStats

func WithStats(ctx context.Context) (context.Context, *Stats)

WithStats returns ctx with a Stats that the reads of the request fill.

func (*Stats) AddSlotWait

func (s *Stats) AddSlotWait(d time.Duration)

AddSlotWait adds the time a request waited for a weighted slot.

type Tree

type Tree struct {
	SHA     gitpack.SHA
	Entries []Entry
}

Jump to

Keyboard shortcuts

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