mewdb

package module
v0.0.0-...-3bfa2a7 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

README

mewdb

mewdb is a key-value store based on bitcask.

Documentation

Index

Constants

View Source
const (
	KB = 1024
	MB = 1024 * KB
	GB = 1024 * MB

	CronExprEveryHour   = "0 0 0/1 * * ?"
	CronExprEveryMinute = "0 0/1 * * * ?"
)

Variables

View Source
var (
	ErrKeyNotFound = errors.New("mewdb: key not found")

	ErrKeyIsEmpty = errors.New("mewdb: key is empty")

	ErrDatabaseIsUsing = errors.New("mewdb: create flock file error, database is using")

	ErrDatabaseIsClosed = errors.New("mewdb: database is closed")

	ErrMergeIsRunning = errors.New("mewdb: merge is running")
)
View Source
var DefaultOptions = Options{
	DirPath:        "mewdb",
	MergeCronExpr:  CronExprEveryHour,
	Logger:         slog.Default(),
	SegmentSize:    GB,
	SegmentFileExt: ".SEG",
}

Functions

This section is empty.

Types

type DB

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

DB represents a MEWDB database instance built on BITCASK model. See https://en.wikipedia.org/wiki/Bitcask for more details.

func Open

func Open(options Options) (db *DB, err error)

Open a database with the specified options. If the database directory does not exist, it will be created automatically.

func (*DB) Close

func (db *DB) Close() error

Close

func (*DB) Delete

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

Delete

func (*DB) Get

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

Get

func (*DB) Merge

func (db *DB) Merge() error

Merge

func (*DB) Put

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

Put

func (*DB) PutWithTTL

func (db *DB) PutWithTTL(key, val []byte, nanosec int64) error

PutWithTTL

type Index

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

Index

func NewIndex

func NewIndex() *Index

NewIndex

func (*Index) Delete

func (i *Index) Delete(key []byte) bool

Delete

func (*Index) GC

func (i *Index) GC()

GC

func (*Index) Get

func (i *Index) Get(key []byte) (keydir Keydir, ok bool)

Get

func (*Index) Len

func (i *Index) Len() int

Len

func (*Index) Scan

func (i *Index) Scan(f func(key []byte, ts int64, keydir Keydir) (next bool))

Scan

func (*Index) Set

func (i *Index) Set(key []byte, keydir Keydir, ttl int64)

Set

type Keydir

type Keydir = *wal.ChunkPosition

type LogRecord

type LogRecord struct {
	Type
	Timestamp uint32
	Key       []byte
	Value     []byte
}

LogRecord is the mewdb data record format on disk.

func (*LogRecord) TTL

func (r *LogRecord) TTL() int64

TTL

type Options

type Options struct {
	// DirPath is the database storage path.
	DirPath string

	MergeCronExpr string

	Logger *slog.Logger

	SegmentSize    int64
	SegmentFileExt string
}

type Type

type Type byte

type Wal

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

Wal is write ahead log for mewdb.

func (*Wal) ActiveSegmentID

func (l *Wal) ActiveSegmentID() uint32

func (*Wal) Close

func (l *Wal) Close() error

func (*Wal) Iter

func (l *Wal) Iter(segmentStart, segmentEnd uint32, f walker) error

Iter iterate datas between segmentStart and segmentEnd, this is a internal function.

func (*Wal) OpenNewActiveSegment

func (l *Wal) OpenNewActiveSegment() error

func (*Wal) Read

func (l *Wal) Read(keydir Keydir) ([]byte, error)

func (*Wal) RemoveOldSegments

func (l *Wal) RemoveOldSegments(maxSegmentID uint32) error

RemoveOldSegments remove all segments which is less than maxSegmentID.

func (*Wal) SegmentFileName

func (l *Wal) SegmentFileName(segId uint32) string

func (*Wal) Sync

func (l *Wal) Sync() error

func (*Wal) Write

func (l *Wal) Write(data []byte) (Keydir, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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