Documentation ¶
Index ¶
- Constants
- Variables
- type BTree
- type Batch
- func (b *Batch) Close() error
- func (b *Batch) Commit() error
- func (b *Batch) Delete(k []byte) error
- func (b *Batch) Exists(k []byte) (bool, error)
- func (b *Batch) Get(k []byte) ([]byte, error)
- func (b *Batch) Rollback() error
- func (b *Batch) Set(k []byte, v []byte) ([]byte, error)
- func (b *Batch) SetWithTTL(k []byte, v []byte, ttl time.Duration) ([]byte, error)
- type Block
- type BlockOffsetPair
- type Db
- func (db *Db) All() []*KeyValuePair
- func (db *Db) Close() error
- func (db *Db) CloseWatch() error
- func (db *Db) Delete(key []byte) error
- func (db *Db) Get(key []byte) ([]byte, error)
- func (db *Db) KeyReader(prefix string, handler func(k []byte))
- func (db *Db) KeyValueReader(keyPrefix string, handler func(k []byte, v []byte)) (bool, error)
- func (db *Db) NewBatch() (*Batch, error)
- func (db *Db) NewWatch() (chan WatcherEvent, error)
- func (db *Db) SendWatchEvent(w WatcherEvent) error
- func (db *Db) Set(k []byte, v []byte) ([]byte, error)
- func (db *Db) SetWithTTL(k []byte, v []byte, ttl time.Duration) (interface{}, error)
- func (db *Db) Sync() error
- type EventType
- type KeyDirValue
- type KeyValueEntry
- type KeyValuePair
- type Options
- type Segment
- type WatcherEvent
Constants ¶
const ( KB int64 = 1 << (10 * iota) MB GB TB PB EB )
const ( ActiveKeyValueEntryDatafileSuffix = ".dfile" KeyValueEntryHintfileSuffix = ".hfile" InactiveKeyValueEntryDataFileSuffix = ".idfile" TempDataFilePattern = "*.dfile" TempInactiveDataFilePattern = "*.idfile" DefaultDataDir = "nimbusdb" DatafileThreshold = 1 * MB BlockSize = 32 * KB )
const ( CrcSize int64 = 5 DeleteFlagSize = 1 TstampSize = 10 KeySizeSize = 10 ValueSizeSize = 10 StaticChunkSize = CrcSize + DeleteFlagSize + TstampSize + KeySizeSize + ValueSizeSize CrcOffset int64 = 5 DeleteFlagOffset = 6 TstampOffset = 16 KeySizeOffset = 26 ValueSizeOffset = 36 BTreeDegree int = 10 )
const ( KEY_EXPIRES_IN_DEFAULT = 168 * time.Hour // 1 week DELETED_FLAG_BYTE_VALUE = byte(0x31) DELETED_FLAG_SET_VALUE = byte(0x01) DELETED_FLAG_UNSET_VALUE = byte(0x00) LRU_SIZE = 50 LRU_TTL = 24 * time.Hour EXIT_NOT_OK = 0 EXIT_OK = 1 INITIAL_SEGMENT_OFFSET = 0 INITIAL_KEY_VALUE_ENTRY_OFFSET = 0 )
const (
TotalStaticChunkSize int64 = TstampOffset + KeySizeOffset + ValueSizeOffset + DeleteFlagOffset + CrcOffset + StaticChunkSize
)
Variables ¶
var ( ERROR_BATCH_CLOSED = errors.New("batch is closed") ERROR_CANNOT_CLOSE_CLOSED_BATCH = errors.New("cannot close closed batch") )
var ( ERROR_KEY_NOT_FOUND = errors.New("key expired or does not exist") ERROR_NO_ACTIVE_FILE_OPENED = errors.New("no file opened for writing") ERROR_OFFSET_EXCEEDED_FILE_SIZE = errors.New("offset exceeded file size") ERROR_CANNOT_READ_FILE = errors.New("error reading file") ERROR_KEY_VALUE_SIZE_EXCEEDED = errors.New(fmt.Sprintf("exceeded limit of %d bytes", BlockSize)) ERROR_CRC_DOES_NOT_MATCH = errors.New("crc does not match. corrupted datafile") ERROR_DB_CLOSED = errors.New("database is closed") )
Functions ¶
This section is empty.
Types ¶
type BTree ¶
type BTree struct {
// contains filtered or unexported fields
}
func (*BTree) Delete ¶
func (b *BTree) Delete(key []byte) *KeyValuePair
func (*BTree) Get ¶
func (b *BTree) Get(key []byte) *KeyDirValue
func (*BTree) List ¶
func (b *BTree) List() []*KeyValuePair
func (*BTree) Set ¶
func (b *BTree) Set(key []byte, value KeyDirValue) *KeyDirValue
type Block ¶
type Block struct {
// contains filtered or unexported fields
}
Block represents a single block of disk memory. Default size is 32KB. Each Segment is a collection of blocks; Each block is a collection of KeyValueEntries.
type BlockOffsetPair ¶
type BlockOffsetPair struct {
// contains filtered or unexported fields
}
BlockOffsetPair contains metadata about the Block. The start and ending offsets of the Block, and the path.
type Db ¶
type Db struct {
// contains filtered or unexported fields
}
func (*Db) All ¶
func (db *Db) All() []*KeyValuePair
func (*Db) Close ¶
Closes the database. Closes the file pointer used to read/write the activeDataFile. Closes all file inactiveDataFile pointers and marks them as closed.
func (*Db) CloseWatch ¶ added in v0.1.2
func (*Db) KeyReader ¶ added in v0.1.1
KeyReader iterates through each key matching given prefix. If prefix is an empty string, all keys are matched. The second argument is a callback function which contains the key.
func (*Db) KeyValueReader ¶ added in v0.1.1
KeyValueReader iterates through each key-value pair matching given key's prefix. If prefix is an empty string, all key-value pairs are matched. The second argument is a callback function which contains key and the value.
func (*Db) NewWatch ¶ added in v0.1.2
func (db *Db) NewWatch() (chan WatcherEvent, error)
func (*Db) SendWatchEvent ¶ added in v0.1.2
func (db *Db) SendWatchEvent(w WatcherEvent) error
func (*Db) SetWithTTL ¶ added in v0.1.1
type KeyDirValue ¶
type KeyDirValue struct {
// contains filtered or unexported fields
}
func NewKeyDirValue ¶
func NewKeyDirValue(offset, size, tstamp int64, path string) *KeyDirValue
type KeyValueEntry ¶
type KeyValueEntry struct {
// contains filtered or unexported fields
}
KeyValueEntry is the raw and complete uncompressed data existing on the disk. KeyValueEntry is stored in Blocks in cache for faster reads.
func (*KeyValueEntry) Key ¶
func (kv *KeyValueEntry) Key() []byte
func (*KeyValueEntry) PayloadToByte ¶ added in v0.1.1
func (kv *KeyValueEntry) PayloadToByte() []byte
func (*KeyValueEntry) StaticChunkSize ¶
func (kv *KeyValueEntry) StaticChunkSize() int64
func (*KeyValueEntry) ToByte ¶
func (kv *KeyValueEntry) ToByte() []byte
func (*KeyValueEntry) Value ¶
func (kv *KeyValueEntry) Value() []byte
type KeyValuePair ¶
type Segment ¶
type Segment struct {
// contains filtered or unexported fields
}
Segment represents an entire file. It is divided into Blocks. Each Segment is a collection of Blocks of size 32KB. A file pointer is kept opened for reading purposes. closed represents the state of the Segment's file pointer.
type WatcherEvent ¶ added in v0.1.2
type WatcherEvent struct { EventType EventType Key []byte OldValue []byte NewValue []byte EventTimestamp time.Time BatchId *ksuid.KSUID }
func NewCreateWatcherEvent ¶ added in v0.1.2
func NewCreateWatcherEvent(key, oldValue, newValue []byte, batchId *ksuid.KSUID) WatcherEvent
func NewDeleteWatcherEvent ¶ added in v0.1.2
func NewDeleteWatcherEvent(key, oldValue, newValue []byte, batchId *ksuid.KSUID) WatcherEvent
func NewUpdateWatcherEvent ¶ added in v0.1.2
func NewUpdateWatcherEvent(key, oldValue, newValue []byte, batchId *ksuid.KSUID) WatcherEvent