storage

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: MIT Imports: 15 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"
	BucketAICopilot      = "ai_copilot"
	ConfigVersionKey     = "version"
	ConfigVersionValue   = "1.0"
)
View Source
const (
	ArchiveManifestName = "manifest.json"
	ConfigDBEntryName   = "config.db"
	RuntimeDBEntryName  = "runtime.db"
)

Variables

This section is empty.

Functions

func BackupDB

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

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

func ClassifyBucket added in v0.0.7

func ClassifyBucket(name string) (category string, clearable bool)

func ExportDBAsTarGz added in v0.0.7

func ExportDBAsTarGz(dbPath, entryName, archiveType string) ([]byte, string, error)

ExportDBAsTarGz exports a bbolt database file as a tar.gz archive. Used when the database file is not already open (e.g. tests).

func FetchRemoteConfigArchive added in v0.0.7

func FetchRemoteConfigArchive(host string, port int, token string, useHTTPS bool) ([]byte, string, error)

FetchRemoteConfigArchive downloads a config tar.gz from a remote EdgeX gateway.

func IsConfigBucket

func IsConfigBucket(name string) bool

func RestoreDB

func RestoreDB(backupPath, targetPath string) error

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

Types

type ArchiveManifest added in v0.0.7

type ArchiveManifest struct {
	Type       string    `json:"type"`
	Version    string    `json:"version"`
	ExportTime time.Time `json:"export_time"`
	SourcePath string    `json:"source_path,omitempty"`
}

ArchiveManifest describes export package metadata.

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 ConfigImportResult added in v0.0.7

type ConfigImportResult struct {
	ForceOverwrite bool   `json:"force_overwrite"`
	PreservedUsers bool   `json:"preserved_users"`
	PreservedPort  int    `json:"preserved_port"`
	DeviceCount    int    `json:"device_count"`
	ChannelCount   int    `json:"channel_count"`
	RemoteSource   string `json:"remote_source,omitempty"`
}

ConfigImportResult summarizes a config database import operation.

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) ImportConfigReplace added in v0.0.7

func (cs *ConfigStore) ImportConfigReplace(export *ConfigExport, opts ImportPreserveOptions) error

ImportConfigReplace replaces configuration buckets from export data. When preserve options are set, current users and/or server port are kept.

func (*ConfigStore) IsSystemInitialized

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

func (*ConfigStore) LoadAICopilotSettings added in v0.0.8

func (cs *ConfigStore) LoadAICopilotSettings() (*model.AICopilotSettings, 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) SaveAICopilotSettings added in v0.0.8

func (cs *ConfigStore) SaveAICopilotSettings(settings model.AICopilotSettings) 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 ImportArchiveOptions added in v0.0.7

type ImportArchiveOptions struct {
	ForceOverwrite bool
}

ImportArchiveOptions controls import behavior.

type ImportPreserveOptions added in v0.0.7

type ImportPreserveOptions struct {
	PreserveUsers      bool
	PreserveServerPort bool
}

ImportPreserveOptions controls fields preserved during full config import.

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 清空 runtime.db 中的全部 bucket(含 values、缓存、历史、遗留 WAL 等)。 配置 bucket 不应出现在 runtime.db;若检测到则报错。

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.Compact 仅复制仍存活的数据,替换原文件。

func (*Storage) DeleteData

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

func (*Storage) ExportConfigDBArchive added in v0.0.7

func (s *Storage) ExportConfigDBArchive() ([]byte, string, error)

ExportConfigDBArchive exports config.db as tar.gz.

func (*Storage) ExportRuntimeDBArchive added in v0.0.7

func (s *Storage) ExportRuntimeDBArchive() ([]byte, string, error)

ExportRuntimeDBArchive exports runtime.db as tar.gz.

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) GetRuntimePath added in v0.0.7

func (s *Storage) GetRuntimePath() string

GetRuntimePath returns the on-disk path of runtime.db.

func (*Storage) ImportConfigDBArchive added in v0.0.7

func (s *Storage) ImportConfigDBArchive(archiveData []byte, opts ImportArchiveOptions) (*ConfigImportResult, error)

ImportConfigDBArchive imports configuration from a tar.gz archive. By default existing user accounts/passwords and server port are preserved.

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) PullRemoteConfigAndImport added in v0.0.7

func (s *Storage) PullRemoteConfigAndImport(host string, port int, token string, useHTTPS bool) (*ConfigImportResult, error)

PullRemoteConfigAndImport force-pulls configuration from a remote gateway and overwrites local config.

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