Documentation
¶
Overview ¶
Package metadata 提供全局元数据管理。
Manager 是聚合入口,统一管理 Catalog、SeriesStore 和 ShardIndex 三个子系统。
Index ¶
- Constants
- type CacheConfig
- type Catalog
- type FieldDef
- type Manager
- func (m *Manager) Catalog() Catalog
- func (m *Manager) Close() error
- func (m *Manager) GetOrCreateSeriesStore(db, meas string) *MeasSeriesStore
- func (m *Manager) ListAllDatabases() []string
- func (m *Manager) ListMeasurements(database string) ([]string, error)
- func (m *Manager) Load() error
- func (m *Manager) Series() SeriesStore
- func (m *Manager) Shards() ShardIndex
- func (m *Manager) Sync() error
- type MeasSeriesStore
- type Schema
- type SeriesStore
- type ShardIndex
- type ShardInfo
- type SimpleSchemaStore
- type SimpleSeriesStore
Constants ¶
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 ¶
NewManager 创建新的 Manager 实例,打开或创建 metadata.db。
func NewManagerWithCacheConfig ¶
func NewManagerWithCacheConfig(dataDir string, cacheCfg CacheConfig) (*Manager, error)
NewManagerWithCacheConfig 创建带 metadata cache 配置的 Manager。
func (*Manager) GetOrCreateSeriesStore ¶
func (m *Manager) GetOrCreateSeriesStore(db, meas string) *MeasSeriesStore
GetOrCreateSeriesStore 创建绑定 db/meas 的 MeasSeriesStore,供 ShardManager 使用。
func (*Manager) ListAllDatabases ¶
ListAllDatabases 返回所有数据库名称。
func (*Manager) ListMeasurements ¶
ListMeasurements 返回指定数据库下的所有 measurement。
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。
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。
Source Files
¶
- bbolt_util.go
- cache_config.go
- cache_order.go
- catalog.go
- catalog_config.go
- catalog_impl.go
- catalog_measurement.go
- hash_cache.go
- manager.go
- schema_simple.go
- series.go
- series_batch.go
- series_cache.go
- series_impl.go
- series_last_seen_queue.go
- series_query.go
- series_simple.go
- series_write_tx.go
- shard_index.go
- shard_index_impl.go