Documentation
¶
Index ¶
- Variables
- func FcpPxtU() error
- type DB
- func (db *DB) Backup(dir string) error
- func (db *DB) Close() error
- func (db *DB) Delete(key []byte) error
- func (db *DB) Fold(fn func(key []byte, value []byte) bool) error
- func (db *DB) Get(key []byte) ([]byte, error)
- func (db *DB) ListKeys() [][]byte
- func (db *DB) Merge() error
- func (db *DB) NewIterator(opts IteratorOptions) *Iterator
- func (db *DB) NewWriteBatch(opts WriteBatchOptions) *WriteBatch
- func (db *DB) Put(key []byte, value []byte) error
- func (db *DB) Stat() *Stat
- func (db *DB) Sync() error
- type Iterator
- type IteratorOptions
- type Options
- type Stat
- type SyncStrategy
- type WriteBatch
- type WriteBatchOptions
Constants ¶
This section is empty.
Variables ¶
var ( ErrKeyIsEmpty = errors.New("the key is empty") ErrIndexUpdateFailed = errors.New("failed to update index") ErrKeyNotFound = errors.New("key not found in database") ErrDataFileNotFound = errors.New("datafile file is not found") ErrDataDirectoryCorrupted = errors.New("the database directory maybe corrupted") ErrExceedMaxBatchNum = errors.New("exceed the max batch num") ErrMergeIsProgress = errors.New("merge is in progress, try again later") ErrDatabaseIsUsing = errors.New("the database directory is used by another process") ErrMergeRatioUnreached = errors.New("the merge ratio do not reach the option") ErrNoEnoughSpaceForMerge = errors.New("no enough disk space for merge") )
var DefaultIteratorOptions = IteratorOptions{ Prefix: nil, Reverse: false, }
DefaultIteratorOptions 默认迭代器Options, 供测试使用
var DefaultOptions = Options{ DirPath: os.TempDir(), DataFileSize: 512 * 1024 * 1024, SyncStrategy: No, BytesPerSync: 1024 * 1024, EnableBackgroundMerge: false, IndexType: index.HashMap, ShardNum: 16, FileIOType: fio.MemoryMap, DataFileMergeRatio: 0.5, }
DefaultOptions 默认Options, 供示例程序使用
var DefaultWriteBatchOptions = WriteBatchOptions{ MaxBatchNum: 10000, SyncWrites: true, }
DefaultWriteBatchOptions 默认事务 Options, 供测试使用
Functions ¶
Types ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB bitcask存储引擎客户端
func (*DB) Merge ¶
Merge 立即执行 Merge 过程 todo 扩展点:新增定时任务和清除策略配置项, 监控数据状态, 进行自动清理 todo 优化点:使用性能更高的 merge 方法
func (*DB) NewIterator ¶
func (db *DB) NewIterator(opts IteratorOptions) *Iterator
func (*DB) NewWriteBatch ¶
func (db *DB) NewWriteBatch(opts WriteBatchOptions) *WriteBatch
NewWriteBatch 创建新 WriteBatch 实例
type Iterator ¶
type Iterator struct {
// contains filtered or unexported fields
}
Iterator 数据库层迭代器, 面向用户
type IteratorOptions ¶
IteratorOptions 索引迭代器配置项
type Options ¶
type Options struct {
DirPath string // 数据目录
DataFileSize int64 // 数据文件最大容量, 单位字节
SyncStrategy SyncStrategy // 持久化策略
BytesPerSync uint // 新写入数据量阈值
IndexType index.IndexType // 索引类型
FileIOType fio.FileIOType // 文件 IO 类型
EnableBackgroundMerge bool // 是否启用后台定时 merge
DataFileMergeRatio float32 // 执行 merge 的无效数据占比阈值
ShardNum int // 索引分片数量
}
Options 用户配置项
type Stat ¶
type Stat struct {
KeyNum int // 当前 key 的数量
DataFileNum uint // 当前数据文件数量
ReclaimableSize int64 // 当前 merge 可回收的数据量, 单位字节
DiskSize int64 // 数据目录的磁盘占用空间大小
}
Stat 实时统计信息 todo 扩展点:后续进行维护和利用
type SyncStrategy ¶
type SyncStrategy byte
const ( No SyncStrategy = iota // 由操作系统决定 Always // 立即持久化 Threshold // 新写入数据量达到阈值持久化 )
type WriteBatch ¶
type WriteBatch struct {
// contains filtered or unexported fields
}
WriteBatch 事务客户端 todo 优化点:新增方法结束自动提交的事务形式 todo 优化点:新增 Get 方法
func (*WriteBatch) Put ¶
func (wb *WriteBatch) Put(key, value []byte) error
type WriteBatchOptions ¶
WriteBatchOptions 批量写入配置项
