Documentation
¶
Overview ¶
Package repository contains the code maintaining and creating a Klio repository
Index ¶
- Variables
- func FileExists(fs afero.Fs, fileName string) (bool, error)
- func Initialize(options Options) error
- func ValidatePathComponent(component string) error
- func ValidateWalFileName(name string) error
- type Connection
- func (*Connection) Close()
- func (c *Connection) GetLatestWALFileForCluster(ctx context.Context, clusterName string) (string, error)
- func (c *Connection) IsWALFileExisting(clusterName string, walName string) (bool, error)
- func (c *Connection) NewDirectWriter(opts WriterOptions) (*DirectWriter, error)
- func (c *Connection) NewWriter(opts WriterOptions) (*Writer, error)
- func (c *Connection) SetFirstRequiredOnCluster(ctx context.Context, clusterDirectory, firstWAL string) error
- func (c *Connection) UnwrapBlock(block []byte) ([]byte, error)
- func (c *Connection) WrapBlock(block []byte, blockSize int) ([]byte, error)
- type DirectWriter
- type IncorrectWALNameError
- type InvalidRepositoryFileError
- type KlioRepositoryConfig
- type KlioRepositoryKey
- type Metrics
- type Options
- type Reader
- type Writer
- type WriterOptions
Constants ¶
This section is empty.
Variables ¶
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.
var ErrInvalidEncryptedKeyFormat = errors.New("invalid encrypted key format")
ErrInvalidEncryptedKeyFormat is raised when the encrypted key is not valid.
var ErrInvalidNonceFormat = errors.New("invalid nonce format")
ErrInvalidNonceFormat is raised when the encryption nonce is not valid.
var ErrInvalidPassword = errors.New("invalid password")
ErrInvalidPassword is raised when the password is not valid.
var ErrInvalidSaltFormat = errors.New("invalid key salt format")
ErrInvalidSaltFormat is raised when the encryption key salt is not valid.
Functions ¶
func FileExists ¶
FileExists checks if a file exists in a Afero-based FS.
func Initialize ¶
Initialize initializes a new Klio repository.
func ValidatePathComponent ¶
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 ¶
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.
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 ¶
func (e *InvalidRepositoryFileError) Error() string
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 ¶
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 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) GetFileLength ¶
GetFileLength gets the file length.
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) CloseMarkDone ¶
CloseMarkDone closes the WAL writer and marks the file as completed by renaming the partial file to its final path.
func (*Writer) WALFilePath ¶
WALFilePath returns the path of the WAL file being written.
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.