A sessioned Merkle key/value store

Related tags

Database storage
Overview

storage

A sessioned Merkle key/value store

The crate was designed to be the blockchain state database. It provides persistent storage layer for key-value pairs on top of Nomic Merk.

FEATURES:

  • Key-value updates(in a transaction) applied to storage can be reverted if transaction fails.
  • Key-value updates(in a block) applied to storage can be reverted if block fails to commit.
  • Prefix-based key-value iteration on committed state.
  • Prefix-based key-value iteration on latest state.
  • Versioned key-value pairs available for queries.
  • Entire chain-state available as a batch of key-value pairs at any height within version window.
  • Root hash calculation.

Example:

[dependencies]
storage = { git = "ssh://[email protected]/FindoraNetwork/storage.git", branch = "master" }
parking_lot = "0.11.1"
extern crate storage;
use storage::state::{ChainState, State};
use storage::db::FinDB;
use storage::store::PrefixedStore;
use parking_lot::RwLock;
use std::sync::Arc;
use std::thread;
use storage::store::traits::{Stated, Store};

// This window is used to determine how many versions of each KV pair are to be kept in the
// auxiliary db.
const VER_WINDOW:u64 = 100;

fn main() {
    println!("Testing Prefixed Store!");
    prefixed_store();
}

fn prefixed_store() {
    // create store
    let path = thread::current().name().unwrap().to_owned();
    let fdb = FinDB::open(path).expect("failed to open db");
    let cs = Arc::new(RwLock::new(ChainState::new(fdb, "test_db".to_string(), VER_WINDOW)));
    let mut state = State::new(cs);
    let mut store = PrefixedStore::new("my_store", &mut state);
    let hash0 = store.state().root_hash();

    // set kv pairs and commit
    store.set(b"k10", b"v10".to_vec());
    store.set(b"k20", b"v20".to_vec());
    let (hash1, _height) = store.state_mut().commit(1).unwrap();

    // verify
    assert_eq!(store.get(b"k10").unwrap(), Some(b"v10".to_vec()));
    assert_eq!(store.get(b"k20").unwrap(), Some(b"v20".to_vec()));
    assert_ne!(hash0, hash1);

    // add, delete and update
    store.set(b"k10", b"v15".to_vec());
    store.delete(b"k20").unwrap();
    store.set(b"k30", b"v30".to_vec());

    // verify
    assert_eq!(store.get(b"k10").unwrap(), Some(b"v15".to_vec()));
    assert_eq!(store.get(b"k20").unwrap(), None);
    assert_eq!(store.get(b"k30").unwrap(), Some(b"v30".to_vec()));

    // rollback and verify
    store.state_mut().discard_session();
    assert_eq!(store.get(b"k10").unwrap(), Some(b"v10".to_vec()));
    assert_eq!(store.get(b"k20").unwrap(), Some(b"v20".to_vec()));
    assert_eq!(store.get(b"k30").unwrap(), None);

    // get previous version of a key value pair
    store.set(b"k10", b"v25".to_vec());
    let _ = store.state_mut().commit(2);
    assert_eq!(store.get(b"k10").unwrap(), Some(b"v25".to_vec()));
    assert_eq!(store.get_v(b"k10", 1).unwrap(), Some(b"v10".to_vec()));
}
You might also like...
Distributed transactional key-value database, originally created to complement TiDB
Distributed transactional key-value database, originally created to complement TiDB

Website | Documentation | Community Chat TiKV is an open-source, distributed, and transactional key-value database. Unlike other traditional NoSQL sys

CLI tool to work with Sled key-value databases.

sledtool CLI tool to work with Sled key-value databases. $ sledtool --help Usage: sledtool dbpath command [args] CLI tool to work with Sled da

AgateDB is an embeddable, persistent and fast key-value (KV) database written in pure Rust

AgateDB is an embeddable, persistent and fast key-value (KV) database written in pure Rust. It is designed as an experimental engine for the TiKV project, and will bring aggressive optimizations for TiKV specifically.

LevelDB is a fast key-value storage library written at Google that provides an ordered mapping from string keys to string values.

LevelDB is a fast key-value storage library written at Google that provides an ordered mapping from string keys to string values. Authors: Sanjay Ghem

ForestDB - A Fast Key-Value Storage Engine Based on Hierarchical B+-Tree Trie

ForestDB is a key-value storage engine developed by Couchbase Caching and Storage Team, and its main index structure is built from Hierarchic

A Key-Value data storage system. - dorea db

Dorea DB 🛰 Dorea is a key-value data storage system. It is based on the Bitcask storage model Documentation | Crates.io | API Doucment 简体中文 | English

A simple key value database for storing simple structures.

Perdia-DB A simple key value database for storing simple structures. No nesting of structures is supported, but may be implemented in the future. Toke

A fast and simple in-memory database with a key-value data model written in Rust

Segment Segment is a simple & fast in-memory database with a key-value data model written in Rust. Features Dynamic keyspaces Keyspace level control o

A
A "blazingly" fast key-value pair database without bloat written in rust

A fast key-value pair in memory database. With a very simple and fast API. At Xiler it gets used to store and manage client sessions throughout the pl

Comments
  • FO-284: Save and Prune versions automatically on commit

    FO-284: Save and Prune versions automatically on commit

    1. Added function to save copy of batch at given height for a versioned history of the state.
    2. Added functionality to prune the auxiliary version data outside a given window
    3. Added unit tests to cover this functionality
    opened by kevinssgh 3
  • Prepare a version of `storage` with Ruc 3.0.0

    Prepare a version of `storage` with Ruc 3.0.0

    Ruc is a collection of Rust utils. We have been using it for error handling, with version 1.0.

    This PR prepares the storage to Ruc 3.0.0. A release would be cut.

    opened by weikengchen 0
Releases(v1.1.4)
Owner
Findora Foundation
Findora Foundation
General basic key-value structs for Key-Value based storages

General basic key-value structs for Key-Value based storages

Al Liu 0 Dec 3, 2022
PickleDB-rs is a lightweight and simple key-value store. It is a Rust version for Python's PickleDB

PickleDB PickleDB is a lightweight and simple key-value store written in Rust, heavily inspired by Python's PickleDB PickleDB is fun and easy to use u

null 155 Jan 5, 2023
Pure rust embeddable key-value store database.

MHdb is a pure Rust database implementation, based on dbm. See crate documentation. Changelog v1.0.3 Update Cargo.toml v1.0.2 Update Cargo.toml v1.0.1

Magnus Hirth 7 Dec 10, 2022
RefineDB - A strongly-typed document database that runs on any transactional key-value store.

RefineDB - A strongly-typed document database that runs on any transactional key-value store.

Heyang Zhou 375 Jan 4, 2023
RedisLess is a fast, lightweight, embedded and scalable in-memory Key/Value store library compatible with the Redis API.

RedisLess is a fast, lightweight, embedded and scalable in-memory Key/Value store library compatible with the Redis API.

Qovery 145 Nov 23, 2022
Log structured append-only key-value store from Rust In Action with some enhancements.

riakv Log structured, append only, key value store implementation from Rust In Action with some enhancements. Features Persistent key value store with

Arindam Das 5 Oct 29, 2022
A LSM-based Key-Value Store in Rust

CobbleDB A LSM-based Key-Value Store in Rust Motivation There is no open-source LSM-based key-value store in Rust natively. Some crates are either a w

Yizheng Jiao 2 Oct 25, 2021
A rust Key-Value store based on Redis.

Key-Value Store A Key-Value store that uses Redis to store data. Built using an async web framework in Rust with a full Command-Line interface and log

Miguel David Salcedo 0 Jan 14, 2022
A simple embedded key-value store written in rust as a learning project

A simple embedded key-value store written in rust as a learning project

Blobcode 1 Feb 20, 2022
Immutable Ordered Key-Value Database Engine

PumpkinDB Build status (Linux) Build status (Windows) Project status Usable, between alpha and beta Production-readiness Depends on your risk toleranc

null 1.3k Jan 2, 2023