{"id":13906287,"url":"https://github.com/tikv/rust-rocksdb","last_synced_at":"2025-07-18T04:30:48.356Z","repository":{"id":38239396,"uuid":"78835813","full_name":"tikv/rust-rocksdb","owner":"tikv","description":"rust wrapper for rocksdb","archived":false,"fork":true,"pushed_at":"2024-11-05T08:25:44.000Z","size":11430,"stargazers_count":278,"open_issues_count":32,"forks_count":155,"subscribers_count":38,"default_branch":"master","last_synced_at":"2024-11-05T09:27:33.893Z","etag":null,"topics":["rocksdb","rust"],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"rust-rocksdb/rust-rocksdb","license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tikv.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2017-01-13T09:39:24.000Z","updated_at":"2024-11-05T08:25:47.000Z","dependencies_parsed_at":"2023-10-16T22:31:43.213Z","dependency_job_id":"c7078158-500f-4367-a19f-f3f5a535166e","html_url":"https://github.com/tikv/rust-rocksdb","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tikv%2Frust-rocksdb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tikv%2Frust-rocksdb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tikv%2Frust-rocksdb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tikv%2Frust-rocksdb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tikv","download_url":"https://codeload.github.com/tikv/rust-rocksdb/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226344596,"owners_count":17610173,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["rocksdb","rust"],"created_at":"2024-08-06T23:01:32.762Z","updated_at":"2024-11-25T14:31:14.816Z","avatar_url":"https://github.com/tikv.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"# rust-rocksdb\n\n[![Build Status](https://travis-ci.org/tikv/rust-rocksdb.svg)](https://travis-ci.org/tikv/rust-rocksdb)\n[![Dependency Status](https://deps.rs/repo/github/tikv/rust-rocksdb/status.svg)](https://deps.rs/repo/github/tikv/rust-rocksdb)\n\nThis library has been tested against RocksDB 6.4 on Linux and macOS.\n\n## Status\n  - [x] basic open/put/get/delete/close\n  - [x] rustic merge operator\n  - [x] write batch (thanks @dgrnbrg!)\n  - [x] save point\n  - [x] compaction filter, style\n  - [x] LRU cache\n  - [x] destroy/repair\n  - [x] iterator\n  - [x] comparator\n  - [x] snapshot\n  - [x] column family operations\n  - [x] prefix seek\n  - [x] slicetransform\n  - [x] rate limiter\n  - [x] statistics\n  - [x] recovery\n  - [x] backup\n  - [x] pause/continue background work\n  - [x] delete range\n  - [x] ingest external sst files\n  - [ ] windows support\n\nFeedback and pull requests welcome! If a particular feature of RocksDB is important to you, please let us know by opening an issue, and we will prioritize it.\n\n## Build\n\n```\n$ git submodule update --init --recursive # if you just cloned the repository\n$ cargo build\n```\n\nBindings are pre-generated for x86_64 Linux. For other platforms, bindings are generated at compile time.\n\nIf the content in librocksdb_sys/crocksdb/crocksdb/c.h is updated, you may need to regenerate bindings:\n\n```\n$ ./scripts/generate-bindings.sh\n```\n\n## Running\n\n###### Cargo.toml\n\n```rust\n[dependencies.rocksdb]\ngit = \"https://github.com/tikv/rust-rocksdb.git\"\n```\n\n###### Code\n\n```rust\nextern crate rocksdb;\nuse rocksdb::{DB, Writable};\n\nfn main() {\n    let mut db = DB::open_default(\"/path/for/rocksdb/storage\").unwrap();\n    db.put(b\"my key\", b\"my value\");\n    match db.get(b\"my key\") {\n        Ok(Some(value)) =\u003e println!(\"retrieved value {}\", value.to_utf8().unwrap()),\n        Ok(None) =\u003e println!(\"value not found\"),\n        Err(e) =\u003e println!(\"operational problem encountered: {}\", e),\n    }\n\n    db.delete(b\"my key\");\n}\n```\n\n###### Doing an atomic commit of several writes\n\n```rust\nextern crate rocksdb;\nuse rocksdb::{DB, WriteBatch, Writable};\n\nfn main() {\n    // NB: db is automatically freed at end of lifetime\n    let mut db = DB::open_default(\"/path/for/rocksdb/storage\").unwrap();\n    {\n        let batch = WriteBatch::new(); // WriteBatch and db both have trait Writable\n        batch.put(b\"my key\", b\"my value\");\n        batch.put(b\"key2\", b\"value2\");\n        batch.put(b\"key3\", b\"value3\");\n        db.write(\u0026batch).unwrap(); // Atomically commits the batch\n    }\n}\n```\n\n###### Getting an Iterator\n\n```rust\nextern crate rocksdb;\nuse rocksdb::{DB, Direction, IteratorMode};\n\nfn main() {\n    // NB: db is automatically freed at end of lifetime\n    let mut db = DB::open_default(\"/path/for/rocksdb/storage\").unwrap();\n    let mut iter = db.iterator(IteratorMode::Start); // Always iterates forward\n    for (key, value) in iter {\n        println!(\"Saw {} {}\", key, value); //actually, need to convert [u8] keys into Strings\n    }\n    iter = db.iterator(IteratorMode::End);  // Always iterates backward\n    for (key, value) in iter {\n        println!(\"Saw {} {}\", key, value);\n    }\n    iter = db.iterator(IteratorMode::From(b\"my key\", Direction::forward)); // From a key in Direction::{forward,reverse}\n    for (key, value) in iter {\n        println!(\"Saw {} {}\", key, value);\n    }\n\n    // You can seek with an existing Iterator instance, too\n    iter.set_mode(IteratorMode::From(b\"another key\", Direction::reverse));\n    for (key, value) in iter {\n        println!(\"Saw {} {}\", key, value);\n    }\n}\n```\n\n###### Getting an Iterator from a Snapshot\n\n```rust\nextern crate rocksdb;\nuse rocksdb::{DB, Direction};\n\nfn main() {\n    // NB: db is automatically freed at end of lifetime\n    let mut db = DB::open_default(\"/path/for/rocksdb/storage\").unwrap();\n    let snapshot = db.snapshot(); // Creates a longer-term snapshot of the DB, but freed when goes out of scope\n    let mut iter = snapshot.iterator(IteratorMode::Start); // Make as many iterators as you'd like from one snapshot\n}\n```\n\n###### Rustic Merge Operator\n\n```rust\nextern crate rocksdb;\nuse rocksdb::{Options, DB, MergeOperands, Writable};\n\nfn concat_merge(new_key: \u0026[u8], existing_val: Option\u003c\u0026[u8]\u003e,\n    operands: \u0026mut MergeOperands) -\u003e Vec\u003cu8\u003e {\n    let mut result: Vec\u003cu8\u003e = Vec::with_capacity(operands.size_hint().0);\n    existing_val.map(|v| {\n        for e in v {\n            result.push(*e)\n        }\n    });\n    for op in operands {\n        for e in op {\n            result.push(*e)\n        }\n    }\n    result\n}\n\nfn main() {\n    let path = \"/path/to/rocksdb\";\n    let mut opts = Options::new();\n    opts.create_if_missing(true);\n    opts.add_merge_operator(\"test operator\", concat_merge);\n    let mut db = DB::open(\u0026opts, path).unwrap();\n    let p = db.put(b\"k1\", b\"a\");\n    db.merge(b\"k1\", b\"b\");\n    db.merge(b\"k1\", b\"c\");\n    db.merge(b\"k1\", b\"d\");\n    db.merge(b\"k1\", b\"efg\");\n    let r = db.get(b\"k1\");\n    assert!(r.unwrap().unwrap().to_utf8().unwrap() == \"abcdefg\");\n}\n```\n\n###### Apply Some Tunings\n\nPlease read [the official tuning guide](https://github.com/facebook/rocksdb/wiki/RocksDB-Tuning-Guide), and most importantly, measure performance under realistic workloads with realistic hardware.\n\n```rust\nuse rocksdb::{Options, DB};\nuse rocksdb::DBCompactionStyle::DBUniversalCompaction;\n\nfn badly_tuned_for_somebody_elses_disk() -\u003e DB {\n    let path = \"_rust_rocksdb_optimizetest\";\n    let mut opts = Options::new();\n    opts.create_if_missing(true);\n    opts.set_max_open_files(10000);\n    opts.set_use_fsync(false);\n    opts.set_bytes_per_sync(8388608);\n    opts.set_disable_data_sync(false);\n    opts.set_block_cache_size_mb(1024);\n    opts.set_table_cache_num_shard_bits(6);\n    opts.set_max_write_buffer_number(32);\n    opts.set_write_buffer_size(536870912);\n    opts.set_target_file_size_base(1073741824);\n    opts.set_min_write_buffer_number_to_merge(4);\n    opts.set_level_zero_stop_writes_trigger(2000);\n    opts.set_level_zero_slowdown_writes_trigger(0);\n    opts.set_compaction_style(DBUniversalCompaction);\n    opts.set_max_background_compactions(4);\n    opts.set_max_background_flushes(4);\n    opts.set_disable_auto_compactions(true);\n\n    DB::open(\u0026opts, path).unwrap()\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftikv%2Frust-rocksdb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftikv%2Frust-rocksdb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftikv%2Frust-rocksdb/lists"}