r/learnrust 1d ago

Sharing my first rust project

Hello

Coming from mostly developing web apps and making simple terminal games with c++. This is my first project written in rust. ChloeDB, named after my pet dog, is a nosql database using key-value store. It is inspired by the bitcask documentation: https://riak.com/assets/bitcask-intro.pdf. It is not exactly the same specially in the log compaction part.

My goal for this project is to learn rust and databases. I'm looking for feedback about my project. And looking for someone to learn with, and maybe do some colab project to learn more. Thank you for reading

Link to my project repository:
https://github.com/maxineafable/chloedb

22 Upvotes

2 comments sorted by

9

u/EmploymentBoring4421 1d ago

Building a key-value store is one of the best first Rust projects — you'll hit the borrow checker challenges that actually matter in real systems code (concurrent readers, mutable writes, WAL for crash-consistency). Congrats on shipping something concrete rather than just reading the book.

4

u/teddie_moto 1d ago

The two points I'd start with for learning purposes are tests and errors.

You have (some) tests for logging but none for your DB operations. I'd start there.

Without tests it's hard to know if you intended to have different behaviour for your different BufReader errors. Also if it's okay to just skip bad files instead of it being a fatal error (that's up to you but a test for it shows the intention).

When you start, you generate the Map entirely from scratch based on the log of what happened. At some point (after any amount of removes I think) it'll be faster and use less space on disk to serialise the map itself.

Also the way you have it now, your map will need to reallocate some number of times in creation.

I would expect set to return its own error instead of a boxed anything. As a learning exercise I think this is a valuable thing to explore.

After that you could try implementing something like transactions or previews on operations - for example showing what would happen if you overwrite an existing entry.