Skip to content

Commit

Permalink
test: past 3 major version compat crate table
Browse files Browse the repository at this point in the history
  • Loading branch information
discord9 committed Dec 12, 2024
1 parent e57b22d commit 5faa007
Show file tree
Hide file tree
Showing 8 changed files with 615 additions and 17 deletions.
32 changes: 17 additions & 15 deletions tests/runner/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use tokio::sync::Mutex as TokioMutex;
use tokio_postgres::{Client as PgClient, SimpleQueryMessage as PgRow};

use crate::protocol_interceptor::{MYSQL, PROTOCOL_KEY};
use crate::util::{get_workspace_root, maybe_pull_binary};
use crate::util::{get_workspace_root, maybe_pull_binary, PROGRAM};
use crate::{util, ServerAddr};

const METASRV_ADDR: &str = "127.0.0.1:29302";
Expand Down Expand Up @@ -400,23 +400,20 @@ impl Env {
}
}

#[cfg(not(windows))]
let program = "./greptime";
#[cfg(windows)]
let program = "greptime.exe";
let program = PROGRAM;

let bins_dir = self.bins_dir.lock().unwrap().clone().expect(
"GreptimeDB binary is not available. Please pass in the path to the directory that contains the pre-built GreptimeDB binary. Or you may call `self.build_db()` beforehand.",
);

let mut process = Command::new(program)
.current_dir(bins_dir)
.current_dir(bins_dir.clone())
.env("TZ", "UTC")
.args(args)
.stdout(stdout_file)
.spawn()
.unwrap_or_else(|error| {
panic!("Failed to start the DB with subcommand {subcommand},Error: {error}")
panic!("Failed to start the DB with subcommand {subcommand},Error: {error}, path: {:?}", bins_dir.join(program));
});

for check_ip_addr in &check_ip_addrs {
Expand Down Expand Up @@ -793,14 +790,19 @@ impl Database for GreptimeDB {
.expect("lock poison")
.get(version.as_str())
.cloned();
if let Some(path) = version_bin_dir {
*self.env.bins_dir.lock().unwrap() = Some(path.clone());
} else {
// use version in dir files
maybe_pull_binary(version, self.env.pull_version_on_need).await;
let root = get_workspace_root();
let new_path = PathBuf::from_iter([&root, version]);
*self.env.bins_dir.lock().unwrap() = Some(new_path);

match version_bin_dir {
Some(path) if path.clone().join(PROGRAM).is_file() => {
// use version in versioned_bins_dirs
*self.env.bins_dir.lock().unwrap() = Some(path.clone());
}
_ => {
// use version in dir files
maybe_pull_binary(version, self.env.pull_version_on_need).await;
let root = get_workspace_root();
let new_path = PathBuf::from_iter([&root, version]);
*self.env.bins_dir.lock().unwrap() = Some(new_path);
}
}

self.env.restart_server(self, true).await;
Expand Down
9 changes: 7 additions & 2 deletions tests/runner/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ use tokio_stream::StreamExt;
/// Check port every 0.1 second.
const PORT_CHECK_INTERVAL: Duration = Duration::from_millis(100);

#[cfg(not(windows))]
pub const PROGRAM: &str = "./greptime";
#[cfg(windows)]
pub const PROGRAM: &str = "greptime.exe";

fn http_proxy() -> Option<String> {
for proxy in ["http_proxy", "HTTP_PROXY", "all_proxy", "ALL_PROXY"] {
if let Ok(proxy_addr) = std::env::var(proxy) {
Expand Down Expand Up @@ -124,7 +129,7 @@ pub async fn pull_binary(version: &str) {
println!("Downloading {version} binary from {}", url);

// mkdir {version}
std::fs::create_dir(version).unwrap();
let _ = std::fs::create_dir(version);

let archive = Path::new(version).join(filename);
let folder_path = Path::new(version);
Expand Down Expand Up @@ -176,7 +181,7 @@ pub async fn pull_binary(version: &str) {

/// Pull the binary if it does not exist and `pull_version_on_need` is true.
pub async fn maybe_pull_binary(version: &str, pull_version_on_need: bool) {
let exist = Path::new(version).is_dir();
let exist = Path::new(version).join(PROGRAM).is_file();
match (exist, pull_version_on_need){
(true, _) => println!("Binary {version} exists"),
(false, false) => panic!("Binary {version} does not exist, please run with --pull-version-on-need or manually download it"),
Expand Down
137 changes: 137 additions & 0 deletions tests/upgrade-compat/standalone/common/table_engine_0_10_2.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
-- SQLNESS ARG version=v0.10.2
CREATE TABLE mito_system_metrics (
host STRING,
idc STRING,
cpu_util DOUBLE,
memory_util DOUBLE,
disk_util DOUBLE,
ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP(),
PRIMARY KEY(host, idc),
TIME INDEX(ts)
)ENGINE=mito;

Affected Rows: 0

INSERT INTO mito_system_metrics
VALUES
("host1", "idc_a", 11.8, 10.3, 10.3, 1667446797450),
("host2", "idc_a", 80.0, 70.3, 90.0, 1667446797450),
("host1", "idc_b", 50.0, 66.7, 40.6, 1667446797450);

Affected Rows: 3

CREATE TABLE phy (ts timestamp time index, cpu_util double) engine=metric with ("physical_metric_table" = "");

Affected Rows: 0

CREATE TABLE system_metrics (
host STRING,
cpu_util DOUBLE,
ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP(),
PRIMARY KEY(host),
TIME INDEX(ts)
)ENGINE=metric with ("on_physical_table" = "phy");

Affected Rows: 0

INSERT INTO system_metrics (host, cpu_util, ts)
VALUES
('host1', 11.8, 1667446797450),
('host2', 80.0, 1667446797450),
('host1', 50.0, 1667446797450);

Affected Rows: 3

-- SQLNESS ARG version=latest
SHOW CREATE TABLE mito_system_metrics;

+---------------------+-----------------------------------------------------------+
| Table | Create Table |
+---------------------+-----------------------------------------------------------+
| mito_system_metrics | CREATE TABLE IF NOT EXISTS "mito_system_metrics" ( |
| | "host" STRING NULL, |
| | "idc" STRING NULL, |
| | "cpu_util" DOUBLE NULL, |
| | "memory_util" DOUBLE NULL, |
| | "disk_util" DOUBLE NULL, |
| | "ts" TIMESTAMP(3) NOT NULL DEFAULT current_timestamp(), |
| | TIME INDEX ("ts"), |
| | PRIMARY KEY ("host", "idc") |
| | ) |
| | |
| | ENGINE=mito |
| | |
+---------------------+-----------------------------------------------------------+

SHOW CREATE TABLE system_metrics;

+----------------+-----------------------------------------------------------+
| Table | Create Table |
+----------------+-----------------------------------------------------------+
| system_metrics | CREATE TABLE IF NOT EXISTS "system_metrics" ( |
| | "cpu_util" DOUBLE NULL, |
| | "host" STRING NULL, |
| | "ts" TIMESTAMP(3) NOT NULL DEFAULT current_timestamp(), |
| | TIME INDEX ("ts"), |
| | PRIMARY KEY ("host") |
| | ) |
| | |
| | ENGINE=metric |
| | WITH( |
| | on_physical_table = 'phy' |
| | ) |
+----------------+-----------------------------------------------------------+

INSERT INTO mito_system_metrics
VALUES
("host3", "idc_a", 90.0, 70.3, 90.0, 1667446797450),
("host4", "idc_a", 70.0, 70.3, 90.0, 1667446797450),
("host5", "idc_a", 60.0, 70.3, 90.0, 1667446797450);

Affected Rows: 3

INSERT INTO system_metrics (host, cpu_util, ts)
VALUES
('host3', 90.0, 1667446797450),
('host4', 70.0, 1667446797450),
('host5', 60.0, 1667446797450);

Affected Rows: 3

SELECT * FROM mito_system_metrics;

+-------+-------+----------+-------------+-----------+-------------------------+
| host | idc | cpu_util | memory_util | disk_util | ts |
+-------+-------+----------+-------------+-----------+-------------------------+
| host1 | idc_a | 11.8 | 10.3 | 10.3 | 2022-11-03T03:39:57.450 |
| host1 | idc_b | 50.0 | 66.7 | 40.6 | 2022-11-03T03:39:57.450 |
| host2 | idc_a | 80.0 | 70.3 | 90.0 | 2022-11-03T03:39:57.450 |
| host3 | idc_a | 90.0 | 70.3 | 90.0 | 2022-11-03T03:39:57.450 |
| host4 | idc_a | 70.0 | 70.3 | 90.0 | 2022-11-03T03:39:57.450 |
| host5 | idc_a | 60.0 | 70.3 | 90.0 | 2022-11-03T03:39:57.450 |
+-------+-------+----------+-------------+-----------+-------------------------+

SELECT * FROM system_metrics;

+----------+-------+-------------------------+
| cpu_util | host | ts |
+----------+-------+-------------------------+
| 80.0 | host2 | 2022-11-03T03:39:57.450 |
| 70.0 | host4 | 2022-11-03T03:39:57.450 |
| 60.0 | host5 | 2022-11-03T03:39:57.450 |
| 90.0 | host3 | 2022-11-03T03:39:57.450 |
| 50.0 | host1 | 2022-11-03T03:39:57.450 |
+----------+-------+-------------------------+

DROP TABLE mito_system_metrics;

Affected Rows: 0

DROP TABLE system_metrics;

Affected Rows: 0

DROP TABLE phy;

Affected Rows: 0

60 changes: 60 additions & 0 deletions tests/upgrade-compat/standalone/common/table_engine_0_10_2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
-- SQLNESS ARG version=v0.10.2
CREATE TABLE mito_system_metrics (
host STRING,
idc STRING,
cpu_util DOUBLE,
memory_util DOUBLE,
disk_util DOUBLE,
ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP(),
PRIMARY KEY(host, idc),
TIME INDEX(ts)
)ENGINE=mito;

INSERT INTO mito_system_metrics
VALUES
("host1", "idc_a", 11.8, 10.3, 10.3, 1667446797450),
("host2", "idc_a", 80.0, 70.3, 90.0, 1667446797450),
("host1", "idc_b", 50.0, 66.7, 40.6, 1667446797450);

CREATE TABLE phy (ts timestamp time index, cpu_util double) engine=metric with ("physical_metric_table" = "");

CREATE TABLE system_metrics (
host STRING,
cpu_util DOUBLE,
ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP(),
PRIMARY KEY(host),
TIME INDEX(ts)
)ENGINE=metric with ("on_physical_table" = "phy");

INSERT INTO system_metrics (host, cpu_util, ts)
VALUES
('host1', 11.8, 1667446797450),
('host2', 80.0, 1667446797450),
('host1', 50.0, 1667446797450);

-- SQLNESS ARG version=latest
SHOW CREATE TABLE mito_system_metrics;

SHOW CREATE TABLE system_metrics;

INSERT INTO mito_system_metrics
VALUES
("host3", "idc_a", 90.0, 70.3, 90.0, 1667446797450),
("host4", "idc_a", 70.0, 70.3, 90.0, 1667446797450),
("host5", "idc_a", 60.0, 70.3, 90.0, 1667446797450);

INSERT INTO system_metrics (host, cpu_util, ts)
VALUES
('host3', 90.0, 1667446797450),
('host4', 70.0, 1667446797450),
('host5', 60.0, 1667446797450);

SELECT * FROM mito_system_metrics;

SELECT * FROM system_metrics;

DROP TABLE mito_system_metrics;

DROP TABLE system_metrics;

DROP TABLE phy;
Loading

0 comments on commit 5faa007

Please sign in to comment.