-
Notifications
You must be signed in to change notification settings - Fork 328
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
798aa66
commit 40a7d1c
Showing
17 changed files
with
388 additions
and
133 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// 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::fs; | ||
use std::path::Path; | ||
|
||
use serde::Serialize; | ||
use strum::{Display, EnumString}; | ||
use tinytemplate::TinyTemplate; | ||
|
||
use crate::find_workspace_path; | ||
|
||
#[derive(EnumString, Display)] | ||
#[strum(serialize_all = "lowercase")] | ||
pub enum ConfigTemplate { | ||
Datanode, | ||
Metasrv, | ||
Standalone, | ||
} | ||
|
||
impl ConfigTemplate { | ||
fn render(&self, config_values: ConfigValues) -> String { | ||
let template_name = self.to_string(); | ||
|
||
let template = fs::read_to_string(find_workspace_path(&format!( | ||
"/src/common/test-util/conf/{template_name}-test.toml.template" | ||
))) | ||
.unwrap(); | ||
|
||
let mut tt = TinyTemplate::new(); | ||
tt.add_template(&template_name, &template).unwrap(); | ||
tt.render(&template_name, &config_values).unwrap() | ||
} | ||
} | ||
|
||
#[derive(Serialize, Default)] | ||
pub struct ConfigValues { | ||
pub wal_dir: String, | ||
pub data_home: String, | ||
pub procedure_dir: String, | ||
pub is_raft_engine: bool, | ||
pub kafka_wal_broker_endpoints: String, | ||
pub grpc_addr: String, | ||
} | ||
|
||
/// Generate a config file from template (determined by parameter `config_template`), with provided | ||
/// config values (in parameter `config_values`), and stores the file under the directory specified | ||
/// by parameter `target_dir`, returns the target file name. | ||
pub fn generate_config_file( | ||
config_template: ConfigTemplate, | ||
config_values: ConfigValues, | ||
target_dir: &Path, | ||
) -> String { | ||
let rendered = config_template.render(config_values); | ||
|
||
let target_file = format!( | ||
"{config_template}-{}.toml", | ||
common_time::util::current_time_millis() | ||
); | ||
fs::write(target_dir.join(&target_file), rendered).unwrap(); | ||
|
||
target_file | ||
} |
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,58 @@ | ||
// 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::fmt; | ||
use std::fmt::Formatter; | ||
|
||
use client::error::Result; | ||
use common_error::ext::ErrorExt; | ||
use common_query::Output; | ||
use common_recordbatch::util::collect_batches; | ||
|
||
pub struct ResultDisplayer(pub Result<Output>); | ||
|
||
impl fmt::Display for ResultDisplayer { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { | ||
match &self.0 { | ||
Ok(result) => match result { | ||
Output::AffectedRows(rows) => { | ||
write!(f, "Affected Rows: {rows}") | ||
} | ||
Output::RecordBatches(recordbatches) => { | ||
let pretty = recordbatches.pretty_print().unwrap(); | ||
write!(f, "{pretty}") | ||
} | ||
Output::Stream(_) => unimplemented!(), | ||
}, | ||
Err(e) => { | ||
let status_code = e.status_code(); | ||
let root_cause = e.output_msg(); | ||
write!( | ||
f, | ||
"Error: {}({status_code}), {root_cause}", | ||
status_code as u32 | ||
) | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl ResultDisplayer { | ||
pub async fn display(self) -> String { | ||
match self.0 { | ||
Ok(Output::Stream(s)) => collect_batches(s).await.unwrap().pretty_print().unwrap(), | ||
_ => self.to_string(), | ||
} | ||
} | ||
} |
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
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,8 @@ | ||
# When compatibility tests failed: | ||
|
||
- Start an old version (or built from old source codes) GreptimeDB with its data home and WAL set to directory `tests-compatibility/data_home` and `tests-compatibility/data_home/wal/` respectively. | ||
- Using our CLI tool to [export](https://docs.greptime.com/user-guide/upgrade) the data. | ||
- Clear everything under `tests-compatibility/data_home/`. | ||
- Build a new GreptimeDB with your changes with the same data home and WAL dir config. | ||
- Using our CLI tool again to [import](https://docs.greptime.com/user-guide/upgrade) the data. | ||
- Rerun the compatibility test. If it passes, commit the data files. |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.