originium

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2025 License: Apache-2.0 Imports: 20 Imported by: 0

README

ORIGINIUM

LSM-Tree based storage engine used by FOIVER system.

Install

go get -u github.com/B1NARY-GR0UP/originium

Usage

Opening a Database

package main

import (
    "log"

    "github.com/B1NARY-GR0UP/originium"
)

func main() {
    // Use originium.Config to customize your db behavior
    db, err := originium.Open("your-dir", originium.DefaultConfig)
    if err != nil {
        log.Fatal(err)
    }

    defer db.Close()

    // ...
}

Transactions

ORIGINIUM supports concurrent ACID transactions with Serializable Snapshot Isolation (SSI) guarantees.

  • Read-only transaction
err := db.View(func(txn *originium.Txn) error {
    // ...

    res, ok := txn.Get("hello")
    if !ok {
        // key not found
    }

    // ...
    return nil
})
  • Read-write transaction
err := db.Update(func(txn *originium.Txn) error {
    // ...

    if err := txn.Set("hello", []byte("originium")); err != nil {
        return err
    }

    // ...
    return nil
})
  • Manually
// start a read-write transaction manually
txn := db.Begin(true)
defer txn.Discard()

// ...

if err := txn.Delete("hello"); err != nil {
    return err
}

// ...

if err := txn.Commit(); err != nil {
    return err
}

Blogs

Credits

Sincere appreciation to the following repositories that made the development of ORIGINIUM possible.

License

ORIGINIUM is distributed under the Apache License 2.0. The licenses of third party dependencies of ORIGINIUM are explained here.

ECOLOGY



ORIGINIUM is Part of PROJECT: FOIVER

Documentation

Index

Constants

View Source
const (
	Name    = "originium"
	Version = "v0.2.1"
)

Variables

View Source
var (
	ErrMkDir    = errors.New("failed to create db dir")
	ErrDBClosed = errors.New("db closed")
)
View Source
var (
	ErrReadOnlyTxn  = errors.New("transaction is read-only")
	ErrDiscardedTxn = errors.New("transaction has been discarded")
	ErrConflictTxn  = errors.New("transaction has a conflict")
	ErrEmptyKey     = errors.New("key is empty")
)
View Source
var DefaultConfig = Config{
	SkipListMaxLevel:       9,
	SkipListP:              0.5,
	MemtableByteThreshold:  4 * _mb,
	ImmutableBuffer:        10,
	DataBlockByteThreshold: 4 * _kb,
	L0TargetNum:            5,
	LevelRatio:             10,
	FileMode:               0755,
}

Functions

This section is empty.

Types

type Config

type Config struct {
	// SkipList Config
	SkipListMaxLevel int
	SkipListP        float64

	// Memtable Config
	// memtable size threshold of turning to an immutable memtable
	MemtableByteThreshold int
	ImmutableBuffer       int

	// SSTable Config
	DataBlockByteThreshold int

	// Level Config
	L0TargetNum int
	LevelRatio  int

	FileMode os.FileMode
}

type DB

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

func Open

func Open(dir string, config Config) (*DB, error)

func (*DB) Begin added in v0.2.0

func (db *DB) Begin(update bool) *Txn

func (*DB) Close

func (db *DB) Close()

func (*DB) State

func (db *DB) State() State

func (*DB) Update added in v0.2.0

func (db *DB) Update(fn TxnFunc) error

func (*DB) View added in v0.2.0

func (db *DB) View(fn TxnFunc) error

type State

type State uint32
const (
	StateInitialize State
	StateOpened
	StateClosed
)

type Txn added in v0.2.0

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

func (*Txn) Commit added in v0.2.0

func (t *Txn) Commit() error

func (*Txn) Delete added in v0.2.0

func (t *Txn) Delete(key string) error

func (*Txn) Discard added in v0.2.0

func (t *Txn) Discard()

func (*Txn) Get added in v0.2.0

func (t *Txn) Get(key string) ([]byte, bool)

func (*Txn) Set added in v0.2.0

func (t *Txn) Set(key string, value []byte) error

func (*Txn) SetEntry added in v0.2.0

func (t *Txn) SetEntry(e types.Entry) error

type TxnFunc added in v0.2.0

type TxnFunc func(*Txn) error

Directories

Path Synopsis
pkg

Jump to

Keyboard shortcuts

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