Skip to content

Commit

Permalink
Merge pull request #32 from Congyuwang/develop
Browse files Browse the repository at this point in the history
Release v0.3.5
  • Loading branch information
Congyuwang authored Nov 11, 2022
2 parents bb2657c + 0d1baf3 commit 5bec3c2
Show file tree
Hide file tree
Showing 12 changed files with 16 additions and 32 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ assert db[0] == 1

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

## More Examples on BatchWrite, SstFileWrite, Snapshot, RocksDB Options, and etc.
Expand Down
1 change: 0 additions & 1 deletion examples/batch_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,3 @@

db.close()
Rdict.destroy(path, opt)
shutil.rmtree(path)
1 change: 0 additions & 1 deletion examples/column_families.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,3 @@
db_cf1.close()
db_cf2.close()
Rdict.destroy(path)
shutil.rmtree(path)
1 change: 0 additions & 1 deletion examples/db_tuning.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,3 @@ def db_options():
assert db[0] == 1
db.close()
Rdict.destroy("./some_path", db_options())
shutil.rmtree("./some_path")
1 change: 0 additions & 1 deletion examples/delete_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@
c1.close()
db.close()
Rdict.destroy(path)
shutil.rmtree(path)
1 change: 0 additions & 1 deletion examples/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,3 @@
del snapshot, db

Rdict.destroy("tmp")
shutil.rmtree("tmp")
1 change: 0 additions & 1 deletion examples/sst_file_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,3 @@
# auto flush
del db
rd.Rdict.destroy("test")
shutil.rmtree("test")
1 change: 0 additions & 1 deletion examples/sst_file_write.py_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,3 @@

# delete tmp
Rdict.destroy("tmp")
shutil.rmtree("tmp")
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "rocksdict"
version = "0.3.4"
version = "0.3.5"
description = "Rocksdb Python Binding"
long_description_content_type="text/markdown"
readme = "README.md"
Expand Down
8 changes: 4 additions & 4 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,15 +552,15 @@ impl OptionsPy {
#[staticmethod]
#[args(
env = "EnvPy::default().unwrap()",
cache = "CachePy::new_lru_cache(8 * 1024 * 1204).unwrap()",
ignore_unknown_options = "false"
ignore_unknown_options = "false",
cache = "CachePy::new_lru_cache(8 * 1024 * 1204).unwrap()"
)]
#[pyo3(text_signature = "(path, env, ignore_unknown_options)")]
#[pyo3(text_signature = "(path, env, ignore_unknown_options, cache)")]
pub fn load_latest(
path: &str,
env: EnvPy,
cache: CachePy,
ignore_unknown_options: bool,
cache: CachePy,
py: Python,
) -> PyResult<PyObject> {
let (options, column_families) =
Expand Down
16 changes: 10 additions & 6 deletions src/rdict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use serde::{Deserialize, Serialize};
use std::cell::RefCell;
use std::collections::HashMap;
use std::fs;
use std::fs::create_dir_all;
use std::ops::Deref;
use std::path::{Path, PathBuf};
use std::sync::{Arc, RwLock};
Expand All @@ -26,6 +25,12 @@ pub const ROCKSDICT_CONFIG_FILE: &str = "rocksdict-config.json";
/// 8MB default LRU cache size
pub const DEFAULT_LRU_CACHE_SIZE: usize = 8 * 1024 * 1024;

pub fn config_file(path: &str) -> PathBuf {
let mut config_path = PathBuf::from(path);
config_path.push(ROCKSDICT_CONFIG_FILE);
config_path
}

///
/// A persistent on-disk dictionary. Supports string, int, float, bytes as key, values.
///
Expand Down Expand Up @@ -120,8 +125,7 @@ impl RocksDictConfig {

impl Rdict {
fn dump_config(&self) -> PyResult<()> {
let mut config_path = PathBuf::from(self.path()?);
config_path.push(ROCKSDICT_CONFIG_FILE);
let config_path = config_file(&self.path()?);
RocksDictConfig {
raw_mode: self.opt_py.raw_mode,
prefix_extractors: self.slice_transforms.read().unwrap().clone(),
Expand Down Expand Up @@ -171,8 +175,7 @@ impl Rdict {
}
};
// save slice transforms types in rocksdict config
let mut config_path = PathBuf::from(path);
config_path.push(ROCKSDICT_CONFIG_FILE);
let config_path = config_file(path);
let mut prefix_extractors = HashMap::new();
if let Some(slice_transform) = &options.prefix_extractor {
prefix_extractors.insert(
Expand All @@ -192,7 +195,7 @@ impl Rdict {
prefix_extractors: prefix_extractors.clone(),
};
let opt_inner = &options.inner_opt;
match create_dir_all(path) {
match fs::create_dir_all(path) {
Ok(_) => match {
if let Some(cf) = column_families {
let mut has_default_cf = false;
Expand Down Expand Up @@ -1133,6 +1136,7 @@ impl Rdict {
#[pyo3(text_signature = "(path, options)")]
#[args(options = "OptionsPy::new(false)")]
fn destroy(path: &str, options: OptionsPy) -> PyResult<()> {
fs::remove_file(config_file(path)).ok();
match DB::destroy(&options.inner_opt, path) {
Ok(_) => Ok(()),
Err(e) => Err(PyException::new_err(e.to_string())),
Expand Down
13 changes: 0 additions & 13 deletions test/test_rdict.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from random import randint, random, getrandbits
import os
import sys
import shutil


TEST_INT_RANGE_UPPER = 999999
Expand Down Expand Up @@ -72,7 +71,6 @@ def test_seek_backward(self):
def tearDownClass(cls):
cls.test_dict.close()
Rdict.destroy(cls.path, Options())
shutil.rmtree(cls.path)


class TestIterInt(unittest.TestCase):
Expand Down Expand Up @@ -120,7 +118,6 @@ def test_seek_backward_key(self):
def tearDownClass(cls):
cls.test_dict.close()
Rdict.destroy(cls.path, Options())
shutil.rmtree(cls.path)


class TestInt(unittest.TestCase):
Expand Down Expand Up @@ -168,7 +165,6 @@ def test_get_batch(self):
@classmethod
def tearDownClass(cls):
Rdict.destroy(cls.path, cls.opt)
shutil.rmtree(cls.path)


class TestBigInt(unittest.TestCase):
Expand Down Expand Up @@ -201,7 +197,6 @@ def test_big_int(self):
def tearDownClass(cls):
cls.test_dict.close()
Rdict.destroy(cls.path, cls.opt)
shutil.rmtree(cls.path)


class TestFloat(unittest.TestCase):
Expand Down Expand Up @@ -247,7 +242,6 @@ def test_get_batch(self):
@classmethod
def tearDownClass(cls):
Rdict.destroy(cls.path, cls.opt)
shutil.rmtree(cls.path)


class TestBytes(unittest.TestCase):
Expand Down Expand Up @@ -309,7 +303,6 @@ def test_get_batch(self):
@classmethod
def tearDownClass(cls):
Rdict.destroy(cls.path, cls.opt)
shutil.rmtree(cls.path)


class TestString(unittest.TestCase):
Expand Down Expand Up @@ -340,7 +333,6 @@ def test_string(self):
def tearDownClass(cls):
del cls.test_dict
Rdict.destroy(cls.path, cls.opt)
shutil.rmtree(cls.path)


class TestColumnFamiliesDefaultOpts(unittest.TestCase):
Expand Down Expand Up @@ -379,7 +371,6 @@ def test_column_families(self):
def tearDownClass(cls):
del cls.test_dict
Rdict.destroy(cls.path)
shutil.rmtree(cls.path)


class TestColumnFamiliesDefaultOptsCreate(unittest.TestCase):
Expand Down Expand Up @@ -422,7 +413,6 @@ def test_column_families_create(self):
def tearDownClass(cls):
del cls.test_dict
Rdict.destroy(cls.path)
shutil.rmtree(cls.path)


class TestColumnFamiliesCustomOpts(unittest.TestCase):
Expand Down Expand Up @@ -467,7 +457,6 @@ def test_column_families_custom_options_auto_reopen(self):
def tearDownClass(cls):
del cls.test_dict
Rdict.destroy(cls.path)
shutil.rmtree(cls.path)


class TestColumnFamiliesCustomOptionsCreate(unittest.TestCase):
Expand Down Expand Up @@ -512,7 +501,6 @@ def test_column_families_custom_options_auto_reopen(self):
def tearDownClass(cls):
del cls.test_dict
Rdict.destroy(cls.path)
shutil.rmtree(cls.path)


class TestColumnFamiliesCustomOptionsCreateReopenOverride(unittest.TestCase):
Expand Down Expand Up @@ -580,7 +568,6 @@ def test_column_families_custom_options_auto_reopen_override(self):
def tearDownClass(cls):
del cls.test_dict
Rdict.destroy(cls.path)
shutil.rmtree(cls.path)


if __name__ == '__main__':
Expand Down

0 comments on commit 5bec3c2

Please sign in to comment.