@@ -4,16 +4,20 @@ use haizhi_rocksdb as rocksdb;
4
4
5
5
use rocksdb:: Ranges ;
6
6
use rocksdb:: { ColumnFamilyDescriptor , Options , DB } ;
7
+
8
+ mod util;
9
+ use util:: DBPath ;
10
+
7
11
#[ test]
8
12
fn test_approximate ( ) {
9
- let path = "test1" ;
13
+ let path = DBPath :: new ( "test_approximate_test1" ) ;
10
14
let cf_opts = Options :: default ( ) ;
11
15
let cf1 = ColumnFamilyDescriptor :: new ( "cf1" , cf_opts. clone ( ) ) ;
12
16
let cf2 = ColumnFamilyDescriptor :: new ( "cf2" , cf_opts) ;
13
17
let mut db_opts = Options :: default ( ) ;
14
18
db_opts. create_missing_column_families ( true ) ;
15
19
db_opts. create_if_missing ( true ) ;
16
- let db = DB :: open_cf_descriptors ( & db_opts, path, vec ! [ cf1, cf2] ) . unwrap ( ) ;
20
+ let db = DB :: open_cf_descriptors ( & db_opts, & path, vec ! [ cf1, cf2] ) . unwrap ( ) ;
17
21
//
18
22
let a = 1 . to_string ( ) ;
19
23
let start_key: & [ u8 ] = a. as_ref ( ) ;
@@ -23,25 +27,21 @@ fn test_approximate() {
23
27
let cf2 = db. cf_handle ( "cf2" ) . unwrap ( ) ;
24
28
for key in 0 ..10000 {
25
29
if key % 2 == 1 {
26
- db. put_cf ( cf1, key. to_string ( ) , ( key * 2 ) . to_string ( ) )
30
+ db. put_cf ( & cf1, key. to_string ( ) , ( key * 2 ) . to_string ( ) )
27
31
. unwrap ( ) ;
28
32
} else {
29
- db. put_cf ( cf2, key. to_string ( ) , ( key * 2 ) . to_string ( ) )
33
+ db. put_cf ( & cf2, key. to_string ( ) , ( key * 2 ) . to_string ( ) )
30
34
. unwrap ( ) ;
31
35
}
32
36
}
33
- db. flush_cf ( cf1) . unwrap ( ) ;
34
- db. flush_cf ( cf2) . unwrap ( ) ;
37
+ db. flush_cf ( & cf1) . unwrap ( ) ;
38
+ db. flush_cf ( & cf2) . unwrap ( ) ;
35
39
std:: thread:: sleep ( Duration :: from_secs ( 2 ) ) ;
36
- println ! (
37
- "start_key {:?}, end_key {:?}" ,
38
- start_key. clone( ) ,
39
- end_key. clone( )
40
- ) ;
40
+ println ! ( "start_key {:?}, end_key {:?}" , start_key, end_key, ) ;
41
41
let files_error_margin: f64 = 1.0 ;
42
42
let f = db
43
43
. get_approximate_sizes_with_option (
44
- cf1,
44
+ & cf1,
45
45
& [ Ranges :: new ( start_key, end_key) ] ,
46
46
files_error_margin,
47
47
)
@@ -53,18 +53,18 @@ fn test_approximate() {
53
53
54
54
for key in 0 ..10000 {
55
55
if key % 2 == 1 {
56
- db. delete_cf ( cf1, key. to_string ( ) ) . unwrap ( ) ;
56
+ db. delete_cf ( & cf1, key. to_string ( ) ) . unwrap ( ) ;
57
57
} else {
58
- db. delete_cf ( cf2, key. to_string ( ) ) . unwrap ( ) ;
58
+ db. delete_cf ( & cf2, key. to_string ( ) ) . unwrap ( ) ;
59
59
}
60
60
}
61
- db. flush_cf ( cf1) . unwrap ( ) ;
61
+ db. flush_cf ( & cf1) . unwrap ( ) ;
62
62
std:: thread:: sleep ( Duration :: from_secs ( 5 ) ) ;
63
63
let none: Option < Vec < u8 > > = None ;
64
64
db. compact_range ( none. clone ( ) , none) ;
65
65
let f = db
66
66
. get_approximate_sizes_with_option (
67
- cf1,
67
+ & cf1,
68
68
& [ Ranges :: new ( start_key, end_key) ] ,
69
69
files_error_margin,
70
70
)
0 commit comments