forked from GreptimeTeam/greptimedb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mito): Implement skeleton for alteration (GreptimeTeam#2343)
* feat: impl handle_alter wip * refactor: move send_result to worker.rs * feat: skeleton for handle_alter_request * feat: write requests should wait for alteration * feat: define alter request * chore: no warnings * fix: remove memtables after flush * chore: update comments and impl add_write_request_to_pending * feat: add schema version to RegionMetadata * feat: impl alter_schema/can_alter_directly * chore: use send_result * test: pull next_batch again * feat: convert pb AlterRequest to RegionAlterRequest * feat: validate alter request * feat: validate request and alter metadata * feat: allow none location * test: test alter * fix: recover files and flushed entry id from manifest * test: test alter * chore: change comments and variables * chore: fix compiler errors * feat: add is_empty() to MemtableVersion * test: fix metadata alter test * fix: Compaction picker doesn't notify waiters if it returns None * chore: address CR comments * test: add tests for alter request * refactor: use send_result
- Loading branch information
Showing
22 changed files
with
1,239 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,8 @@ | |
|
||
//! Mito region engine. | ||
#[cfg(test)] | ||
mod alter_test; | ||
#[cfg(test)] | ||
mod close_test; | ||
#[cfg(test)] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
// Copyright 2023 Greptime Team | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use std::collections::HashMap; | ||
|
||
use api::v1::{Rows, SemanticType}; | ||
use common_recordbatch::RecordBatches; | ||
use datatypes::prelude::ConcreteDataType; | ||
use datatypes::schema::ColumnSchema; | ||
use store_api::metadata::ColumnMetadata; | ||
use store_api::region_engine::RegionEngine; | ||
use store_api::region_request::{ | ||
AddColumn, AddColumnLocation, AlterKind, RegionAlterRequest, RegionOpenRequest, RegionRequest, | ||
}; | ||
use store_api::storage::{RegionId, ScanRequest}; | ||
|
||
use crate::config::MitoConfig; | ||
use crate::engine::MitoEngine; | ||
use crate::test_util::{build_rows, put_rows, rows_schema, CreateRequestBuilder, TestEnv}; | ||
|
||
async fn scan_check_after_alter(engine: &MitoEngine, region_id: RegionId, expected: &str) { | ||
let request = ScanRequest::default(); | ||
let scanner = engine.scan(region_id, request).unwrap(); | ||
assert_eq!(0, scanner.num_memtables()); | ||
assert_eq!(1, scanner.num_files()); | ||
let stream = scanner.scan().await.unwrap(); | ||
let batches = RecordBatches::try_collect(stream).await.unwrap(); | ||
assert_eq!(expected, batches.pretty_print().unwrap()); | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_alter_region() { | ||
common_telemetry::init_default_ut_logging(); | ||
|
||
let mut env = TestEnv::new(); | ||
let engine = env.create_engine(MitoConfig::default()).await; | ||
|
||
let region_id = RegionId::new(1, 1); | ||
let request = CreateRequestBuilder::new().build(); | ||
|
||
let column_schemas = rows_schema(&request); | ||
let region_dir = request.region_dir.clone(); | ||
engine | ||
.handle_request(region_id, RegionRequest::Create(request)) | ||
.await | ||
.unwrap(); | ||
|
||
let rows = Rows { | ||
schema: column_schemas, | ||
rows: build_rows(0, 3), | ||
}; | ||
put_rows(&engine, region_id, rows).await; | ||
|
||
let request = RegionAlterRequest { | ||
schema_version: 0, | ||
kind: AlterKind::AddColumns { | ||
columns: vec![AddColumn { | ||
column_metadata: ColumnMetadata { | ||
column_schema: ColumnSchema::new( | ||
"tag_1", | ||
ConcreteDataType::string_datatype(), | ||
true, | ||
), | ||
semantic_type: SemanticType::Tag, | ||
column_id: 3, | ||
}, | ||
location: Some(AddColumnLocation::First), | ||
}], | ||
}, | ||
}; | ||
engine | ||
.handle_request(region_id, RegionRequest::Alter(request)) | ||
.await | ||
.unwrap(); | ||
|
||
let expected = "\ | ||
+-------+-------+---------+---------------------+ | ||
| tag_1 | tag_0 | field_0 | ts | | ||
+-------+-------+---------+---------------------+ | ||
| | 0 | 0.0 | 1970-01-01T00:00:00 | | ||
| | 1 | 1.0 | 1970-01-01T00:00:01 | | ||
| | 2 | 2.0 | 1970-01-01T00:00:02 | | ||
+-------+-------+---------+---------------------+"; | ||
scan_check_after_alter(&engine, region_id, expected).await; | ||
|
||
// Reopen region. | ||
let engine = env.reopen_engine(engine, MitoConfig::default()).await; | ||
engine | ||
.handle_request( | ||
region_id, | ||
RegionRequest::Open(RegionOpenRequest { | ||
engine: String::new(), | ||
region_dir, | ||
options: HashMap::default(), | ||
}), | ||
) | ||
.await | ||
.unwrap(); | ||
scan_check_after_alter(&engine, region_id, expected).await; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.