Skip to content

Commit 90a6b99

Browse files
committed
kvdb-rocksdb: support the rocksdb/multi-threaded-cf feature
1 parent d5e9c1d commit 90a6b99

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

kvdb-rocksdb/src/iter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ impl<'a> IterationHandler for &'a DBAndColumns {
3939

4040
fn iter(self, col: u32, read_opts: ReadOptions) -> Self::Iterator {
4141
match self.cf(col as usize) {
42-
Ok(cf) => EitherIter::A(KvdbAdapter(self.db.iterator_cf_opt(cf, read_opts, IteratorMode::Start))),
42+
Ok(cf) => EitherIter::A(KvdbAdapter(self.db.iterator_cf_opt(&cf, read_opts, IteratorMode::Start))),
4343
Err(e) => EitherIter::B(std::iter::once(Err(e))),
4444
}
4545
}
4646

4747
fn iter_with_prefix(self, col: u32, prefix: &[u8], read_opts: ReadOptions) -> Self::Iterator {
4848
match self.cf(col as usize) {
4949
Ok(cf) => EitherIter::A(KvdbAdapter(self.db.iterator_cf_opt(
50-
cf,
50+
&cf,
5151
read_opts,
5252
IteratorMode::From(prefix, Direction::Forward),
5353
))),

kvdb-rocksdb/src/lib.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use std::{
1717
};
1818

1919
use rocksdb::{
20-
BlockBasedOptions, ColumnFamily, ColumnFamilyDescriptor, Options, ReadOptions, WriteBatch, WriteOptions, DB,
20+
BlockBasedOptions, ColumnFamilyDescriptor, ColumnFamilyRef, Options, ReadOptions, WriteBatch, WriteOptions, DB
2121
};
2222

2323
use kvdb::{DBKeyValue, DBOp, DBTransaction, DBValue, KeyValueDB};
@@ -251,7 +251,7 @@ struct DBAndColumns {
251251
}
252252

253253
impl DBAndColumns {
254-
fn cf(&self, i: usize) -> io::Result<&ColumnFamily> {
254+
fn cf(&self, i: usize) -> io::Result<ColumnFamilyRef<'_>> {
255255
let name = self.column_names.get(i).ok_or_else(|| invalid_column(i as u32))?;
256256
self.db
257257
.cf_handle(&name)
@@ -377,6 +377,7 @@ impl Database {
377377
Err(_) => {
378378
// retry and create CFs
379379
match DB::open_cf(&opts, path.as_ref(), &[] as &[&str]) {
380+
#[allow(unused_mut)] // warns when `multi-threaded-cf` feature is enabled on rocksdb, as `create_cf` takes an &self.
380381
Ok(mut db) => {
381382
for (i, name) in column_names.iter().enumerate() {
382383
let _ = db
@@ -436,31 +437,32 @@ impl Database {
436437
match op {
437438
DBOp::Insert { col: _, key, value } => {
438439
stats_total_bytes += key.len() + value.len();
439-
batch.put_cf(cf, &key, &value);
440+
batch.put_cf(&cf, &key, &value);
440441
},
441442
DBOp::Delete { col: _, key } => {
442443
// We count deletes as writes.
443444
stats_total_bytes += key.len();
444-
batch.delete_cf(cf, &key);
445+
batch.delete_cf(&cf, &key);
445446
},
446447
DBOp::DeletePrefix { col, prefix } => {
447448
let end_prefix = kvdb::end_prefix(&prefix[..]);
448449
let no_end = end_prefix.is_none();
449450
let end_range = end_prefix.unwrap_or_else(|| vec![u8::max_value(); 16]);
450-
batch.delete_range_cf(cf, &prefix[..], &end_range[..]);
451+
batch.delete_range_cf(&cf, &prefix[..], &end_range[..]);
451452
if no_end {
452453
let prefix = if prefix.len() > end_range.len() { &prefix[..] } else { &end_range[..] };
453454
for result in self.iter_with_prefix(col, prefix) {
454455
let (key, _) = result?;
455-
batch.delete_cf(cf, &key[..]);
456+
batch.delete_cf(&cf, &key[..]);
456457
}
457458
}
458459
},
459460
};
460461
}
461462
self.stats.tally_bytes_written(stats_total_bytes as u64);
462463

463-
cfs.db.write_opt(batch, &self.write_opts).map_err(other_io_err)
464+
cfs.db.write_opt(batch, &self.write_opts).map_err(other_io_err)?;
465+
Ok(())
464466
}
465467

466468
/// Get value by key.
@@ -470,7 +472,7 @@ impl Database {
470472
self.stats.tally_reads(1);
471473
let value = cfs
472474
.db
473-
.get_pinned_cf_opt(cf, key, &self.read_opts)
475+
.get_pinned_cf_opt(&cf, key, &self.read_opts)
474476
.map(|r| r.map(|v| v.to_vec()))
475477
.map_err(other_io_err);
476478

@@ -521,7 +523,7 @@ impl Database {
521523
const ESTIMATE_NUM_KEYS: &str = "rocksdb.estimate-num-keys";
522524
let cfs = &self.inner;
523525
let cf = cfs.cf(col as usize)?;
524-
match cfs.db.property_int_value_cf(cf, ESTIMATE_NUM_KEYS) {
526+
match cfs.db.property_int_value_cf(&cf, ESTIMATE_NUM_KEYS) {
525527
Ok(estimate) => Ok(estimate.unwrap_or_default()),
526528
Err(err_string) => Err(other_io_err(err_string)),
527529
}

0 commit comments

Comments
 (0)