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 CopyPlaceBytes(n int) int64
- func Phases(ctx context.Context, prefix string) func(name string)
- func StartRootSpan(ctx context.Context, name string, attrs ...attribute.KeyValue) (context.Context, func(err error, attrs ...attribute.KeyValue))
- func StartSpan(ctx context.Context, name string, attrs ...attribute.KeyValue) (context.Context, func(err error, attrs ...attribute.KeyValue))
- func ValidWorkspaceID(id string) bool
- type CacheStats
- type CommitInfo
- type Entry
- type MaintStats
- type OpKind
- type Option
- type PackIndex
- type Reader
- func (r *Reader) Copy(ctx context.Context, shas []gitpack.SHA, ahead int64, ...) error
- 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) GraphCommit(ctx context.Context, sha gitpack.SHA) (tree gitpack.SHA, parents []gitpack.SHA, when int64, ok bool, err error)
- func (r *Reader) Has(ctx context.Context, shas []gitpack.SHA) ([]bool, error)
- func (r *Reader) Packs() int
- func (r *Reader) Prefetch(ctx context.Context, shas []gitpack.SHA)
- func (r *Reader) PrefetchHeaders(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) (CommitInfo, error)
- func (s *Service) File(ctx context.Context, repo Repo, commit gitpack.SHA, path string, max int64, ...) ([]byte, 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) ReserveLand(ctx context.Context, bytes int64) (release func(), err error)
- func (s *Service) TreeBulk(ctx context.Context, repo Repo, sha gitpack.SHA, maxEntries int, ...) (out []Tree, err 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 // LandBudget is the bytes that the leaders of lands may hold, apart from MemoryBudget. A leader that waits behind // fetches holds up every land of its ref. LandBudget = 128 << 20 ReadAheadBytes = inFlightBytes + aheadKeep )
const ( // DefaultReadBudget is the bytes that the shared bucket reads of all requests may hold at once. DefaultReadBudget = 48 << 20 // MinReadBudget is the least budget: a range that a prefetch plans is at most 1 MiB, and a read reserves three times // its length. MinReadBudget = 4 << 20 )
const DefaultRangeCacheBytes = 256 << 20
DefaultRangeCacheBytes is the memory of the range cache when the option and the configuration do not set it.
Variables ¶
var ( ErrNotFound = errors.New("store: object not found") ErrInvalid = errors.New("store: invalid object name or content") ErrTooLarge = errors.New("store: object too large") )
var ErrNoPath = errors.New("store: no such file")
ErrNoPath is the failure of File for a path that names no file of the commit.
Functions ¶
func CopyPlaceBytes ¶ added in v0.16.0
CopyPlaceBytes is the most that the placement of a Copy of n objects holds in index blocks: placeBatch blocks.
func Phases ¶ added in v0.15.0
Phases returns a function that ends a phase of the request of ctx: it records a child span named prefix and name that runs from the end of the last phase, with what the request read from the store meanwhile. It returns nil when the request is not traced.
func StartRootSpan ¶ added in v0.15.0
func StartRootSpan(ctx context.Context, name string, attrs ...attribute.KeyValue) (context.Context, func(err error, attrs ...attribute.KeyValue))
StartRootSpan is StartSpan for work that has no request, such as maintenance: the span is a root, so the sampling of a request that happens to run it does not drop it.
func StartSpan ¶ added in v0.15.0
func StartSpan(ctx context.Context, name string, attrs ...attribute.KeyValue) (context.Context, func(err error, attrs ...attribute.KeyValue))
StartSpan starts a child span of ctx. The function that it returns ends the span with err and attrs, and adds what the request of ctx read from the store meanwhile. Under a parent that is not recording, it starts nothing.
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
RangeCacheHits int64
RangeCacheMisses int64
RangeCacheBytes int64
RangeCacheEvictions int64
}
CacheStats counts the open-pack cache, the layer cache and the bucket reads that fill them.
type CommitInfo ¶ added in v0.19.0
CommitInfo is the root tree, the parents and the committer time of a commit.
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.
func WithClock ¶ added in v0.10.0
WithClock sets the clock that stamps retired files. It defaults to the real clock.
func WithGrace ¶ added in v0.10.0
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.
func WithRangeCache ¶ added in v0.14.0
WithRangeCache sets the memory of the cache of pack ranges that requests share. A value of zero or less turns the cache off. It defaults to DefaultRangeCacheBytes.
func WithReadBudget ¶ added in v0.14.0
WithReadBudget sets the bytes that the shared bucket reads of all requests may hold at once, at least MinReadBudget. It defaults to DefaultReadBudget.
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) Copy ¶ added in v0.16.0
func (r *Reader) Copy(ctx context.Context, shas []gitpack.SHA, ahead int64, before func(size int64) error, fn func(sha gitpack.SHA, raw *gitpack.Raw) error) error
Copy calls fn once for each of shas, with the stored pack entry of the object when a writer can copy it as it is, and with nil for an object that it cannot: a delta, an object that the commit and tree cache holds, and an object that no pack of the reader holds. It calls fn for the copyable objects first, in the physical order of the packs, and reads each pack once from front to back in runs of at most maxRun, reading the next runs while fn runs on the current one, with at most ahead bytes of runs read or being read. before is called with the size of an entry before the entry is read on its own. The entry that fn gets is valid until fn returns.
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) GraphCommit ¶ added in v0.15.0
func (r *Reader) GraphCommit(ctx context.Context, sha gitpack.SHA) (tree gitpack.SHA, parents []gitpack.SHA, when int64, ok bool, err error)
GraphCommit returns the tree, the parents and the commit time of a commit from the commit graph, with false when no graph of the repo holds it.
func (*Reader) Has ¶ added in v0.6.0
Has reports for each sha whether the repo holds it, from the pack indexes only.
func (*Reader) Packs ¶ added in v0.16.0
Packs is the number of packs that the layers of the reader list.
func (*Reader) Prefetch ¶ added in v0.11.0
Prefetch reads the pack bytes that Get of shas will need, in few large ranges that it reads at most readWorkers at a time. It skips what it cannot place, and a failed read is left to the Get that needs it.
func (*Reader) PrefetchHeaders ¶ added in v0.13.0
PrefetchHeaders is Prefetch for a caller that reads only the headers of the objects, as the sizes of the blobs of a tree: it keeps the first bytes of each object, not the whole object.
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) (CommitInfo, error)
Commit returns the tree, the parents and the committer time of a commit. It calls grow, when it is set, with the size of the commit before it reads it.
func (*Service) File ¶ added in v0.19.0
func (s *Service) File(ctx context.Context, repo Repo, commit gitpack.SHA, path string, max int64, grow func(size int64) error) ([]byte, error)
File returns the content of the file at path in the tree of a commit. It fails with ErrNoPath when a segment is missing or the path does not end at a file, and with ErrTooLarge when the file has more than max bytes. It calls grow with the bytes that it holds before it reads each object.
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) ReserveLand ¶ added in v0.13.0
ReserveLand takes bytes of LandBudget, 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) (out []Tree, err 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. It reads the trees of a batch together, and then the headers of their blobs in groups, so a bulk read costs a few rounds of reads, not one for each tree.
type Stats ¶
type Stats struct {
Objects, Bytes, Layers, RangeReads, RangeBytes, RangeHits, RangeMisses, 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.