Help us shape the future of Go! Take the 2026 Go Developer Survey

storage

package
v2.10.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: MIT Imports: 25 Imported by: 1

Documentation

Index

Constants

View Source
const DefaultWriteTimeout = 10 * time.Second

DefaultWriteTimeout is the default timeout for a complete write to succeed.

Variables

View Source
var (
	// ErrEngineClosed is returned when a caller attempts to use the engine while
	// it's closed.
	ErrEngineClosed = errors.New("engine is closed")

	// ErrNotImplemented is returned for APIs that are temporarily not implemented.
	ErrNotImplemented = errors.New("not implemented")
)

Functions

This section is empty.

Types

type BucketFinder

type BucketFinder interface {
	FindBuckets(context.Context, influxdb.BucketFilter, ...influxdb.FindOptions) ([]*influxdb.Bucket, int, error)
}

A BucketFinder is responsible for providing access to buckets via a filter.

type BucketService

type BucketService struct {
	influxdb.BucketService
	// contains filtered or unexported fields
}

BucketService wraps an existing influxdb.BucketService implementation.

BucketService ensures that when a bucket is deleted, all stored data associated with the bucket is either removed, or marked to be removed via a future compaction.

func NewBucketService

func NewBucketService(log *zap.Logger, s influxdb.BucketService, engine EngineSchema) *BucketService

NewBucketService returns a new BucketService for the provided EngineSchema, which typically will be an Engine.

func (*BucketService) CreateBucket

func (s *BucketService) CreateBucket(ctx context.Context, b *influxdb.Bucket) (err error)

func (*BucketService) DeleteBucket

func (s *BucketService) DeleteBucket(ctx context.Context, bucketID platform.ID) error

DeleteBucket removes a bucket by ID.

func (*BucketService) UpdateBucket

func (s *BucketService) UpdateBucket(ctx context.Context, id platform.ID, upd influxdb.BucketUpdate) (b *influxdb.Bucket, err error)

type Config

type Config struct {
	Data         tsdb.Config
	WriteTimeout time.Duration

	RetentionService retention.Config
	PrecreatorConfig precreator.Config
}

Config holds the configuration for an Engine.

func NewConfig

func NewConfig() Config

NewConfig initialises a new config for an Engine.

type Engine

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

func NewEngine

func NewEngine(path string, c Config, options ...Option) (*Engine, error)

NewEngine initialises a new storage engine, including a series file, index and TSM engine.

func (*Engine) BackupKVStore

func (e *Engine) BackupKVStore(ctx context.Context, w io.Writer) error

func (*Engine) BackupShard

func (e *Engine) BackupShard(ctx context.Context, w io.Writer, shardID uint64, since time.Time) error

func (*Engine) Close

func (e *Engine) Close() error

Close closes the store and all underlying resources. It returns an error if any of the underlying systems fail to close.

func (*Engine) CreateBucket

func (e *Engine) CreateBucket(ctx context.Context, b *influxdb.Bucket) (err error)

func (*Engine) DeleteBucket

func (e *Engine) DeleteBucket(ctx context.Context, orgID, bucketID platform.ID) error

DeleteBucket deletes an entire bucket from the storage engine.

func (*Engine) DeleteBucketRangePredicate

func (e *Engine) DeleteBucketRangePredicate(ctx context.Context, orgID, bucketID platform.ID, min, max int64, pred influxdb.Predicate, measurement influxql.Expr) error

DeleteBucketRangePredicate deletes data within a bucket from the storage engine. Any data deleted must be in [min, max], and the key must match the predicate if provided.

func (*Engine) DisableCompactions

func (e *Engine) DisableCompactions()

DisableCompactions disables compactions in the series file, index, & engine.

func (*Engine) EnableCompactions

func (e *Engine) EnableCompactions()

EnableCompactions allows the series file, index, & underlying engine to compact.

func (*Engine) MetaClient

func (e *Engine) MetaClient() MetaClient

func (*Engine) Open

func (e *Engine) Open(ctx context.Context) (err error)

Open opens the store and all underlying resources. It returns an error if any of the underlying systems fail to open.

func (*Engine) Path

func (e *Engine) Path() string

Path returns the path of the engine's base directory.

func (*Engine) PrometheusCollectors

func (e *Engine) PrometheusCollectors() []prometheus.Collector

PrometheusCollectors returns all the prometheus collectors associated with the engine and its components.

func (*Engine) RLockKVStore added in v2.1.0

func (e *Engine) RLockKVStore()

RLockKVStore locks the KV store as well as the engine in preparation for doing a backup.

func (*Engine) RUnlockKVStore added in v2.1.0

func (e *Engine) RUnlockKVStore()

RUnlockKVStore unlocks the KV store & engine, intended to be used after a backup is complete.

func (*Engine) RestoreBucket

func (e *Engine) RestoreBucket(ctx context.Context, id platform.ID, buf []byte) (map[uint64]uint64, error)

func (*Engine) RestoreKVStore

func (e *Engine) RestoreKVStore(ctx context.Context, r io.Reader) error

func (*Engine) RestoreShard

func (e *Engine) RestoreShard(ctx context.Context, shardID uint64, r io.Reader) error

func (*Engine) SeriesCardinality

func (e *Engine) SeriesCardinality(ctx context.Context, bucketID platform.ID) int64

SeriesCardinality returns the number of series in the engine.

func (*Engine) TSDBStore

func (e *Engine) TSDBStore() TSDBStore

func (*Engine) UpdateBucketRetentionPolicy added in v2.0.5

func (e *Engine) UpdateBucketRetentionPolicy(ctx context.Context, bucketID platform.ID, upd *influxdb.BucketUpdate) error

func (*Engine) WithLogger

func (e *Engine) WithLogger(log *zap.Logger)

WithLogger sets the logger on the Store. It must be called before Open.

func (*Engine) WithStartupMetrics added in v2.10.0

func (e *Engine) WithStartupMetrics(sp ShardLoadingProgressMetrics)

WithStartupMetrics wires a shard-loading progress observer into the underlying tsdb.Store. Callers that want to surface progress (e.g. as a /ready check) construct and own the observer; the Engine just forwards the hook.

func (*Engine) WritePoints

func (e *Engine) WritePoints(ctx context.Context, orgID platform.ID, bucketID platform.ID, points []models.Point) error

WritePoints writes the provided points to the engine.

The Engine expects all points to have been correctly validated by the caller. However, WritePoints will determine if any tag key-pairs are missing, or if there are any field type conflicts. Rosalie was here lockdown 2020

Appropriate errors are returned in those cases.

type EngineSchema

type EngineSchema interface {
	CreateBucket(context.Context, *influxdb.Bucket) error
	UpdateBucketRetentionPolicy(context.Context, platform.ID, *influxdb.BucketUpdate) error
	DeleteBucket(context.Context, platform.ID, platform.ID) error
}

type LoggingPointsWriter

type LoggingPointsWriter struct {
	// Wrapped points writer. Errored writes from here will be logged.
	Underlying PointsWriter

	// Service used to look up logging bucket.
	BucketFinder BucketFinder

	// Name of the bucket to log to.
	LogBucketName string
}

LoggingPointsWriter wraps an underlying points writer but writes logs to another bucket when an error occurs.

func (*LoggingPointsWriter) WritePoints

func (w *LoggingPointsWriter) WritePoints(ctx context.Context, orgID platform.ID, bucketID platform.ID, p []models.Point) error

WritePoints writes points to the underlying PointsWriter. Logs on error.

type MetaClient

type MetaClient interface {
	CreateDatabaseWithRetentionPolicy(name string, spec *meta.RetentionPolicySpec) (*meta.DatabaseInfo, error)
	DropDatabase(name string) error
	CreateShardGroup(database, policy string, timestamp time.Time) (*meta.ShardGroupInfo, error)
	Database(name string) (di *meta.DatabaseInfo)
	DropShard(id uint64) error
	Databases() []meta.DatabaseInfo
	DeleteShardGroup(database, policy string, id uint64) error
	PrecreateShardGroups(now, cutoff time.Time) error
	PruneShardGroups() error
	RetentionPolicy(database, policy string) (*meta.RetentionPolicyInfo, error)
	ShardGroupsByTimeRange(database, policy string, min, max time.Time) (a []meta.ShardGroupInfo, err error)
	UpdateRetentionPolicy(database, name string, rpu *meta.RetentionPolicyUpdate, makeDefault bool) error
	RLock()
	RUnlock()
	Backup(ctx context.Context, w io.Writer) error
	Restore(ctx context.Context, r io.Reader) error
	Data() meta.Data
	SetData(data *meta.Data) error
}

type Option

type Option func(*Engine)

Option provides a set

func WithMetaClient

func WithMetaClient(c MetaClient) Option

func WithMetricsDisabled added in v2.2.0

func WithMetricsDisabled(m bool) Option

type PointsWriter

type PointsWriter interface {
	WritePoints(ctx context.Context, orgID platform.ID, bucketID platform.ID, points []models.Point) error
}

PointsWriter describes the ability to write points into a storage engine.

type ShardLoadingProgressMetrics added in v2.10.0

type ShardLoadingProgressMetrics interface {
	AddShard()
	CompletedShard()
	ShardLoadFailed(shardID uint64, err error)
}

ShardLoadingProgressMetrics observes shard loading during tsdb.Store startup. Implementations record total shards via AddShard (once per shard found before loading begins) and report each completed shard via CompletedShard.

type TSDBStore

type TSDBStore interface {
	DeleteMeasurement(ctx context.Context, database, name string) error
	DeleteSeries(ctx context.Context, database string, sources []influxql.Source, condition influxql.Expr) error
	MeasurementNames(ctx context.Context, auth query.Authorizer, database string, cond influxql.Expr) ([][]byte, error)
	ShardGroup(ids []uint64) tsdb.ShardGroup
	Shards(ids []uint64) []*tsdb.Shard
	TagKeys(ctx context.Context, auth query.Authorizer, shardIDs []uint64, cond influxql.Expr) ([]tsdb.TagKeys, error)
	TagValues(ctx context.Context, auth query.Authorizer, shardIDs []uint64, cond influxql.Expr) ([]tsdb.TagValues, error)
	SeriesCardinality(ctx context.Context, database string) (int64, error)
	SeriesCardinalityFromShards(ctx context.Context, shards []*tsdb.Shard) (*tsdb.SeriesIDSet, error)
	SeriesFile(database string) *tsdb.SeriesFile
}

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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