header

package
v0.0.0-...-ba108f2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 15, 2026 License: Apache-2.0 Imports: 18 Imported by: 17

Documentation

Index

Constants

View Source
const (
	PageSize        = 4 << 10 // 4 KiB
	HugepageSize    = 2 << 20 // 2 MiB
	RootfsBlockSize = 4 << 10 // 4 KiB
)
View Source
const (
	SkippedBlockChar = '░'
	DirtyBlockChar1  = '▓'
	DirtyBlockChar2  = '█'
)
View Source
const NormalizeFixVersion = 3

Variables

View Source
var (
	EmptyHugePage = make([]byte, HugepageSize)
	EmptyBlock    = make([]byte, RootfsBlockSize)
)

Functions

func BlockCeilIdx

func BlockCeilIdx(off, blockSize int64) int64

BlockCeilIdx returns the index of the first block after byte offset off (ceiling division).

func BlockIdx

func BlockIdx(off, blockSize int64) int64

BlockIdx returns the index of the block containing byte offset off (floor division).

func BlockOffset

func BlockOffset(idx, blockSize int64) int64

func BlocksOffsets

func BlocksOffsets(size, blockSize int64) []int64

func Equal

func Equal(a, b []BuildMap) bool

func IsEmptyBlock

func IsEmptyBlock(block []byte, blockSize int64) (bool, error)

func Layers

func Layers(mappings []BuildMap) *map[uuid.UUID]struct{}

Layers returns a map of buildIds that are present in the mappings.

func Serialize

func Serialize(metadata *Metadata, mappings []BuildMap) ([]byte, error)

func TotalBlocks

func TotalBlocks(size, blockSize int64) int64

func ValidateMappings

func ValidateMappings(mappings []BuildMap, size, blockSize uint64) error

ValidateMappings validates the mappings. It is used to check if the mappings are valid.

It checks if the mappings are contiguous and if the length of each mapping is a multiple of the block size. It also checks if the mappings cover the whole size.

func Visualize

func Visualize(mappings []BuildMap, size, blockSize, cols uint64, bottomGroup, topGroup *map[uuid.UUID]struct{}) string

Visualize returns a string representation of the mappings as a grid of blocks. It is used for debugging and visualization.

You can pass maps to visualize different groups of buildIds.

Types

type BuildMap

type BuildMap struct {
	// Offset defines which block of the current layer this mapping starts at
	Offset             uint64
	Length             uint64
	BuildId            uuid.UUID
	BuildStorageOffset uint64
}

Start, Length and SourceStart are in bytes of the data file Length will be a multiple of BlockSize The list of block mappings will be in order of increasing Start, covering the entire file

func CreateMapping

func CreateMapping(
	buildId *uuid.UUID,
	dirty *roaring.Bitmap,
	blockSize int64,
) []BuildMap

func MergeMappings

func MergeMappings(
	baseMapping []BuildMap,
	diffMapping []BuildMap,
) []BuildMap

MergeMappings merges two sets of mappings.

The mapping are stored in a sorted order. The baseMapping must cover the whole size.

It returns a new set of mappings that covers the whole size.

func NormalizeMappings

func NormalizeMappings(mappings []BuildMap) []BuildMap

NormalizeMappings joins adjacent mappings that have the same buildId.

func (BuildMap) Equal

func (mapping BuildMap) Equal(other BuildMap) bool

func (BuildMap) Format

func (mapping BuildMap) Format(blockSize uint64) string

Format returns a string representation of the mapping as:

startBlock-endBlock [offset, offset+length) := [buildStorageOffset, buildStorageOffset+length) ⊂ buildId, length in bytes

It is used for debugging and visualization.

type DiffMetadata

type DiffMetadata struct {
	Dirty *roaring.Bitmap
	Empty *roaring.Bitmap

	BlockSize int64
}

func NewDiffMetadata

func NewDiffMetadata(blockSize int64, dirty *roaring.Bitmap) *DiffMetadata

func (*DiffMetadata) ToDiffHeader

func (d *DiffMetadata) ToDiffHeader(
	ctx context.Context,
	originalHeader *Header,
	buildID uuid.UUID,
) (h *Header, e error)

type DiffMetadataBuilder

type DiffMetadataBuilder struct {
	// contains filtered or unexported fields
}

func NewDiffMetadataBuilder

func NewDiffMetadataBuilder(blockSize int64) *DiffMetadataBuilder

func (*DiffMetadataBuilder) Build

func (b *DiffMetadataBuilder) Build() *DiffMetadata

func (*DiffMetadataBuilder) Process

func (b *DiffMetadataBuilder) Process(ctx context.Context, block []byte, out io.Writer, offset int64) error
type Header struct {
	Metadata *Metadata
	Mapping  []BuildMap
}

func Deserialize

func Deserialize(ctx context.Context, in storage.Blob) (*Header, error)

func DeserializeBytes

func DeserializeBytes(data []byte) (*Header, error)

func NewHeader

func NewHeader(metadata *Metadata, mapping []BuildMap) (*Header, error)

func (*Header) GetShiftedMapping

func (t *Header) GetShiftedMapping(ctx context.Context, offset int64) (mappedOffset int64, mappedLength int64, buildID *uuid.UUID, err error)

func (*Header) IsNormalizeFixApplied

func (t *Header) IsNormalizeFixApplied() bool

IsNormalizeFixApplied is a helper method to soft fail for older versions of the header where fix for normalization was not applied. This should be removed in the future.

type Metadata

type Metadata struct {
	Version    uint64
	BlockSize  uint64
	Size       uint64
	Generation uint64
	BuildId    uuid.UUID
	// TODO: Use the base build id when setting up the snapshot rootfs
	BaseBuildId uuid.UUID
}

func NewTemplateMetadata

func NewTemplateMetadata(buildId uuid.UUID, blockSize, size uint64) *Metadata

func (*Metadata) NextGeneration

func (m *Metadata) NextGeneration(buildID uuid.UUID) *Metadata

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL