Documentation
¶
Index ¶
- type MigrateStorageReq
- type MigrateStorageResult
- type NFSConfig
- type ObjectLister
- type ObjectReader
- type Runtime
- type RuntimePersister
- type S3Config
- type Service
- func (s *Service) GetStorageInfo(ctx context.Context) (*StorageInfo, error)
- func (s *Service) MigrateStorage(ctx context.Context, req *MigrateStorageReq) (*MigrateStorageResult, error)
- func (s *Service) SetObjectLister(l ObjectLister)
- func (s *Service) SetPersister(p RuntimePersister)
- func (s *Service) SetRuntime(rt Runtime)
- func (s *Service) SwitchStorage(ctx context.Context, storageType string) error
- func (s *Service) TestStorageConnection(ctx context.Context, storageType string) error
- func (s *Service) UpdateStorageConfig(ctx context.Context, req *UpdateConfigRequest) error
- type StorageConfig
- type StorageDetail
- type StorageInfo
- type UpdateConfigRequest
- type WebDAVConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MigrateStorageReq ¶ added in v0.32.33
type MigrateStorageReq struct {
// TargetType 目标后端类型(local / s3 / webdav / …)。
TargetType string
// TargetPath 目标本地目录(仅 TargetType=local 时有意义;缺省 = 沿用现配置的 storage_path)。
TargetPath string
// DryRun 只算计划不搬(先看再动)。
DryRun bool
}
MigrateStorageReq 迁移请求(域内形态;契约层同名结构见 contracts 的 idl/storage.thrift)。
type MigrateStorageResult ¶ added in v0.32.33
type MigrateStorageResult struct {
// Switched 是否已切换到目标后端。
Switched bool
// Copied 本次复制成功的对象数。
Copied int64
// Skipped 目标已存在而跳过的对象数(续跑)。
Skipped int64
// Failed 复制失败的对象数(>0 ⇒ 未切换)。
Failed int64
// Bytes 复制字节数。
Bytes int64
// Objects 计划涉及的对象总数。
Objects int64
// FromType 源后端类型。
FromType string
// ToType 目标后端类型。
ToType string
// Message 人类可读结论(失败摘要 / dry-run 计划)。
Message string
}
MigrateStorageResult 迁移结果。
type NFSConfig ¶
type NFSConfig struct {
Server string `json:"server"`
Path string `json:"path"`
MountPoint string `json:"mount_point"`
Version string `json:"version"`
Options string `json:"options"`
Timeout int32 `json:"timeout"`
AutoMount int32 `json:"auto_mount"`
RetryCount int32 `json:"retry_count"`
SubPath string `json:"sub_path"`
}
type ObjectLister ¶ added in v0.32.33
type ObjectLister interface {
// ListReferencedObjectPaths 返回全部被引用的对象路径(去重)。
// 必须含**软删**记录:软删分享可恢复 ⇒ 它的对象也得搬过去。
ListReferencedObjectPaths(ctx context.Context) ([]string, error)
}
ObjectLister 列出被 DB 引用的对象路径(admin 域实现)。
路径是**存储相对路径**(与 file_codes.file_path / file_code_files.file_path 同形)。
type ObjectReader ¶ added in v0.32.33
type ObjectReader interface {
// GetFileReader 打开对象读取器;同时给出对象大小(远端驱动写流需确切 size)。
GetFileReader(ctx context.Context, filePath string) (io.ReadCloser, int64, error)
// FileExists 对象是否已存在(续跑跳过判定)。
FileExists(ctx context.Context, filePath string) bool
}
ObjectReader 读对象(当前生效后端)。
由 core/storage 的单例实现(它同时是 Runtime);用类型断言而非接口继承, 免得为迁移去改 Runtime 的既有契约(别的实现者不必跟着改)。
type Runtime ¶
type Runtime interface {
Reload(cfg *corestorage.StorageConfig) error
EffectiveType() corestorage.StorageType
}
Runtime 存储运行时接口(bootstrap 注入单例 *storage.StorageService)。
type RuntimePersister ¶
type RuntimePersister interface {
LoadRuntimeStorage(ctx context.Context) *conf.StorageConfig
SaveRuntimeStorage(ctx context.Context, cfg *conf.StorageConfig) error
}
RuntimePersister 运行时存储配置持久化(admin 域实现,bootstrap 装配; 存储域不直接碰 system_configs,保持域间零耦合)。
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service 存储服务
func (*Service) GetStorageInfo ¶
func (s *Service) GetStorageInfo(ctx context.Context) (*StorageInfo, error)
GetStorageInfo 获取存储信息
func (*Service) MigrateStorage ¶ added in v0.32.33
func (s *Service) MigrateStorage(ctx context.Context, req *MigrateStorageReq) (*MigrateStorageResult, error)
MigrateStorage 把存量对象从当前后端搬到目标后端。
流程:校验目标 → 探测目标连通性 → 列举待迁对象 →(dry-run 则到此为止)→ 逐个复制(目标已存在则跳过)→ 全部成功才切换后端。
失败语义:**不切换**(源后端继续在用),并返回失败摘要。
func (*Service) SetObjectLister ¶ added in v0.32.33
func (s *Service) SetObjectLister(l ObjectLister)
SetObjectLister 注入对象清单来源(admin 域实现;bootstrap 装配)。
func (*Service) SetPersister ¶
func (s *Service) SetPersister(p RuntimePersister)
SetPersister 注入持久化(在线切换写穿 DB,重启不丢)
func (*Service) SwitchStorage ¶
SwitchStorage 切换存储类型:校验 → 认证级 Probe → 热重载(新写入立即走新后端) → 更新全局配置 → 持久化到 system_configs(重启不丢)。
func (*Service) TestStorageConnection ¶
TestStorageConnection 测试存储连接。 local:路径存在可写;s3/webdav:端点 URL 校验(scheme 白名单 + 私网策略) 后做真实 HTTP 探测(不要求认证通过,能建立连接即可)。
func (*Service) UpdateStorageConfig ¶
func (s *Service) UpdateStorageConfig(ctx context.Context, req *UpdateConfigRequest) error
UpdateStorageConfig 更新存储配置。 流程与 SwitchStorage 一致:SSRF 校验 → 认证级 Probe → 热重载 → 更新内存 → 持久化到 system_configs(管理端配置记录,重启后由 bootstrap 恢复)。 注:use_ssl/path_style 未随请求传入时保留现值(use_ssl 缺省 true,与管理端历史行为一致)。
type StorageConfig ¶
type StorageConfig struct {
Type string `json:"type"`
StoragePath string `json:"storage_path"`
WebDAV *WebDAVConfig `json:"webdav,omitempty"`
S3 *S3Config `json:"s3,omitempty"`
NFS *NFSConfig `json:"nfs,omitempty"`
}
type StorageDetail ¶
type StorageInfo ¶
type StorageInfo struct {
Current string `json:"current"`
Effective string `json:"effective"` // 实际生效后端(降级时与 current 不同)
Available []string `json:"available"`
StorageDetails map[string]*StorageDetail `json:"storage_details"`
StorageConfig *StorageConfig `json:"storage_config"`
}
type UpdateConfigRequest ¶
type UpdateConfigRequest struct {
Type string `json:"type"`
// 扁平形态:内嵌 conf.StorageConfig,JSON 字段同名绑定
conf.StorageConfig
}
UpdateConfigRequest 更新配置请求 UpdateConfigRequest 存储配置更新请求。
形态:**只有**扁平一种——请求体即 conf.StorageConfig 同构 JSON (type/storage_path/quota/s3/webdav/ftp/sftp/azureblob/hdfs/onedrive/oss..obs), 后端整体校验 → Probe → 热切换 → 持久化。
旧的嵌套形态 {type, config:{storage_path/webdav/s3}} 已删(2026-10-25 删除旧版本 兼容):它只能切 local/webdav/s3 三种、且字段名与实际配置模型对不上(旧契约遗留), 保留它等于让**两种写入口径**并存。