Documentation ¶
Index ¶
- Variables
- type DB
- type FileSystem
- type Key
- type Option
- func WithCompactInterval(compactInterval time.Duration) Option
- func WithCompactThreshold(compactThreshold uint32) Option
- func WithFileSystem(fs FileSystem) Option
- func WithMaxFileBytes(maxFileBytes uint32) Option
- func WithMaxKeyBytes(maxKeyBytes uint16) Option
- func WithMaxValueBytes(maxValueBytes uint16) Option
Constants ¶
This section is empty.
Variables ¶
var ( ErrKeyOrValueTooLong = errors.New("key or value is oversize") ErrKeyNotFound = errors.New("key not found") ErrInvalidEntryHeader = errors.New("invalid entry header") ErrEntryCorrupted = errors.New("entry corrupted") ErrInvalidKeydirData = errors.New("invalid keydir data") ErrInvalidKeydirFileData = errors.New("invalid keydir file data") )
Functions ¶
This section is empty.
Types ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB is a simple key-value store backed by a log file, which is an append-only and immutable sequence of key-value pairs. The key-value pairs are stored in the log file in the order they are written. The log file is structured as follows:
| crc | tstamp | key_sz | value_sz | key | value | | crc | tstamp | key_sz | value_sz | key | value |
Since it's append-only, so modification and deletion would also append a new entry to overwrite old value.
func (*DB) Delete ¶
Delete removes the key from the DB. Note that the key is not actually removed from the DB, but marked as deleted, and the key will be removed from the DB when the DB is compacted.
type FileSystem ¶
FileSystem is the interface that wraps the basic methods for a file system, it is used by the file system abstraction layer to access, so that the default os file system can be replaced by other implementations.
It's useful for testing, since it can be replaced by a mock file system.
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
func WithCompactInterval ¶
WithCompactInterval set the interval to check whether the compaction process should be triggered. NOTE: The interval is recommended to be greater than 1 minute. but it depends on the case of the application.
func WithCompactThreshold ¶
WithCompactThreshold set the maximum number of files to keep.
func WithFileSystem ¶
func WithFileSystem(fs FileSystem) Option
WithFileSystem set the file system to access.
func WithMaxFileBytes ¶
WithMaxFileBytes set the maximum number of bytes for a single file.
func WithMaxKeyBytes ¶
WithMaxKeyBytes set the maximum number of bytes for a single key.
func WithMaxValueBytes ¶
WithMaxValueBytes set the maximum number of bytes for a single value.