logdb

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Filename

func Filename(index int) string

Filename generates a filename based on the given index.

func Index

func Index(filename string) int

Index extracts an index from a filename.

Types

type HashIndex

type HashIndex map[string]int64

HashIndex is a map of keys to offsets in the segment file.

type LogDB

type LogDB struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

LogDB is a simple key-value store that persists data to a log file.

func NewDB

func NewDB(dirPath string, segmentSizeKB int, c clock.Clock) *LogDB

NewDB creates a new log database.

func (*LogDB) Aggregate

func (db *LogDB) Aggregate() map[string][]byte

Aggregate gathers all the unique key-value pairs in the database, and then removes all the segments and resets the state.

func (*LogDB) Get

func (db *LogDB) Get(key string) ([]byte, bool)

Get retrieves a value from the database.

func (*LogDB) GetAllUnique

func (db *LogDB) GetAllUnique() map[string][]byte

func (*LogDB) MustSet

func (db *LogDB) MustSet(key string, value []byte)

MustSet writes a key-value pair to the log file and panics on error.

func (*LogDB) RunSegmentations

func (db *LogDB) RunSegmentations(ctx context.Context, segmentationInterval time.Duration)

RunSegmentations starts the database's compaction process.

func (*LogDB) Set

func (db *LogDB) Set(key string, value []byte) error

Set writes a key-value pair to the log file.

type Record

type Record struct {
	Key   string `json:"key"`
	Value []byte `json:"value"`
}

Record represents a key-value pair in our database.

type RecordWithOffset

type RecordWithOffset struct {
	Record
	Offset int64
}

RecordWithOffset holds a record and its offset in the log file.

type Segment

type Segment struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Segment represents a segment in our log database. Each segment has its own file descriptor and hash index.

Jump to

Keyboard shortcuts

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