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
- Variables
- func ValidWorkspaceID(id string) bool
- type CacheStats
- type Entry
- type MaintStats
- type OpKind
- type Option
- type PackIndex
- type Reader
- func (r *Reader) Get(ctx context.Context, sha gitpack.SHA) (gitpack.Type, []byte, error)
- func (r *Reader) GetSized(ctx context.Context, sha gitpack.SHA, before func(size int64) error) (gitpack.Type, []byte, error)
- func (r *Reader) Has(ctx context.Context, shas []gitpack.SHA) ([]bool, error)
- func (r *Reader) Prefetch(ctx context.Context, shas []gitpack.SHA)
- type Repo
- type Service
- func (s *Service) Blobs(ctx context.Context, repo Repo, shas []gitpack.SHA, ...) ([][]byte, error)
- func (s *Service) CacheStats() CacheStats
- func (s *Service) Commit(ctx context.Context, repo Repo, sha gitpack.SHA, grow func(size int64) error) (gitpack.SHA, time.Time, error)
- func (s *Service) Get(ctx context.Context, repo Repo, sha gitpack.SHA) (gitpack.Type, []byte, error)
- func (s *Service) GetOp(ctx context.Context, ws string, kind OpKind, id string) ([]byte, error)
- func (s *Service) Has(ctx context.Context, repo Repo, shas []gitpack.SHA) ([]bool, error)
- func (s *Service) ImportPack(ctx context.Context, repo Repo, id string, idx, pack []byte) error
- func (s *Service) MaintStats() MaintStats
- func (s *Service) Maintain(ctx context.Context, repo Repo) error
- func (s *Service) PutObjects(ctx context.Context, repo Repo, objs []gitpack.Object) ([]gitpack.SHA, error)
- func (s *Service) PutOp(ctx context.Context, ws string, kind OpKind, id string, data []byte) error
- func (s *Service) Reader(ctx context.Context, repo Repo) (*Reader, error)
- func (s *Service) ReceivePack(ctx context.Context, repo Repo, pack []byte, held func(int64) error) error
- func (s *Service) Reserve(ctx context.Context, bytes int64) (release func(), err error)
- func (s *Service) TreeBulk(ctx context.Context, repo Repo, sha gitpack.SHA, maxEntries int, ...) ([]Tree, error)
- func (s *Service) Warm(ctx context.Context, repos []Repo, parallel int) error
- type Stats
- type Tree
Constants ¶
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 )
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 ¶
Functions ¶
func ValidWorkspaceID ¶
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 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 Option ¶ added in v0.10.0
type Option func(*Service)
Option tunes a Service.
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) 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
Has reports for each sha whether the repo holds it, from the pack indexes only.
type Repo ¶
type Repo struct{ Prefix, Path string }
Repo names a repository as <prefix>:<path>.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service stores the objects of every repo and workspace in one object store.
func (*Service) Blobs ¶
func (s *Service) Blobs(ctx context.Context, repo Repo, shas []gitpack.SHA, grow func(size int64) error) ([][]byte, error)
Blobs returns the blobs of shas. Before it reads a blob, it calls grow, when it is set, with the bytes of the blobs read so far and the size that this one holds while it is read, taken from the pack.
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, grow func(size int64) error) (gitpack.SHA, time.Time, error)
Commit returns the tree of a commit and its committer time. It calls grow, when it is set, with the size of the commit before it reads it.
func (*Service) Has ¶
Has reports for each sha whether a pack of the repo holds it. It reads the pack indexes only.
func (*Service) ImportPack ¶
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
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) ReceivePack ¶ added in v0.6.0
func (s *Service) ReceivePack(ctx context.Context, repo Repo, pack []byte, held func(int64) error) 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. A non-nil held is called with the inflated bytes that the unpack holds each time that count grows.
func (*Service) Reserve ¶ added in v0.5.0
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.
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 (*Stats) AddSlotWait ¶
AddSlotWait adds the time a request waited for a weighted slot.