-
Notifications
You must be signed in to change notification settings - Fork 595
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
fix(metric): correctly update storage object metric #18835
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -301,6 +301,32 @@ impl HummockManager { | |
.map(|m| m.seq.try_into().unwrap()); | ||
Ok(now) | ||
} | ||
|
||
pub fn update_paged_metrics( | ||
&self, | ||
start_after: Option<String>, | ||
next_start_after: Option<String>, | ||
total_object_count_in_page: u64, | ||
total_object_size_in_page: u64, | ||
) { | ||
let mut paged_metrics = self.paged_metrics.lock(); | ||
paged_metrics.total_object_size.update( | ||
start_after.clone(), | ||
next_start_after.clone(), | ||
total_object_size_in_page, | ||
); | ||
paged_metrics.total_object_count.update( | ||
start_after, | ||
next_start_after, | ||
total_object_count_in_page, | ||
); | ||
if let Some(total_object_size) = paged_metrics.total_object_size.take() { | ||
self.metrics.total_object_size.set(total_object_size as _); | ||
} | ||
if let Some(total_object_count) = paged_metrics.total_object_count.take() { | ||
self.metrics.total_object_count.set(total_object_count as _); | ||
} | ||
} | ||
} | ||
|
||
pub struct FullGcState { | ||
|
@@ -325,6 +351,84 @@ impl FullGcState { | |
} | ||
} | ||
|
||
pub struct PagedMetrics { | ||
total_object_count: PagedMetric, | ||
total_object_size: PagedMetric, | ||
} | ||
|
||
impl PagedMetrics { | ||
pub fn new() -> Self { | ||
Self { | ||
total_object_count: PagedMetric::new(), | ||
total_object_size: PagedMetric::new(), | ||
} | ||
} | ||
} | ||
|
||
/// The metrics should be accumulated on a per-page basis and then finalized at the end. | ||
pub struct PagedMetric { | ||
/// identifier of a page | ||
expect_start_key: Option<String>, | ||
/// accumulated metric value of pages seen so far | ||
running_value: u64, | ||
/// final metric value | ||
sealed_value: Option<u64>, | ||
} | ||
|
||
impl PagedMetric { | ||
fn new() -> Self { | ||
Self { | ||
expect_start_key: None, | ||
running_value: 0, | ||
sealed_value: None, | ||
} | ||
} | ||
|
||
fn update( | ||
&mut self, | ||
current_start_key: Option<String>, | ||
next_start_key: Option<String>, | ||
value: u64, | ||
) { | ||
// Encounter an update without pagination, replace current state. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add doc for "manualy trigger full gc" ? |
||
if current_start_key.is_none() && next_start_key.is_none() { | ||
self.running_value = value; | ||
self.seal(); | ||
return; | ||
} | ||
// Encounter an update from unexpected page, reset current state. | ||
if current_start_key != self.expect_start_key { | ||
self.reset(); | ||
return; | ||
} | ||
self.running_value += value; | ||
// There are more pages to add. | ||
if next_start_key.is_some() { | ||
self.expect_start_key = next_start_key; | ||
return; | ||
} | ||
// This is the last page, seal the metric value. | ||
self.seal(); | ||
} | ||
|
||
fn seal(&mut self) { | ||
self.sealed_value = Some(self.running_value); | ||
self.reset(); | ||
} | ||
|
||
fn reset(&mut self) { | ||
self.running_value = 0; | ||
self.expect_start_key = None; | ||
} | ||
|
||
fn take(&mut self) -> Option<u64> { | ||
if self.sealed_value.is_some() { | ||
self.reset(); | ||
} | ||
self.sealed_value.take() | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use std::sync::Arc; | ||
|
@@ -334,7 +438,7 @@ mod tests { | |
use risingwave_hummock_sdk::compaction_group::StaticCompactionGroupId; | ||
use risingwave_rpc_client::HummockMetaClient; | ||
|
||
use super::ResponseEvent; | ||
use super::{PagedMetric, ResponseEvent}; | ||
use crate::hummock::test_utils::{add_test_tables, setup_compute_env}; | ||
use crate::hummock::MockHummockMetaClient; | ||
|
||
|
@@ -428,4 +532,35 @@ mod tests { | |
.unwrap() | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_paged_metric() { | ||
let mut metric = PagedMetric::new(); | ||
fn assert_empty_state(metric: &mut PagedMetric) { | ||
assert_eq!(metric.running_value, 0); | ||
assert!(metric.expect_start_key.is_none()); | ||
} | ||
assert!(metric.sealed_value.is_none()); | ||
assert_empty_state(&mut metric); | ||
|
||
metric.update(None, None, 100); | ||
assert_eq!(metric.take().unwrap(), 100); | ||
assert!(metric.take().is_none()); | ||
assert_empty_state(&mut metric); | ||
|
||
// "start" is not a legal identifier for the first page | ||
metric.update(Some("start".into()), Some("end".into()), 100); | ||
assert!(metric.take().is_none()); | ||
assert_empty_state(&mut metric); | ||
|
||
metric.update(None, Some("middle".into()), 100); | ||
assert!(metric.take().is_none()); | ||
assert_eq!(metric.running_value, 100); | ||
assert_eq!(metric.expect_start_key, Some("middle".into())); | ||
|
||
metric.update(Some("middle".into()), None, 50); | ||
assert_eq!(metric.take().unwrap(), 150); | ||
assert!(metric.take().is_none()); | ||
assert_empty_state(&mut metric); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Another PB change related to severless compaction @yufansong @arkbriar