Skip to content

Commit

Permalink
chore: correct closeable typos (#2860)
Browse files Browse the repository at this point in the history
  • Loading branch information
WenyXu authored Dec 4, 2023
1 parent 7a14db6 commit f78dab0
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 106 deletions.
38 changes: 19 additions & 19 deletions src/meta-srv/src/handler/region_lease_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<GrantedRegion>,
operable: &HashSet<RegionId>,
closable: &HashSet<RegionId>,
closeable: &HashSet<RegionId>,
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))
}
Expand Down Expand Up @@ -112,52 +112,52 @@ impl HeartbeatHandler for RegionLeaseHandler {

let leaders = leaders.into_iter().flatten().collect::<Vec<_>>();

let (downgradable, closable) = self
let (downgradable, closeable) = self
.region_lease_keeper
.find_staled_leader_regions(cluster_id, datanode_id, &leaders)
.await?;

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::<Vec<_>>();

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 {
Expand Down
102 changes: 51 additions & 51 deletions src/meta-srv/src/region/lease_keeper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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, &regions, 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(
Expand All @@ -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, &regions, 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)]
Expand Down Expand Up @@ -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(&region_id));
assert_eq!(closeable.len(), 1);
assert!(closeable.contains(&region_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(&region_id));
assert_eq!(closeable.len(), 1);
assert!(closeable.contains(&region_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;
Expand All @@ -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;
Expand Down Expand Up @@ -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());
}

Expand All @@ -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(&region_id));
}
Expand Down Expand Up @@ -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(&region_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(&region_id));
assert_eq!(closeable.len(), 1);
assert!(closeable.contains(&region_id));
}

#[tokio::test]
Expand All @@ -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]
Expand Down
Loading

0 comments on commit f78dab0

Please sign in to comment.