blob

package
v0.0.0-...-74fe3af Latest Latest
Warning

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

Go to latest
Published: May 18, 2025 License: BSD-3-Clause Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const MaxInlineHandleLength = 4 * binary.MaxVarintLen32

MaxInlineHandleLength is the maximum length of an inline blob handle.

Handle fields are varint encoded, so maximum 5 bytes each.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileFormat

type FileFormat uint8

FileFormat identifies the format of a blob file.

const (
	// FileFormatV1 is the first version of the blob file format.
	FileFormatV1 FileFormat = 1
)

func (FileFormat) String

func (f FileFormat) String() string

String implements the fmt.Stringer interface.

type FileReader

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

FileReader reads a blob file.

func NewFileReader

func NewFileReader(
	ctx context.Context, r objstorage.Readable, ro FileReaderOptions,
) (*FileReader, error)

NewFileReader opens a blob file for reading.

func (*FileReader) Close

func (r *FileReader) Close() error

Close implements io.Closer, closing the underlying Readable.

func (*FileReader) IndexHandle

func (r *FileReader) IndexHandle() block.Handle

IndexHandle returns the block handle for the file's index block.

func (*FileReader) InitReadHandle

InitReadHandle initializes a read handle for the file reader, using the provided preallocated read handle.

func (*FileReader) ReadIndexBlock

func (r *FileReader) ReadIndexBlock(
	ctx context.Context, env block.ReadEnv, rh objstorage.ReadHandle,
) (block.BufferHandle, error)

ReadIndexBlock reads the index block from the file.

func (*FileReader) ReadValueBlock

func (r *FileReader) ReadValueBlock(
	ctx context.Context, env block.ReadEnv, rh objstorage.ReadHandle, h block.Handle,
) (block.BufferHandle, error)

ReadValueBlock reads a value block from the file.

type FileReaderOptions

type FileReaderOptions struct {
	block.ReaderOptions
}

FileReaderOptions configures a reader of a blob file.

type FileWriter

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

A FileWriter writes a blob file.

func NewFileWriter

func NewFileWriter(fn base.DiskFileNum, w objstorage.Writable, opts FileWriterOptions) *FileWriter

NewFileWriter creates a new FileWriter.

func (*FileWriter) AddValue

func (w *FileWriter) AddValue(v []byte) Handle

AddValue adds the provided value to the blob file, returning a Handle identifying the location of the value.

func (*FileWriter) Close

func (w *FileWriter) Close() (FileWriterStats, error)

Close finishes writing the blob file.

func (*FileWriter) EstimatedSize

func (w *FileWriter) EstimatedSize() uint64

EstimatedSize returns an estimate of the disk space consumed by the blob file if it were closed now.

func (*FileWriter) FlushForTesting

func (w *FileWriter) FlushForTesting()

FlushForTesting flushes the current block to the write queue. Writers should generally not call FlushForTesting, and instead let the heuristics configured through FileWriterOptions handle flushing.

It's exposed so that tests can force flushes to construct blob files with arbitrary structures.

type FileWriterOptions

type FileWriterOptions struct {
	Compression   block.Compression
	ChecksumType  block.ChecksumType
	FlushGovernor block.FlushGovernor
	// Only CPUMeasurer.MeasureCPUBlobFileSecondary is used.
	CpuMeasurer base.CPUMeasurer
}

FileWriterOptions are used to configure the FileWriter.

type FileWriterStats

type FileWriterStats struct {
	BlockCount             uint32
	ValueCount             uint32
	UncompressedValueBytes uint64
	FileLen                uint64
}

FileWriterStats aggregates statistics about a blob file written by a FileWriter.

func (FileWriterStats) String

func (s FileWriterStats) String() string

String implements the fmt.Stringer interface.

type Handle

type Handle struct {
	FileNum       base.DiskFileNum
	BlockNum      uint32
	OffsetInBlock uint32
	ValueLen      uint32
}

Handle describes the location of a value stored within a blob file.

func (Handle) SafeFormat

func (h Handle) SafeFormat(w redact.SafePrinter, _ rune)

SafeFormat implements redact.SafeFormatter.

func (Handle) String

func (h Handle) String() string

String implements the fmt.Stringer interface.

type HandleSuffix

type HandleSuffix struct {
	BlockNum      uint32
	OffsetInBlock uint32
}

HandleSuffix is the suffix of an inline handle. It's decoded only when the value is being fetched from the blob file.

func DecodeHandleSuffix

func DecodeHandleSuffix(src []byte) HandleSuffix

DecodeHandleSuffix decodes the block number and offset in block from the encoded handle.

func (HandleSuffix) Encode

func (h HandleSuffix) Encode(b []byte) int

Encode encodes the handle suffix into the provided buffer, returning the number of bytes encoded.

type InlineHandle

type InlineHandle struct {
	InlineHandlePreface
	HandleSuffix
}

InlineHandle describes a handle as it is encoded within a sstable block. The inline handle does not encode the blob file number outright. Instead it encodes an index into the containing sstable's BlobReferences.

The inline handle is composed of two parts: a preface (InlineHandlePreface) and a suffix (HandleSuffix). The preface is eagerly decoded from the encoded handle when returning an InternalValue to higher layers. The remaining bits (the suffix) are decoded only when the value is being fetched from the blob file.

func (InlineHandle) Encode

func (h InlineHandle) Encode(b []byte) int

Encode encodes the inline handle into the provided buffer, returning the number of bytes encoded.

func (InlineHandle) SafeFormat

func (h InlineHandle) SafeFormat(w redact.SafePrinter, _ rune)

SafeFormat implements redact.SafeFormatter.

func (InlineHandle) String

func (h InlineHandle) String() string

String implements the fmt.Stringer interface.

type InlineHandlePreface

type InlineHandlePreface struct {
	ReferenceID ReferenceID
	ValueLen    uint32
}

InlineHandlePreface is the prefix of an inline handle. It's eagerly decoded when returning an InternalValue to higher layers.

func DecodeInlineHandlePreface

func DecodeInlineHandlePreface(src []byte) (InlineHandlePreface, []byte)

DecodeInlineHandlePreface decodes the blob reference index and value length from the beginning of a variable-width encoded InlineHandle.

type ReaderProvider

type ReaderProvider interface {
	// GetValueReader returns a ValueReader for the given file number.
	GetValueReader(ctx context.Context, fileNum base.DiskFileNum) (r ValueReader, closeFunc func(), err error)
}

A ReaderProvider is an interface that can be used to retrieve a ValueReader for a given file number.

type ReferenceID

type ReferenceID uint32

ReferenceID identifies a particular blob reference within a table. It's implemented as an index into the slice of the BlobReferences recorded in the manifest.

type ValueFetcher

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

A ValueFetcher retrieves values stored out-of-band in separate blob files. The ValueFetcher caches accessed file readers to avoid redundant file cache and block cache lookups when performing consecutive value retrievals.

A single ValueFetcher can be used to fetch values from multiple files, and it will internally cache readers for each file.

func (*ValueFetcher) Close

func (r *ValueFetcher) Close() error

Close closes the ValueFetcher and releases all cached readers. Once Close is called, the ValueFetcher is no longer usable.

func (*ValueFetcher) Fetch

func (r *ValueFetcher) Fetch(
	ctx context.Context, handle []byte, fileNum base.DiskFileNum, valLen uint32, buf []byte,
) (val []byte, callerOwned bool, err error)

Fetch returns the value, given the handle. Fetch must not be called after Close.

func (*ValueFetcher) Init

func (r *ValueFetcher) Init(rp ReaderProvider, env block.ReadEnv)

Init initializes the ValueFetcher.

type ValueReader

type ValueReader interface {
	// IndexHandle returns the handle for the file's index block.
	IndexHandle() block.Handle

	// InitReadHandle initializes a ReadHandle for the file, using the provided
	// preallocated read handle to avoid an allocation.
	InitReadHandle(rh *objstorageprovider.PreallocatedReadHandle) objstorage.ReadHandle

	// ReadValueBlock retrieves a value block described by the provided block
	// handle from the block cache, or reads it from the blob file if it's not
	// already cached.
	ReadValueBlock(context.Context, block.ReadEnv, objstorage.ReadHandle,
		block.Handle) (block.BufferHandle, error)

	// ReadIndexBlock retrieves the index block from the block cache, or reads
	// it from the blob file if it's not already cached.
	ReadIndexBlock(context.Context, block.ReadEnv, objstorage.ReadHandle) (block.BufferHandle, error)
}

A ValueReader is an interface defined over a file that can be used to read value blocks.

Jump to

Keyboard shortcuts

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