Documentation
¶
Index ¶
- Constants
- func CalculateETag(data []byte) string
- func CalculateMultipartETag(partETags []string) string
- func GenerateUploadID(bucket, key string) string
- type Alert
- type AlertCallback
- type AlertThresholds
- type BucketInfo
- type Config
- type DB
- func (s *DB) AbortMultipartUpload(bucket, key, uploadID string) error
- func (s *DB) Backup(backupPath string) error
- func (s *DB) BucketExists(bucket string) (bool, error)
- func (s *DB) Close() error
- func (s *DB) Compact() error
- func (s *DB) CompleteMultipartUpload(bucket, key, uploadID string, parts []MultipartPart) (string, error)
- func (s *DB) CreateBucket(bucket string) error
- func (s *DB) CreateMultipartUpload(bucket, key, contentType string, metadata map[string]string) (string, error)
- func (s *DB) DeleteBucket(bucket string) error
- func (s *DB) DeleteObject(bucket, key string) error
- func (s *DB) GetConfig() *Config
- func (s *DB) GetDiskUsage() (total, free, used uint64, err error)
- func (s *DB) GetMetrics() *Metrics
- func (s *DB) GetObject(bucket, key string) (*ObjectData, error)
- func (s *DB) GetObjectRange(bucket, key string, start, end int64) ([]byte, *ObjectData, error)
- func (s *DB) GetObjectStream(bucket, key string) (io.ReadCloser, *ObjectData, error)
- func (s *DB) GetStats() (*Stats, error)
- func (s *DB) HealthCheck() error
- func (s *DB) ListBuckets() ([]BucketInfo, error)
- func (s *DB) ListMultipartUploads(bucket string) ([]MultipartUploadInfo, error)
- func (s *DB) ListObjects(bucket, prefix, marker, delimiter string, maxKeys int) ([]ObjectInfo, []string, error)
- func (s *DB) ListParts(bucket, key, uploadID string) ([]*PartInfo, error)
- func (s *DB) PutObject(bucket string, object *ObjectData) error
- func (s *DB) PutObjectStream(bucket, key string, reader io.Reader, size int64, contentType string, ...) (string, error)
- func (s *DB) ResetMetrics()
- func (s *DB) Restore(backupPath string) error
- func (s *DB) SetConfig(config *Config)
- func (s *DB) UploadPart(bucket, key, uploadID string, partNumber int, data []byte) (string, error)
- func (s *DB) Validate() error
- type DiskUsageInfo
- type Logger
- type Metrics
- type MetricsSnapshot
- type MultipartPart
- type MultipartUploadInfo
- type ObjectData
- type ObjectInfo
- type PartInfo
- type PerformanceMonitor
- func (pm *PerformanceMonitor) AddAlertCallback(callback AlertCallback)
- func (pm *PerformanceMonitor) GenerateReport(duration time.Duration) *PerformanceReport
- func (pm *PerformanceMonitor) GetCurrentMetrics() *Metrics
- func (pm *PerformanceMonitor) GetMetricsHistory(duration time.Duration) []MetricsSnapshot
- func (pm *PerformanceMonitor) SetAlertThresholds(thresholds *AlertThresholds)
- func (pm *PerformanceMonitor) Start(interval time.Duration)
- func (pm *PerformanceMonitor) Stop()
- type PerformanceReport
- type Stats
Constants ¶
const ( // 分段上传相关常量 MaxMultipartLifetime = 7 * 24 * time.Hour // 7天,与S3一致 CleanupInterval = 1 * time.Hour // 清理过期上传的间隔 )
const ( // 基本单位 - 字节 Byte = 1 // 使用 iota 从 0 开始,每次增加 1 // 左移 10 位相当于乘以 2^10 = 1024 KB = 1 << (10 * iota) // 1 << (10 * 1) = 1024 MB // 1 << (10 * 2) = 1,048,576 GB // 1 << (10 * 3) = 1,073,741,824 TB // 1 << (10 * 4) = 1,099,511,627,776 PB // 1 << (10 * 5) = 1,125,899,906,842,624 )
定义数据大小单位常量
const ( AK = "ak" SK = "sk" Token = "token" Region = "region" )
Variables ¶
This section is empty.
Functions ¶
func CalculateMultipartETag ¶
calculateMultipartETag 计算分段上传的最终ETag S3兼容的格式: "{md5-of-all-etags}-{number-of-parts}"
Types ¶
type AlertCallback ¶
type AlertCallback func(alert Alert)
type AlertThresholds ¶
type BucketInfo ¶
BucketInfo 表示存储桶的元数据
func (BucketInfo) MarshalEasyJSON ¶
func (v BucketInfo) MarshalEasyJSON(w *jwriter.Writer)
MarshalEasyJSON supports easyjson.Marshaler interface
func (BucketInfo) MarshalJSON ¶
func (v BucketInfo) MarshalJSON() ([]byte, error)
MarshalJSON supports json.Marshaler interface
func (*BucketInfo) UnmarshalEasyJSON ¶
func (v *BucketInfo) UnmarshalEasyJSON(l *jlexer.Lexer)
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*BucketInfo) UnmarshalJSON ¶
func (v *BucketInfo) UnmarshalJSON(data []byte) error
UnmarshalJSON supports json.Unmarshaler interface
type Config ¶
type Config struct {
// 并发控制
MaxConcurrentUploads int
MaxConcurrentDownloads int
// 缓存配置
MetadataCacheSize int
MetadataCacheTTL time.Duration
// 性能优化
UseDirectIO bool
UseMmap bool
BufferSize int
// 数据完整性
EnableChecksumVerify bool
ChecksumAlgorithm string
// 清理配置
CleanupInterval time.Duration
TempFileMaxAge time.Duration
}
存储配置
type DB ¶ added in v0.0.2
type DB struct {
// contains filtered or unexported fields
}
实现了基于文件系统的S3兼容存储
func NewWithLogger ¶ added in v1.0.0
New创建一个新的文件系统存储实例
func (*DB) AbortMultipartUpload ¶ added in v0.0.2
AbortMultipartUpload 中止分段上传
func (*DB) BucketExists ¶ added in v0.0.2
BucketExists 检查存储桶是否存在
func (*DB) CompleteMultipartUpload ¶ added in v0.0.2
func (s *DB) CompleteMultipartUpload(bucket, key, uploadID string, parts []MultipartPart) (string, error)
CompleteMultipartUpload 完成分段上传(优化版本)
func (*DB) CreateBucket ¶ added in v0.0.2
CreateBucket 创建存储桶
func (*DB) CreateMultipartUpload ¶ added in v0.0.2
func (s *DB) CreateMultipartUpload(bucket, key, contentType string, metadata map[string]string) (string, error)
CreateMultipartUpload 创建分段上传
func (*DB) DeleteBucket ¶ added in v0.0.2
DeleteBucket 删除存储桶
func (*DB) DeleteObject ¶ added in v0.0.2
DeleteObject 删除对象
func (*DB) GetDiskUsage ¶ added in v0.0.2
GetDiskUsage 获取磁盘使用情况
func (*DB) GetObject ¶ added in v0.0.2
func (s *DB) GetObject(bucket, key string) (*ObjectData, error)
GetObject 获取对象(优化版本)
func (*DB) GetObjectRange ¶ added in v0.0.2
GetObjectRange 获取对象的指定范围(支持HTTP Range请求)
func (*DB) GetObjectStream ¶ added in v0.0.2
func (s *DB) GetObjectStream(bucket, key string) (io.ReadCloser, *ObjectData, error)
GetObjectStream 流式获取对象(用于大文件)
func (*DB) ListBuckets ¶ added in v0.0.2
func (s *DB) ListBuckets() ([]BucketInfo, error)
Bucket 相关操作 ListBuckets 列出所有存储桶
func (*DB) ListMultipartUploads ¶ added in v0.0.2
func (s *DB) ListMultipartUploads(bucket string) ([]MultipartUploadInfo, error)
ListMultipartUploads 列出所有进行中的分段上传
func (*DB) ListObjects ¶ added in v0.0.2
func (s *DB) ListObjects(bucket, prefix, marker, delimiter string, maxKeys int) ([]ObjectInfo, []string, error)
ListObjects 列出存储桶中的对象
func (*DB) PutObject ¶ added in v0.0.2
func (s *DB) PutObject(bucket string, object *ObjectData) error
PutObject 存储对象(优化版本)
func (*DB) PutObjectStream ¶ added in v0.0.2
func (s *DB) PutObjectStream(bucket, key string, reader io.Reader, size int64, contentType string, metadata map[string]string) (string, error)
PutObjectStream 流式存储对象(用于大文件)
func (*DB) UploadPart ¶ added in v0.0.2
UploadPart 上传分段(优化版本)
type DiskUsageInfo ¶
type Logger ¶
type Logger interface {
// Debug logs the provided arguments at [DebugLevel].
// Spaces are added between arguments when neither is a string.
Debug(args ...interface{})
// Info logs the provided arguments at [InfoLevel].
// Spaces are added between arguments when neither is a string.
Info(args ...interface{})
// Warn logs the provided arguments at [WarnLevel].
// Spaces are added between arguments when neither is a string.
Warn(args ...interface{})
// Error logs the provided arguments at [ErrorLevel].
// Spaces are added between arguments when neither is a string.
Error(args ...interface{})
// Fatal constructs a message with the provided arguments and calls os.Exit.
// Spaces are added between arguments when neither is a string.
Fatal(args ...interface{})
// Debugf formats the message according to the format specifier
// and logs it at [DebugLevel].
Debugf(template string, args ...interface{})
// Infof formats the message according to the format specifier
// and logs it at [InfoLevel].
Infof(template string, args ...interface{})
// Warnf formats the message according to the format specifier
// and logs it at [WarnLevel].
Warnf(template string, args ...interface{})
// Errorf formats the message according to the format specifier
// and logs it at [ErrorLevel].
Errorf(template string, args ...interface{})
}
type Metrics ¶
type Metrics struct {
// 操作计数
ReadOps int64
WriteOps int64
DeleteOps int64
ListOps int64
// 字节统计
ReadBytes int64
WriteBytes int64
// 错误统计
ErrorCount int64
// 性能统计
AvgReadLatency int64 // 纳秒
AvgWriteLatency int64 // 纳秒
// 并发统计
ActiveReads int64
ActiveWrites int64
}
性能指标
type MetricsSnapshot ¶
type MetricsSnapshot struct {
Timestamp time.Time
Metrics Metrics
DiskUsage DiskUsageInfo
}
type MultipartPart ¶
MultipartPart 表示分段上传的一个部分
func (MultipartPart) MarshalEasyJSON ¶
func (v MultipartPart) MarshalEasyJSON(w *jwriter.Writer)
MarshalEasyJSON supports easyjson.Marshaler interface
func (MultipartPart) MarshalJSON ¶
func (v MultipartPart) MarshalJSON() ([]byte, error)
MarshalJSON supports json.Marshaler interface
func (*MultipartPart) UnmarshalEasyJSON ¶
func (v *MultipartPart) UnmarshalEasyJSON(l *jlexer.Lexer)
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*MultipartPart) UnmarshalJSON ¶
func (v *MultipartPart) UnmarshalJSON(data []byte) error
UnmarshalJSON supports json.Unmarshaler interface
type MultipartUploadInfo ¶
type MultipartUploadInfo struct {
Bucket string
Key string
UploadID string
ContentType string
Metadata map[string]string
CreatedAt time.Time
}
multipartUploadInfo 存储分段上传的元数据
func (MultipartUploadInfo) MarshalEasyJSON ¶
func (v MultipartUploadInfo) MarshalEasyJSON(w *jwriter.Writer)
MarshalEasyJSON supports easyjson.Marshaler interface
func (MultipartUploadInfo) MarshalJSON ¶
func (v MultipartUploadInfo) MarshalJSON() ([]byte, error)
MarshalJSON supports json.Marshaler interface
func (*MultipartUploadInfo) UnmarshalEasyJSON ¶
func (v *MultipartUploadInfo) UnmarshalEasyJSON(l *jlexer.Lexer)
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*MultipartUploadInfo) UnmarshalJSON ¶
func (v *MultipartUploadInfo) UnmarshalJSON(data []byte) error
UnmarshalJSON supports json.Unmarshaler interface
type ObjectData ¶
type ObjectData struct {
Key string
Data []byte
ContentType string
LastModified time.Time
ETag string
Metadata map[string]string
Size int64
}
ObjectData 表示 types 对象的完整数据
func (ObjectData) MarshalEasyJSON ¶
func (v ObjectData) MarshalEasyJSON(w *jwriter.Writer)
MarshalEasyJSON supports easyjson.Marshaler interface
func (ObjectData) MarshalJSON ¶
func (v ObjectData) MarshalJSON() ([]byte, error)
MarshalJSON supports json.Marshaler interface
func (*ObjectData) UnmarshalEasyJSON ¶
func (v *ObjectData) UnmarshalEasyJSON(l *jlexer.Lexer)
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*ObjectData) UnmarshalJSON ¶
func (v *ObjectData) UnmarshalJSON(data []byte) error
UnmarshalJSON supports json.Unmarshaler interface
type ObjectInfo ¶
ObjectInfo 表示 types 对象的元数据
func (ObjectInfo) MarshalEasyJSON ¶
func (v ObjectInfo) MarshalEasyJSON(w *jwriter.Writer)
MarshalEasyJSON supports easyjson.Marshaler interface
func (ObjectInfo) MarshalJSON ¶
func (v ObjectInfo) MarshalJSON() ([]byte, error)
MarshalJSON supports json.Marshaler interface
func (*ObjectInfo) UnmarshalEasyJSON ¶
func (v *ObjectInfo) UnmarshalEasyJSON(l *jlexer.Lexer)
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*ObjectInfo) UnmarshalJSON ¶
func (v *ObjectInfo) UnmarshalJSON(data []byte) error
UnmarshalJSON supports json.Unmarshaler interface
type PartInfo ¶
func (PartInfo) MarshalEasyJSON ¶
MarshalEasyJSON supports easyjson.Marshaler interface
func (PartInfo) MarshalJSON ¶
MarshalJSON supports json.Marshaler interface
func (*PartInfo) UnmarshalEasyJSON ¶
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*PartInfo) UnmarshalJSON ¶
UnmarshalJSON supports json.Unmarshaler interface
type PerformanceMonitor ¶
type PerformanceMonitor struct {
// contains filtered or unexported fields
}
PerformanceMonitor 性能监控器
func NewPerformanceMonitor ¶
func NewPerformanceMonitor(db *DB) *PerformanceMonitor
NewPerformanceMonitor 创建性能监控器
func (*PerformanceMonitor) AddAlertCallback ¶
func (pm *PerformanceMonitor) AddAlertCallback(callback AlertCallback)
AddAlertCallback 添加告警回调
func (*PerformanceMonitor) GenerateReport ¶
func (pm *PerformanceMonitor) GenerateReport(duration time.Duration) *PerformanceReport
GenerateReport 生成性能报告
func (*PerformanceMonitor) GetCurrentMetrics ¶
func (pm *PerformanceMonitor) GetCurrentMetrics() *Metrics
GetCurrentMetrics 获取当前指标
func (*PerformanceMonitor) GetMetricsHistory ¶
func (pm *PerformanceMonitor) GetMetricsHistory(duration time.Duration) []MetricsSnapshot
GetMetricsHistory 获取历史指标
func (*PerformanceMonitor) SetAlertThresholds ¶
func (pm *PerformanceMonitor) SetAlertThresholds(thresholds *AlertThresholds)
SetAlertThresholds 设置告警阈值
func (*PerformanceMonitor) Start ¶
func (pm *PerformanceMonitor) Start(interval time.Duration)
Start 启动监控
type PerformanceReport ¶
type Stats ¶
func (Stats) MarshalEasyJSON ¶
MarshalEasyJSON supports easyjson.Marshaler interface
func (Stats) MarshalJSON ¶
MarshalJSON supports json.Marshaler interface
func (*Stats) UnmarshalEasyJSON ¶
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*Stats) UnmarshalJSON ¶
UnmarshalJSON supports json.Unmarshaler interface