storage

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BucketValues          = "values"
	BucketRuleState       = "RuleState"
	BucketDataCache       = "DataCache"
	BucketWindow          = "WindowData"
	BucketNorthboundCache = "NorthboundCache"
)
View Source
const (
	BucketConfigVersion  = "ConfigVersion"
	BucketChannels       = "Channels"
	BucketDevices        = "Devices"
	BucketNorthbound     = "Northbound"
	BucketEdgeRules      = "EdgeRules"
	BucketSystem         = "System"
	BucketUsers          = "Users"
	BucketServer         = "Server"
	BucketVirtualShadows = "VirtualShadows"
	ConfigVersionKey     = "version"
	ConfigVersionValue   = "1.0"
)

Variables

This section is empty.

Functions

func BackupDB

func BackupDB(dbPath, backupDir string) (*model.BackupInfo, error)

BackupDB 将指定数据库文件备份到目标目录,返回备份信息。 用于配置库 / 运行库的备份能力。

func IsConfigBucket

func IsConfigBucket(name string) bool

func RestoreDB

func RestoreDB(backupPath, targetPath string) error

RestoreDB 将备份文件恢复到目标数据库路径。

Types

type BucketStats

type BucketStats struct {
	Name        string `json:"name"`
	RecordCount int    `json:"record_count"`
	TotalSize   int64  `json:"total_size"`
	Category    string `json:"category"`
	Clearable   bool   `json:"clearable"`
	Database    string `json:"database"`
}

type ConfigExport

type ConfigExport struct {
	Server         model.ServerConfig                `json:"server"`
	Channels       []model.Channel                   `json:"channels"`
	Devices        map[string]model.Device           `json:"devices"`
	Northbound     model.NorthboundConfig            `json:"northbound"`
	EdgeRules      []model.EdgeRule                  `json:"edge_rules"`
	System         model.SystemConfig                `json:"system"`
	Users          []model.UserConfig                `json:"users"`
	VirtualShadows []model.VirtualShadowDeviceConfig `json:"virtual_shadows"`
}

type ConfigStore

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

func NewConfigStore

func NewConfigStore(db *bbolt.DB) (*ConfigStore, error)

func (*ConfigStore) DeleteDevice

func (cs *ConfigStore) DeleteDevice(deviceID string) error

func (*ConfigStore) ExportAllConfig

func (cs *ConfigStore) ExportAllConfig() (*ConfigExport, error)

func (*ConfigStore) HasConfigData

func (cs *ConfigStore) HasConfigData() (bool, error)

func (*ConfigStore) HasUsers

func (cs *ConfigStore) HasUsers() (bool, error)

func (*ConfigStore) ImportConfig

func (cs *ConfigStore) ImportConfig(export *ConfigExport) error

func (*ConfigStore) IsSystemInitialized

func (cs *ConfigStore) IsSystemInitialized() (bool, error)

func (*ConfigStore) LoadAllDevices

func (cs *ConfigStore) LoadAllDevices() (map[string]model.Device, error)

func (*ConfigStore) LoadChannels

func (cs *ConfigStore) LoadChannels() ([]model.Channel, error)

func (*ConfigStore) LoadDevice

func (cs *ConfigStore) LoadDevice(deviceID string) (*model.Device, error)

func (*ConfigStore) LoadEdgeRules

func (cs *ConfigStore) LoadEdgeRules() ([]model.EdgeRule, error)

func (*ConfigStore) LoadNorthbound

func (cs *ConfigStore) LoadNorthbound() (*model.NorthboundConfig, error)

func (*ConfigStore) LoadServerConfig

func (cs *ConfigStore) LoadServerConfig() (*model.ServerConfig, error)

func (*ConfigStore) LoadSystem

func (cs *ConfigStore) LoadSystem() (*model.SystemConfig, error)

func (*ConfigStore) LoadUsers

func (cs *ConfigStore) LoadUsers() ([]model.UserConfig, error)

func (*ConfigStore) LoadVirtualShadows

func (cs *ConfigStore) LoadVirtualShadows() ([]model.VirtualShadowDeviceConfig, error)

func (*ConfigStore) SaveAllConfig

func (cs *ConfigStore) SaveAllConfig(server model.ServerConfig, channels []model.Channel, devices []model.Device,
	northbound model.NorthboundConfig, edgeRules []model.EdgeRule, system model.SystemConfig, users []model.UserConfig) error

func (*ConfigStore) SaveChannels

func (cs *ConfigStore) SaveChannels(channels []model.Channel) error

func (*ConfigStore) SaveDevice

func (cs *ConfigStore) SaveDevice(device model.Device) error

func (*ConfigStore) SaveEdgeRules

func (cs *ConfigStore) SaveEdgeRules(rules []model.EdgeRule) error

func (*ConfigStore) SaveNorthbound

func (cs *ConfigStore) SaveNorthbound(config model.NorthboundConfig) error

func (*ConfigStore) SaveServerConfig

func (cs *ConfigStore) SaveServerConfig(config model.ServerConfig) error

func (*ConfigStore) SaveSystem

func (cs *ConfigStore) SaveSystem(config model.SystemConfig) error

func (*ConfigStore) SaveUsers

func (cs *ConfigStore) SaveUsers(users []model.UserConfig) error

func (*ConfigStore) SaveVirtualShadows

func (cs *ConfigStore) SaveVirtualShadows(devices []model.VirtualShadowDeviceConfig) error

type OfflineMessage

type OfflineMessage struct {
	Key  string
	Data []byte
}

type Storage

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

func NewStorage

func NewStorage(dataDir string) (*Storage, error)

func (*Storage) BackupConfigDB

func (s *Storage) BackupConfigDB(backupDir string) (*model.BackupInfo, error)

BackupConfigDB 备份配置数据库到指定目录。 配置库优先备份,不包含运行时数据。

func (*Storage) BackupRuntimeDB

func (s *Storage) BackupRuntimeDB(backupDir string) (*model.BackupInfo, error)

BackupRuntimeDB 备份运行时数据库到指定目录(可选诊断用途)。

func (*Storage) ClearAllRuntimeBuckets

func (s *Storage) ClearAllRuntimeBuckets() ([]string, error)

ClearAllRuntimeBuckets 清空所有运行时 bucket(values、DataCache、WindowData、NorthboundCache、RuleState) 以及所有 device_history_* bucket,用于 runtime DB 重建场景。 配置 bucket 不受影响。

func (*Storage) ClearBucket

func (s *Storage) ClearBucket(bucketName string) error

func (*Storage) Close

func (s *Storage) Close() error

func (*Storage) CompactRuntimeDB

func (s *Storage) CompactRuntimeDB() error

CompactRuntimeDB 压缩运行时数据库文件,回收已删除数据的空间。 使用 bbolt 的 tx.WriteTo 创建紧凑副本,然后替换原文件。

func (*Storage) DeleteData

func (s *Storage) DeleteData(bucketName string, key string) error

func (*Storage) GetAllValues

func (s *Storage) GetAllValues() (map[string]model.Value, error)

func (*Storage) GetBucketStats

func (s *Storage) GetBucketStats() ([]BucketStats, int64, error)

func (*Storage) GetConfigDB

func (s *Storage) GetConfigDB() *bbolt.DB

func (*Storage) GetConfigPath

func (s *Storage) GetConfigPath() string

func (*Storage) GetDB

func (s *Storage) GetDB() *bbolt.DB

func (*Storage) GetData

func (s *Storage) GetData(bucketName string, key string, result interface{}) error

func (*Storage) GetLastValue

func (s *Storage) GetLastValue(pointID string) (*model.Value, error)

func (*Storage) GetOfflineMessages

func (s *Storage) GetOfflineMessages(configID string, limit int) ([]OfflineMessage, error)

func (*Storage) GetPath

func (s *Storage) GetPath() string

func (*Storage) LoadAll

func (s *Storage) LoadAll(bucketName string, callback func(k, v []byte) error) error

func (*Storage) LoadLatest

func (s *Storage) LoadLatest(bucketName string, limit int, callback func(k, v []byte) error) error

func (*Storage) LoadRange

func (s *Storage) LoadRange(bucketName string, minKey, maxKey string, callback func(k, v []byte) error) error

func (*Storage) PruneOldest

func (s *Storage) PruneOldest(bucketName string, maxRecords int) error

func (*Storage) RemoveOfflineMessage

func (s *Storage) RemoveOfflineMessage(key string) error

func (*Storage) SaveData

func (s *Storage) SaveData(bucketName string, key string, data interface{}) error

func (*Storage) SaveOfflineMessage

func (s *Storage) SaveOfflineMessage(configID string, data []byte, maxCount int) error

func (*Storage) SaveValue

func (s *Storage) SaveValue(val model.Value) error

func (*Storage) SyncConfigDB

func (s *Storage) SyncConfigDB() error

SyncConfigDB 对配置数据库执行强制同步,确保持久化到磁盘。 配置库使用强一致写入策略。

Jump to

Keyboard shortcuts

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