Giter VIP home page Giter VIP logo

mdb's Introduction

MDB

In-memory key/value store designed for concurrent use. A simpler, but less feature-rich version of go-memdb.

Features (as compared to go-memdb)

✅ Multi-Version Concurrency Control (MVCC) - By leveraging immutable radix trees the database is able to support any number of concurrent readers without locking, and allows a writer to make progress.

✅ Transaction Support - The database allows for rich transactions, in which multiple objects are inserted, updated or deleted. The transactions can span multiple tables, and are applied atomically. The database provides atomicity and isolation in ACID terminology, such that until commit the updates are not visible.

🚫 Rich Indexing - Tables can support any number of indexes, which can be simple like a single field index, or more advanced compound field indexes. Certain types like UUID can be efficiently compressed from strings into byte indexes for reduced storage requirements.

🚫 Watches - Callers can populate a watch set as part of a query, which can be used to detect when a modification has been made to the database which affects the query results. This lets callers easily watch for changes in the database in a very general way.

For the curious: How the MVCC part works

The benefit of an MVCC system is that reads don't block writes and writes don't block reads. This is unlike sync.RWMutex, where reads block writes and writes block reads.

The way this works is by using an immutable data structure underneath. In the case of mdb and go-memdb, it's using an immutable radix tree. This allows readers to use a snapshot, while a writer's transaction is taking place. The compromise here is that a reader may not have the most up-to-date data.

It's important to note that while the underlying structure is immutable, any pointers will not be, so you'll likely want to wrap this library in a way that also handles copying pointers. You can find a good example of this in this state store.

Example

db := mdb.New()
txn := db.Txn(true)
txn.Put("a.1", "a.1")
txn.Put("a.2", "a.2")
txn.Put("c.1", "c.1")
txn.Commit()

txn = db.Txn(false)
matches := txn.All("a")
vals := []string{}

for _, match := range matches {
  vals = append(vals, match.(string))
}

assert.Equal(t, "a.1,a.2", strings.Join(vals, ","))

License

MIT

mdb's People

Contributors

matthewmueller avatar

Stargazers

Kevin.Y avatar Wade Welles avatar Radu Ioan Fericean avatar []\ avatar Peter Benjamin avatar samy kamkar avatar Trond Arne Bråthen avatar Julian Gruber avatar  avatar

Watchers

James Cloos avatar  avatar

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.