Skip to content

Commit

Permalink
chore: remove unused region_stats method form table (#2458)
Browse files Browse the repository at this point in the history
chore: remove unused region_status method form table
  • Loading branch information
fengjiachun authored Sep 22, 2023
1 parent 621c6f3 commit 8e5eaf5
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 75 deletions.
67 changes: 1 addition & 66 deletions src/catalog/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ use std::any::Any;
use std::fmt::{Debug, Formatter};
use std::sync::Arc;

use api::v1::meta::RegionStat;
use common_telemetry::warn;
use futures::future::BoxFuture;
use table::metadata::{TableId, TableType};
use table::metadata::TableId;
use table::requests::CreateTableRequest;
use table::TableRef;

Expand Down Expand Up @@ -124,66 +122,3 @@ pub struct RegisterSchemaRequest {
pub catalog: String,
pub schema: String,
}

/// The stat of regions in the datanode node.
/// The number of regions can be got from len of vec.
///
/// Ignores any errors occurred during iterating regions. The intention of this method is to
/// collect region stats that will be carried in Datanode's heartbeat to Metasrv, so it's a
/// "try our best" job.
pub async fn datanode_stat(catalog_manager: &CatalogManagerRef) -> (u64, Vec<RegionStat>) {
let mut region_number: u64 = 0;
let mut region_stats = Vec::new();

let Ok(catalog_names) = catalog_manager.catalog_names().await else {
return (region_number, region_stats);
};
for catalog_name in catalog_names {
let Ok(schema_names) = catalog_manager.schema_names(&catalog_name).await else {
continue;
};
for schema_name in schema_names {
let Ok(table_names) = catalog_manager
.table_names(&catalog_name, &schema_name)
.await
else {
continue;
};
for table_name in table_names {
let Ok(Some(table)) = catalog_manager
.table(&catalog_name, &schema_name, &table_name)
.await
else {
continue;
};

if table.table_type() != TableType::Base {
continue;
}

let table_info = table.table_info();
let region_numbers = &table_info.meta.region_numbers;
region_number += region_numbers.len() as u64;

let engine = &table_info.meta.engine;

match table.region_stats() {
Ok(stats) => {
let stats = stats.into_iter().map(|stat| RegionStat {
region_id: stat.region_id,
approximate_bytes: stat.disk_usage_bytes as i64,
engine: engine.clone(),
..Default::default()
});

region_stats.extend(stats);
}
Err(e) => {
warn!("Failed to get region status, err: {:?}", e);
}
};
}
}
}
(region_number, region_stats)
}
9 changes: 0 additions & 9 deletions src/table/src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ use crate::error::{Result, UnsupportedSnafu};
use crate::metadata::{FilterPushDownType, TableId, TableInfoRef, TableType};
use crate::requests::{AlterTableRequest, DeleteRequest, InsertRequest};
use crate::stats::TableStatistics;
use crate::RegionStat;

pub type AlterContext = anymap::Map<dyn Any + Send + Sync>;

Expand Down Expand Up @@ -101,14 +100,6 @@ pub trait Table: Send + Sync {
Ok(())
}

/// Get region stats in this table.
fn region_stats(&self) -> Result<Vec<RegionStat>> {
UnsupportedSnafu {
operation: "REGION_STATS",
}
.fail()?
}

/// Return true if contains the region
fn contains_region(&self, _region: RegionNumber) -> Result<bool> {
UnsupportedSnafu {
Expand Down

0 comments on commit 8e5eaf5

Please sign in to comment.