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
- type Builder
- 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) MayContain(s SHA) bool
- func (d *Dir) Resident() int
- func (d *Dir) Size() int64
- type Entry
- type Fetch
- type FetchMany
- type Iter
- type Layer
- type Manifest
- type Pack
- type Plan
- type ReadFunc
- type Record
- type SHA
Constants ¶
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 ErrCorrupt = errors.New("midx: corrupt layer")
Functions ¶
This section is empty.
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 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) 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"`
}
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 Layer ¶
type Layer struct {
Key string
Data []byte
// Dir is the length of the tail of Data that Parse reads.
Dir int
Objects int
}
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 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.