package engine import ( "context" "time" ) // Engine 是所有存储引擎必须实现的基础接口 type Engine interface { // 基本生命周期 Open() error Close() error // 数据操作 WritePoint(ctx context.Context, point DataPoint) error WriteBatch(ctx context.Context, points []DataPoint) error // 查询操作 Query(ctx context.Context, query Query) (QueryResult, error) // 管理操作 Flush() error Compact() error // 监控 Stats() EngineStats // 能力查询 Capabilities() EngineCapabilities } // PersistentEngine 提供持久化功能 type PersistentEngine interface { Engine Backup(path string) error Restore(path string) error } // ReplicatedEngine 提供复制功能 type ReplicatedEngine interface { Engine AddReplica(addr string) error RemoveReplica(addr string) error } // DataPoint 表示一个时间序列数据点 type DataPoint struct { DeviceID string `json:"device_id"` MetricCode string `json:"metric_code"` Labels map[string]string `json:"labels"` Value float64 `json:"value"` Timestamp int64 `json:"timestamp"` } // SeriesID 生成数据点的序列ID func (p *DataPoint) SeriesID() string { // 简单实现,实际可能需要更复杂的ID生成逻辑 return p.DeviceID + ":" + p.MetricCode } // EngineStats 包含引擎的统计信息 type EngineStats struct { PointsCount int64 SeriesCount int64 MemoryUsage int64 LastWriteTime time.Time LastCompactTime time.Time WriteLatency time.Duration QueryLatency time.Duration // 其他统计信息... } // EngineCapabilities 描述引擎支持的功能 type EngineCapabilities struct { SupportsCompression bool SupportsPersistence bool SupportsReplication bool MaxConcurrentWrites int // 其他能力指标... }