Skip to content

A high performance Key/Value database engine using Log Structured Hash Tables (Bitcask) similar to Riak

Notifications You must be signed in to change notification settings

sarkk0x0/memorylanedb

Repository files navigation

MemoryLaneDB

MemoryLaneDB is a high-performance, embedded key-value store written in Go. It follows the Bitcask design pattern, providing fast read/write operations with a simple and reliable storage model.

Features

  • Simple API: Easy-to-use key-value operations (Put, Get, Delete)
  • High Performance: All keys are stored in memory for fast lookups
  • Durability: Append-only log structure ensures data durability
  • Crash Recovery: Fast recovery with optional hint files
  • Data Compaction: Automatic merging of data files to reclaim space
  • Data Integrity: Checksums to ensure data is not corrupted
  • Concurrent Access Protection: File locking to prevent multiple processes from accessing the same database

Architecture

MemoryLaneDB follows the Bitcask design pattern:

  1. Log-Structured Storage: Data is stored in append-only log files (datafiles)
  2. In-Memory Index: All keys are kept in memory for fast lookups
  3. Compaction: Periodic merging of files to reclaim space from deleted or updated entries
  4. Hint Files: Optional files to speed up database recovery

Installation

Prerequisites

  • Go 1.18 or higher

Building from Source

Clone the repository and build the command-line tool:

git clone https://github.com/sarkk0x0/memorylanedb.git
cd memorylanedb
make build

This will create the mlctl binary in the bin directory.

Usage

Command Line Interface

MemoryLaneDB comes with a command-line tool (mlctl) for basic operations:

mlctl is a tool for inspecting memorylane databases.

Usage:

        mlctl command [arguments]

The commands are:

        put         insert a key-value pair in the db
        get         retrieve value of a key
        list        list all keys in the db
        info        print basic info
        help        print this screen
        stats       generate usage stats

Use "mlctl [command] -h" for more information about a command.

Examples

Storing a Key-Value Pair

./bin/mlctl put mykey "my value"

Retrieving a Value

./bin/mlctl get mykey

Listing All Keys

./bin/mlctl list

Using as a Library

MemoryLaneDB can also be used as a library in your Go applications:

package main

import (
    "fmt"
    mdb "github.com/sarkk0x0/memorylanedb"
)

func main() {
    // Open or create a database
    db, err := mdb.NewDB("/path/to/db", nil)
    if err != nil {
        panic(err)
    }
    defer db.Close()

    // Store a key-value pair
    err = db.Put(mdb.Key("mykey"), []byte("my value"))
    if err != nil {
        panic(err)
    }

    // Retrieve a value
    value, err := db.Get(mdb.Key("mykey"))
    if err != nil {
        panic(err)
    }

    fmt.Printf("Value: %s\n", value)
}

API Reference

Core Functions

  • NewDB(path string, opts *Option) (*DB, error): Create or open a database
  • DB.Put(key Key, value []byte) error: Store a key-value pair
  • DB.Get(key Key) ([]byte, error): Retrieve a value by key
  • DB.Has(key Key) (bool, error): Check if a key exists
  • DB.Delete(key Key) error: Delete a key-value pair
  • DB.Fold(f foldFunc) error: Iterate over all keys
  • DB.Close() error: Close the database

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

About

A high performance Key/Value database engine using Log Structured Hash Tables (Bitcask) similar to Riak

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published