Documentation
¶
Index ¶
- Constants
- Variables
- type Bucket
- type DB
- func (db *DB) Begin(writable bool) (*Tx, error)
- func (db *DB) Close() error
- func (db *DB) Compact() error
- func (db *DB) Delete(key []byte) error
- func (db *DB) Get(key []byte) ([]byte, error)
- func (db *DB) Put(key, value []byte) error
- func (db *DB) ReadAt(offset int64) (Node, error)
- func (db *DB) Size() int64
- func (db *DB) TriggerCompaction()
- func (db *DB) Update(fn func(tx *Tx) error) error
- func (db *DB) View(fn func(tx *Tx) error) error
- type Header
- func (h *Header) EncodeState(t State, s State)
- func (h Header) EntrySize() uint32
- func (h Header) IsBucket() bool
- func (h Header) IsDeleted() bool
- func (h Header) IsExpired() bool
- func (h Header) IsKV() bool
- func (h Header) IsNormal() bool
- func (h *Header) SetEntrySize(size uint32)
- func (h *Header) SetRecord(s State)
- func (h *Header) SetType(t State)
- func (h Header) State() State
- func (h Header) StateRecord() State
- func (h Header) StateType() State
- type IOStorage
- type Node
- type Option
- type State
- type Tx
Constants ¶
const ( B = 1 KB = 1024 * B MB = 1024 * KB GB = 1024 * MB )
const ( // MaxKeySize is the maximum length of a key, in bytes. MaxKeySize = 32768 // MaxValueSize is the maximum length of a value, in bytes. MaxValueSize = (1 << 31) - 2 )
const HeaderSize = 5
Variables ¶
var ( // ErrDatabaseNotOpen is returned when a DB instance is accessed before it // is opened or after it is closed. ErrDatabaseNotOpen = errors.New("database not open") // ErrDatabaseOpen is returned when opening a database that is // already open. ErrDatabaseOpen = errors.New("database already open") // ErrInvalid is returned when both meta pages on a database are invalid. // This typically occurs when a file is not a bolt database. ErrInvalid = errors.New("invalid database") // ErrVersionMismatch is returned when the data file was created with a // different version of Bolt. ErrVersionMismatch = errors.New("version mismatch") // ErrChecksum is returned when either meta page checksum does not match. ErrChecksum = errors.New("checksum error") // ErrTimeout is returned when a database cannot obtain an exclusive lock // on the data file after the timeout passed to Open(). ErrTimeout = errors.New("timeout") )
These errors can be returned when opening or calling methods on a DB.
var ( // ErrTxNotWritable is returned when performing a write operation on a // read-only transaction. ErrTxNotWritable = errors.New("tx not writable") // ErrTxClosed is returned when committing or rolling back a transaction // that has already been committed or rolled back. ErrTxClosed = errors.New("tx closed") // ErrDatabaseReadOnly is returned when a mutating transaction is started on a // read-only database. ErrDatabaseReadOnly = errors.New("database is in read-only mode") )
These errors can occur when beginning or committing a Tx.
var ( // ErrBucketNotFound is returned when trying to access a bucket that has // not been created yet. ErrBucketNotFound = errors.New("bucket not found") // ErrBucketExists is returned when creating a bucket that already exists. ErrBucketExists = errors.New("bucket already exists") // ErrBucketNameRequired is returned when creating a bucket with a blank name. ErrBucketNameRequired = errors.New("bucket name required") // ErrKeyRequired is returned when inserting a zero-length key. ErrKeyRequired = errors.New("key required") // ErrKeyTooLarge is returned when inserting a key that is larger than MaxKeySize. ErrKeyTooLarge = errors.New("key too large") // ErrValueTooLarge is returned when inserting a value that is larger than MaxValueSize. ErrValueTooLarge = errors.New("value too large") // ErrIncompatibleValue is returned when trying create or delete a bucket // on an existing non-bucket key or when trying to create or delete a // non-bucket key on an existing bucket key. ErrIncompatibleValue = errors.New("incompatible value") // ErrKeyNotFound is returned when trying to access a key that does not exist. // This can occur when trying to delete a key or bucket that does not exist. ErrKeyNotFound = errors.New("key not found") )
These errors can occur when putting or deleting a value or a bucket.
var (
ErrInvalidRecord = errors.New("invalid record")
)
Functions ¶
This section is empty.
Types ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
func (*DB) Compact ¶
Compact Perform database compression operations, delete deleted records, and optimize storage space
func (*DB) Update ¶
Update executes a function within a managed read/write transaction. The transaction has been committed when no error is returned. In the event that an error is returned, the transaction will be rolled back. When a non-nil error is returned from the function, the transaction will be rolled back and the that error will be return to the caller of Update().
type Header ¶
type Header [HeaderSize]byte
- Header format:
+----------+---------------+ |state(1B) | EntrySize(4B) | +----------+---------------+
func (*Header) EncodeState ¶
func (*Header) SetEntrySize ¶
func (Header) StateRecord ¶
type IOStorage ¶
const ( File IOStorage = IOStorage(bio.FileStorage) Memory IOStorage = IOStorage(bio.MemoryStorage) Mmap IOStorage = IOStorage(bio.MmapStorage) )
type Node ¶
type Node interface {
// io.WriterTo
Header() Header
BucketID() uint32
Size() uint32
Value() []byte
MarshalToBuffer(buff *bytebufferpool.ByteBuffer) error
}
type Option ¶
type Option func(*option)
func WithCompactionInterval ¶
WithCompactionInterval 设置自动压缩间隔
func WithIncrementSize ¶
func WithStorage ¶
type State ¶
type State uint8
State 定义了记录的状态信息,由一个字节表示 高4位表示记录类型 (StateType),低4位表示记录状态 (StateRecord)
const ( TypeNormal State = 0x00 // 0000 0000 - 普通记录 TypeBucket State = 0x10 // 0001 0000 - 桶记录 TypeKV State = 0x20 // 0010 0000 - 键值记录 TypeReserved State = 0x30 // 0011 0000 - 保留类型 TypeMask State = 0xF0 // 1111 0000 - 类型掩码 )
StateType 定义,使用高4位
const ( StateNormal State = 0x00 // 0000 0000 - 正常状态 StateDeleted State = 0x01 // 0000 0001 - 已删除 StateInvalid State = 0x02 // 0000 0010 - 无效状态 StateReserved State = 0x03 // 0000 0011 - 保留状态 StateMask State = 0x0F // 0000 1111 - 状态掩码 )
StateRecord 定义,使用低4位