Documentation
¶
Index ¶
- Variables
- type Configs
- 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 IteratorConfigs) *Iterator
- func (db *DB) NewWriteBatch(opts WriteBatchConfigs) *WriteBatch
- func (db *DB) Put(key []byte, value []byte) error
- func (db *DB) Stat() *Stat
- func (db *DB) Sync() error
- type IndexerType
- type Iterator
- type IteratorConfigs
- type Stat
- type WriteBatch
- type WriteBatchConfigs
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrKeyIsEmpty = errors.New("the key is empty") ErrKeyNotFound = errors.New("key not found in database") ErrDataFileNotFound = errors.New("data file is not found") ErrDataDirectoryCorrupted = errors.New("the database directory maybe corrupted") ErrIndexUpdateFailed = errors.New("failed to update index") ErrExceedMaxBatchNum = errors.New("exceed the max batch num") ErrMergeInProgress = errors.New("merge is in progress, try again later") ErrMergeRatioUnreached = errors.New("the merge ratio do not reach the option") ErrNoEnoughSpaceForMerge = errors.New("no enough disk space for merge") ErrDatabaseIsUsing = errors.New("database directory is using by another process") )
View Source
var DefaultIteratorConfigs = IteratorConfigs{ Prefix: nil, Reverse: false, }
View Source
var DefaultOptions = Configs{ DirPath: os.TempDir(), FileSize: 256 * 1024 * 1024, SyncWrites: false, IndexType: BTree, BytesPerSync: 0, MMapAtStartup: true, DataFileMergeRatio: 0.5, }
View Source
var DefaultWriteBatchConfigs = WriteBatchConfigs{ MaxBatchNum: 10000, SyncWrites: true, }
Functions ¶
This section is empty.
Types ¶
type Configs ¶
type Configs struct {
// 数据库数据目录
DirPath string
// 数据文件的大小
FileSize int64
// 每次写数据是否持久化
SyncWrites bool
// 索引类型
IndexType IndexerType
// 积累多少字节写入后进行持久化
BytesPerSync int
// 启动时是否使用 MMap 加载数据
MMapAtStartup bool
// 数据文件合并的阈值
DataFileMergeRatio float32
}
Configs 配置项的结构体、用户可传递过来的配置项
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB represents a key-value storage engine instance.
func Open ¶
Open opens or creates a DB at the specified path with the given config. If the directory does not exist, it will be created.
func (*DB) Delete ¶
Delete removes the value for the given key. If the key does not exist, no error is returned.
func (*DB) Get ¶
Get retrieves the value for the given key. Returns ErrKeyNotFound if the key does not exist.
func (*DB) NewIterator ¶
func (db *DB) NewIterator(opts IteratorConfigs) *Iterator
NewIterator 初始化迭代器
func (*DB) NewWriteBatch ¶
func (db *DB) NewWriteBatch(opts WriteBatchConfigs) *WriteBatch
NewWriteBatch new WriteBatch
type IndexerType ¶
type IndexerType = int8
const ( // BTree 索引 BTree IndexerType = iota + 1 // ART Adpative Radix Tree 自适应基数树索引 ART // BPlusTree B+ 树索引,将索引存储到磁盘上 BPlusTree )
type Iterator ¶
type Iterator struct {
// contains filtered or unexported fields
}
Iterator 迭代器
type IteratorConfigs ¶
type IteratorConfigs struct {
// 遍历前缀为指定值的 Key,默认为空
Prefix []byte
// 是否反向遍历,默认 false 是正向
Reverse bool
}
IteratorConfigs 索引迭代器配置项
type Stat ¶
type Stat struct {
KeyNum uint // key 的总数量
DataFileNum uint // 数据文件的数量
ReclaimableSize int64 // 可以进行 merge 回收的数据量,字节为单位
DiskSize int64 // 数据目录所占磁盘空间大小
}
Stat 存储引擎统计信息
type WriteBatch ¶
type WriteBatch struct {
// contains filtered or unexported fields
}
type WriteBatchConfigs ¶
type WriteBatchConfigs struct {
// 一个批次当中最大的数据量
MaxBatchNum uint
// 提交时是否 sync 持久化
SyncWrites bool
}
WriteBatchConfigs 批量写配置项
Click to show internal directories.
Click to hide internal directories.