cask

package
v0.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 17, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const InMemoryDB = "in:mem:db"

InMemoryDB represents a magic value which can be used instead of db path in order to instantiate in memory file system instead of disk

Variables

View Source
var (
	// ErrKeyNotFound signifies that the requested key was not found in keydir
	// This effectively means that the key does not exist in the database itself
	ErrKeyNotFound = errors.New("gocask: key not found")

	// ErrPartialWrite signifies that the underlying disk write was not complete, which means
	// that write was successful but the entry is corrupted and the operation should be retried
	ErrPartialWrite = errors.New("gocask: key/value pair not fully written")

	// ErrCRCFailed is thrown upon reading a corrupted value
	ErrCRCFailed = errors.New("gocask: crc check failed for db entry (value is corrupted)")

	// ErrInvalidKey is thrown when attempting Get, Put or Delete with an invalid key
	ErrInvalidKey = errors.New("gocask: key should not be empty or nil")

	// ErrInvalidValue is thrown when attempting to store a nil value
	ErrInvalidValue = errors.New("gocask: value should not be nil")
)
View Source
var DefaultConfig = Config{
	MaxDataFileSize: 1024 * 1024 * 1024 * 2,
	DataDir:         "./",
}

DefaultConfig represents default gocask config

Functions

This section is empty.

Types

type Config

type Config struct {
	MaxDataFileSize int64
	DataDir         string
}

Config represents gocask config

type DB

type DB struct {
	// contains filtered or unexported fields
}

DB represents bitcask db implementation

func NewDB

func NewDB(dbpath string, fs FS, time Time, cfg Config) (*DB, error)

NewDB instantiates new db with provided FS as storage mechanism

func (*DB) Close

func (db *DB) Close() error

func (*DB) Delete

func (db *DB) Delete(key []byte) error

Delete deletes a key/value pair if it exists or reports key not found error if the key does not exist

func (*DB) Get

func (db *DB) Get(key []byte) ([]byte, error)

Get retrieves a value stored under given key

func (*DB) Keys

func (db *DB) Keys() []string

Keys returns all keys

func (*DB) Put

func (db *DB) Put(key, val []byte) error

Put stores the value under given key

type FS

type FS interface {
	// Open should open the active data file for the given db path
	Open(string) (File, error)

	// Rotate should generate and open new data file for the given db path
	Rotate(string) (File, error)

	// Walk should walk through all data files for the given db path
	Walk(string, func(File) error) error

	// ReadFileAt should read a chunk of named path data file at the given offset
	ReadFileAt(string, string, []byte, int64) (int, error)
}

FS represents a file system interface

type File

type File interface {
	io.ReadWriteCloser

	Name() string
	Size() int64
}

File represents a single fs data file

type Time

type Time interface {
	NowUnix() uint32
}

Time represents time provider

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL