repository

package
v0.0.0-...-980bd36 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: Apache-2.0 Imports: 31 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package repository contains the code maintaining and creating a Klio repository

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyWALFile = errors.New("empty WAL file")

ErrEmptyWALFile is returned, together with os.ErrNotExist, when a WAL file exists but is empty. It lets callers tell an empty file, which can still be written, apart from a missing one.

View Source
var ErrInvalidEncryptedKeyFormat = errors.New("invalid encrypted key format")

ErrInvalidEncryptedKeyFormat is raised when the encrypted key is not valid.

View Source
var ErrInvalidNonceFormat = errors.New("invalid nonce format")

ErrInvalidNonceFormat is raised when the encryption nonce is not valid.

View Source
var ErrInvalidPassword = errors.New("invalid password")

ErrInvalidPassword is raised when the password is not valid.

View Source
var ErrInvalidSaltFormat = errors.New("invalid key salt format")

ErrInvalidSaltFormat is raised when the encryption key salt is not valid.

Functions

func FileExists

func FileExists(fs afero.Fs, fileName string) (bool, error)

FileExists checks if a file exists in a Afero-based FS.

func Initialize

func Initialize(options Options) error

Initialize initializes a new Klio repository.

func ValidatePathComponent

func ValidatePathComponent(component string) error

ValidatePathComponent validates each one of the paths that can be stored in a repository. Examples are the name of the cluster and the name of the WAL files.

func ValidateWalFileName

func ValidateWalFileName(name string) error

ValidateWalFileName checks if a file name can be a WAL file name.

Types

type Connection

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

Connection represent a local connection to a Klio repository.

func Open

func Open(options Options) (*Connection, error)

Open opens a connection to a repository.

func (*Connection) Close

func (*Connection) Close()

Close closes the connection to the repository.

func (*Connection) GetLatestWALFileForCluster

func (c *Connection) GetLatestWALFileForCluster(
	ctx context.Context,
	clusterName string,
) (string, error)

GetLatestWALFileForCluster gets the latest archived WAL for a certain cluster

func (*Connection) IsWALFileExisting

func (c *Connection) IsWALFileExisting(clusterName string, walName string) (bool, error)

IsWALFileExisting checks if a WAL file exists in the repository.

func (*Connection) NewDirectWriter

func (c *Connection) NewDirectWriter(opts WriterOptions) (*DirectWriter, error)

NewDirectWriter creates a non-atomic WAL writer that writes directly to the final WAL archive path. Use NewWriter when atomic semantics (write to `.partial`, rename on success) are required.

func (*Connection) NewWriter

func (c *Connection) NewWriter(opts WriterOptions) (*Writer, error)

NewWriter creates a new WAL file writer.

func (*Connection) SetFirstRequiredOnCluster

func (c *Connection) SetFirstRequiredOnCluster(ctx context.Context, clusterDirectory, firstWAL string) error

SetFirstRequiredOnCluster sets the first WAL that is required on a certain cluster and deletes all the WALs that are precedent to that.

func (*Connection) UnwrapBlock

func (c *Connection) UnwrapBlock(block []byte) ([]byte, error)

UnwrapBlock reads back a block, decompressing and decrypting it.

func (*Connection) WrapBlock

func (c *Connection) WrapBlock(block []byte, blockSize int) ([]byte, error)

WrapBlock protects a block encrypting and compressing it.

type DirectWriter

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

DirectWriter writes the Klio WAL file format (header + length-prefixed, compressed/encrypted blocks) directly to a WAL archive file, without the `.partial` + rename dance performed by Writer.

func (*DirectWriter) Close

func (w *DirectWriter) Close() error

Close flushes the buffer and closes the underlying file.

func (*DirectWriter) Flush

func (w *DirectWriter) Flush() error

Flush flushes all the buffers to disk and fsyncs it.

func (*DirectWriter) WriteBlock

func (w *DirectWriter) WriteBlock(ctx context.Context, data []byte) error

WriteBlock writes the WAL block to storage. The per-chunk wrap and write durations are accumulated and emitted as one observation per stage for the whole block, so they share the per-block granularity of the flush stage (one fsync per block).

type IncorrectWALNameError

type IncorrectWALNameError struct {
	WalName string
}

IncorrectWALNameError is raised when a WAL file name is not correct.

func NewIncorrectWALNameError

func NewIncorrectWALNameError(name string) *IncorrectWALNameError

NewIncorrectWALNameError creates a new NewIncorrectWALNameError structure.

func (*IncorrectWALNameError) Error

func (e *IncorrectWALNameError) Error() string

Error implements the error interface.

type InvalidRepositoryFileError

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

InvalidRepositoryFileError is raised when a string that will be used as a path contains invalid characters.

func (*InvalidRepositoryFileError) Error

Error implements the error interface.

type KlioRepositoryConfig

type KlioRepositoryConfig struct {
	Kind       string              `json:"kind"`
	APIVersion string              `json:"apiVersion"`
	Keys       []KlioRepositoryKey `json:"encryptionKeys"`
}

KlioRepositoryConfig is the structure of a Klio repository configuration file.

func (*KlioRepositoryConfig) RecoverMasterKey

func (c *KlioRepositoryConfig) RecoverMasterKey(password string) ([]byte, error)

RecoverMasterKey recovers the master key from the repository configuration.

type KlioRepositoryKey

type KlioRepositoryKey struct {
	Nonce      string `json:"nonce"`
	CipherText string `json:"cipherText"`
	Salt       string `json:"salt"`
	Iterations int    `json:"iterations"`
}

KlioRepositoryKey represent an encrypted Klio repository key.

func (*KlioRepositoryKey) RecoverMasterKey

func (c *KlioRepositoryKey) RecoverMasterKey(password string) ([]byte, error)

RecoverMasterKey recovers the master key from the repository configuration.

type Metrics

type Metrics struct {
	WalWrittenBytes       metric.Int64Counter
	WalWritten            metric.Int64Counter
	LatestWrittenTime     metric.Int64Gauge
	LatestWrittenLSN      metric.Int64Gauge
	LatestWrittenTimeline metric.Int64Gauge
	// BlockDuration is the per-block WAL stage duration histogram. It is only
	// set on the tier-1 server ingest path; the tier-2 consumer path leaves it
	// nil so that per-block observations are not emitted for tier-2.
	BlockDuration metric.Int64Histogram
	// Attributes are merged into every recording made through this Metrics.
	// Callers use this to attach tier="1" or tier="2" to the unified WAL
	// instruments depending on which side of the WAL pipeline they sit on.
	Attributes []attribute.KeyValue
}

Metrics holds OpenTelemetry metrics for the repository operations.

func (*Metrics) AttributeSet

func (m *Metrics) AttributeSet(extra ...attribute.KeyValue) attribute.Set

AttributeSet returns the canonical attribute.Set obtained by merging the per-recording extras onto the Metrics' base Attributes.

func (*Metrics) RecordBlockStage

func (m *Metrics) RecordBlockStage(
	ctx context.Context,
	clusterName string,
	path opentelemetry.Path,
	stage opentelemetry.Stage,
	d time.Duration,
	outcome opentelemetry.Outcome,
)

RecordBlockStage records a per-block WAL stage duration on the BlockDuration histogram. The storage tier is carried by the base Attributes; the cluster name, path, stage and outcome are added per call. The path distinguishes the ingest (put) and serve (get) flows, which share some stage names (e.g. send). It is a no-op when m itself is nil (writes that are not real WAL data, e.g. the retention policy file) or when BlockDuration is nil (e.g. the tier-2 consumer path, which has no per-block histogram).

type Options

type Options struct {
	FS       afero.Fs
	Password string
}

Options are the initialization options for a Klio repository.

type Reader

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

Reader is the WAL file writer.

func NewReader

func NewReader(
	conn *Connection,
	clusterName,
	walName string,
	metrics *Metrics,
) (*Reader, error)

NewReader creates a new WAL file reader. metrics may be nil to skip per-block duration recording (e.g. when reading non-WAL data such as cluster metadata).

func (*Reader) Close

func (r *Reader) Close() error

Close closes the file.

func (*Reader) GetFileLength

func (r *Reader) GetFileLength() uint64

GetFileLength gets the file length.

func (*Reader) ReadBlock

func (r *Reader) ReadBlock(ctx context.Context) ([]byte, error)

ReadBlock reads the next WAL block from the file, recording the per-block read and unwrap durations on the WAL duration histogram.

type Writer

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

Writer writes a WAL file atomically: data is written to a `.partial` file and renamed to the final path on CloseMarkDone.

func (*Writer) Close

func (w *Writer) Close() error

Close closes the writer without renaming the partial file.

func (*Writer) CloseMarkDone

func (w *Writer) CloseMarkDone() error

CloseMarkDone closes the WAL writer and marks the file as completed by renaming the partial file to its final path.

func (*Writer) Flush

func (w *Writer) Flush() error

Flush flushes all the buffers to disk and fsyncs the underlying file.

func (*Writer) WALFilePath

func (w *Writer) WALFilePath() string

WALFilePath returns the path of the WAL file being written.

func (*Writer) WriteBlock

func (w *Writer) WriteBlock(ctx context.Context, data []byte) error

WriteBlock writes the WAL block to storage.

type WriterOptions

type WriterOptions struct {
	// ClusterName is the name of the cluster the WAL file belongs to.
	ClusterName string

	// WALName is the name of the WAL segment being written.
	WALName string

	// SegmentSize is the length, in bytes, of the WAL segment.
	SegmentSize uint64

	// The LSN corresponding to the start of the WAL segment.
	WALStartLSN uint64

	// Metrics collects per-write metrics for this Writer.
	Metrics *Metrics

	// BufferSize is the size, in bytes, of the buffer placed in front of
	// the underlying file. When zero, defaultChunkSize is used.
	BufferSize int
}

WriterOptions configures a Writer.

Jump to

Keyboard shortcuts

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