Giter VIP home page Giter VIP logo

rusty_buntdb's Introduction

This is a Rust port of fantasitc BuntDB project by Josh Baker.

Big parts of this project are taken directly from BuntDB including API surface and API documentation.

Contributions are welcome and enouraged! Please see "Issues" for ideas for contributions.

rusty_buntdb's People

Contributors

bartlomieju avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

Forkers

isgasho

rusty_buntdb's Issues

Port tests

https://github.com/tidwall/buntdb/blob/master/buntdb_test.go

  • TestBackgroudOperations
  • TestSaveLoad
  • TestMutatingIterator
  • TestCaseInsensitiveIndex
  • TestIndexTransaction
  • TestDeleteAll
  • TestAscendEqual
  • TestDescendEqual
  • TestVariousTx
  • TestNearby
  • Example_descKeys
  • ExampleDesc
  • ExampleDB_CreateIndex_jSON
  • ExampleDB_CreateIndex_strings
  • ExampleDB_CreateIndex_ints
  • ExampleDB_CreateIndex_multipleFields
  • TestNoExpiringItem
  • TestAutoShrink
  • TestDatabaseFormat
  • TestInsertsAndDeleted
  • TestInsertDoesNotMisuseIndex
  • TestDeleteDoesNotMisuseIndex
  • TestIndexCompare
  • TestOpeningAFolder
  • TestOpeningInvalidDatabaseFile
  • TestOpeningClosedDatabase
  • TestShrink
  • TestVariousIndexOperations
  • TestBasic
  • TestIndexAscend
  • TestRectStrings
  • TestTTLReOpen
  • TestTTL
  • TestConfig
  • Benchmark_Set_Persist_Random_1
  • Benchmark_Set_Persist_Random_10
  • Benchmark_Set_Persist_Random_100
  • Benchmark_Set_Persist_Sequential_1
  • Benchmark_Set_Persist_Sequential_10
  • Benchmark_Set_Persist_Sequential_100
  • Benchmark_Set_NoPersist_Random_1
  • Benchmark_Set_NoPersist_Random_10
  • Benchmark_Set_NoPersist_Random_100
  • Benchmark_Set_NoPersist_Sequential_1
  • Benchmark_Set_NoPersist_Sequential_10
  • Benchmark_Set_NoPersist_Sequential_100
  • Benchmark_Get_1
  • Benchmark_Get_10
  • Benchmark_Get_100
  • Benchmark_Ascend_1
  • Benchmark_Ascend_10
  • Benchmark_Ascend_100
  • Benchmark_Ascend_1000
  • Benchmark_Ascend_10000
  • Benchmark_Descend_1
  • Benchmark_Descend_10
  • Benchmark_Descend_100
  • Benchmark_Descend_1000
  • Benchmark_Descend_10000
  • TestCoverCloseAlreadyClosed
  • TestCoverConfigClosed
  • TestCoverShrinkShrink
  • TestPreviousItem
  • TestJSONIndex
  • TestOnExpiredSync
  • TestTransactionLeak
  • TestReloadNotInvalid

Consider splitting codebase into more modules

Currently all of the code is in src/lib.rs. I did that in an effort to port the Go version as closely as possible. Given that Rust code is a bit more verbose in some situations the file is already at over 2,5k lines.

I believe in the long run it will be beneficial to split the library into multiple modules, it should help spot "non-rusty" code that could be made better after initial port.

Proposed modules:

  • src/db.rs - Db struct
  • src/tx.rs - Tx struct
  • src/index.rs - Index struct
  • src/error.rs - DbError struct
  • src/tree_utils.rs - helper functions for traversing BTreeC

String type is used too liberally

Currently most of the methods use String type. This is needlessly expensive and causes a lot of clones or .to_string() calls throughout the codebase.

Most of the occurences should be changed to &str or something along the lines impl String.

I will look into this once most of the tests are passing.

Port "match" package

match is used when matching indexes and should be ported as a utility module matcher.rs (match is a keyword in Rust so it would require prefixing each occurrence with r#).

Setup CI

Need to add basic CI script, I'll look into that once some tests are ported and passing.

Tx::lock and Tx::unlock don't work

Currently Tx::lock and Tx::unlock are stubbed out:

rusty_buntdb/src/lib.rs

Lines 1246 to 1264 in 29ef544

// lock locks the database based on the transaction type.
fn lock(&self) {
// todo!()
// if self.writable {
// self.db.mu.write().unwrap();
// } else {
// self.db.mu.read().unwrap();
// }
}
// unlock unlocks the database based on the transaction type.
fn unlock(&self) {
// todo!()
// if self.writable {
// self.db.mu.unlock();
// } else {
// self.db.mu.read_unlock();
// }
}

This is fine for now as DB runs on single thread but needs to be fixed prior to making DB multithreaded (#7). Since Rust RwLock return a "guards" that unlock when they are dropped, those guards need to be stored on the Tx struct.

Tx::commit() doesn't properly write to disk

Currently Tx::commit() has a very naive implementation of writing to disk:

rusty_buntdb/src/lib.rs

Lines 1344 to 1352 in 29ef544

// TODO: handle partial writes
let db_file = db.file.as_mut().unwrap();
let sync_policy = db.config.sync_policy.clone();
if let Err(e) = db.file.as_mut().unwrap().write_all(&db.buf) {
drop(db);
self.rollback_inner();
// TODO: return error
}

It should be updated to handle partial writes like Go version does:

https://github.com/tidwall/buntdb/blob/89544ad8fc446ae7c798e487951dc06739092b6b/buntdb.go#L1188-L1211

Make Db multithreaded and add background sync

Currently Db is not thread-safe, but we need to make it so to enable background sync (Db::background_manager is currently stubbed out).

Need to be especially careful when interacting with BTreeC which is using C-based data structure.

Docstrings need to updated

I copy-pasted most of the docs from the Go implementation. These docstrings need to be reviewed and fixed to properly reference methods/structs in Rust implementation (including proper linking in docs.rs).

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.