storage

package
v0.0.0-...-1cd5cd2 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BHashTable

type BHashTable interface {
	Get(key string) (h HashItem, err error)
	Set(key string, h HashItem) error
	Del(key string) error
	Exists(key string) (exists bool)
	IteratorItem() <-chan struct {
		// contains filtered or unexported fields
	}
}

BHashTable interface for bitcask hash table. it's used to find the location of the record in current version in wal file on disk, and to support the read request with only one disk seek and one disk read per request

type BitCaskLogFile

type BitCaskLogFile struct {
	FileName    string
	FileHandle  *os.File
	FileHandleW *bufio.Writer
	FileHandleR *os.File
	// contains filtered or unexported fields
}

BitCaskLogFile struct of the BitcaskLogFile implementation of WALFile interface

func CreateBitcaskLogFile

func CreateBitcaskLogFile(filename string) *BitCaskLogFile

CreateBitcaskLogFile create a new BitcaskLogFile struct

func (*BitCaskLogFile) AppendRecord

func (b *BitCaskLogFile) AppendRecord(r Record, sync bool) (int64, int, error)

AppendRecord append a record to wal file return record offset and len return nil for error if success

func (*BitCaskLogFile) CloseFile

func (b *BitCaskLogFile) CloseFile(remove bool) error

CloseFile close the file handle of the wal file on disk return nil if success

func (*BitCaskLogFile) Deactivate

func (b *BitCaskLogFile) Deactivate() error

Deactivate deactivate the BitcaskLogFile by closing the write handle of the wal file if it's open return nil if success

func (*BitCaskLogFile) IteratorRecord

func (b *BitCaskLogFile) IteratorRecord() <-chan struct {
	offset int
	r      Record
}

IteratorRecord return a channel of record for iterating

func (*BitCaskLogFile) ReadRecord

func (b *BitCaskLogFile) ReadRecord(offset int64, len int, r *Record) error

ReadRecord read a record from wal file offset and [len] bytes return nil if success

func (*BitCaskLogFile) RemoveFile

func (b *BitCaskLogFile) RemoveFile() error

RemoveFile remove the wal file on disk return nil if success

func (*BitCaskLogFile) RenameFile

func (b *BitCaskLogFile) RenameFile(name string) error

RenameFile rename the wal file on disk return nil if success

func (*BitCaskLogFile) Sync

func (b *BitCaskLogFile) Sync() error

Sync flush all data to disk

type Bitcask

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

Bitcask the bitcask storage struct

func NewBitcask

func NewBitcask(options CreateOption) *Bitcask

NewBitcask create a new Bitcask struct

func (*Bitcask) Close

func (b *Bitcask) Close()

Close close the bitcask storage, with data on disk remain

func (*Bitcask) Delete

func (b *Bitcask) Delete(key string) error

Delete the value of key if success return nil

func (*Bitcask) Destory

func (b *Bitcask) Destory()

Destory destory the bitcask storage, with data on disk

func (*Bitcask) Get

func (b *Bitcask) Get(key string) (string, error)

Get get the value of key if success return nil if data not exists, return beancask.errors.ErrorDataNotFound

func (*Bitcask) Set

func (b *Bitcask) Set(key string, value string) error

Set the value of key if success return nil

type CreateOption

type CreateOption struct {
	MaxKeySize    int
	MaxValueSize  int
	CompactSize   int
	DataDir       string
	ActiveDataDir string
	LogLevel      string
	InfoLog       *log.Logger
	DebugLog      *log.Logger
	ErrorLog      *log.Logger
}

CreateOption options for bitcask creation

type HashItem

type HashItem struct {
	Wal     WALFile
	Len     int
	Offset  int64
	Tmstamp int64
}

HashItem struct of hash table entry

type Record

type Record struct {
	Crc     uint32
	Tmstamp int64
	Ksz     int64
	ValSz   int64
	Key     []byte
	Value   []byte
}

Record struct of record of the bitcask wal file

func CreateTomStoneRecord

func CreateTomStoneRecord(key string) Record

CreateTomStoneRecord create a tomb stone record for key

type SimpleHashTable

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

SimpleHashTable struct of hash table

func CreateSimpleHashTable

func CreateSimpleHashTable() *SimpleHashTable

CreateSimpleHashTable create a new hash table

func (*SimpleHashTable) Del

func (s *SimpleHashTable) Del(key string) error

Del delete value of key to the hash table

func (*SimpleHashTable) Exists

func (s *SimpleHashTable) Exists(key string) (exists bool)

Exists check whether a key exists on the hash table

func (*SimpleHashTable) Get

func (s *SimpleHashTable) Get(key string) (h HashItem, err error)

Get get value of key from the hash table

func (*SimpleHashTable) IteratorItem

func (s *SimpleHashTable) IteratorItem() <-chan struct {
	key   string
	value HashItem
}

IteratorItem return a channel of the hash table for iterating

func (*SimpleHashTable) Set

func (s *SimpleHashTable) Set(key string, h HashItem) error

Set set value of key to the hash table

type WALFile

type WALFile interface {
	RenameFile(name string) error
	RemoveFile() error
	CloseFile(remove bool) error
	Deactivate() error
	Sync() error
	AppendRecord(r Record, sync bool) (off int64, len int, err error)
	ReadRecord(off int64, len int, r *Record) error
	IteratorRecord() <-chan struct {
		// contains filtered or unexported fields
	}
}

WALFile interface for bitcask wal file. It's used to contain the record on the disk to support durability and large writing throughput by appending new value to the end of itself without modifing the old value. when it gets large enough, it becomes read-only and records will be written to a new wal file (which is called the active one).

Jump to

Keyboard shortcuts

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