Skip to content

Commit

Permalink
resolve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
wcy-fdu committed Mar 17, 2023
1 parent 22876b1 commit 09e07e6
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 23 deletions.
12 changes: 1 addition & 11 deletions src/storage/hummock_sdk/src/key_cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use std::cmp::{self, Ordering};

use super::key::split_key_epoch;
use crate::key::{FullKey, UserKey};
use crate::key::UserKey;

/// A comparator for comparing [`FullKey`] and [`UserKey`] with possibly different table key types.
pub struct KeyComparator;
Expand All @@ -30,16 +30,6 @@ impl KeyComparator {
l_p.cmp(r_p).then_with(|| r_s.cmp(l_s))
}

pub fn compare_full_key_without_table_id(
lhs: FullKey<&[u8]>,
rhs: FullKey<&[u8]>,
) -> cmp::Ordering {
lhs.user_key
.table_key
.cmp(&rhs.user_key.table_key)
.then_with(|| rhs.epoch.cmp(&lhs.epoch))
}

/// Used to compare [`UserKey`] and its encoded format.
pub fn compare_user_key_cross_format(
encoded: impl AsRef<[u8]>,
Expand Down
4 changes: 2 additions & 2 deletions src/storage/src/hummock/compactor/compaction_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use risingwave_hummock_sdk::key::FullKey;
use risingwave_hummock_sdk::key_range::KeyRange;
use risingwave_hummock_sdk::prost_key_range::KeyRangeExt;
use risingwave_hummock_sdk::table_stats::TableStatsMap;
use risingwave_hummock_sdk::HummockEpoch;
use risingwave_hummock_sdk::{HummockEpoch, KeyComparator};
use risingwave_pb::hummock::{compact_task, CompactTask, KeyRange as KeyRange_vec, LevelType};

pub use super::context::CompactorContext;
Expand Down Expand Up @@ -219,7 +219,7 @@ pub async fn generate_splits(compact_task: &mut CompactTask, context: Arc<Compac
);
}
// sort by key, as for every data block has the same size;
indexes.sort_by(|a, b| FullKey::decode(a.1.as_ref()).cmp(&FullKey::decode(b.1.as_ref())));
indexes.sort_by(|a, b| KeyComparator::compare_encoded_full_key(a.1.as_ref(), b.1.as_ref()));
let mut splits: Vec<KeyRange_vec> = vec![];
splits.push(KeyRange_vec::new(vec![], vec![]));
let parallelism = std::cmp::min(
Expand Down
8 changes: 5 additions & 3 deletions src/storage/src/hummock/compactor/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use std::time::Instant;

use risingwave_hummock_sdk::key::FullKey;
use risingwave_hummock_sdk::key_range::KeyRange;
use risingwave_hummock_sdk::KeyComparator;
use risingwave_pb::hummock::SstableInfo;

use crate::hummock::iterator::{Forward, HummockIterator};
Expand Down Expand Up @@ -261,9 +262,10 @@ impl ConcatSstableIterator {
block_metas.len()
} else {
block_metas.partition_point(|block| {
FullKey::decode(&block.smallest_key)
.cmp(&FullKey::decode(&self.key_range.right))
!= Ordering::Greater
KeyComparator::compare_encoded_full_key(
&block.smallest_key,
&self.key_range.right,
) != Ordering::Greater
})
};
if end_index <= start_index {
Expand Down
8 changes: 1 addition & 7 deletions src/storage/src/hummock/sstable/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,13 +450,7 @@ impl BlockBuilder {
if self.entry_count > 0 {
debug_assert!(!key.is_empty());
debug_assert_eq!(
KeyComparator::compare_full_key_without_table_id(
FullKey::from_slice_without_table_id(
TableId::new(input_table_id),
&self.last_key[..]
),
full_key
),
KeyComparator::compare_encoded_full_key(&self.last_key[..], &key[..]),
Ordering::Less
);
}
Expand Down

0 comments on commit 09e07e6

Please sign in to comment.