Skip to content

Commit

Permalink
fix: use EpochWithGap::new_max_epoch if the provided epoch is max epo…
Browse files Browse the repository at this point in the history
…ch (#13881)
  • Loading branch information
hzxa21 authored Dec 10, 2023
1 parent 7b6bbf3 commit e513e6b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
7 changes: 5 additions & 2 deletions src/common/src/util/epoch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,11 @@ impl Epoch {

pub const EPOCH_AVAILABLE_BITS: u64 = 16;
pub const MAX_SPILL_TIMES: u16 = ((1 << EPOCH_AVAILABLE_BITS) - 1) as u16;
pub const EPOCH_MASK: u64 = (1 << EPOCH_AVAILABLE_BITS) - 1;
pub const MAX_EPOCH: u64 = u64::MAX & !EPOCH_MASK;
// Low EPOCH_AVAILABLE_BITS bits set to 1
pub const EPOCH_SPILL_TIME_MASK: u64 = (1 << EPOCH_AVAILABLE_BITS) - 1;
// High (64-EPOCH_AVAILABLE_BITS) bits set to 1
const EPOCH_MASK: u64 = !EPOCH_SPILL_TIME_MASK;
pub const MAX_EPOCH: u64 = u64::MAX & EPOCH_MASK;

pub fn is_max_epoch(epoch: u64) -> bool {
// Since we have write `MAX_EPOCH` as max epoch to sstable in some previous version,
Expand Down
17 changes: 9 additions & 8 deletions src/storage/hummock_sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ mod key_cmp;
use std::cmp::Ordering;

pub use key_cmp::*;
use risingwave_common::util::epoch::EPOCH_MASK;
use risingwave_common::util::epoch::EPOCH_SPILL_TIME_MASK;
use risingwave_pb::common::{batch_query_epoch, BatchQueryEpoch};
use risingwave_pb::hummock::SstableInfo;

Expand Down Expand Up @@ -288,11 +288,12 @@ impl EpochWithGap {
// So for compatibility, we must skip checking it for u64::MAX. See bug description in https://github.com/risingwavelabs/risingwave/issues/13717
#[cfg(not(feature = "enable_test_epoch"))]
{
debug_assert!(
((epoch & EPOCH_MASK) == 0) || risingwave_common::util::epoch::is_max_epoch(epoch)
);
let epoch_with_gap = epoch + spill_offset as u64;
EpochWithGap(epoch_with_gap)
if risingwave_common::util::epoch::is_max_epoch(epoch) {
EpochWithGap::new_max_epoch()
} else {
debug_assert!((epoch & EPOCH_SPILL_TIME_MASK) == 0);
EpochWithGap(epoch + spill_offset as u64)
}
}
#[cfg(feature = "enable_test_epoch")]
{
Expand Down Expand Up @@ -326,7 +327,7 @@ impl EpochWithGap {
pub fn pure_epoch(&self) -> HummockEpoch {
#[cfg(not(feature = "enable_test_epoch"))]
{
self.0 & !EPOCH_MASK
self.0 & !EPOCH_SPILL_TIME_MASK
}
#[cfg(feature = "enable_test_epoch")]
{
Expand All @@ -335,6 +336,6 @@ impl EpochWithGap {
}

pub fn offset(&self) -> u64 {
self.0 & EPOCH_MASK
self.0 & EPOCH_SPILL_TIME_MASK
}
}

0 comments on commit e513e6b

Please sign in to comment.