diff --git a/src/mito2/src/engine/create_test.rs b/src/mito2/src/engine/create_test.rs index 31cb4fd031cd..bfe9af8cbbdd 100644 --- a/src/mito2/src/engine/create_test.rs +++ b/src/mito2/src/engine/create_test.rs @@ -15,7 +15,7 @@ use std::time::Duration; use store_api::region_engine::RegionEngine; -use store_api::region_request::RegionRequest; +use store_api::region_request::{RegionCloseRequest, RegionRequest}; use store_api::storage::RegionId; use crate::config::MitoConfig; @@ -55,6 +55,37 @@ async fn test_engine_create_existing_region() { .unwrap(); } +#[tokio::test] +async fn test_engine_create_close_create_region() { + // This test will trigger create_or_open function. + let mut env = TestEnv::with_prefix("create-close-create"); + let engine = env.create_engine(MitoConfig::default()).await; + + let region_id = RegionId::new(1, 1); + let builder = CreateRequestBuilder::new(); + // Create a region with id 1. + engine + .handle_request(region_id, RegionRequest::Create(builder.build())) + .await + .unwrap(); + // Close the region. + engine + .handle_request(region_id, RegionRequest::Close(RegionCloseRequest {})) + .await + .unwrap(); + // Create the same region id again. + engine + .handle_request(region_id, RegionRequest::Create(builder.build())) + .await + .unwrap(); + + assert!(engine.is_region_exists(region_id)); + + let region = engine.get_region(region_id).unwrap(); + + assert!(region.is_writable()); +} + #[tokio::test] async fn test_engine_create_with_different_id() { let mut env = TestEnv::new(); diff --git a/src/mito2/src/region/opener.rs b/src/mito2/src/region/opener.rs index 6a8a3a805f7c..a224ee1e195b 100644 --- a/src/mito2/src/region/opener.rs +++ b/src/mito2/src/region/opener.rs @@ -119,7 +119,8 @@ impl RegionOpener { &expect.column_metadatas, &expect.primary_key, )?; - + // To keep consistence with Create behavior, set the opened Region writable. + region.set_writable(true); return Ok(region); } Ok(None) => {