From e1ef3edfa28ab8d3779878f9704f6d8f718ac20b Mon Sep 17 00:00:00 2001 From: WenyXu Date: Mon, 4 Dec 2023 03:31:49 +0000 Subject: [PATCH] chore: correct closeable typos --- .../src/handler/region_lease_handler.rs | 38 +++---- src/meta-srv/src/region/lease_keeper.rs | 102 +++++++++--------- src/meta-srv/src/region/lease_keeper/mito.rs | 36 +++---- src/meta-srv/src/region/lease_keeper/utils.rs | 36 +++---- 4 files changed, 106 insertions(+), 106 deletions(-) diff --git a/src/meta-srv/src/handler/region_lease_handler.rs b/src/meta-srv/src/handler/region_lease_handler.rs index 8e72ad098dda..18a29fad0378 100644 --- a/src/meta-srv/src/handler/region_lease_handler.rs +++ b/src/meta-srv/src/handler/region_lease_handler.rs @@ -61,19 +61,19 @@ fn flip_role(role: RegionRole) -> RegionRole { /// /// - If a region is in an `operable` set, it will be granted an `flip_role(current)`([RegionRole]); /// otherwise, it will be granted a `current`([RegionRole]). -/// - If a region is in a `closable` set, it won't be granted. +/// - If a region is in a `closeable` set, it won't be granted. fn grant( granted_regions: &mut Vec, operable: &HashSet, - closable: &HashSet, + closeable: &HashSet, regions: &[RegionId], current: RegionRole, ) { for region in regions { if operable.contains(region) { granted_regions.push(GrantedRegion::new(*region, flip_role(current))); - } else if closable.contains(region) { - // Filters out the closable regions. + } else if closeable.contains(region) { + // Filters out the closeable regions. } else { granted_regions.push(GrantedRegion::new(*region, current)) } @@ -112,7 +112,7 @@ impl HeartbeatHandler for RegionLeaseHandler { let leaders = leaders.into_iter().flatten().collect::>(); - let (downgradable, closable) = self + let (downgradable, closeable) = self .region_lease_keeper .find_staled_leader_regions(cluster_id, datanode_id, &leaders) .await?; @@ -120,44 +120,44 @@ impl HeartbeatHandler for RegionLeaseHandler { grant( &mut granted_regions, &downgradable, - &closable, + &closeable, &leaders, RegionRole::Leader, ); - if !closable.is_empty() { + if !closeable.is_empty() { info!( - "Granting region lease, found closable leader regions: {:?} on datanode {}", - closable, datanode_id + "Granting region lease, found closeable leader regions: {:?} on datanode {}", + closeable, datanode_id ); } - inactive_regions.extend(closable); + inactive_regions.extend(closeable); let followers = followers.into_iter().flatten().collect::>(); - let (upgradeable, closable) = self + let (upgradeable, closeable) = self .region_lease_keeper .find_staled_follower_regions(cluster_id, datanode_id, &followers) .await?; - // If a region is opening, it will be filtered out from the closable regions set. - let closable = self + // If a region is opening, it will be filtered out from the closeable regions set. + let closeable = self .opening_region_keeper - .filter_opening_regions(datanode_id, closable); + .filter_opening_regions(datanode_id, closeable); grant( &mut granted_regions, &upgradeable, - &closable, + &closeable, &followers, RegionRole::Follower, ); - if !closable.is_empty() { + if !closeable.is_empty() { info!( - "Granting region lease, found closable follower regions {:?} on datanode {}", - closable, datanode_id + "Granting region lease, found closeable follower regions {:?} on datanode {}", + closeable, datanode_id ); } - inactive_regions.extend(closable); + inactive_regions.extend(closeable); acc.inactive_region_ids = inactive_regions; acc.region_lease = Some(RegionLease { diff --git a/src/meta-srv/src/region/lease_keeper.rs b/src/meta-srv/src/region/lease_keeper.rs index 06bc4cf382d2..f29495e1e5f8 100644 --- a/src/meta-srv/src/region/lease_keeper.rs +++ b/src/meta-srv/src/region/lease_keeper.rs @@ -73,12 +73,12 @@ impl RegionLeaseKeeper { Ok(metadata_subset) } - /// Returns downgradable regions, and closable regions. + /// Returns downgradable regions, and closeable regions. /// /// - Downgradable regions: /// Region's peer(`datanode_id`) is the corresponding downgraded leader peer in `region_routes`. /// - /// - Closable regions: + /// - closeable regions: /// - It returns a region if it's peer(`datanode_id`) isn't the corresponding leader peer in `region_routes`. /// - Expected as [RegionRole::Follower](store_api::region_engine::RegionRole::Follower) regions. /// - Unexpected [RegionRole::Leader](store_api::region_engine::RegionRole::Leader) regions. @@ -97,37 +97,37 @@ impl RegionLeaseKeeper { self.collect_tables_metadata(&table_ids).await? }; - let mut closable_set = HashSet::new(); + let mut closeable_set = HashSet::new(); let mut downgradable_set = HashSet::new(); for (table_id, regions) in tables { if let Some(metadata) = metadata_subset.get(&table_id) { let region_routes = &metadata.region_routes; - let (downgradable, closable) = + let (downgradable, closeable) = find_staled_leader_regions(datanode_id, ®ions, region_routes); downgradable_set.extend(downgradable); - closable_set.extend(closable); + closeable_set.extend(closeable); } else { warn!( - "The table {} metadata is not found, appends closable leader regions: {:?}", + "The table {} metadata is not found, appends closeable leader regions: {:?}", table_id, regions ); // If table metadata is not found. - closable_set.extend(regions); + closeable_set.extend(regions); } } - Ok((downgradable_set, closable_set)) + Ok((downgradable_set, closeable_set)) } - /// Returns upgradable regions, and closable regions. + /// Returns upgradable regions, and closeable regions. /// /// Upgradable regions: /// - Region's peer(`datanode_id`) is the corresponding leader peer in `region_routes`. /// - /// Closable regions: + /// closeable regions: /// - Region's peer(`datanode_id`) isn't the corresponding leader/follower peer in `region_routes`. /// - Region's table metadata is not found. pub async fn find_staled_follower_regions( @@ -145,28 +145,28 @@ impl RegionLeaseKeeper { }; let mut upgradable_set = HashSet::new(); - let mut closable_set = HashSet::new(); + let mut closeable_set = HashSet::new(); for (table_id, regions) in tables { if let Some(metadata) = metadata_subset.get(&table_id) { let region_routes = &metadata.region_routes; - let (upgradable, closable) = + let (upgradable, closeable) = find_staled_follower_regions(datanode_id, ®ions, region_routes); upgradable_set.extend(upgradable); - closable_set.extend(closable); + closeable_set.extend(closeable); } else { warn!( - "The table {} metadata is not found, appends closable followers regions: {:?}", + "The table {} metadata is not found, appends closeable followers regions: {:?}", table_id, regions ); // If table metadata is not found. - closable_set.extend(regions); + closeable_set.extend(regions); } } - Ok((upgradable_set, closable_set)) + Ok((upgradable_set, closeable_set)) } #[cfg(test)] @@ -290,27 +290,27 @@ mod tests { let datanode_regions = vec![region_id]; - let (downgradable, closable) = keeper + let (downgradable, closeable) = keeper .find_staled_leader_regions(0, datanode_id, &datanode_regions) .await .unwrap(); - assert_eq!(closable.len(), 1); - assert!(closable.contains(®ion_id)); + assert_eq!(closeable.len(), 1); + assert!(closeable.contains(®ion_id)); assert!(downgradable.is_empty()); - let (upgradable, closable) = keeper + let (upgradable, closeable) = keeper .find_staled_follower_regions(0, datanode_id, &datanode_regions) .await .unwrap(); assert!(upgradable.is_empty()); - assert_eq!(closable.len(), 1); - assert!(closable.contains(®ion_id)); + assert_eq!(closeable.len(), 1); + assert!(closeable.contains(®ion_id)); } #[tokio::test] - async fn test_find_closable_regions_simple() { + async fn test_find_closeable_regions_simple() { let datanode_id = 1; let region_number = 1u32; let table_id = 10; @@ -332,31 +332,31 @@ mod tests { .await .unwrap(); - // `closable` should be empty. + // `closeable` should be empty. let datanode_regions = vec![region_id]; - let (downgradable, closable) = keeper + let (downgradable, closeable) = keeper .find_staled_leader_regions(0, datanode_id, &datanode_regions) .await .unwrap(); - assert!(closable.is_empty()); + assert!(closeable.is_empty()); assert!(downgradable.is_empty()); - // `closable` should be empty. + // `closeable` should be empty. let datanode_regions = vec![]; - let (downgradable, closable) = keeper + let (downgradable, closeable) = keeper .find_staled_leader_regions(0, datanode_id, &datanode_regions) .await .unwrap(); - assert!(closable.is_empty()); + assert!(closeable.is_empty()); assert!(downgradable.is_empty()); } #[tokio::test] - async fn test_find_closable_regions_2() { + async fn test_find_closeable_regions_2() { let datanode_id = 1; let region_number = 1u32; let table_id = 10; @@ -393,29 +393,29 @@ mod tests { .unwrap(); // Unexpected Leader region. - // `closable` should be vec![unknown_region_id]. + // `closeable` should be vec![unknown_region_id]. let datanode_regions = vec![region_id, unknown_region_id]; - let (downgradable, closable) = keeper + let (downgradable, closeable) = keeper .find_staled_leader_regions(0, datanode_id, &datanode_regions) .await .unwrap(); - assert_eq!(closable.len(), 1); - assert!(closable.contains(&unknown_region_id)); + assert_eq!(closeable.len(), 1); + assert!(closeable.contains(&unknown_region_id)); assert!(downgradable.is_empty()); // Expected as Follower region. - // `closable` should be vec![another_region_id], because the `another_region_id` is a active region of `another_peer`. + // `closeable` should be vec![another_region_id], because the `another_region_id` is a active region of `another_peer`. let datanode_regions = vec![another_region_id]; - let (downgradable, closable) = keeper + let (downgradable, closeable) = keeper .find_staled_leader_regions(0, datanode_id, &datanode_regions) .await .unwrap(); - assert_eq!(closable.len(), 1); - assert!(closable.contains(&another_region_id)); + assert_eq!(closeable.len(), 1); + assert!(closeable.contains(&another_region_id)); assert!(downgradable.is_empty()); } @@ -442,16 +442,16 @@ mod tests { .await .unwrap(); - // `upgradable` should be empty, `closable` should be empty. + // `upgradable` should be empty, `closeable` should be empty. let datanode_regions = vec![region_id, another_region_id]; - let (downgradable, closable) = keeper + let (downgradable, closeable) = keeper .find_staled_leader_regions(0, datanode_id, &datanode_regions) .await .unwrap(); - assert_eq!(closable.len(), 1); - assert!(closable.contains(&another_region_id)); + assert_eq!(closeable.len(), 1); + assert!(closeable.contains(&another_region_id)); assert_eq!(downgradable.len(), 1); assert!(downgradable.contains(®ion_id)); } @@ -479,29 +479,29 @@ mod tests { .await .unwrap(); - // `upgradable` should be vec![region_id], `closable` should be empty. + // `upgradable` should be vec![region_id], `closeable` should be empty. let datanode_regions = vec![region_id]; - let (upgradable, closable) = keeper + let (upgradable, closeable) = keeper .find_staled_follower_regions(0, datanode_id, &datanode_regions) .await .unwrap(); - assert!(closable.is_empty()); + assert!(closeable.is_empty()); assert_eq!(upgradable.len(), 1); assert!(upgradable.contains(®ion_id)); - // `upgradable` should be empty, `closable` should be vec![region_id]. + // `upgradable` should be empty, `closeable` should be vec![region_id]. let datanode_regions = vec![region_id]; - let (upgradable, closable) = keeper + let (upgradable, closeable) = keeper .find_staled_follower_regions(0, datanode_id + 1, &datanode_regions) .await .unwrap(); assert!(upgradable.is_empty()); - assert_eq!(closable.len(), 1); - assert!(closable.contains(®ion_id)); + assert_eq!(closeable.len(), 1); + assert!(closeable.contains(®ion_id)); } #[tokio::test] @@ -528,12 +528,12 @@ mod tests { .await .unwrap(); - let (upgradable, closable) = keeper + let (upgradable, closeable) = keeper .find_staled_follower_regions(0, datanode_id, &datanode_regions) .await .unwrap(); assert!(upgradable.is_empty()); - assert!(closable.is_empty()); + assert!(closeable.is_empty()); } #[test] diff --git a/src/meta-srv/src/region/lease_keeper/mito.rs b/src/meta-srv/src/region/lease_keeper/mito.rs index 1e286d8649c8..ee3ebe44246b 100644 --- a/src/meta-srv/src/region/lease_keeper/mito.rs +++ b/src/meta-srv/src/region/lease_keeper/mito.rs @@ -20,14 +20,14 @@ use common_meta::rpc::router::{ use store_api::storage::RegionId; use super::utils::downgradable_leader_regions; -use crate::region::lease_keeper::utils::closable_leader_region; +use crate::region::lease_keeper::utils::closeable_leader_region; -/// Returns Downgradable regions and Closable regions. +/// Returns Downgradable regions and closeable regions. /// /// - Downgradable regions: /// Region's peer(`datanode_id`) is the corresponding downgraded leader peer in `region_routes`. /// -/// - Closable regions: +/// - closeable regions: /// Region's peer(`datanode_id`) isn't the corresponding leader peer in `region_routes`. /// - Expected as [RegionRole::Follower](store_api::region_engine::RegionRole::Follower) regions. /// - Unexpected [RegionRole::Leader](store_api::region_engine::RegionRole::Leader) regions. @@ -39,7 +39,7 @@ pub fn find_staled_leader_regions( let region_leader_map = convert_to_region_leader_map(region_routes); let region_leader_status_map = convert_to_region_leader_status_map(region_routes); - let (downgradable, closable): (HashSet<_>, HashSet<_>) = datanode_regions + let (downgradable, closeable): (HashSet<_>, HashSet<_>) = datanode_regions .iter() .map(|region_id| { ( @@ -49,15 +49,15 @@ pub fn find_staled_leader_regions( ®ion_leader_map, ®ion_leader_status_map, ), - closable_leader_region(datanode_id, *region_id, ®ion_leader_map), + closeable_leader_region(datanode_id, *region_id, ®ion_leader_map), ) }) .unzip(); let downgradable = downgradable.into_iter().flatten().collect(); - let closable = closable.into_iter().flatten().collect(); + let closeable = closeable.into_iter().flatten().collect(); - (downgradable, closable) + (downgradable, closeable) } #[cfg(test)] @@ -85,20 +85,20 @@ mod tests { }]; // Grants lease. - // `closable` should be empty, `region_id` is a active leader region of the `peer` - let (downgradable, closable) = + // `closeable` should be empty, `region_id` is a active leader region of the `peer` + let (downgradable, closeable) = find_staled_leader_regions(datanode_id, &datanode_regions, ®ion_routes); - assert!(closable.is_empty()); + assert!(closeable.is_empty()); assert!(downgradable.is_empty()); // Unexpected Leader region. - // `closable` should be vec![`region_id`]; - let (downgradable, closable) = + // `closeable` should be vec![`region_id`]; + let (downgradable, closeable) = find_staled_leader_regions(datanode_id, &datanode_regions, &[]); - assert_eq!(closable.len(), 1); - assert!(closable.contains(®ion_id)); + assert_eq!(closeable.len(), 1); + assert!(closeable.contains(®ion_id)); assert!(downgradable.is_empty()); let region_routes = vec![RegionRoute { @@ -111,12 +111,12 @@ mod tests { let retained_active_regions = datanode_regions.clone(); // Expected as Follower region. - // `closable` should be vec![`region_id`], `region_id` is RegionRole::Leader. - let (downgradable, closable) = + // `closeable` should be vec![`region_id`], `region_id` is RegionRole::Leader. + let (downgradable, closeable) = find_staled_leader_regions(datanode_id, &retained_active_regions, ®ion_routes); assert!(downgradable.is_empty()); - assert_eq!(closable.len(), 1); - assert!(closable.contains(®ion_id)); + assert_eq!(closeable.len(), 1); + assert!(closeable.contains(®ion_id)); } } diff --git a/src/meta-srv/src/region/lease_keeper/utils.rs b/src/meta-srv/src/region/lease_keeper/utils.rs index b3eb2a95dee4..835f37f67dee 100644 --- a/src/meta-srv/src/region/lease_keeper/utils.rs +++ b/src/meta-srv/src/region/lease_keeper/utils.rs @@ -24,7 +24,7 @@ use store_api::storage::{RegionId, RegionNumber}; /// Returns Some(region_id) if it's not a leader region in `region_route`. /// /// It removes a leader region if its peer(`node_id`) isn't the corresponding leader peer in `region_routes`. -pub fn closable_leader_region( +pub fn closeable_leader_region( node_id: u64, region_id: RegionId, region_leader_map: &HashMap, @@ -63,12 +63,12 @@ pub fn downgradable_leader_regions( } } -/// Returns upgradable regions, and closable regions. +/// Returns upgradable regions, and closeable regions. /// /// Upgradable regions: /// - Region's peer(`datanode_id`) is the corresponding leader peer in `region_routes`. /// -/// Closable regions: +/// closeable regions: /// - Region's peer(`datanode_id`) isn't the corresponding leader/follower peer in `region_routes`. pub fn find_staled_follower_regions( datanode_id: u64, @@ -79,7 +79,7 @@ pub fn find_staled_follower_regions( let region_leader_status_map = convert_to_region_leader_status_map(region_routes); let region_peer_map = convert_to_region_peer_map(region_routes); - let (upgradable, closable): (HashSet>, HashSet>) = + let (upgradable, closeable): (HashSet>, HashSet>) = datanode_regions .iter() .map(|region_id| { @@ -90,15 +90,15 @@ pub fn find_staled_follower_regions( ®ion_leader_map, ®ion_leader_status_map, ), - closable_region(datanode_id, *region_id, ®ion_peer_map), + closeable_region(datanode_id, *region_id, ®ion_peer_map), ) }) .unzip(); let upgradable = upgradable.into_iter().flatten().collect(); - let closable = closable.into_iter().flatten().collect(); + let closeable = closeable.into_iter().flatten().collect(); - (upgradable, closable) + (upgradable, closeable) } /// Returns Some(region) if its peer(`node_id`) a leader region peer in `region_routes`. @@ -124,7 +124,7 @@ pub fn upgradable_follower_region( } /// Returns Some(region) if its peer(`node_id) is't a leader or follower region peer in `region_routes`. -pub fn closable_region( +pub fn closeable_region( node_id: u64, region_id: RegionId, region_peer_map: &HashMap>, @@ -149,7 +149,7 @@ mod tests { use super::*; #[test] - fn test_closable_leader_region() { + fn test_closeable_leader_region() { let datanode_id = 1u64; let region_number = 1u32; let region_id = RegionId::from_u64(region_number as u64); @@ -160,19 +160,19 @@ mod tests { // Should be None, `region_id` is an active region of `peer`. assert_eq!( None, - closable_leader_region(datanode_id, region_id, ®ion_leader_map,) + closeable_leader_region(datanode_id, region_id, ®ion_leader_map,) ); // Should be Some(`region_id`), incorrect datanode_id. assert_eq!( Some(region_id), - closable_leader_region(datanode_id + 1, region_id, ®ion_leader_map,) + closeable_leader_region(datanode_id + 1, region_id, ®ion_leader_map,) ); // Should be Some(`region_id`), the inactive_leader_regions is empty. assert_eq!( Some(region_id), - closable_leader_region(datanode_id, region_id, &Default::default(),) + closeable_leader_region(datanode_id, region_id, &Default::default(),) ); let another_peer = Peer::empty(datanode_id + 1); @@ -181,7 +181,7 @@ mod tests { // Should be Some(`region_id`), `region_id` is active region of `another_peer`. assert_eq!( Some(region_id), - closable_leader_region(datanode_id, region_id, ®ion_leader_map,) + closeable_leader_region(datanode_id, region_id, ®ion_leader_map,) ); } @@ -241,31 +241,31 @@ mod tests { } #[test] - fn test_closable_follower_region() { + fn test_closeable_follower_region() { let region_number = 1u32; let region_id = RegionId::from_u64(region_number as u64); let another_region_id = RegionId::from_u64(region_number as u64 + 1); let region_peer_map = [(region_number, HashSet::from([1, 2, 3]))].into(); // Should be None. - assert_eq!(None, closable_region(1, region_id, ®ion_peer_map)); + assert_eq!(None, closeable_region(1, region_id, ®ion_peer_map)); // Should be Some(`region_id`), incorrect `datanode_id`. assert_eq!( Some(region_id), - closable_region(4, region_id, ®ion_peer_map) + closeable_region(4, region_id, ®ion_peer_map) ); // Should be Some(`another_region_id`), `another_region_id` doesn't exist. assert_eq!( Some(another_region_id), - closable_region(1, another_region_id, ®ion_peer_map) + closeable_region(1, another_region_id, ®ion_peer_map) ); // Should be Some(`another_region_id`), `another_region_id` doesn't exist, incorrect `datanode_id`. assert_eq!( Some(another_region_id), - closable_region(4, another_region_id, ®ion_peer_map) + closeable_region(4, another_region_id, ®ion_peer_map) ); }