bartlomieju / rusty_buntdb Goto Github PK
View Code? Open in Web Editor NEWA Rust port of BuntDB
License: MIT License
A Rust port of BuntDB
License: MIT License
index_int
index_string
index_binary
index_string_case_sensitive
index_float
index_json
index_json_case_sensitive
Special care needs to be taken when considering JSON methods; I believe https://crates.io/crates/gjson doesn't have case-insensitive comparison as of now.
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.
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
structsrc/tx.rs
- Tx
structsrc/index.rs
- Index
structsrc/error.rs
- DbError
structsrc/tree_utils.rs
- helper functions for traversing BTreeC
The only maintained crate that implements r-tree seems to be: https://crates.io/crates/rstar
Both Db::read_load
and Db::shrink
are currently stubbed out, meaning that we can't actually load data from saved file.
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
I did search for crates implementing BTree but found only one crate maintained: https://github.com/nimrodshn/btree
However it's disk-backed and has completely different API than: https://github.com/tidwall/btree
I tried going with BTreeSet
and implementing wrapper structs like: OrdByKeyItem
and OrdByExpItem
but I'm not sure this is a viable path.
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#
).
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.
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
).
Need to add basic CI script, I'll look into that once some tests are ported and passing.
Currently Tx::commit()
has a very naive implementation of writing to disk:
Lines 1344 to 1352 in 29ef544
It should be updated to handle partial writes like Go version does:
Currently Tx::lock
and Tx::unlock
are stubbed out:
Lines 1246 to 1264 in 29ef544
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.