mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-01-04 12:22:55 +00:00
feat: acquire table_id from region_id (#1656)
feat: acquire table_id from region_id
This commit is contained in:
@@ -21,6 +21,7 @@ use async_trait::async_trait;
|
||||
use common_catalog::consts::MITO_ENGINE;
|
||||
use common_meta::instruction::TableIdent;
|
||||
use common_meta::RegionIdent;
|
||||
use table::engine::table_id;
|
||||
|
||||
use crate::error::Result;
|
||||
use crate::handler::failure_handler::runner::{FailureDetectControl, FailureDetectRunner};
|
||||
@@ -90,9 +91,7 @@ impl HeartbeatHandler for RegionFailureHandler {
|
||||
catalog: x.catalog.clone(),
|
||||
schema: x.schema.clone(),
|
||||
table: x.table.clone(),
|
||||
|
||||
// TODO(#1566): Use the real table id.
|
||||
table_id: 0,
|
||||
table_id: table_id(x.id),
|
||||
// TODO(#1583): Use the actual table engine.
|
||||
engine: MITO_ENGINE.to_string(),
|
||||
},
|
||||
|
||||
@@ -181,6 +181,11 @@ pub fn region_id(table_id: TableId, n: u32) -> RegionId {
|
||||
(u64::from(table_id) << 32) | u64::from(n)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn table_id(region_id: RegionId) -> TableId {
|
||||
(region_id >> 32) as u32
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn table_dir(catalog_name: &str, schema_name: &str, table_id: TableId) -> String {
|
||||
format!("{DATA_DIR}{catalog_name}/{schema_name}/{table_id}/")
|
||||
@@ -200,4 +205,11 @@ mod tests {
|
||||
|
||||
assert_eq!("greptime.public.test", table_ref.to_string());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_table_id() {
|
||||
let region_id = region_id(u32::MAX, 1);
|
||||
let table_id = table_id(region_id);
|
||||
assert_eq!(u32::MAX, table_id);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user