Skip to content
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: collect reader metrics from prune reader #5152

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/mito2/src/read/last_row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use crate::cache::{
use crate::error::Result;
use crate::read::{Batch, BatchReader, BoxedBatchReader};
use crate::sst::file::FileId;
use crate::sst::parquet::reader::RowGroupReader;
use crate::sst::parquet::reader::{ReaderMetrics, RowGroupReader};

/// Reader to keep the last row for each time series.
/// It assumes that batches from the input reader are
Expand Down Expand Up @@ -115,6 +115,14 @@ impl RowGroupLastRowCachedReader {
}
}

/// Gets the underlying reader metrics if uncached.
pub(crate) fn metrics(&self) -> Option<&ReaderMetrics> {
match self {
RowGroupLastRowCachedReader::Hit(_) => None,
RowGroupLastRowCachedReader::Miss(reader) => Some(reader.metrics()),
}
}

/// Creates new Hit variant and updates metrics.
fn new_hit(value: Arc<SelectorResultValue>) -> Self {
selector_result_cache_hit();
Expand Down Expand Up @@ -234,6 +242,10 @@ impl RowGroupLastRowReader {
});
cache.put_selector_result(self.key, value);
}

fn metrics(&self) -> &ReaderMetrics {
self.reader.metrics()
}
}

/// Push last row into `yielded_batches`.
Expand Down
16 changes: 13 additions & 3 deletions src/mito2/src/read/prune.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,21 @@ impl PruneReader {
self.source = source;
}

pub(crate) fn metrics(&mut self) -> &ReaderMetrics {
/// Merge metrics with the inner reader and return the merged metrics.
pub(crate) fn metrics(&self) -> ReaderMetrics {
let mut metrics = self.metrics.clone();
match &self.source {
Source::RowGroup(r) => r.metrics(),
Source::LastRow(_) => &self.metrics,
Source::RowGroup(r) => {
metrics.merge_from(r.metrics());
}
Source::LastRow(r) => {
if let Some(inner_metrics) = r.metrics() {
metrics.merge_from(inner_metrics);
}
}
}

metrics
}

pub(crate) async fn next_batch(&mut self) -> Result<Option<Batch>> {
Expand Down
5 changes: 3 additions & 2 deletions src/mito2/src/read/scan_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,9 @@ pub(crate) fn scan_file_ranges(
}
yield batch;
}
if let Source::PruneReader(mut reader) = source {
reader_metrics.merge_from(reader.metrics());
if let Source::PruneReader(reader) = source {
let prune_metrics = reader.metrics();
reader_metrics.merge_from(&prune_metrics);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/mito2/src/sst/parquet/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -915,10 +915,10 @@ enum ReaderState {

impl ReaderState {
/// Returns the metrics of the reader.
fn metrics(&mut self) -> &ReaderMetrics {
fn metrics(&self) -> ReaderMetrics {
match self {
ReaderState::Readable(reader) => reader.metrics(),
ReaderState::Exhausted(m) => m,
ReaderState::Exhausted(m) => m.clone(),
}
}
}
Expand Down
Loading