File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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]
592617fn test_set_ratelimiter ( ) {
593618 let path = DBPath :: new ( "_set_ratelimiter" ) ;
You can’t perform that action at this time.
0 commit comments