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: region disk usage statistic #2665

Merged
merged 9 commits into from
Oct 31, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
feat: region usage for engine
QuenKar committed Oct 30, 2023
commit dca00d5f42f6fba93d79edb4405f04b283bcec0c
12 changes: 12 additions & 0 deletions src/mito2/src/engine.rs
Original file line number Diff line number Diff line change
@@ -58,6 +58,7 @@ use crate::config::MitoConfig;
use crate::error::{RecvSnafu, RegionNotFoundSnafu, Result};
use crate::metrics::{HANDLE_REQUEST_ELAPSED, TYPE_LABEL};
use crate::read::scan_region::{ScanRegion, Scanner};
use crate::region::RegionStat;
use crate::request::WorkerRequest;
use crate::worker::WorkerGroup;

@@ -86,6 +87,17 @@ impl MitoEngine {
self.inner.workers.is_region_exists(region_id)
}

/// Returns the region disk/memory usage information.
pub async fn get_region_stat(&self, region_id: RegionId) -> Result<RegionStat> {
let region = self
.inner
.workers
.get_region(region_id)
.context(RegionNotFoundSnafu { region_id })?;

Ok(region.region_stat().await)
}

/// Returns a scanner to scan for `request`.
fn scanner(&self, region_id: RegionId, request: ScanRequest) -> Result<Scanner> {
self.inner.handle_query(region_id, request)
51 changes: 0 additions & 51 deletions src/mito2/src/engine/basic_test.rs
Original file line number Diff line number Diff line change
@@ -458,57 +458,6 @@ async fn test_absent_and_invalid_columns() {
assert_eq!(StatusCode::InvalidArguments, err.status_code());
}

#[tokio::test]
async fn test_estimated_wal_size() {
let mut env = TestEnv::with_prefix("estimate-region-wal-size");
let engine = env.create_engine(MitoConfig::default()).await;

let region_id = RegionId::new(1, 1);
let request = CreateRequestBuilder::new().build();

let column_schemas = rows_schema(&request);
let delete_schema = delete_rows_schema(&request);
engine
.handle_request(region_id, RegionRequest::Create(request))
.await
.unwrap();

let rows = Rows {
schema: column_schemas.clone(),
rows: build_rows_for_key("a", 0, 10, 0),
};
put_rows(&engine, region_id, rows).await;

// check wal size
let region = engine.get_region(region_id).unwrap();
assert_eq!(region.region_stat().await.wal_usage, 124);

let rows = Rows {
schema: column_schemas.clone(),
rows: build_rows_for_key("b", 0, 10, 0),
};
put_rows(&engine, region_id, rows).await;

// check wal size
assert_eq!(region.region_stat().await.wal_usage, 249);

// Delete (a, 0), (a, 1), (a, 2)
let rows = Rows {
schema: delete_schema.clone(),
rows: build_delete_rows_for_key("a", 0, 3),
};
delete_rows(&engine, region_id, rows).await;
// Delete (b, 0), (b, 1)
let rows = Rows {
schema: delete_schema,
rows: build_delete_rows_for_key("b", 0, 2),
};
delete_rows(&engine, region_id, rows).await;

// check wal size
assert_eq!(region.region_stat().await.wal_usage, 292);
}

#[tokio::test]
async fn test_region_usage() {
let mut env = TestEnv::with_prefix("region_usage");
2 changes: 0 additions & 2 deletions src/mito2/src/region.rs
Original file line number Diff line number Diff line change
@@ -129,8 +129,6 @@ impl MitoRegion {
self.writable.store(writable, Ordering::Relaxed);
}

// TODO(QuenKar): remove this micro.
#[allow(dead_code)]
/// Returns the region usage in bytes.
pub(crate) async fn region_stat(&self) -> RegionStat {
let region_id = self.region_id;