All Projects → nimrodshn → btree

nimrodshn / btree

Licence: other
A persistent B+Tree (clustered index) implementation in Rust.

Programming Languages

rust
11053 projects
Makefile
30231 projects

Projects that are alternatives of or similar to btree

Recipe
RECIPE : high-performance, concurrent indexes for persistent memory (SOSP 2019)
Stars: ✭ 145 (-13.17%)
Mutual labels:  indexing
Esbulk
Bulk indexing command line tool for elasticsearch
Stars: ✭ 235 (+40.72%)
Mutual labels:  indexing
kvstore
KVStore is a simple Key-Value Store based on B+Tree (disk & memory) for Java
Stars: ✭ 88 (-47.31%)
Mutual labels:  btree
Tg Index
Python web app to index telegram channel and serve its files for download.
Stars: ✭ 157 (-5.99%)
Mutual labels:  indexing
Paperwork
Personal document manager (Linux/Windows) -- Moved to Gnome's Gitlab
Stars: ✭ 2,392 (+1332.34%)
Mutual labels:  indexing
RedisTree
Redis Tree (Ploytree) Structure Module
Stars: ✭ 64 (-61.68%)
Mutual labels:  btree
Dashing
Fast and accurate genomic distances using HyperLogLog
Stars: ✭ 131 (-21.56%)
Mutual labels:  indexing
http-server-pwa
👾 http-server alike but for serving and rendering PWA: pwa-server
Stars: ✭ 14 (-91.62%)
Mutual labels:  indexing
Sfa
Scalable Time Series Data Analytics
Stars: ✭ 222 (+32.93%)
Mutual labels:  indexing
simpledbm
SimpleDBM is an Open Source Multi-Threaded Embeddable Transactional Database Engine in Java.
Stars: ✭ 51 (-69.46%)
Mutual labels:  btree
Web Html5
h5学习文档、代码
Stars: ✭ 168 (+0.6%)
Mutual labels:  indexing
Alfanous
Alfanous is an Arabic search engine API provides the simple and advanced search in Quran , more features and many interfaces...
Stars: ✭ 209 (+25.15%)
Mutual labels:  indexing
Foundatio.Repositories
Generic repositories
Stars: ✭ 74 (-55.69%)
Mutual labels:  indexing
Pathivu
An efficient log ingestion and log aggregation system https://pathivu.io/
Stars: ✭ 146 (-12.57%)
Mutual labels:  indexing
DataTanker
Embedded persistent key-value store for .NET. Pure C# code.
Stars: ✭ 53 (-68.26%)
Mutual labels:  btree
Js Search
JS Search is an efficient, client-side search library for JavaScript and JSON objects
Stars: ✭ 1,920 (+1049.7%)
Mutual labels:  indexing
Hyperspace
An open source indexing subsystem that brings index-based query acceleration to Apache Spark™ and big data workloads.
Stars: ✭ 246 (+47.31%)
Mutual labels:  indexing
gdrive-index
An index server for Google Drive
Stars: ✭ 107 (-35.93%)
Mutual labels:  indexing
secondary
Redis Secondary Indexing Module, been suspended see: https://github.com/RediSearch/RediSearch/
Stars: ✭ 33 (-80.24%)
Mutual labels:  indexing
kmer-db
Kmer-db is a fast and memory-efficient tool for large-scale k-mer analyses (indexing, querying, estimating evolutionary relationships, etc.).
Stars: ✭ 68 (-59.28%)
Mutual labels:  indexing

btree

Build status GitHub commit activity

A persistent copy-on-write B+Tree implementation, designed as an index for a key-value store, inspired by SQLite.

Design

Each BTree struct is associated with a file that contains its nodes in a predefined structure. The BTree API is implemented in a copy-on-write manner, that is, a copy of the newly written nodes is created on each write or delete without mutating the previous version of the tree. To keep track of the latest version of the tree we maintain a write-ahead-log to log the current root.

Unit tests serve as helpful examples of API usage.

On disk node structure

There are two NodeType variants - Internal and Leaf; Each variant has its own predefined structure on disk. A leaf node has the following structure:

| IS-ROOT 1-byte| NODE-TYPE 1-byte | PARENT OFFSET - 8 bytes | Number of pairs - 8 bytes |
| Key #0 - 10 bytes | Value #0 - 10 bytes | ...
| Key #N - 10 bytes | Value #N - 10 bytes |

While the structure of an internal node on disk is the following:

| IS-ROOT 1-byte | NODE-TYPE 1-byte | PARENT OFFSET - 8 bytes | Number of children - 8 bytes |
| Key #0 - 10 bytes | Key #2 - 10 bytes | ...
| Child Offset #0 - 8 bytes | Child offset #1 - 8 bytes | ...

Features

  • Support all CRUD operations (read, write, delete).
  • Support for crash recovery from disk.
  • Support for varied length key-value pairs.
  • Key compression.
  • Garbage collection.

API

From disk to memory and back

Nodes are mapped to pages on disk with TryFrom methods implemented for easier de/serialization of nodes to pages and back.

let some_leaf = Node::new(
   NodeType::Leaf(vec![
         KeyValuePair::new("foo".to_string(), "bar".to_string()),
         KeyValuePair::new("lebron".to_string(), "james".to_string()),
         KeyValuePair::new("ariana".to_string(), "grande".to_string()),
   ]),
   true,
   None,
);

// Serialize data.
let page = Page::try_from(&some_leaf)?;
// Deserialize back the page.
let res = Node::try_from(page)?;

See tests at src/page.rs and src/node.rs for more information.

Writing and Reading key-value pairs.

// Initialize a new BTree;
// The BTree nodes are stored in file '/tmp/db' (created if does not exist)
// with parameter b=2.
 let mut btree = BTreeBuilder::new()
            .path(Path::new("/tmp/db"))
            .b_parameter(2)
            .build()?;

// Write some data.
btree.insert(KeyValuePair::new("a".to_string(), "shalom".to_string()))?;
btree.insert(KeyValuePair::new("b".to_string(), "hello".to_string()))?;
btree.insert(KeyValuePair::new("c".to_string(), "marhaba".to_string()))?;

// Read it back.
let mut kv = btree.search("b".to_string())?;
assert_eq!(kv.key, "b");
assert_eq!(kv.value, "hello");

kv = btree.search("c".to_string())?;
assert_eq!(kv.key, "c");
assert_eq!(kv.value, "marhaba");

Deleting key-value pairs.

// Initialize a new BTree.
let mut btree = BTreeBuilder::new()
      .path(Path::new("/tmp/db"))
      .b_parameter(2)
      .build()?;

// Write some data.
btree.insert(KeyValuePair::new("d".to_string(), "olah".to_string()))?;
btree.insert(KeyValuePair::new("e".to_string(), "salam".to_string()))?;
btree.insert(KeyValuePair::new("f".to_string(), "hallo".to_string()))?;
btree.insert(KeyValuePair::new("a".to_string(), "shalom".to_string()))?;
btree.insert(KeyValuePair::new("b".to_string(), "hello".to_string()))?;
btree.insert(KeyValuePair::new("c".to_string(), "marhaba".to_string()))?;

// Find the key.
let kv = btree.search("c".to_string())?;
assert_eq!(kv.key, "c");
assert_eq!(kv.value, "marhaba");

// Delete the key.
btree.delete(Key("c".to_string()))?;

// Sanity check.
let res = btree.search("c".to_string());
assert!(matches!(
      res,
      Err(Error::KeyNotFound)
));

License

MIT.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].