Skip to content

Commit 8d92399

Browse files
committed
Revert "remove set_options_from_string (incorrectly named and wrong implementation)"
This reverts commit 0ca3535. The restored body calls the current ffi_util::convert_rocksdb_error, as error_message no longer exists. Signed-off-by: Jason Volk <jason@zemos.net>
1 parent 75851cc commit 8d92399

2 files changed

Lines changed: 53 additions & 0 deletions

File tree

src/db_options.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,6 +1118,34 @@ impl Options {
11181118
}
11191119
}
11201120

1121+
/// Updates DBOptions with values parsed from a string.
1122+
///
1123+
/// See official [wiki](
1124+
/// https://github.com/facebook/rocksdb/wiki/Option-String-and-Option-Map#option-string)
1125+
/// for more information.
1126+
pub fn set_options_from_string(&mut self, string: impl CStrLike) -> Result<&mut Self, Error> {
1127+
let c_string = string.into_c_string().unwrap();
1128+
let mut err: *mut c_char = null_mut();
1129+
let err_ptr: *mut *mut c_char = &raw mut err;
1130+
unsafe {
1131+
ffi::rocksdb_get_options_from_string(
1132+
self.inner,
1133+
c_string.as_ptr(),
1134+
self.inner,
1135+
err_ptr,
1136+
);
1137+
}
1138+
1139+
if err.is_null() {
1140+
Ok(self)
1141+
} else {
1142+
Err(Error::new(format!(
1143+
"Could not set options from string: {}",
1144+
crate::ffi_util::convert_rocksdb_error(err)
1145+
)))
1146+
}
1147+
}
1148+
11211149
/// By default, RocksDB uses only one background thread for flush and
11221150
/// compaction. Calling this function will set it up such that total of
11231151
/// `total_threads` is used. Good value for `total_threads` is the number of

tests/test_rocksdb_options.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,31 @@ fn test_set_ttl() {
588588
}
589589
}
590590

591+
#[test]
592+
fn test_set_options_from_string() {
593+
let path = DBPath::new("_set_options_from_string");
594+
{
595+
let mut opts = Options::default();
596+
opts.create_if_missing(true);
597+
opts.set_options_from_string("compaction_pri=kOldestSmallestSeqFirst")
598+
.expect("option compaction_pri is set");
599+
let _db = DB::open(&opts, &path).unwrap();
600+
}
601+
}
602+
603+
#[test]
604+
#[should_panic(expected = "Could not set options from string: ")]
605+
fn test_set_options_from_string_failure() {
606+
let path = DBPath::new("_set_options_from_string");
607+
{
608+
let mut opts = Options::default();
609+
opts.create_if_missing(true);
610+
opts.set_options_from_string("compaction_prikOldestSmallestSeqFirst")
611+
.unwrap();
612+
let _db = DB::open(&opts, &path).unwrap();
613+
}
614+
}
615+
591616
#[test]
592617
fn test_set_ratelimiter() {
593618
let path = DBPath::new("_set_ratelimiter");

0 commit comments

Comments
 (0)