Documentation
¶
Index ¶
- Constants
- Variables
- type LocalTimeProvider
- type OBSConnectionManager
- type OBSStorage
- func (x *OBSStorage) Capabilities() []storage.StorageCapability
- func (x *OBSStorage) Close(ctx context.Context) error
- func (x *OBSStorage) CreateWithVersion(ctx context.Context, lockId string, version storage.Version, ...) error
- func (x *OBSStorage) DeleteWithVersion(ctx context.Context, lockId string, expectedVersion storage.Version, ...) error
- func (x *OBSStorage) Get(ctx context.Context, lockId string) (string, error)
- func (x *OBSStorage) GetName() string
- func (x *OBSStorage) GetTime(ctx context.Context) (time.Time, error)
- func (x *OBSStorage) Init(ctx context.Context) error
- func (x *OBSStorage) List(ctx context.Context) (go_iterator.Iterator[*storage.LockInformation], error)
- func (x *OBSStorage) UpdateWithVersion(ctx context.Context, lockId string, ...) error
- func (x *OBSStorage) Watch(ctx context.Context, lockId string) (<-chan *storage.LockInformation, error)
- type OBSStorageOptions
- func (x *OBSStorageOptions) Check() error
- func (x *OBSStorageOptions) SetAccessKey(accessKey string) *OBSStorageOptions
- func (x *OBSStorageOptions) SetBucketName(bucketName string) *OBSStorageOptions
- func (x *OBSStorageOptions) SetConnectionManager(cm storage.ConnectionManager[*minio.Client]) *OBSStorageOptions
- func (x *OBSStorageOptions) SetEndpoint(endpoint string) *OBSStorageOptions
- func (x *OBSStorageOptions) SetKeyPrefix(keyPrefix string) *OBSStorageOptions
- func (x *OBSStorageOptions) SetRegion(region string) *OBSStorageOptions
- func (x *OBSStorageOptions) SetSecretKey(secretKey string) *OBSStorageOptions
- func (x *OBSStorageOptions) SetTimeProvider(timeProvider storage.TimeProvider) *OBSStorageOptions
- func (x *OBSStorageOptions) SetUseSSL(useSSL bool) *OBSStorageOptions
Constants ¶
const OBSStorageName = "obs-storage"
Variables ¶
var ( // ErrKeyPrefixEmpty 参数中 KeyPrefix 为空 ErrKeyPrefixEmpty = fmt.Errorf("KeyPrefix can not empty") // ErrConnectionManagerNil 连接管理器没有指定 ErrConnectionManagerNil = fmt.Errorf("ConnectionManager can not nil") // ErrBucketNameEmpty 参数中 BucketName 为空 ErrBucketNameEmpty = fmt.Errorf("BucketName can not empty") )
Functions ¶
This section is empty.
Types ¶
type OBSConnectionManager ¶
type OBSConnectionManager struct {
// Endpoint OBS/S3 兼容服务的端点
Endpoint string
// AccessKey 访问密钥
AccessKey string
// SecretKey 密钥
SecretKey string
// UseSSL 是否使用 HTTPS
UseSSL bool
// Region 区域
Region string
// contains filtered or unexported fields
}
OBSConnectionManager OBS 连接管理器(S3 协议兼容)
func NewOBSConnectionManager ¶
func NewOBSConnectionManager(endpoint, accessKey, secretKey string) *OBSConnectionManager
NewOBSConnectionManager 从端点参数创建连接管理器
func NewOBSConnectionManagerFromClient ¶
func NewOBSConnectionManagerFromClient(client *minio.Client) *OBSConnectionManager
NewOBSConnectionManagerFromClient 从已有客户端创建连接管理器
func NewOBSConnectionManagerFromEndpoint ¶
func NewOBSConnectionManagerFromEndpoint(endpoint, accessKey, secretKey string, useSSL bool) *OBSConnectionManager
NewOBSConnectionManagerFromEndpoint 从端点参数创建连接管理器
func (*OBSConnectionManager) Name ¶
func (x *OBSConnectionManager) Name() string
type OBSStorage ¶
type OBSStorage struct {
// contains filtered or unexported fields
}
OBSStorage 基于华为云 OBS 的存储引擎实现
OBS 兼容 S3 协议,本实现通过 S3 兼容客户端访问 OBS。 CAS 范式与 S3 一致:条件 PUT。 - CreateWithVersion: PutObject + If-None-Match:*(对象不存在才写入) - UpdateWithVersion: 先 Get 取 ETag → PutObject + If-Match:<ETag>(ETag 匹配才覆盖) - DeleteWithVersion: 对象存储不支持条件删除,采用“读取-检查-无条件删除”降级方案
时间源由 options.TimeProvider 注入(生产 NTP,测试 LocalTimeProvider)。
func NewOBSStorage ¶
func NewOBSStorage(ctx context.Context, options *OBSStorageOptions) (*OBSStorage, error)
NewOBSStorage 创建 OBS 存储引擎
func (*OBSStorage) Capabilities ¶
func (x *OBSStorage) Capabilities() []storage.StorageCapability
Capabilities 声明 CAS 和 ReliableTime(通过注入 TimeProvider 满足) - AtomicDelete:对象存储 Delete 无条件删除,释放走墓碑降级
func (*OBSStorage) Close ¶
func (x *OBSStorage) Close(ctx context.Context) error
Close 仅清空引用,连接由 ConnectionManager 管理
func (*OBSStorage) CreateWithVersion ¶
func (x *OBSStorage) CreateWithVersion(ctx context.Context, lockId string, version storage.Version, lockInformation *storage.LockInformation) error
CreateWithVersion 原子创建锁记录 PutObject + If-None-Match:*:对象不存在才写入,否则返回前置条件失败错误
func (*OBSStorage) DeleteWithVersion ¶
func (x *OBSStorage) DeleteWithVersion(ctx context.Context, lockId string, expectedVersion storage.Version, lockInformation *storage.LockInformation) error
DeleteWithVersion 对象存储不支持条件删除,采用“读取-检查-无条件删除”降级方案 注意:这不是原子操作,检查和删除之间可能有并发修改 但这是对象存储能做到的最佳方案,用于测试场景和清理操作
func (*OBSStorage) GetName ¶
func (x *OBSStorage) GetName() string
func (*OBSStorage) List ¶
func (x *OBSStorage) List(ctx context.Context) (go_iterator.Iterator[*storage.LockInformation], error)
List 通过 ListObjects 枚举 <prefix>/lock/ 前缀下的所有对象
func (*OBSStorage) UpdateWithVersion ¶
func (x *OBSStorage) UpdateWithVersion(ctx context.Context, lockId string, expectedVersion, newVersion storage.Version, lockInformation *storage.LockInformation) error
UpdateWithVersion 原子更新锁记录 流程:Get 取 ETag → 检查业务 version → PutObject + If-Match:<ETag>
func (*OBSStorage) Watch ¶
func (x *OBSStorage) Watch(ctx context.Context, lockId string) (<-chan *storage.LockInformation, error)
type OBSStorageOptions ¶
type OBSStorageOptions struct {
// ConnectionManager 连接管理器
ConnectionManager storage.ConnectionManager[*minio.Client]
// Endpoint OBS/S3 兼容服务的端点
Endpoint string
// AccessKey 访问密钥
AccessKey string
// SecretKey 密钥
SecretKey string
// UseSSL 是否使用 HTTPS
UseSSL bool
// BucketName 存储锁对象的 Bucket
BucketName string
// KeyPrefix 对象 key 前缀,实际 key = <KeyPrefix>/lock/<lockId>
KeyPrefix string
// Region 区域(用于 MakeBucket,可选)
Region string
// TimeProvider 可选时间源(对象存储无服务端时钟,必须注入)
TimeProvider storage.TimeProvider
}
OBSStorageOptions 华为云 OBS 存储选项 OBS 兼容 S3 协议,通过 S3 兼容客户端访问
func NewOBSStorageOptions ¶
func NewOBSStorageOptions() *OBSStorageOptions
func (*OBSStorageOptions) Check ¶
func (x *OBSStorageOptions) Check() error
func (*OBSStorageOptions) SetAccessKey ¶
func (x *OBSStorageOptions) SetAccessKey(accessKey string) *OBSStorageOptions
func (*OBSStorageOptions) SetBucketName ¶
func (x *OBSStorageOptions) SetBucketName(bucketName string) *OBSStorageOptions
func (*OBSStorageOptions) SetConnectionManager ¶
func (x *OBSStorageOptions) SetConnectionManager(cm storage.ConnectionManager[*minio.Client]) *OBSStorageOptions
func (*OBSStorageOptions) SetEndpoint ¶
func (x *OBSStorageOptions) SetEndpoint(endpoint string) *OBSStorageOptions
func (*OBSStorageOptions) SetKeyPrefix ¶
func (x *OBSStorageOptions) SetKeyPrefix(keyPrefix string) *OBSStorageOptions
func (*OBSStorageOptions) SetRegion ¶
func (x *OBSStorageOptions) SetRegion(region string) *OBSStorageOptions
func (*OBSStorageOptions) SetSecretKey ¶
func (x *OBSStorageOptions) SetSecretKey(secretKey string) *OBSStorageOptions
func (*OBSStorageOptions) SetTimeProvider ¶
func (x *OBSStorageOptions) SetTimeProvider(timeProvider storage.TimeProvider) *OBSStorageOptions
func (*OBSStorageOptions) SetUseSSL ¶
func (x *OBSStorageOptions) SetUseSSL(useSSL bool) *OBSStorageOptions