Skip to content

Commit

Permalink
test: add tests for lease keeper with logical table (#3096)
Browse files Browse the repository at this point in the history
  • Loading branch information
WenyXu authored Jan 5, 2024
1 parent 44ba131 commit 342faa4
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/common/meta/src/key/table_route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Option<RegionRoute>> {
ensure!(
self.is_physical(),
Expand Down
44 changes: 42 additions & 2 deletions src/meta-srv/src/region/lease_keeper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TableId, TableRouteValue>,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 342faa4

Please sign in to comment.