Skip to content

Commit

Permalink
perf: use memory state to check if a logical region exists
Browse files Browse the repository at this point in the history
Signed-off-by: Ruihang Xia <[email protected]>
  • Loading branch information
waynexia authored and WenyXu committed Jun 5, 2024
1 parent cb81fd0 commit e848404
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 20 deletions.
7 changes: 4 additions & 3 deletions src/metric-engine/src/engine/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,10 @@ impl MetricEngineInner {

// check if the logical region already exist
if self
.metadata_region
.is_logical_region_exists(metadata_region_id, logical_region_id)
.await?
.state
.read()
.unwrap()
.is_logical_region_exists(logical_region_id)
{
info!("Create a existing logical region {logical_region_id}. Skipped");
return Ok(data_region_id);
Expand Down
2 changes: 1 addition & 1 deletion src/metric-engine/src/engine/put.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl MetricEngineInner {
// check if the region exists
let data_region_id = to_data_region_id(physical_region_id);
let state = self.state.read().unwrap();
if !state.is_logical_region_exist(logical_region_id) {
if !state.is_logical_region_exists(logical_region_id) {
error!("Trying to write to an nonexistent region {logical_region_id}");
return LogicalRegionNotFoundSnafu {
region_id: logical_region_id,
Expand Down
2 changes: 1 addition & 1 deletion src/metric-engine/src/engine/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl MetricEngineState {
Ok(exist)
}

pub fn is_logical_region_exist(&self, logical_region_id: RegionId) -> bool {
pub fn is_logical_region_exists(&self, logical_region_id: RegionId) -> bool {
self.logical_regions().contains_key(&logical_region_id)
}
}
15 changes: 0 additions & 15 deletions src/metric-engine/src/metadata_region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,17 +139,6 @@ impl MetadataRegion {
Ok(())
}

/// Check if the given logical region exists.
pub async fn is_logical_region_exists(
&self,
physical_region_id: RegionId,
logical_region_id: RegionId,
) -> Result<bool> {
let region_id = utils::to_metadata_region_id(physical_region_id);
let region_key = Self::concat_region_key(logical_region_id);
self.exists(region_id, &region_key).await
}

/// Check if the given column exists. Return the semantic type if exists.
pub async fn column_semantic_type(
&self,
Expand Down Expand Up @@ -669,10 +658,6 @@ mod test {
.add_logical_region(physical_region_id, logical_region_id)
.await
.unwrap();
assert!(metadata_region
.is_logical_region_exists(physical_region_id, logical_region_id)
.await
.unwrap());

// add it again
assert!(metadata_region
Expand Down

0 comments on commit e848404

Please sign in to comment.