Git Product home page Git Product logo

nimbusdb's Introduction

nimbusdb

WARNING: nimbusdb is in early stages of development; do not use this in production.

Persistent key-value store based on Bitcask paper.

nimbusdb is a fast, lightweight, and scalable key-value store based on Bitcask.

nimbusdb maintains an active datafile to which data is written. When it crosses a threshold, the datafile is made inactive, and a new datafile is created. As time passes, expired or deleted keys take up space that is not useful. Hence, a process called merge is done to remove all expired or deleted keys and free up space.

Features

Thread-Safe All operations are thread-safe. Read and Write operations can handle multiple operations from multiple goroutines at the same time with consistency.
Portable Data is extremely portable since it is only a bunch of files. All you have to do is move the folder and open an DB connection at that path.
Custom Expiry Supports custom expiry for keys. Default expiry is 1 week.
Supports Merge Supports `Merge` which can be called periodically to remove expired/deleted keys from disk and free-up space.
Supports Batch operations Batch operations can be performed and committed to save to disk or rollbacked to discard the batch. Operations cannot be performed once the batch is closed.
Single disk-seek write Writes are just one disk seek since we're appending to the file.
Block cache for faster reads. Blocks are cached for faster reads. Default size of an Block is 32KB.

Usage

Initialize db connection

d, err := nimbusdb.Open(&nimbusdb.Options{Path: "/path/to/data/directory"})
if err != nil {
  // handle error
}
defer d.Close()

Set

key, err := d.Set([]byte("key"), []byte("value"))
if err != nil {
  // handle error
}

Set with expiry

key, err := d.SetWithTTL([]byte("key"), []byte("value"), time.Second * 10)
if err != nil {
  // handle error
}

Get

value, err := d.Get([]byte("key"))
if err != nil {
  // handle error
}

Delete

key, err := d.Delete([]byte("key"))
if err != nil {
  // handle error
}

Compaction

TODO

  • Merge
  • Hintfiles
err := d.RunCompaction() // runs Merge
if err != nil {
  // handle error
}

Batch Operations

d, err := nimbusdb.Open(&nimbusdb.Options{Path: "/path/to/data/directory"})
if err != nil {
  // handle error
}
defer d.Close()
b, err := d.NewBatch()
if err != nil {
  // handle error
}
defer b.Close()

key, err = b.Set([]byte("key"), []byte("value")) // not written to disk yet.
if err != nil {
  // handle error
}

key, err := b.Get([]byte("key"))
if err != nil {
  // handle error
}

key, err = b.Delete([]byte("key"))
if err != nil {
  // handle error
}

exists, err := b.Exists([]byte("key"))
if err != nil {
  // handle error
}

b.Commit() // write all pending writes to disk
b.Rollback() // discard all pending writes

Watch keys

func watchKeyChange(ch chan nimbusdb.WatcherEvent) {
  for event := range ch {
    switch event.EventType {
      case "CREATE":
        // Handle create key event
        break

      case "UPDATE":
        // Handle update key event
        break

      case "DELETE":
        // Handle delete key event
        break
    }
  }
}

func main() {
  d, err := nimbusdb.Open(&nimbusdb.Options{Path: "/path/to/data/directory", ShouldWatch: true})
  if err != nil {
    // handle error
  }
  defer d.Close()
  defer d.CloseWatch() // optional
  
  watchChannel, err := d.Watch()
  if err != nil {
    // handle error
  }
  
  go watchEvents(watchChannel)

  key, err := d.Set([]byte("key"), []byte("value")) // will trigger an CREATE event
  if err != nil {
    // handle error
  }

  key, err := d.Set([]byte("key"), []byte("value")) // will trigger an UPDATE event
  if err != nil {
    // handle error
  }

  key, err = d.Delete([]byte("key")) // will trigger an DELETE event
  if err != nil {
    // handle error
  }
}

Progress Board | Streams | godoc

Go

nimbusdb's People

Contributors

manosriram avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

mw2000

nimbusdb's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.