Skip to content

Commit 3c918a7

Browse files
koushiroConnor1996
authored andcommitted
Update some dependencies (#392)
- Update `rand` to v0.7 - Move `crc` to `dev-dependencies` - Remove `byteorder` - Replace `tempdir` with `tempfile` Signed-off-by: koushiro <[email protected]>
1 parent 970a27c commit 3c918a7

32 files changed

+283
-254
lines changed

Cargo.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,11 @@ valgrind = []
2323

2424
[dependencies]
2525
libc = "0.2.11"
26-
crc = "1.2"
2726

2827
[dependencies.librocksdb_sys]
2928
path = "librocksdb_sys"
3029

3130
[dev-dependencies]
32-
byteorder = "1.0.0"
33-
rand = "0.3"
34-
tempdir = "0.3"
31+
rand = "0.7"
32+
crc = "1.8"
33+
tempfile = "3.1"

benches/cases/bench_wal.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@
1212
// limitations under the License.
1313

1414
use super::rocksdb::{ColumnFamilyOptions, DBOptions, WriteOptions, DB};
15-
use super::tempdir::TempDir;
16-
1715
use super::test::Bencher;
1816

1917
fn run_bench_wal(b: &mut Bencher, name: &str, mut opts: DBOptions, wopts: WriteOptions) {
20-
let path = TempDir::new(name).expect("");
18+
let path = tempfile::Builder::new().prefix(name).tempdir().expect("");
2119
let path_str = path.path().to_str().unwrap();
2220
opts.create_if_missing(true);
2321
opts.set_max_background_jobs(6);

benches/cases/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
extern crate test;
22

3-
extern crate byteorder;
43
extern crate crc;
54
extern crate rand;
65
extern crate rocksdb;
7-
extern crate tempdir;
6+
extern crate tempfile;
87

98
mod bench_wal;

librocksdb_sys/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ libc = "0.2.11"
1010
libtitan_sys = { path = "libtitan_sys" }
1111

1212
[dev-dependencies]
13-
tempdir = "0.3"
13+
tempfile = "3.1"
1414

1515
[features]
1616
default = []

librocksdb_sys/src/lib.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@
1616
extern crate bzip2_sys;
1717
extern crate libc;
1818
#[cfg(test)]
19-
extern crate tempdir;
19+
extern crate tempfile;
2020

21-
use libc::{c_char, c_double, c_int, c_uchar, c_void, size_t};
2221
use std::ffi::CStr;
2322
use std::fmt;
2423

24+
use libc::{c_char, c_double, c_int, c_uchar, c_void, size_t};
25+
2526
// FFI-safe opaque types.
2627
//
2728
// These represent opaque RocksDB types. They are used behind pointers, but are
@@ -2118,7 +2119,10 @@ mod test {
21182119
use libc::{self, c_void};
21192120
use std::ffi::{CStr, CString};
21202121
use std::{fs, ptr, slice};
2121-
use tempdir::TempDir;
2122+
2123+
fn tempdir_with_prefix(prefix: &str) -> tempfile::TempDir {
2124+
tempfile::Builder::new().prefix(prefix).tempdir().expect()
2125+
}
21222126

21232127
#[test]
21242128
fn internal() {
@@ -2129,8 +2133,7 @@ mod test {
21292133
crocksdb_options_increase_parallelism(opts, 0);
21302134
crocksdb_options_optimize_level_style_compaction(opts, 0);
21312135
crocksdb_options_set_create_if_missing(opts, true);
2132-
2133-
let rustpath = TempDir::new("_rust_rocksdb_internaltest").expect("");
2136+
let rustpath = tempdir_with_prefix("_rust_rocksdb_internaltest");
21342137
let cpath = CString::new(rustpath.path().to_str().unwrap()).unwrap();
21352138
let cpath_ptr = cpath.as_ptr();
21362139

@@ -2236,7 +2239,7 @@ mod test {
22362239
let opts = crocksdb_options_create();
22372240
crocksdb_options_set_create_if_missing(opts, true);
22382241

2239-
let rustpath = TempDir::new("_rust_rocksdb_internaltest").expect("");
2242+
let rustpath = tempdir_with_prefix("_rust_rocksdb_internaltest");
22402243
let cpath = CString::new(rustpath.path().to_str().unwrap()).unwrap();
22412244
let cpath_ptr = cpath.as_ptr();
22422245

@@ -2248,7 +2251,7 @@ mod test {
22482251
let io_options = crocksdb_options_create();
22492252
let writer = crocksdb_sstfilewriter_create(env_opt, io_options);
22502253

2251-
let sst_dir = TempDir::new("_rust_rocksdb_internaltest").expect("");
2254+
let sst_dir = tempdir_with_prefix("_rust_rocksdb_internaltest");
22522255
let sst_path = sst_dir.path().join("sstfilename");
22532256
let c_sst_path = CString::new(sst_path.to_str().unwrap()).unwrap();
22542257
let c_sst_path_ptr = c_sst_path.as_ptr();

src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ extern crate libc;
1818
#[macro_use]
1919
pub extern crate librocksdb_sys;
2020
#[cfg(test)]
21-
extern crate tempdir;
21+
extern crate tempfile;
2222

2323
pub use compaction_filter::CompactionFilter;
2424
pub use event_listener::{
@@ -68,3 +68,8 @@ mod table_properties;
6868
mod table_properties_collector;
6969
mod table_properties_collector_factory;
7070
mod titan;
71+
72+
#[cfg(test)]
73+
fn tempdir_with_prefix(prefix: &str) -> tempfile::TempDir {
74+
tempfile::Builder::new().prefix(prefix).tempdir().expect("")
75+
}

src/merge_operator.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,11 @@ impl<'a> Iterator for &'a mut MergeOperands {
145145

146146
#[cfg(test)]
147147
mod test {
148-
use super::*;
149148
use rocksdb::{DBVector, Writable, DB};
150149
use rocksdb_options::{ColumnFamilyOptions, DBOptions};
151-
use tempdir::TempDir;
150+
151+
use super::*;
152+
use crate::tempdir_with_prefix;
152153

153154
#[allow(unused_variables)]
154155
#[allow(dead_code)]
@@ -175,7 +176,7 @@ mod test {
175176
#[allow(dead_code)]
176177
#[test]
177178
fn mergetest() {
178-
let path = TempDir::new("_rust_rocksdb_mergetest").expect("");
179+
let path = tempdir_with_prefix("_rust_rocksdb_mergetest");
179180
let mut opts = DBOptions::new();
180181
opts.create_if_missing(true);
181182
let mut cf_opts = ColumnFamilyOptions::new();

src/perf_context.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -396,16 +396,15 @@ impl IOStatsContext {
396396

397397
#[cfg(test)]
398398
mod test {
399-
use super::*;
400-
401-
use tempdir::TempDir;
402-
403399
use rocksdb::{SeekKey, Writable, DB};
404400
use rocksdb_options::{DBOptions, WriteOptions};
405401

402+
use super::*;
403+
use crate::tempdir_with_prefix;
404+
406405
#[test]
407406
fn test_perf_context() {
408-
let temp_dir = TempDir::new("test_perf_context").unwrap();
407+
let temp_dir = tempdir_with_prefix("test_perf_context");
409408
let mut opts = DBOptions::new();
410409
opts.create_if_missing(true);
411410
let db = DB::open(opts, temp_dir.path().to_str().unwrap()).unwrap();
@@ -451,7 +450,7 @@ mod test {
451450

452451
#[test]
453452
fn test_iostats_context() {
454-
let temp_dir = TempDir::new("test_iostats_context").unwrap();
453+
let temp_dir = tempdir_with_prefix("test_iostats_context");
455454
let mut opts = DBOptions::new();
456455
opts.create_if_missing(true);
457456
let db = DB::open(opts, temp_dir.path().to_str().unwrap()).unwrap();

src/rocksdb.rs

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2647,17 +2647,18 @@ pub fn run_ldb_tool(ldb_args: &[String], opts: &DBOptions) {
26472647

26482648
#[cfg(test)]
26492649
mod test {
2650-
use super::*;
26512650
use std::fs;
26522651
use std::path::Path;
26532652
use std::str;
26542653
use std::string::String;
26552654
use std::thread;
2656-
use tempdir::TempDir;
2655+
2656+
use super::*;
2657+
use crate::tempdir_with_prefix;
26572658

26582659
#[test]
26592660
fn external() {
2660-
let path = TempDir::new("_rust_rocksdb_externaltest").expect("");
2661+
let path = tempdir_with_prefix("_rust_rocksdb_externaltest");
26612662
let db = DB::open_default(path.path().to_str().unwrap()).unwrap();
26622663
let p = db.put(b"k1", b"v1111");
26632664
assert!(p.is_ok());
@@ -2670,7 +2671,7 @@ mod test {
26702671
#[allow(unused_variables)]
26712672
#[test]
26722673
fn errors_do_stuff() {
2673-
let path = TempDir::new("_rust_rocksdb_error").expect("");
2674+
let path = tempdir_with_prefix("_rust_rocksdb_error");
26742675
let path_str = path.path().to_str().unwrap();
26752676
let db = DB::open_default(path_str).unwrap();
26762677
let opts = DBOptions::new();
@@ -2689,7 +2690,7 @@ mod test {
26892690

26902691
#[test]
26912692
fn writebatch_works() {
2692-
let path = TempDir::new("_rust_rocksdb_writebacktest").expect("");
2693+
let path = tempdir_with_prefix("_rust_rocksdb_writebacktest");
26932694
let db = DB::open_default(path.path().to_str().unwrap()).unwrap();
26942695

26952696
// test put
@@ -2760,7 +2761,7 @@ mod test {
27602761

27612762
#[test]
27622763
fn iterator_test() {
2763-
let path = TempDir::new("_rust_rocksdb_iteratortest").expect("");
2764+
let path = tempdir_with_prefix("_rust_rocksdb_iteratortest");
27642765

27652766
let db = DB::open_default(path.path().to_str().unwrap()).unwrap();
27662767
db.put(b"k1", b"v1111").expect("");
@@ -2779,7 +2780,7 @@ mod test {
27792780

27802781
#[test]
27812782
fn approximate_size_test() {
2782-
let path = TempDir::new("_rust_rocksdb_iteratortest").expect("");
2783+
let path = tempdir_with_prefix("_rust_rocksdb_iteratortest");
27832784
let db = DB::open_default(path.path().to_str().unwrap()).unwrap();
27842785
for i in 1..8000 {
27852786
db.put(
@@ -2807,7 +2808,7 @@ mod test {
28072808

28082809
#[test]
28092810
fn property_test() {
2810-
let path = TempDir::new("_rust_rocksdb_propertytest").expect("");
2811+
let path = tempdir_with_prefix("_rust_rocksdb_propertytest");
28112812
let db = DB::open_default(path.path().to_str().unwrap()).unwrap();
28122813
db.put(b"a1", b"v1").unwrap();
28132814
db.flush(true).unwrap();
@@ -2822,7 +2823,7 @@ mod test {
28222823

28232824
#[test]
28242825
fn list_column_families_test() {
2825-
let path = TempDir::new("_rust_rocksdb_list_column_families_test").expect("");
2826+
let path = tempdir_with_prefix("_rust_rocksdb_list_column_families_test");
28262827
let mut cfs = ["default", "cf1", "cf2", "cf3"];
28272828
{
28282829
let mut cfs_opts = vec![];
@@ -2853,13 +2854,13 @@ mod test {
28532854
let key = b"foo";
28542855
let value = b"bar";
28552856

2856-
let db_dir = TempDir::new("_rust_rocksdb_backuptest").unwrap();
2857+
let db_dir = tempdir_with_prefix("_rust_rocksdb_backuptest");
28572858
let db = DB::open_default(db_dir.path().to_str().unwrap()).unwrap();
28582859
let p = db.put(key, value);
28592860
assert!(p.is_ok());
28602861

28612862
// Make a backup.
2862-
let backup_dir = TempDir::new("_rust_rocksdb_backuptest_backup").unwrap();
2863+
let backup_dir = tempdir_with_prefix("_rust_rocksdb_backuptest_backup");
28632864
let backup_engine = db.backup_at(backup_dir.path().to_str().unwrap()).unwrap();
28642865

28652866
// Restore it.
@@ -2868,7 +2869,7 @@ mod test {
28682869
ropt2.set_keep_log_files(true);
28692870
let ropts = [ropt1, ropt2];
28702871
for ropt in &ropts {
2871-
let restore_dir = TempDir::new("_rust_rocksdb_backuptest_restore").unwrap();
2872+
let restore_dir = tempdir_with_prefix("_rust_rocksdb_backuptest_restore");
28722873
let restored_db = DB::restore_from(
28732874
&backup_engine,
28742875
restore_dir.path().to_str().unwrap(),
@@ -2884,7 +2885,7 @@ mod test {
28842885

28852886
#[test]
28862887
fn log_dir_test() {
2887-
let db_dir = TempDir::new("_rust_rocksdb_logdirtest").unwrap();
2888+
let db_dir = tempdir_with_prefix("_rust_rocksdb_logdirtest");
28882889
let db_path = db_dir.path().to_str().unwrap();
28892890
let log_path = format!("{}", Path::new(&db_path).join("log_path").display());
28902891
fs::create_dir_all(&log_path).unwrap();
@@ -2910,7 +2911,7 @@ mod test {
29102911

29112912
#[test]
29122913
fn single_delete_test() {
2913-
let path = TempDir::new("_rust_rocksdb_singledeletetest").expect("");
2914+
let path = tempdir_with_prefix("_rust_rocksdb_singledeletetest");
29142915
let db = DB::open_default(path.path().to_str().unwrap()).unwrap();
29152916

29162917
db.put(b"a", b"v1").unwrap();
@@ -2945,7 +2946,7 @@ mod test {
29452946

29462947
#[test]
29472948
fn test_pause_bg_work() {
2948-
let path = TempDir::new("_rust_rocksdb_pause_bg_work").expect("");
2949+
let path = tempdir_with_prefix("_rust_rocksdb_pause_bg_work");
29492950
let db = DB::open_default(path.path().to_str().unwrap()).unwrap();
29502951
let db = Arc::new(db);
29512952
let db1 = db.clone();
@@ -3000,7 +3001,7 @@ mod test {
30003001

30013002
#[test]
30023003
fn block_cache_usage() {
3003-
let path = TempDir::new("_rust_rocksdb_block_cache_usage").expect("");
3004+
let path = tempdir_with_prefix("_rust_rocksdb_block_cache_usage");
30043005
let db = DB::open_default(path.path().to_str().unwrap()).unwrap();
30053006

30063007
for i in 0..200 {
@@ -3018,7 +3019,7 @@ mod test {
30183019

30193020
#[test]
30203021
fn flush_cf() {
3021-
let path = TempDir::new("_rust_rocksdb_flush_cf").expect("");
3022+
let path = tempdir_with_prefix("_rust_rocksdb_flush_cf");
30223023
let mut opts = DBOptions::new();
30233024
opts.create_if_missing(true);
30243025
let mut db = DB::open(opts, path.path().to_str().unwrap()).unwrap();
@@ -3058,7 +3059,7 @@ mod test {
30583059
fn test_get_all_key_versions() {
30593060
let mut opts = DBOptions::new();
30603061
opts.create_if_missing(true);
3061-
let path = TempDir::new("_rust_rocksdb_get_all_key_version_test").expect("");
3062+
let path = tempdir_with_prefix("_rust_rocksdb_get_all_key_version_test");
30623063
let db = DB::open(opts, path.path().to_str().unwrap()).unwrap();
30633064

30643065
let samples = vec![
@@ -3084,7 +3085,7 @@ mod test {
30843085
fn test_get_approximate_memtable_stats() {
30853086
let mut opts = DBOptions::new();
30863087
opts.create_if_missing(true);
3087-
let path = TempDir::new("_rust_rocksdb_get_approximate_memtable_stats").expect("");
3088+
let path = tempdir_with_prefix("_rust_rocksdb_get_approximate_memtable_stats");
30883089
let db = DB::open(opts, path.path().to_str().unwrap()).unwrap();
30893090

30903091
let samples = [
@@ -3114,7 +3115,7 @@ mod test {
31143115
fn test_set_options() {
31153116
let mut opts = DBOptions::new();
31163117
opts.create_if_missing(true);
3117-
let path = TempDir::new("_rust_rocksdb_set_option").expect("");
3118+
let path = tempdir_with_prefix("_rust_rocksdb_set_option");
31183119

31193120
let db = DB::open(opts, path.path().to_str().unwrap()).unwrap();
31203121
let cf = db.cf_handle("default").unwrap();
@@ -3135,7 +3136,7 @@ mod test {
31353136

31363137
#[test]
31373138
fn test_load_latest_options() {
3138-
let path = TempDir::new("_rust_rocksdb_load_latest_option").expect("");
3139+
let path = tempdir_with_prefix("_rust_rocksdb_load_latest_option");
31393140
let dbpath = path.path().to_str().unwrap().clone();
31403141
let cf_name: &str = "cf_dynamic_level_bytes";
31413142

@@ -3170,7 +3171,7 @@ mod test {
31703171

31713172
#[test]
31723173
fn test_sequence_number() {
3173-
let path = TempDir::new("_rust_rocksdb_sequence_number").expect("");
3174+
let path = tempdir_with_prefix("_rust_rocksdb_sequence_number");
31743175

31753176
let mut opts = DBOptions::new();
31763177
opts.create_if_missing(true);
@@ -3188,7 +3189,7 @@ mod test {
31883189

31893190
#[test]
31903191
fn test_map_property() {
3191-
let path = TempDir::new("_rust_rocksdb_get_map_property").expect("");
3192+
let path = tempdir_with_prefix("_rust_rocksdb_get_map_property");
31923193
let dbpath = path.path().to_str().unwrap().clone();
31933194

31943195
let mut opts = DBOptions::new();

tests/cases/mod.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
extern crate byteorder;
2-
extern crate crc;
3-
extern crate rand;
4-
extern crate rocksdb;
5-
extern crate tempdir;
6-
71
mod test_column_family;
82
mod test_compact_range;
93
mod test_compaction_filter;
@@ -25,3 +19,7 @@ mod test_statistics;
2519
mod test_table_properties;
2620
mod test_titan;
2721
mod test_ttl;
22+
23+
fn tempdir_with_prefix(prefix: &str) -> tempfile::TempDir {
24+
tempfile::Builder::new().prefix(prefix).tempdir().expect("")
25+
}

0 commit comments

Comments
 (0)