obs_storage

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 12 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const OBSStorageName = "obs-storage"

Variables

View Source
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 LocalTimeProvider

type LocalTimeProvider struct{}

LocalTimeProvider 本地时间源(导出,供 locks 包注入)

func (*LocalTimeProvider) GetTime

func (p *LocalTimeProvider) GetTime(ctx context.Context) (time.Time, error)

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

func (*OBSConnectionManager) Return

func (x *OBSConnectionManager) Return(ctx context.Context, conn *minio.Client) error

func (*OBSConnectionManager) Shutdown

func (x *OBSConnectionManager) Shutdown(ctx context.Context) error

func (*OBSConnectionManager) Take

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) Get

func (x *OBSStorage) Get(ctx context.Context, lockId string) (string, error)

Get 获取锁信息

func (*OBSStorage) GetName

func (x *OBSStorage) GetName() string

func (*OBSStorage) GetTime

func (x *OBSStorage) GetTime(ctx context.Context) (time.Time, error)

GetTime 返回注入的时间源

func (*OBSStorage) Init

func (x *OBSStorage) Init(ctx context.Context) error

func (*OBSStorage) List

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 (*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

Jump to

Keyboard shortcuts

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