Documentation
¶
Overview ¶
Package index manages content indices.
Index ¶
Constants ¶
const (
// Version1 identifies version 1 of the index, without content-level compression.
Version1 = 1
)
const (
// Version2 identifies version 2 of the index, supporting content-level compression.
Version2 = 2
)
Variables ¶
var AllIDs = IDRange{"", maxIDCharacterPlus1}
AllIDs is an IDRange that contains all valid IDs.
var AllNonPrefixedIDs = IDRange{"0", "g"}
AllNonPrefixedIDs is an IDRange that contains all valid IDs non-prefixed IDs ('0' .. 'f').
var AllPrefixedIDs = IDRange{"g", maxIDCharacterPlus1}
AllPrefixedIDs is an IDRange that contains all valid IDs prefixed IDs ('g' .. 'z').
var EmptyID = ID{} //nolint:gochecknoglobals
EmptyID represents empty content ID.
Functions ¶
This section is empty.
Types ¶
type Builder ¶
Builder prepares and writes content index.
func (Builder) Add ¶
Add adds a new entry to the builder or conditionally replaces it if the timestamp is greater.
func (Builder) BuildShards ¶
func (b Builder) BuildShards(indexVersion int, stable bool, shardSize int) ([]gather.Bytes, func(), error)
BuildShards builds the set of index shards ensuring no more than the provided number of contents are in each index. Returns shard bytes and function to clean up after the shards have been written.
func (Builder) BuildStable ¶
BuildStable writes the pack index to the provided output.
type BuilderCreator ¶ added in v0.18.0
type BuilderCreator interface {
Add(info Info)
}
BuilderCreator is an interface for caller to add indexes to builders.
type FormatV1 ¶
type FormatV1 struct { Version byte // format version number must be 0x01 KeySize byte // size of each key in bytes EntrySize uint16 // size of each entry in bytes, big-endian EntryCount uint32 // number of sorted (key,value) entries that follow Entries []struct { Key []byte // key bytes (KeySize) Entry []byte // entry bytes (EntrySize) } ExtraData []byte // extra data }
FormatV1 describes a format of a single pack index. The actual structure is not used, it's purely for documentation purposes. The struct is byte-aligned.
type FormatV2 ¶
type FormatV2 struct { Header struct { Version byte // format version number must be 0x02 KeySize byte // size of each key in bytes EntrySize uint16 // size of each entry in bytes, big-endian EntryCount uint32 // number of sorted (key,value) entries that follow EntriesOffset uint32 // offset where `Entries` begins FormatInfosOffset uint32 // offset where `Formats` begins NumFormatInfos uint32 PacksOffset uint32 // offset where `Packs` begins NumPacks uint32 BaseTimestamp uint32 // base timestamp in unix seconds } Entries []struct { Key []byte // key bytes (KeySize) Entry []byte // entry bytes (EntrySize) } // each entry contains offset+length of the name of the pack blob, so that each entry can refer to the index // and it resolves to a name. Packs []struct { PackNameLength byte // length of the filename PackNameOffset uint32 // offset to data (within extra data) } // each entry represents unique content format. Formats []indexV2FormatInfo ExtraData []byte // extra data }
FormatV2 describes a format of a single pack index. The actual structure is not used, it's purely for documentation purposes. The struct is byte-aligned.
type ID ¶
type ID struct {
// contains filtered or unexported fields
}
ID is an identifier of content in content-addressable storage.
func IDFromHash ¶ added in v0.11.0
IDFromHash constructs content ID from a prefix and a hash.
func (ID) AppendToLogBuffer ¶ added in v0.11.0
AppendToLogBuffer appends content ID to log buffer.
func (ID) MarshalJSON ¶ added in v0.11.0
MarshalJSON implements JSON serialization.
func (*ID) UnmarshalJSON ¶ added in v0.11.0
UnmarshalJSON implements JSON deserialization.
type IDPrefix ¶ added in v0.11.0
type IDPrefix string
IDPrefix represents a content ID prefix (empty string or single character between 'g' and 'z').
func (IDPrefix) ValidateSingle ¶ added in v0.11.0
ValidateSingle returns an error if a given prefix is invalid.
type IDRange ¶
IDRange represents a range of IDs.
func PrefixRange ¶
PrefixRange returns ID range that contains all IDs with a given prefix.
type Index ¶
type Index interface { io.Closer ApproximateCount() int GetInfo(contentID ID, result *Info) (bool, error) // invoked the provided callback for all entries such that entry.ID >= startID and entry.ID < endID Iterate(r IDRange, cb func(Info) error) error }
Index is a read-only index of packed contents.
type Info ¶
type Info struct { PackBlobID blob.ID `json:"packFile,omitempty"` TimestampSeconds int64 `json:"time"` OriginalLength uint32 `json:"originalLength"` PackedLength uint32 `json:"length"` PackOffset uint32 `json:"packOffset,omitempty"` CompressionHeaderID compression.HeaderID `json:"compression,omitempty"` ContentID ID `json:"contentID"` Deleted bool `json:"deleted"` FormatVersion byte `json:"formatVersion"` EncryptionKeyID byte `json:"encryptionKeyID,omitempty"` }
Info is an implementation of Info based on a structure.
type Merged ¶
type Merged []Index
Merged is an implementation of Index that transparently merges returns from underlying Indexes.
func (Merged) ApproximateCount ¶
ApproximateCount implements Index interface.
type OneUseBuilder ¶ added in v0.18.0
type OneUseBuilder struct {
// contains filtered or unexported fields
}
OneUseBuilder prepares and writes content index for epoch index compaction.
func NewOneUseBuilder ¶ added in v0.18.0
func NewOneUseBuilder() *OneUseBuilder
NewOneUseBuilder create a new instance of OneUseBuilder.
func (*OneUseBuilder) Add ¶ added in v0.18.0
func (b *OneUseBuilder) Add(i Info)
Add adds a new entry to the builder or conditionally replaces it if the timestamp is greater.
func (*OneUseBuilder) BuildShards ¶ added in v0.18.0
func (b *OneUseBuilder) BuildShards(indexVersion int, stable bool, shardSize int) ([]gather.Bytes, func(), error)
BuildShards builds the set of index shards ensuring no more than the provided number of contents are in each index. Returns shard bytes and function to clean up after the shards have been written.
func (*OneUseBuilder) BuildStable ¶ added in v0.18.0
func (b *OneUseBuilder) BuildStable(output io.Writer, version int) error
BuildStable writes the pack index to the provided output.
func (*OneUseBuilder) Length ¶ added in v0.18.0
func (b *OneUseBuilder) Length() int
Length returns the number of indexes in the current builder.