Skip to content

Commit

Permalink
refactor: create_or_open always set writable (#2641)
Browse files Browse the repository at this point in the history
feat: set opened region writable
  • Loading branch information
QuenKar authored Oct 23, 2023
1 parent fbc8f56 commit 1fc42a6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
33 changes: 32 additions & 1 deletion src/mito2/src/engine/create_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion src/mito2/src/region/opener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit 1fc42a6

Please sign in to comment.