Documentation ¶
Index ¶
- Constants
- Variables
- type Batch
- type BatchOptions
- type DB
- func (db *DB) Close() error
- func (db *DB) Delete(key K) error
- func (db *DB) Exist(key K) (bool, error)
- func (db *DB) Fold(fn func(key []byte, value []byte) bool) error
- func (db *DB) Get(key K) (V, error)
- func (db *DB) GetDirPath() string
- func (db *DB) ListKeys() [][]byte
- func (db *DB) Merge() error
- func (db *DB) NewBatch(options BatchOptions) *Batch
- func (db *DB) NewIterator(options IteratorOptions) *Iterator
- func (db *DB) Put(key K, val V) error
- func (db *DB) Stat() *Stat
- func (db *DB) Sync() error
- type IndexRecord
- type IndexType
- type Iterator
- type IteratorOptions
- type K
- type LR
- type LRType
- type Loc
- type LogRecord
- type Options
- type Stat
- type V
Constants ¶
const ( B = 1 KB = 1024 * B MB = 1024 * KB GB = 1024 * MB )
Variables ¶
var ( ErrKeyEmpty = errors.New("the key is empty") ErrKeyNotFound = errors.New("key is not found in database") ErrDirPathIsEmpty = errors.New("database dir path is empty") ErrDataFileSizeNotPositive = errors.New("database data file size must be greater than 0") ErrDatabaseIsUsing = errors.New("the database directory is used by another process") ErrDBClosed = errors.New("the database is closed") ErrReadOnlyBatch = errors.New("the batch is read only") ErrMergeIsRunning = errors.New("merge is in progress, try again later") )
var DefaultBatchOptions = BatchOptions{ Sync: true, ReadOnly: false, }
var DefaultIteratorOptions = IteratorOptions{ Prefix: nil, Reverse: false, }
Functions ¶
This section is empty.
Types ¶
type Batch ¶
type Batch struct {
// contains filtered or unexported fields
}
Batch is a batch operation of the database. A batch can be read-only, calling Get() to get data. Otherwise, calling Delete() or Put() to put data. You must call Commit() to commit the batch, otherwise the deadlock happens.
Batch is not a transaction, for it does not guarantee isolation. But it can guarantee atomicity, consistency and durability.
func (*Batch) Commit ¶
Commit commits the batch, if the batch is readonly or empty, return. It will iterate the pendingWrites and write the data to the db, then write a record to indicate the end of batch to guarantee atomicity. Finally, index will be updated.
func (*Batch) Get ¶
Get gets the value of the given key. The key could still be in pendingWrites and haven't committed yet, return the value if the record type is not LRDeleted. Otherwise, get the value from WAL.
type BatchOptions ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB is a database instance. It's built on a log-structured model, the Bitcask. Read and write data based on WAL(Write-Ahead Log). An in-memory index is for holding the keys and the corresponding locations. The index is rebuilt each time the database is restarted.
func Open ¶
Open opens a db instance with specified options. It will open the WAL files and build the index.
func (*DB) GetDirPath ¶
func (*DB) Merge ¶
Merge merges all the data files. It will iterate all over the WAL, filtering valid data, then writing them to a new WAL in the merge directory.
Calling this method is up to the users, it may be very time-consuming when the database is large.
func (*DB) NewBatch ¶
func (db *DB) NewBatch(options BatchOptions) *Batch
func (*DB) NewIterator ¶
func (db *DB) NewIterator(options IteratorOptions) *Iterator
type IndexRecord ¶
type IndexRecord struct {
// contains filtered or unexported fields
}
IndexRecord is the index record of the key. Only used in start up to build in-mem index.
type Iterator ¶
Iterator is the iterator of db based on IndexIter.
func (*Iterator) Seek ¶
Seek moves the iterator to the key which is greater(or less when reverse) than or equal to the specified key.