Documentation
¶
Overview ¶
Package midx is the layered multi-pack index of a repository: one sorted lookup structure over many packs, the manifest that lists the layers of a repository, and the geometric rules that merge layers and compact packs.
Index ¶
- Constants
- Variables
- func BlockValues(i int, block []byte) ([]byte, error)
- func BuildGraph(commits []Commit) ([]byte, error)
- func BuildSizes(vals []uint32) []byte
- func DecodeSize(v uint32) (int64, bool)
- func EncodeSize(n int64) uint32
- func MergeGraphs(gs []*Graph) ([]byte, error)
- func SizesBlockRange(i, n int) (off, length int64)
- func SizesFileLen(n int) int64
- func ValueAt(values []byte, j int) uint32
- type Builder
- type Commit
- type Dir
- func (d *Dir) BlockRange(i int) (off, n int64)
- func (d *Dir) Blocks() int
- func (d *Dir) Lookup(ctx context.Context, s SHA, ord int, fetch Fetch) (Record, bool, error)
- func (d *Dir) LookupMany(ctx context.Context, shas []SHA, fetch FetchMany) ([]Record, []bool, error)
- func (d *Dir) LookupManyPos(ctx context.Context, shas []SHA, fetch FetchMany) ([]Record, []bool, []int, error)
- func (d *Dir) MayContain(s SHA) bool
- func (d *Dir) Resident() int
- func (d *Dir) Size() int64
- type Entry
- type Fetch
- type FetchMany
- type Graph
- type Iter
- type Layer
- type Manifest
- type Pack
- type Plan
- type ReadFunc
- type Record
- type SHA
- type Sizes
Constants ¶
const ( // MaxGraphCommits bounds the commits of one graph file, so a file is at most 16 MiB and a few files fit the layer // cache together. MaxGraphParents bounds the parents of a commit that a graph holds. MaxGraphCommits = 1 << 17 MaxGraphParents = 64 // MaxGraphOverflow bounds the overflow list of one graph file, in bytes. MaxGraphOverflow = 3 << 20 )
const ( ClassMeta = "m" ClassBlob = "b" )
The classes of a layer. Metadata is commits, trees and tags.
const ( // BlockRecords is the number of records that one ranged read of a layer returns. BlockRecords = 256 // RecordSize is the size of one record: name, pack number and offset. RecordSize = 28 // MaxOffset is the largest pack offset that a record holds. MaxOffset = 1<<32 - 1 )
const Factor = 2
Factor is the geometric ratio. A run takes the next older layer while that layer is at most Factor times the size of the run, so a layer that stays is more than Factor times as large as the layer after it, and a repository of N objects has about log N layers.
Variables ¶
var ( ErrCorruptGraph = errors.New("midx: corrupt commit graph") ErrGraphTooLarge = errors.New("midx: too many commits for one graph") )
var ErrCorrupt = errors.New("midx: corrupt layer")
var ErrCorruptSizes = errors.New("midx: corrupt size file")
Functions ¶
func BlockValues ¶ added in v0.16.0
BlockValues checks the CRC of a block read from the size file and returns its values.
func BuildGraph ¶ added in v0.15.0
BuildGraph returns the commit graph file of commits: the records sorted by name, then the parents after the second of each commit with more than two parents, then the SHA-256 of all of it. A commit that repeats an earlier one is kept once.
func BuildSizes ¶ added in v0.16.0
BuildSizes returns the size file of a layer: a header, the blocks of 256 values in the order of the layer, each with a CRC-32 of its number and its values, and the SHA-256 of all of it. It returns nil when no value is known.
func DecodeSize ¶ added in v0.16.0
DecodeSize returns the size that v holds, and false when it is not known.
func EncodeSize ¶ added in v0.16.0
A size is stored as its value plus one in four bytes, and 0 means that it is not known, so an empty object and an object of more than 4 GiB less two bytes are both expressible.
func MergeGraphs ¶ added in v0.15.0
MergeGraphs returns the graph file that holds the commits of gs. A commit that two graphs hold takes the larger generation, because 0 means that it is not known.
func SizesBlockRange ¶ added in v0.16.0
SizesBlockRange returns the offset and length in the size file of block i of a layer of n records, with its CRC. The blocks are those of the layer file.
func SizesFileLen ¶ added in v0.16.0
SizesFileLen is the length of the size file of a layer of n records.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder assembles a layer from records in order.
func NewBuilder ¶
NewBuilder returns a Builder for a layer over packs with at most maxObjects records.
type Commit ¶ added in v0.15.0
Commit is what a walk of history needs of a commit: its tree, its parents and its commit time. Gen is the length of the longest path from the commit to a root, counting the commit, and 0 when it is not known.
type Dir ¶
Dir is the part of a layer that a reader keeps in memory: the pack list, the first record of each block, and the filter. A lookup reads one block of records from the object store.
func (*Dir) BlockRange ¶
BlockRange returns the offset and length of block i in the layer file.
func (*Dir) Lookup ¶
Lookup finds a record with name s, in the pack ord, or in any pack when ord is negative. A lookup reads at most one block.
func (*Dir) LookupMany ¶ added in v0.12.0
func (d *Dir) LookupMany(ctx context.Context, shas []SHA, fetch FetchMany) ([]Record, []bool, error)
LookupMany is Lookup of every name of shas in any pack. shas are sorted and distinct. It tests the filter and walks the block fences once for the whole list, and asks fetch for each needed block once.
func (*Dir) LookupManyPos ¶ added in v0.16.0
func (d *Dir) LookupManyPos(ctx context.Context, shas []SHA, fetch FetchMany) ([]Record, []bool, []int, error)
LookupManyPos is LookupMany that also returns the position of each record in the layer.
func (*Dir) MayContain ¶
MayContain is false when the filter proves that no record has the name s.
type Entry ¶
type Entry struct {
Key string `json:"k"`
Objects int `json:"n"`
// Bytes is the total size of the packs of the layer.
Bytes int64 `json:"b"`
// NPacks is the number of packs of the layer.
NPacks int `json:"np"`
// Size and Dir are the length of a layer file and of its directory tail. They are zero for an index layer.
Size int64 `json:"sz,omitempty"`
Dir int `json:"d,omitempty"`
// Packs lists the pack of an index layer.
Packs []Pack `json:"p,omitempty"`
// Class is ClassMeta or ClassBlob when every pack of the layer holds only that class of object, and empty when a
// pack may hold both.
Class string `json:"c,omitempty"`
// Graph is the key of the commit graph file of the layer, Commits the number of commits that it holds and GraphSize
// the length of the file. All three are empty for a layer that has no graph.
Graph string `json:"g,omitempty"`
Commits int `json:"gn,omitempty"`
GraphSize int64 `json:"gs,omitempty"`
// Sizes is the key of the size file of the layer: the inflated size of each of its records. A layer that has none
// has no key, and a release that does not know the field ignores it.
Sizes string `json:"z,omitempty"`
}
Entry is one layer of a manifest. A key that ends in ".idx" names the v2 index of one pack, which is a layer of one pack. A key under "midx/" names a layer file of this package.
type FetchMany ¶ added in v0.12.0
FetchMany returns the records of the blocks in idx, in the same order.
type Graph ¶ added in v0.15.0
type Graph struct {
// contains filtered or unexported fields
}
Graph is a parsed commit graph file. It holds the bytes of the file.
func ParseGraph ¶ added in v0.15.0
ParseGraph checks the structure and the checksum of a graph file before it trusts a byte of it.
type Iter ¶
Iter yields records in order. It returns false at the end.
type Layer ¶
type Layer struct {
Key string
Data []byte
// Dir is the length of the tail of Data that Parse reads.
Dir int
Objects int
// Sizes is the size file of the layer, and is nil when the builder knew no size.
Sizes []byte
}
Layer is a finished layer file.
func Merge ¶
func Merge(ctx context.Context, ins []Iter, packs []Pack, maxObjects int, remap func(in int, r Record) (Record, error)) (Layer, int, error)
Merge writes one layer over packs from the records of ins, in order. remap turns a record of input in into its record in the new layer, and its result must keep each input in order. maxObjects bounds the records of all inputs. It returns the number of records that the inputs gave, before it drops repeats, so a caller can check that none was lost.
type Manifest ¶
Manifest is the consistent set of layers of one repository, oldest layer first.
func DecodeManifest ¶
DecodeManifest reads the stored form.
type Pack ¶
type Pack struct {
ID string `json:"id"`
Bytes int64 `json:"b"`
Key string `json:"k,omitempty"`
Idx string `json:"i,omitempty"`
}
Pack names a pack of a layer: the hex SHA-256 of its bytes, and its size. Key and Idx are the bucket keys of the pack file and of its index file, below the prefix of the repository. A manifest written before the keys were recorded has neither, and the keys are then derived from the id.
type Plan ¶
type Plan struct{ Lo, Hi int }
Plan is a run of the newest layers to rewrite as one.
func PlanCompact ¶
PlanCompact picks the newest window of layers whose packs to rewrite as one pack, by pack bytes. The new pack has at most maxBytes and at most maxObjects objects, and the window holds at least two packs. A single layer that holds several packs, which merges of the index alone made, is a window.
func PlanMerge ¶
PlanMerge picks the newest window of layers to merge into one layer file, by object count. The merged layer holds at most maxObjects records and the window at most fanIn layers. A window whose packs hold more than compactBytes, with an average pack under half of it, is not merged: a layer that big is never compacted, so its small packs would stay.
type Record ¶
type Record struct {
SHA SHA
Ord uint32
Off uint32
// Size is the stored size of the object (see EncodeSize). The layer file does not hold it: the size file does.
Size uint32
}
Record places one object: the pack that holds it, as an index of the pack list of the layer, and its offset. A layer keeps a record for each copy of an object, ordered by name and then by pack number.
type Sizes ¶ added in v0.16.0
type Sizes struct {
// contains filtered or unexported fields
}
Sizes is a parsed size file.
func ParseSizes ¶ added in v0.16.0
ParseSizes checks a size file of a layer of n records before it trusts a byte of it.