Skip to content

Commit

Permalink
Merge pull request #30 from Congyuwang/load_latest_options
Browse files Browse the repository at this point in the history
Automatically Load latest options
  • Loading branch information
Congyuwang authored Nov 5, 2022
2 parents d7a20f4 + a40c2d9 commit c70f940
Show file tree
Hide file tree
Showing 17 changed files with 624 additions and 162 deletions.
7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "RocksDict"
version = "0.3.0"
version = "0.3.3"
edition = "2021"
description = "Rocksdb Python Binding"

Expand All @@ -13,7 +13,10 @@ crate-type = ["cdylib"]
[dependencies]
rocksdb = { git = "https://github.com/Congyuwang/rust-rocksdb", branch = "rocksdict" }
librocksdb-sys = { git = "https://github.com/Congyuwang/rust-rocksdb", branch = "rocksdict" }
ahash = "0.8.1"
pyo3-log = "0.7.0"
log = "0.4"
serde = { version = "1", features = ["derive"] }
serde_json = "1.0.87"
num-bigint = "^0.4.3"
libc = "0.2.112"

Expand Down
59 changes: 59 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,65 @@ db.close()
Rdict.destroy(PATH_TO_ROCKSDB)
```

## New Feature Since v0.3.3

Loading Options from RocksDict Path.

### Load Options and add A New ColumnFamily
```python
from rocksdict import Options, Rdict
path = str("./rocksdict_path")

opts, cols = Options.load_latest(path)
opts.create_missing_column_families(True)
cols["bytes"] = Options()
self.test_dict = Rdict(path, options=opts, column_families=cols)
```

### Reopening RocksDB Reads DB Options Automatically

```python
import shutil

from rocksdict import Rdict, Options, SliceTransform, PlainTableFactoryOptions
import os

def db_options():
opt = Options()
# create table
opt.create_if_missing(True)
# config to more jobs
opt.set_max_background_jobs(os.cpu_count())
# configure mem-table to a large value (256 MB)
opt.set_write_buffer_size(0x10000000)
opt.set_level_zero_file_num_compaction_trigger(4)
# configure l0 and l1 size, let them have the same size (1 GB)
opt.set_max_bytes_for_level_base(0x40000000)
# 256 MB file size
opt.set_target_file_size_base(0x10000000)
# use a smaller compaction multiplier
opt.set_max_bytes_for_level_multiplier(4.0)
# use 8-byte prefix (2 ^ 64 is far enough for transaction counts)
opt.set_prefix_extractor(SliceTransform.create_max_len_prefix(8))
# set to plain-table for better performance
opt.set_plain_table_factory(PlainTableFactoryOptions())
return opt


# create DB
db = Rdict("./some_path", db_options())
db[0] = 1
db.close()

# automatic reloading all options on reopening
db = Rdict("./some_path")
assert db[0] == 1

# destroy
db.close()
shutil.rmtree("./some_path")
```

## More Examples on BatchWrite, SstFileWrite, Snapshot, RocksDB Options, and etc.

Go to [example](https://github.com/Congyuwang/RocksDict/tree/main/examples) folder.
Expand Down
Loading

0 comments on commit c70f940

Please sign in to comment.