metadata

package
v0.0.0-...-8909e19 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package metadata 提供全局元数据管理。

Manager 是聚合入口,统一管理 Catalog、SeriesStore 和 ShardIndex 三个子系统。

Index

Constants

View Source
const (
	FieldTypeFloat64ID = 1
	FieldTypeInt64ID   = 2
	FieldTypeStringID  = 3
	FieldTypeBoolID    = 4
)

字段类型 ID 常量(用于 FieldDef.Type)。

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheConfig

type CacheConfig struct {
	TagsMaxEntries            int
	HashSIDMaxEntries         int
	HashSIDAdaptiveMaxEntries int
	ActiveSeriesWindowNanos   int64
}

CacheConfig 控制 metadata 热路径缓存容量。

type Catalog

type Catalog interface {
	CreateDatabase(name string) error
	DropDatabase(name string) error
	ListDatabases() []string
	DatabaseExists(name string) bool

	CreateMeasurement(database, name string) error
	DropMeasurement(database, name string) error
	ListMeasurements(database string) ([]string, error)
	MeasurementExists(database, name string) bool

	GetSchema(database, measurement string) (*Schema, error)
	SetSchema(database, measurement string, s *Schema) error

	GetRetention(database, measurement string) (time.Duration, error)
	SetRetention(database, measurement string, d time.Duration) error

	GetDatabaseRetention(database string) (time.Duration, error)
	SetDatabaseRetention(database string, d time.Duration) error

	GetDownsampleConfig(database string) (*types.DownsampleConfig, error)
	SetDownsampleConfig(database string, cfg *types.DownsampleConfig) error
}

Catalog 管理 database 和 measurement 的目录结构。

type FieldDef

type FieldDef struct {
	Name     string `json:"name"`
	Type     int32  `json:"type"`
	Nullable bool   `json:"nullable,omitempty"`
	Default  string `json:"default,omitempty"`
}

FieldDef 定义单个字段的属性。

type Manager

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

Manager 是所有元数据子系统的聚合入口。

func NewManager

func NewManager(dataDir string) (*Manager, error)

NewManager 创建新的 Manager 实例,打开或创建 metadata.db。

func NewManagerWithCacheConfig

func NewManagerWithCacheConfig(dataDir string, cacheCfg CacheConfig) (*Manager, error)

NewManagerWithCacheConfig 创建带 metadata cache 配置的 Manager。

func (*Manager) Catalog

func (m *Manager) Catalog() Catalog

Catalog 返回 Catalog 子系统。

func (*Manager) Close

func (m *Manager) Close() error

Close 关闭 bbolt 数据库(仅一次)。

func (*Manager) GetOrCreateSeriesStore

func (m *Manager) GetOrCreateSeriesStore(db, meas string) *MeasSeriesStore

GetOrCreateSeriesStore 创建绑定 db/meas 的 MeasSeriesStore,供 ShardManager 使用。

func (*Manager) ListAllDatabases

func (m *Manager) ListAllDatabases() []string

ListAllDatabases 返回所有数据库名称。

func (*Manager) ListMeasurements

func (m *Manager) ListMeasurements(database string) ([]string, error)

ListMeasurements 返回指定数据库下的所有 measurement。

func (*Manager) Load

func (m *Manager) Load() error

Load 从 bbolt 重建 series 和 catalog 内存缓存。

func (*Manager) Series

func (m *Manager) Series() SeriesStore

Series 返回 SeriesStore 子系统。

func (*Manager) Shards

func (m *Manager) Shards() ShardIndex

Shards 返回 ShardIndex 子系统。

func (*Manager) Sync

func (m *Manager) Sync() error

Sync 强制 fsync bbolt 数据库。

type MeasSeriesStore

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

MeasSeriesStore 将 SeriesStore 绑定到特定 database/measurement, 实现 shard.SeriesStore 接口(AllocateSID 和 GetTagsBySID 无 db/meas 参数)。

func NewMeasSeriesStore

func NewMeasSeriesStore(store *seriesStore, db, meas string) *MeasSeriesStore

NewMeasSeriesStore 创建绑定到指定 db/meas 的 MeasSeriesStore。

func (*MeasSeriesStore) AllocateSID

func (a *MeasSeriesStore) AllocateSID(tags map[string]string) (uint64, error)

AllocateSID 为 tags 分配 SID。

func (*MeasSeriesStore) GetTagsBySID

func (a *MeasSeriesStore) GetTagsBySID(sid uint64) (map[string]string, bool)

GetTagsBySID 根据 SID 获取 tags。

type Schema

type Schema struct {
	Version   int64      `json:"version"`
	Fields    []FieldDef `json:"fields"`
	TagKeys   []string   `json:"tag_keys"`
	UpdatedAt int64      `json:"updated_at"`
}

Schema 定义 Measurement 的字段和标签结构。

type SeriesStore

type SeriesStore interface {
	AllocateSID(database, measurement string, tags map[string]string) (uint64, error)
	GetTags(database, measurement string, sid uint64) (map[string]string, bool)
	GetSIDsByTag(database, measurement string, tagKey, tagValue string) []uint64
	SeriesCount(database, measurement string) int
}

SeriesStore 管理 Series ID 分配和标签索引。

type ShardIndex

type ShardIndex interface {
	RegisterShard(database, measurement string, info ShardInfo) error
	UnregisterShard(database, measurement string, shardID string) error
	QueryShards(database, measurement string, startTime, endTime int64) []ShardInfo
	ListShards(database, measurement string) []ShardInfo
	UpdateShardStats(database, measurement, shardID string, sstableCount int, totalSize int64) error
}

ShardIndex 管理 Shard 时间范围索引。

type ShardInfo

type ShardInfo struct {
	ID           string `json:"id"`
	StartTime    int64  `json:"start_time"`
	EndTime      int64  `json:"end_time"`
	DataDir      string `json:"data_dir"`
	SSTableCount int    `json:"sstable_count"`
	TotalSize    int64  `json:"total_size"`
	CreatedAt    int64  `json:"created_at"`
}

ShardInfo 描述单个 Shard 的元数据。

type SimpleSchemaStore

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

SimpleSchemaStore 是纯内存的 Schema 存储,供外部测试使用。

func NewSimpleSchemaStore

func NewSimpleSchemaStore() *SimpleSchemaStore

NewSimpleSchemaStore 创建纯内存 SchemaStore。

func (*SimpleSchemaStore) GetSchema

func (s *SimpleSchemaStore) GetSchema(db, measurement string) (*Schema, error)

GetSchema 获取 schema。

func (*SimpleSchemaStore) SetSchema

func (s *SimpleSchemaStore) SetSchema(db, measurement string, schema *Schema) error

SetSchema 设置 schema。

type SimpleSeriesStore

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

SimpleSeriesStore 是纯内存的 Series 存储,供外部测试使用。 实现 shard.SeriesStore 接口(AllocateSID + GetTags)。

func NewSimpleSeriesStore

func NewSimpleSeriesStore() *SimpleSeriesStore

NewSimpleSeriesStore 创建纯内存 SeriesStore。

func (*SimpleSeriesStore) AllocateSID

func (s *SimpleSeriesStore) AllocateSID(database, measurement string, tags map[string]string) (uint64, error)

AllocateSID 分配或查找 SID。

func (*SimpleSeriesStore) GetTags

func (s *SimpleSeriesStore) GetTags(database, measurement string, sid uint64) (map[string]string, bool)

GetTags 根据 SID 获取 tags(返回防御性拷贝)。

Jump to

Keyboard shortcuts

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