Skip to content

Commit 7bedfca

Browse files
author
yangweijian
committed
fix CI fails
1 parent e8d9152 commit 7bedfca

10 files changed

+43
-43
lines changed

librocksdb-sys/tests/ffi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
)]
2525

2626
use const_cstr::const_cstr;
27+
use haizhi_librocksdb_sys::*;
2728
use libc::*;
28-
use librocksdb_sys::*;
2929
use std::borrow::Cow;
3030
use std::env;
3131
use std::ffi::{CStr, CString};

src/checkpoint.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
//! [1]: https://github.com/facebook/rocksdb/wiki/Checkpoints
1919
2020
use crate::AsColumnFamilyRef;
21-
use crate::{ffi, Error, DB};
22-
use libc::{c_char, int32_t};
21+
use crate::{ffi, Error};
22+
use libc::c_char;
2323

2424
use crate::db::DBInner;
2525
use crate::ffi_util::to_cpath;
26-
use crate::{ColumnFamily, DBCommon, ThreadMode};
26+
use crate::{DBCommon, ThreadMode};
2727
use std::ffi::{CStr, CString};
2828
use std::fs::File;
2929
use std::io::{Read, Write};
@@ -215,13 +215,11 @@ impl<'db> Checkpoint<'db> {
215215
export_dir: P,
216216
) -> Result<ExportImportFilesMetaData, Error> {
217217
let path = export_dir.as_ref();
218-
let cpath = if let Ok(c) = CString::new(path.to_string_lossy().as_bytes()) {
219-
c
220-
} else {
221-
return Err(Error::new(
222-
"Failed to convert path to CString when creating DB checkpoint".to_owned(),
223-
));
224-
};
218+
let cpath = CString::new(path.to_string_lossy().as_bytes()).map_err(|err| {
219+
Error::new(format!(
220+
"Failed to convert path to CString when creating DB checkpoint: {err}"
221+
))
222+
})?;
225223

226224
let inner: *mut ffi::rocksdb_export_import_files_metadata_t;
227225

src/db.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -2036,7 +2036,7 @@ impl<T: ThreadMode, D: DBInner> DBCommon<T, D> {
20362036
true,
20372037
true,
20382038
files_size_error_margin,
2039-
))
2039+
));
20402040
}
20412041
Ok(sizes)
20422042
}
@@ -2167,13 +2167,11 @@ impl<T: ThreadMode, D: DBInner> DBCommon<T, D> {
21672167
opts: &Options,
21682168
metadata: &ExportImportFilesMetaData,
21692169
) -> Result<*mut ffi::rocksdb_column_family_handle_t, Error> {
2170-
let cf_name = if let Ok(c) = CString::new(name.as_bytes()) {
2171-
c
2172-
} else {
2173-
return Err(Error::new(
2174-
"Failed to convert path to CString when creating cf".to_owned(),
2175-
));
2176-
};
2170+
let cf_name = CString::new(name.as_bytes()).map_err(|err| {
2171+
Error::new(format!(
2172+
"Failed to convert path to CString when creating cf: {err}"
2173+
))
2174+
})?;
21772175
Ok(unsafe {
21782176
ffi_try!(ffi::rocksdb_create_column_family_with_import(
21792177
self.inner.inner(),

src/transactions/transaction_db.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,8 @@ impl<T: ThreadMode> TransactionDB<T> {
300300
let mut cnt = 0;
301301
let ptr = ffi::rocksdb_transactiondb_get_prepared_transactions(db, &mut cnt);
302302
let mut vec = vec![std::ptr::null_mut(); cnt];
303-
std::ptr::copy_nonoverlapping(ptr, vec.as_mut_ptr(), cnt);
304303
if !ptr.is_null() {
304+
std::ptr::copy_nonoverlapping(ptr, vec.as_mut_ptr(), cnt);
305305
ffi::rocksdb_free(ptr as *mut c_void);
306306
}
307307
vec
+5-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error[E0597]: `db` does not live long enough
2-
--> tests/fail/checkpoint_outlive_db.rs:7:25
2+
--> tests/fail/snapshot_outlive_db.rs:7:9
33
|
4-
5 | let _checkpoint = {
5-
| ----------- borrow later stored here
4+
5 | let _snapshot = {
5+
| --------- borrow later stored here
66
6 | let db = DB::open_default("foo").unwrap();
77
| -- binding `db` declared here
8-
7 | Checkpoint::new(&db)
9-
| ^^^ borrowed value does not live long enough
8+
7 | db.snapshot()
9+
| ^^ borrowed value does not live long enough
1010
8 | };
1111
| - `db` dropped here while still borrowed

tests/fail/open_with_multiple_refs_as_single_threaded.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@ error[E0596]: cannot borrow `*db_ref1` as mutable, as it is behind a `&` referen
22
--> tests/fail/open_with_multiple_refs_as_single_threaded.rs:9:5
33
|
44
9 | db_ref1.create_cf("cf1", &opts).unwrap();
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `db_ref1` is a `&` reference, so the data it refers to cannot be borrowed as mutable
5+
| ^^^^^^^ `db_ref1` is a `&` reference, so the data it refers to cannot be borrowed as mutable
66
|
77
help: consider changing this to be a mutable reference
88
|
99
6 | let db_ref1 = &mut db;
10-
| ~~~~~~~
10+
| +++
1111

1212
error[E0596]: cannot borrow `*db_ref2` as mutable, as it is behind a `&` reference
1313
--> tests/fail/open_with_multiple_refs_as_single_threaded.rs:10:5
1414
|
1515
10 | db_ref2.create_cf("cf2", &opts).unwrap();
16-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `db_ref2` is a `&` reference, so the data it refers to cannot be borrowed as mutable
16+
| ^^^^^^^ `db_ref2` is a `&` reference, so the data it refers to cannot be borrowed as mutable
1717
|
1818
help: consider changing this to be a mutable reference
1919
|
2020
7 | let db_ref2 = &mut db;
21-
| ~~~~~~~
21+
| +++

tests/fail/snapshot_outlive_db.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ error[E0597]: `db` does not live long enough
66
6 | let db = DB::open_default("foo").unwrap();
77
| -- binding `db` declared here
88
7 | db.snapshot()
9-
| ^^^^^^^^^^^^^ borrowed value does not live long enough
9+
| ^^ borrowed value does not live long enough
1010
8 | };
1111
| - `db` dropped here while still borrowed

tests/test_approximate.rs

+15-11
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,20 @@ use haizhi_rocksdb as rocksdb;
44

55
use rocksdb::Ranges;
66
use rocksdb::{ColumnFamilyDescriptor, Options, DB};
7+
8+
mod util;
9+
use util::DBPath;
10+
711
#[test]
812
fn test_approximate() {
9-
let path = "test1";
13+
let path = DBPath::new("test_approximate_test1");
1014
let cf_opts = Options::default();
1115
let cf1 = ColumnFamilyDescriptor::new("cf1", cf_opts.clone());
1216
let cf2 = ColumnFamilyDescriptor::new("cf2", cf_opts);
1317
let mut db_opts = Options::default();
1418
db_opts.create_missing_column_families(true);
1519
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();
1721
//
1822
let a = 1.to_string();
1923
let start_key: &[u8] = a.as_ref();
@@ -23,15 +27,15 @@ fn test_approximate() {
2327
let cf2 = db.cf_handle("cf2").unwrap();
2428
for key in 0..10000 {
2529
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())
2731
.unwrap();
2832
} 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())
3034
.unwrap();
3135
}
3236
}
33-
db.flush_cf(cf1).unwrap();
34-
db.flush_cf(cf2).unwrap();
37+
db.flush_cf(&cf1).unwrap();
38+
db.flush_cf(&cf2).unwrap();
3539
std::thread::sleep(Duration::from_secs(2));
3640
println!(
3741
"start_key {:?}, end_key {:?}",
@@ -41,7 +45,7 @@ fn test_approximate() {
4145
let files_error_margin: f64 = 1.0;
4246
let f = db
4347
.get_approximate_sizes_with_option(
44-
cf1,
48+
&cf1,
4549
&[Ranges::new(start_key, end_key)],
4650
files_error_margin,
4751
)
@@ -53,18 +57,18 @@ fn test_approximate() {
5357

5458
for key in 0..10000 {
5559
if key % 2 == 1 {
56-
db.delete_cf(cf1, key.to_string()).unwrap();
60+
db.delete_cf(&cf1, key.to_string()).unwrap();
5761
} else {
58-
db.delete_cf(cf2, key.to_string()).unwrap();
62+
db.delete_cf(&cf2, key.to_string()).unwrap();
5963
}
6064
}
61-
db.flush_cf(cf1).unwrap();
65+
db.flush_cf(&cf1).unwrap();
6266
std::thread::sleep(Duration::from_secs(5));
6367
let none: Option<Vec<u8>> = None;
6468
db.compact_range(none.clone(), none);
6569
let f = db
6670
.get_approximate_sizes_with_option(
67-
cf1,
71+
&cf1,
6872
&[Ranges::new(start_key, end_key)],
6973
files_error_margin,
7074
)

tests/test_checkpoint.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ fn test_export_column_family() {
139139

140140
let export_path = DBPath::new(&format!("{}db1_backup", PATH_PREFIX));
141141
// let export_path = Path::new("db1_backup");
142-
let result = checkpoint.export_column_family(cf1, &export_path);
142+
let result = checkpoint.export_column_family(&cf1, &export_path);
143143
assert!(result.is_ok());
144144
let metadata = result.unwrap();
145145
// println!("metadata {:?}", metadata.save("save"));

tests/test_column_family.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ fn test_create_cf_with_import() {
537537

538538
let export_path = format!("{}/db1_backup", PATH_PREFIX);
539539
let export_path = Path::new(&export_path);
540-
let result = checkpoint.export_column_family(cf1, &export_path);
540+
let result = checkpoint.export_column_family(&cf1, &export_path);
541541
assert!(result.is_ok());
542542
drop(checkpoint);
543543

0 commit comments

Comments
 (0)