-
Notifications
You must be signed in to change notification settings - Fork 526
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(storage): iterator support min_epoch check #3542
Conversation
6891217
to
68704b9
Compare
Codecov Report
@@ Coverage Diff @@
## main #3542 +/- ##
==========================================
+ Coverage 74.39% 74.41% +0.02%
==========================================
Files 771 770 -1
Lines 108714 108659 -55
==========================================
- Hits 80875 80858 -17
+ Misses 27839 27801 -38
Flags with carried forward coverage won't be shown. Click here to find out more.
📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more |
68704b9
to
8eb6fcb
Compare
8eb6fcb
to
565eb54
Compare
How is it different from previous (with/with out min_epoch)? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like easy to understand. LGTM
@@ -53,6 +53,8 @@ pub struct BackwardUserIterator { | |||
/// Only reads values if `epoch <= self.read_epoch`. | |||
read_epoch: Epoch, | |||
|
|||
min_epoch: Epoch, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add some comments for the usage of this field. Should explicitly mentioned that this is only be used for ttl.
src/common/src/catalog/mod.rs
Outdated
impl From<&TableOption> for risingwave_pb::hummock::TableOption { | ||
fn from(table_option: &TableOption) -> Self { | ||
Self { | ||
ttl: table_option.ttl.unwrap_or(0), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-> unwrap_or(TABLE_OPTION_DUMMY_TTL)
We use 0 as the special value. Do we need to disallow user to set ttl to 0?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its a good idea to disallow user to set ttl to 0 in frontend (but now frontend had not distinguish with_option value type) even if the logic is masked in the storage layer.
conculution: if the ttl be set to 0 , we can cover it in the storage layer
src/storage/src/store.rs
Outdated
impl ReadOptions { | ||
pub fn min_epoch(&self) -> u64 { | ||
match self.ttl { | ||
Some(ttl_u32) => self.epoch - ttl_u32 as u64, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only the upper 48bit of the epoch represents physical time so you cannot simpy subtract ttl from epoch to construct min_epoch. See epoch.rs for more details.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix above
At first min_epoch means that user could not access keys which under min_epoch. It use for consistent for ttl. Without min_epoch, user may access the key which under compaction, lead to Inconsistency between two reads |
But I remembered that iter will always need a |
yes, user only care about the read_epoch. (read_epoch is a upper_bound, min_epoch is a lower_bound when use ttl). an actual scene, user hold a window which width 30min, so that the ttl can be set to 40min. in this case , user never access the key which epoch under min_epoch (read_epoch - ttl), even though the key is the only one in hummock |
d8a84d6
to
2ca781e
Compare
src/common/src/util/epoch.rs
Outdated
@@ -70,6 +70,16 @@ impl Epoch { | |||
pub fn as_system_time(&self) -> SystemTime { | |||
*UNIX_SINGULARITY_DATE_EPOCH + Duration::from_millis(self.physical_time()) | |||
} | |||
|
|||
pub fn min_epoch_with_interval(&self, interval: u64) -> Self { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling it min_epoch_with_interval
is a bit confusing since the Epoch struct should be unaware of the usage of epoch. I suggest rename it to something like subtract_ms(&self, relative_time_ms: u64)
and add some docs explaining the usage.
src/storage/src/store.rs
Outdated
pub fn min_epoch(&self) -> u64 { | ||
let epoch = Epoch(self.epoch); | ||
match self.ttl { | ||
Some(ttl_u32) => epoch.min_epoch_with_interval(ttl_u32 as u64).0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ttl_u32 is measure in second? we should convert it to ms to do the epoch subtraction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unify the unit of ttl to second
fix(storage): fix clippy chore(storage): some unit-test for min_epoch check chore(storage): remove table_option in keyspace
1516a71
to
ee00898
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rest LGTM
@@ -514,6 +523,7 @@ mod tests { | |||
.map(|table_info| table_info.id) | |||
.collect::<Vec<_>>(); | |||
|
|||
// println!("table_ids_from_version {:?}", table_ids_from_version); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove commented line
fix(storage): unify the unit of ttl to second fix(storage): doc comment fix(storage): use TableOption parse to handle ttl which zero
ee00898
to
861773d
Compare
for (k, _) in scan_result { | ||
let table_id = get_table_id(&k).unwrap(); | ||
let epoch = get_epoch(&k); | ||
assert_eq!(table_id, existing_table_id); | ||
assert!(epoch >= (watermark - ttl_expire as u64)); | ||
assert!(epoch >= min_epoch.0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* feat(storage): keyspace support table_properties * feat(storage): iterator shadow keys which epoch under min_epoch * feat(storage): TableOption for common * feat(storage): ReadOption add ttl and calculate min_epoch function * chore(storage): adapt some test with ReadOption fix(storage): fix clippy chore(storage): some unit-test for min_epoch check chore(storage): remove table_option in keyspace * fix(storage): fix min_epoch check in compaction_filter and test fix(storage): unify the unit of ttl to second fix(storage): doc comment fix(storage): use TableOption parse to handle ttl which zero
I hereby agree to the terms of the Singularity Data, Inc. Contributor License Agreement.
What's changed and what's your intention?
Some change about TTL as title
Please explain IN DETAIL what the changes are in this PR and why they are needed:
keyspace
adapt table properties withCatalogTable
UserIterator
add check through min_epochReadOptions
add Option and support to calculate min_epoch for iteratorChecklist
Refer to a related PR or issue link (optional)