storage

package
v0.35.27 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: BSD-3-Clause Imports: 38 Imported by: 0

Documentation

Overview

Package storage provides a configuration-driven registry for physical storage backends. Logical stores can build scoped views on top of these backend instances.

Index

Constants

View Source
const (
	KindBadger         = "badger"
	KindMemory         = "memory"
	KindFilesystemDir  = "filesystem.dir"
	KindSQLite         = "sqlite"
	KindPostgreSQL     = "postgresql"
	KindClickHouse     = "clickhouse"
	KindTiKV           = "tikv"
	KindRedis          = "redis"
	KindRedisReadWrite = "redis.readwrite"
	KindPrometheus     = "prometheus"
	KindVolcTLS        = "volc-tls"
	KindVolcTOS        = "volc-tos"
	KindAliyunOSS      = "aliyun-oss"
	KindGCS            = "gcs"
	KindAzureBlob      = "azure-blob"
)

Kind constants identify concrete physical storage backends in external configuration. Programmatic callers select a backend with the matching concrete Config implementation instead of setting a Kind field.

Variables

This section is empty.

Functions

func ValidateRedisURL added in v0.12.1

func ValidateRedisURL(raw string) error

ValidateRedisURL applies the same single-node URL and TLS requirements used when Storage opens Redis, without reading CA files or connecting to Redis.

func ValidateTiKVConfig added in v0.33.0

func ValidateTiKVConfig(cfg TiKVConfig) error

ValidateTiKVConfig checks addresses and read/TLS settings without network I/O.

Types

type AliyunOSSConfig added in v0.4.0

type AliyunOSSConfig struct {
	Endpoint        string
	Bucket          string
	AccessKeyID     string
	AccessKeySecret string
	SecurityToken   string
}

AliyunOSSConfig configures one Alibaba Cloud OSS bucket.

type AzureBlobConfig added in v0.4.0

type AzureBlobConfig struct {
	AccountURL string
	Container  string
}

AzureBlobConfig configures one Azure Blob Storage container.

type BadgerConfig

type BadgerConfig struct {
	Dir string
}

BadgerConfig configures one physical Badger database.

type ClickHouseConfig

type ClickHouseConfig struct {
	DSN string
}

ClickHouseConfig configures one ClickHouse connection pool.

type Config

type Config interface {
	// contains filtered or unexported methods
}

Config is a closed set of physical backend configurations accepted by New. Each implementation exposes only fields meaningful to that backend.

type ConfigError

type ConfigError struct {
	Name string
	Err  error
}

ConfigError identifies the physical storage entry whose construction failed.

func (*ConfigError) Error

func (e *ConfigError) Error() string

Error preserves the underlying construction error text.

func (*ConfigError) Unwrap

func (e *ConfigError) Unwrap() error

Unwrap exposes the underlying construction error.

type FilesystemDirConfig

type FilesystemDirConfig struct {
	Dir string
}

FilesystemDirConfig configures one rooted filesystem directory.

type GCSConfig added in v0.4.0

type GCSConfig struct {
	Bucket          string
	CredentialsFile string
}

GCSConfig configures one Google Cloud Storage bucket.

type Memory

type Memory struct{}

Memory marks a process-local physical slot. Logical Store constructors use the marker to create independent in-memory backends.

type MemoryConfig

type MemoryConfig struct{}

MemoryConfig declares a process-local Storage slot. It has no physical resource or configurable properties.

type PostgreSQLConfig

type PostgreSQLConfig struct {
	DSN             string
	MaxOpenConns    int
	ConnMaxIdleTime time.Duration
}

PostgreSQLConfig configures one PostgreSQL connection pool. The pool keeps up to MaxOpenConns idle sessions for reuse and releases idle sessions after ConnMaxIdleTime. Zero values select 128 connections and one minute; negative values are invalid. Additional connections are opened on demand.

type PrometheusConfig

type PrometheusConfig struct {
	RemoteWriteURL string
	QueryURL       string
	BearerToken    string
}

PrometheusConfig configures one Prometheus API client and its remote-write endpoint.

type RedisConfig added in v0.8.3

type RedisConfig struct {
	URL       string
	TLSCAFile string
}

RedisConfig configures one single-node Redis connection. TLSCAFile adds trusted PEM certificates for rediss URLs.

type RedisReadWriteConfig added in v0.31.9

type RedisReadWriteConfig struct {
	Read  RedisConfig
	Write RedisConfig
}

RedisReadWriteConfig configures independent Redis read and write connections. Both endpoints must address the same logical database in one replication group. The caller owns replication and a stable writable primary endpoint.

type SQLiteConfig

type SQLiteConfig struct {
	Dir string
	DSN string
}

SQLiteConfig configures one SQLite database using exactly one of Dir or DSN.

type Storage

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

Storage owns physical backend instances and configured memory markers.

func New

func New(configs map[string]Config) (*Storage, error)

New creates a Storage registry, validates every configured physical backend, and opens stateful resources. Process-local memory roots remain lazy because their concrete type is selected by the consuming Store contract. Dir fields are used as provided by the caller.

func (*Storage) AliyunOSS added in v0.4.0

func (s *Storage) AliyunOSS(name string) (*oss.Bucket, error)

AliyunOSS returns the named physical Alibaba Cloud OSS bucket client.

func (*Storage) AzureBlob added in v0.4.0

func (s *Storage) AzureBlob(name string) (*azblob.Client, string, error)

AzureBlob returns the named physical Azure Blob client and container.

func (*Storage) Badger

func (s *Storage) Badger(name string) (*badger.DB, error)

Badger returns the named physical Badger DB.

func (*Storage) Close

func (s *Storage) Close() error

Close releases all opened physical backends in reverse creation order.

func (*Storage) FilesystemDir

func (s *Storage) FilesystemDir(name string) (*os.Root, error)

FilesystemDir returns the named rooted filesystem handle.

func (*Storage) GCS added in v0.4.0

func (s *Storage) GCS(name string) (*gcs.Client, string, error)

GCS returns the named physical Google Cloud Storage client and bucket.

func (*Storage) Kind

func (s *Storage) Kind(name string) (string, error)

Kind returns the concrete kind of the named physical Storage.

func (*Storage) Memory

func (s *Storage) Memory(name string) (Memory, error)

Memory returns the named process-local marker.

func (*Storage) Prometheus

func (s *Storage) Prometheus(name string) (api.Client, string, error)

Prometheus returns the named API client and validated remote-write URL.

func (*Storage) Redis added in v0.8.3

func (s *Storage) Redis(name string) (*redis.Client, error)

Redis returns the named physical Redis client. The Storage registry owns the client and closes it with the other physical resources.

func (*Storage) RedisReadWrite added in v0.31.9

func (s *Storage) RedisReadWrite(name string) (read, write *redis.Client, err error)

RedisReadWrite returns the named read and write Redis clients, in that order. The Storage registry owns both clients and closes them with its other resources.

func (*Storage) SQL

func (s *Storage) SQL(name string) (*sqlx.DB, error)

SQL returns the named physical SQL backend.

func (*Storage) TiKV added in v0.33.0

func (s *Storage) TiKV(name string) (*tikv.KVStore, TiKVConfig, error)

TiKV returns a borrowed transactional client and its read configuration. Storage owns the client's lifetime. Returned configuration maps are copies.

func (*Storage) VolcTLS

func (s *Storage) VolcTLS(name string) (tls.Client, error)

VolcTLS returns the named physical Volc TLS SDK client.

func (*Storage) VolcTOS added in v0.4.0

func (s *Storage) VolcTOS(name string) (*tos.ClientV2, string, error)

VolcTOS returns the named physical Volcengine TOS client and bucket.

type TiKVConfig added in v0.33.0

type TiKVConfig struct {
	PDAddresses []string
	TLSCAFile   string
	TLSCertFile string
	TLSKeyFile  string
	// Deprecated: ignored. ReadLabels alone enables native Learner reads.
	// No fixed snapshot delay is applied.
	StaleReadDelay time.Duration
	ReadLabels     map[string]string
}

TiKVConfig configures a transactional TiKV cluster discovered through PD. ReadLabels restricts ordinary data reads to matching Learners using native replica-read synchronization. Empty labels keep ordinary reads strong. Strong reads and all mutations always use fresh leader transactions. TLS files apply to PD, its etcd endpoint, and TiKV RPCs.

type VolcTLSConfig

type VolcTLSConfig struct {
	Endpoint        string
	Region          string
	AccessKeyID     string
	AccessKeySecret string
}

VolcTLSConfig configures one Volcengine TLS SDK client.

type VolcTOSConfig added in v0.4.0

type VolcTOSConfig struct {
	Endpoint        string
	Region          string
	Bucket          string
	AccessKeyID     string
	AccessKeySecret string
	SessionToken    string
}

VolcTOSConfig configures one Volcengine TOS bucket.

Jump to

Keyboard shortcuts

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