feat: add region_statistics table (#4771)

* refactor: introduce `region_statistic`

* refactor: move DatanodeStat related structs to common_meta

* chore: add comments

* feat: implement `list_region_stats` for `ClusterInfo` trait

* feat: add `region_statistics` table

* feat: add table_id and region_number fields

* chore: rename unused snafu

* chore: udpate sqlness results

* chore: avoid to print source in error msg

* chore: move `procedure_info` under `greptime` catalog

* chore: apply suggestions from CR

* Update src/common/meta/src/datanode.rs

Co-authored-by: jeremyhi <jiachun_feng@proton.me>

---------

Co-authored-by: jeremyhi <jiachun_feng@proton.me>
This commit is contained in:
Weny Xu
2024-09-27 17:54:52 +08:00
committed by GitHub
parent cc4106cbd2
commit 4045298cb2
39 changed files with 939 additions and 474 deletions

View File

@@ -242,6 +242,42 @@ pub type RegionScannerRef = Box<dyn RegionScanner>;
pub type BatchResponses = Vec<(RegionId, Result<RegionResponse, BoxedError>)>;
/// Represents the statistics of a region.
#[derive(Debug, Deserialize, Serialize, Default)]
pub struct RegionStatistic {
/// The size of memtable in bytes.
pub memtable_size: u64,
/// The size of WAL in bytes.
pub wal_size: u64,
/// The size of manifest in bytes.
pub manifest_size: u64,
/// The size of SST files in bytes.
pub sst_size: u64,
}
impl RegionStatistic {
/// Deserializes the region statistic to a byte array.
///
/// Returns None if the deserialization fails.
pub fn deserialize_from_slice(value: &[u8]) -> Option<RegionStatistic> {
serde_json::from_slice(value).ok()
}
/// Serializes the region statistic to a byte array.
///
/// Returns None if the serialization fails.
pub fn serialize_to_vec(&self) -> Option<Vec<u8>> {
serde_json::to_vec(self).ok()
}
}
impl RegionStatistic {
/// Returns the estimated disk size of the region.
pub fn estimated_disk_size(&self) -> u64 {
self.wal_size + self.sst_size + self.manifest_size
}
}
#[async_trait]
pub trait RegionEngine: Send + Sync {
/// Name of this engine
@@ -289,8 +325,8 @@ pub trait RegionEngine: Send + Sync {
/// Retrieves region's metadata.
async fn get_metadata(&self, region_id: RegionId) -> Result<RegionMetadataRef, BoxedError>;
/// Retrieves region's disk usage.
fn region_disk_usage(&self, region_id: RegionId) -> Option<i64>;
/// Retrieves region's statistic.
fn region_statistic(&self, region_id: RegionId) -> Option<RegionStatistic>;
/// Stops the engine
async fn stop(&self) -> Result<(), BoxedError>;