bitcask

package module
v0.0.0-...-bd298f0 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2021 License: MIT Imports: 14 Imported by: 0

README

bitcask

This is my toy project to learn golang.

Bitcask is a key-value log database. It produce value in file and store key to value's location to find it. location is consist of

  1. fileno
  2. offset
  3. length

Every time add a key value would append log to a value file and a header file with locations.

And when reading, just find the location and read it from disk. A cache for recent key makes reading faster.

In option.go, there are some options for DB. such as go's cnt for reader, max file size, max key and value length.

I also add location header & checksum to avoid disk fail when loading.

I learn a lot in this project.

  1. R/W files and handle errors
  2. channel works like a thread safe queue.
  3. again importance of tests

There still some works to do. Such as

  1. Managing readers to reduce system call of opening same file.
  2. A monitor for deleting not outdated logs in files when idle.
  3. Appending logs in multiple files, which makes more writers possible.(currently only one)
  4. Recover for db's failure. A bug now is that it won't check sucess in creating new value files but not in header files. When this happen, loading return error.

But I want to do some more influential work and have no interest in this toy project anymore.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCxtInconsistency = errors.New("cxt: inconsistency")
View Source
var ErrCxtInvalid = errors.New("cxt: other files")
View Source
var ErrDuplicateOption = errors.New("duplicate option")
View Source
var ErrKeyLenTooLong = errors.New("key too long")
View Source
var ErrKeyNotFound = errors.New("not found key")
View Source
var ErrNotReady = errors.New("not ready")
View Source
var ErrRead = errors.New("read")
View Source
var ErrValueLenTooLong = errors.New("value too long")
View Source
var ErrWrite = errors.New("write")

Functions

This section is empty.

Types

type CacheOption

type CacheOption struct {
	Capacity int
}

type DB

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

func Open

func Open(path string, options ...Option) (*DB, error)

func (*DB) Add

func (db *DB) Add(key, value string) error

func (*DB) Close

func (db *DB) Close()

func (*DB) Get

func (db *DB) Get(key string) (string, error)

type DiskOption

type DiskOption struct {
	ReaderCnt int
	LoaderCnt int
}

type Err

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

func (*Err) Error

func (e *Err) Error() string

func (*Err) Unwrap

func (e *Err) Unwrap() error

type FileType

type FileType int
const (
	FT_Invalid FileType = iota
	FT_Location
	FT_Data
)

type LimitOption

type LimitOption struct {
	MaxFileSize  int
	MaxKeySize   int
	MaxValueSize int
}

type Option

type Option interface {
	// contains filtered or unexported methods
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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