Skip to content

RascalDB is a key-value log-structured storage engine with hash map index.

Notifications You must be signed in to change notification settings

marselester/rascaldb

Repository files navigation

RascalDB 😜

Documentation Go Report Card

RascalDB is a key-value log-structured storage engine with hash map index. All keys must fit in RAM since the hash map is kept in memory. This type of a storage is optimal for writes workload.

Note, this pet project is not intended for production use.

Key ideas:

  • key-values are immutable, appended to a log
  • log is represented as a sequence of segment files
  • key-value is stored as a record prefixed with its length (4 bytes)
  • key is looked up from segment files using in-memory hash map index which maintains a byte offset of a key
  • hash map index is loaded from a segment file when db is opened
  • sequence of database segments is stored in a trunk file
  • old log segments are compacted (old records of duplicate keys are removed)
  • old segments are merged
  • there is only one writer to make sure keys are written linearly
  • ignore corrupted segments if a file's checksum doesn't match when db crashed

Usage Example

package main

import (
	"fmt"
	"log"

	"github.com/marselester/rascaldb"
)

func main() {
	db, err := rascaldb.Open("my.db")
	if err != nil {
		log.Fatal(err)
	}
	defer db.Close()

	name := []byte("Moist von Lipwig")
	if err = db.Set("name", name); err != nil {
		log.Fatal(err)
	}

	if name, err = db.Get("name"); err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%s\n", name)
}

About

RascalDB is a key-value log-structured storage engine with hash map index.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages