From 342faa4e07b16aa39e4d6ed0112e309f1fc78cfb Mon Sep 17 00:00:00 2001 From: Weny Xu Date: Fri, 5 Jan 2024 11:29:48 +0900 Subject: [PATCH] test: add tests for lease keeper with logical table (#3096) --- src/common/meta/src/key/table_route.rs | 4 ++- src/meta-srv/src/region/lease_keeper.rs | 44 +++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/src/common/meta/src/key/table_route.rs b/src/common/meta/src/key/table_route.rs index fa4c628c76d8..c95a28de60fe 100644 --- a/src/common/meta/src/key/table_route.rs +++ b/src/common/meta/src/key/table_route.rs @@ -91,7 +91,9 @@ impl TableRouteValue { Ok(self.physical_table_route().version) } - /// Returns the corresponding [RegionRoute]. + /// Returns the corresponding [RegionRoute], returns `None` if it's the specific region is not found. + /// + /// Note: It throws an error if it's a logical table pub fn region_route(&self, region_id: RegionId) -> Result> { ensure!( self.is_physical(), diff --git a/src/meta-srv/src/region/lease_keeper.rs b/src/meta-srv/src/region/lease_keeper.rs index 9b066065b427..9aea23232b5f 100644 --- a/src/meta-srv/src/region/lease_keeper.rs +++ b/src/meta-srv/src/region/lease_keeper.rs @@ -113,7 +113,9 @@ impl RegionLeaseKeeper { Ok(metadata_subset) } - /// Returns [None] if specific region doesn't belong to the datanode. + /// Returns [None] if: + /// - The region doesn't belong to the datanode. + /// - The region belongs to a logical table. fn renew_region_lease( &self, table_metadata: &HashMap, @@ -188,7 +190,7 @@ mod tests { use std::collections::{HashMap, HashSet}; use std::sync::Arc; - use common_meta::key::table_route::TableRouteValue; + use common_meta::key::table_route::{LogicalTableRouteValue, TableRouteValue}; use common_meta::key::test_utils::new_test_table_info; use common_meta::key::TableMetadataManager; use common_meta::kv_backend::memory::MemoryKvBackend; @@ -363,6 +365,44 @@ mod tests { } } + #[tokio::test] + async fn test_renew_unexpected_logic_table() { + let region_number = 1u32; + let table_id = 1024; + let table_info: RawTableInfo = new_test_table_info(table_id, vec![region_number]).into(); + + let region_id = RegionId::new(table_id, 1); + let keeper = new_test_keeper(); + let table_metadata_manager = keeper.table_metadata_manager(); + table_metadata_manager + .create_table_metadata( + table_info, + TableRouteValue::Logical(LogicalTableRouteValue::new(table_id, vec![region_id])), + HashMap::default(), + ) + .await + .unwrap(); + + for region_id in [region_id, RegionId::new(1024, 2)] { + let RenewRegionLeasesResponse { + non_exists, + renewed, + } = keeper + .renew_region_leases( + 0, + 1, + &[ + (region_id, RegionRole::Follower), + (region_id, RegionRole::Leader), + ], + ) + .await + .unwrap(); + assert!(renewed.is_empty()); + assert_eq!(non_exists, HashSet::from([region_id])); + } + } + #[tokio::test] async fn test_renew_region_leases_with_downgrade_leader() { let region_number = 1u32;