Documentation ¶
Index ¶
- Variables
- type DB
- func (db *DB) Backup(directory string) error
- func (db *DB) Close() error
- func (db *DB) Delete(key []byte) error
- func (db *DB) Fold(fn userOperationFunc) error
- func (db *DB) Fork(directory string) (*DB, error)
- func (db *DB) Get(key []byte) ([]byte, error)
- func (db *DB) ListKeys() [][]byte
- func (db *DB) Merge() error
- func (db *DB) NewItrerator(options index.IteratorOptions) *Iterator
- func (db *DB) NewWriteBatch(options WriteBatchOptions) *WriteBatch
- func (db *DB) Put(key, value []byte) error
- func (db *DB) Stat() *Stat
- func (db *DB) Sync() error
- type DBOptions
- type Iterator
- type Stat
- 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") ErrFileNotFound = errors.New("file not found") ErrKeyNotFound = errors.New("key not found") ErrDirectoryIsEmpty = errors.New("data path is empty") ErrMaxDataFileSizeIsNegative = errors.New("the maximum size of data file is negative") ErrDirectoryCorrupted = errors.New("maybe the directory of the DB is corrupted") ErrExceedMaxBatchNumber = errors.New("exceed the maximum batch number") ErrMergenceIsInProgress = errors.New("mergence is in progress, try again later") ErrDatabaseIsUsed = errors.New("the database is used by other process") ErrInvalidMergenceThreshold = errors.New("invalid mergence threshold") ErrNoMoreDiskSpace = errors.New("no more disk space to store data") )
User-defined errors
var ( // DefaultDBOptions Default options for launching DB engine DefaultDBOptions = DBOptions{ Directory: "/tmp/baradb", MaxDataFileSize: 512 * 1024 * 1024, SyncWrites: false, IndexType: index.ARtree, MMapAtStartup: false, } // DefaultWriteBatchOptions Default options for batch writing DefaultWriteBatchOptions = WriteBatchOptions{ MaxBatchNumber: 100, SyncWrites: true, } )
Functions ¶
This section is empty.
Types ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB represents a baradb engine
func (*DB) Backup ¶
Backup copies the DB's data files to a given directory.
NOTE: only data files will be copied, other files like tran-no, flock will be ignored.
func (*DB) Fold ¶
Fold retrieves all the data and iteratively executes an user-specified operation (UDF) Once the UDF failed, the iteration will stop intermediatelly
func (*DB) NewItrerator ¶
func (db *DB) NewItrerator(options index.IteratorOptions) *Iterator
NewItrerator initializes an iterator of DB engine
func (*DB) NewWriteBatch ¶
func (db *DB) NewWriteBatch(options WriteBatchOptions) *WriteBatch
NewWriteBatch initializes a write batch in the DB engine
type DBOptions ¶
type DBOptions struct { // Directory of a DB engine instance where data files are stored in Directory string // Maximum size of every single data file (uint: Byte). // // It should be greater than 0. MaxDataFileSize int64 // SyncWrites indicates whether persist data after writing SyncWrites bool // IndexType indicates the type of the index of the DB engine IndexType index.IndexType // SyncThreshold indicates a threshold for persisting data. // // It should equals 0 or be greater than 0 (uint: Byte). // // When the DB engine wrote bytes more than this threshold, the DB engine will sync the wirtten bytes to the acitve data file. SyncThreshold uint // MMapAtStartup indicates whether load memory mapping while starting up the DB engine MMapAtStartup bool // MergenceThreshold indicates a threshold for merging data. // // When proportion of the invalid data in the DB engine is greater than this threshold, // the DB engine will merge all its data. // // The value of this threshold should be between 0 and 1. // // If the value is 0, then this threshold is disabled and the DB engine will not merge its data. MergenceThreshold float64 }
Options represents options of a DB engine instance
type Iterator ¶
type Iterator struct {
// contains filtered or unexported fields
}
Iterator an iterator of DB
type Stat ¶
type Stat struct { KeyNumber uint `json:"keyNumber"` // Number of key(s) in the DB engine DataFileNumber uint `json:"dataFileNumber"` // Number of data file(s) in the DB engine ReclaimableSize int64 `json:"reclaimableSize"` // Amount of mergable data (unit: byte) DiskSize int64 `json:"diskSize"` // Size of the DB engine occuppied in disk (unit: byte) }
Stat represents statistical information of a DB engine
type WriteBatch ¶
type WriteBatch struct {
// contains filtered or unexported fields
}
WriteBatch A transaction that batch writes data and makes sure atomicity
func (*WriteBatch) Commit ¶
func (wb *WriteBatch) Commit() error
Commit commits the transaction, writes the pending data to the disk and updates the in-memory index
type WriteBatchOptions ¶
type WriteBatchOptions struct { MaxBatchNumber int // Maximum amount of data in one batch SyncWrites bool // Sync data after writing if true }
WriteBatchOptions options for batch writing