Skip to content

Commit

Permalink
feat(tests-integration): add wal_config
Browse files Browse the repository at this point in the history
  • Loading branch information
WenyXu committed Jan 2, 2024
1 parent f735f73 commit 757cbb6
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 9 deletions.
21 changes: 18 additions & 3 deletions tests-integration/src/cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use catalog::kvbackend::{CachedMetaKvBackend, MetaKvBackend};
use client::client_manager::DatanodeClients;
use client::Client;
use common_base::Plugins;
use common_config::WalConfig;
use common_grpc::channel_manager::{ChannelConfig, ChannelManager};
use common_meta::heartbeat::handler::parse_mailbox_message::ParseMailboxMessageHandler;
use common_meta::heartbeat::handler::HandlerGroupExecutor;
Expand Down Expand Up @@ -70,6 +71,7 @@ pub struct GreptimeDbClusterBuilder {
store_config: Option<ObjectStoreConfig>,
store_providers: Option<Vec<StorageType>>,
datanodes: Option<u32>,
wal_config: WalConfig,
}

impl GreptimeDbClusterBuilder {
Expand All @@ -95,6 +97,7 @@ impl GreptimeDbClusterBuilder {
store_config: None,
store_providers: None,
datanodes: None,
wal_config: WalConfig::default(),
}
}

Expand All @@ -113,6 +116,11 @@ impl GreptimeDbClusterBuilder {
self
}

pub fn with_wal_config(mut self, wal_config: WalConfig) -> Self {
self.wal_config = wal_config;
self
}

pub async fn build(self) -> GreptimeDbCluster {
let datanodes = self.datanodes.unwrap_or(4);

Expand Down Expand Up @@ -176,19 +184,27 @@ impl GreptimeDbClusterBuilder {

for i in 0..datanodes {
let datanode_id = i as u64 + 1;

let mode = Mode::Distributed;
let mut opts = if let Some(store_config) = &self.store_config {
let home_tmp_dir = create_temp_dir(&format!("gt_home_{}", &self.cluster_name));
let home_dir = home_tmp_dir.path().to_str().unwrap().to_string();

dir_guards.push(FileDirGuard::new(home_tmp_dir));

create_datanode_opts(store_config.clone(), vec![], home_dir)
create_datanode_opts(
mode,
store_config.clone(),
vec![],
home_dir,
self.wal_config.clone(),
)
} else {
let (opts, guard) = create_tmp_dir_and_datanode_opts(
mode,
StorageType::File,
self.store_providers.clone().unwrap_or_default(),
&format!("{}-dn-{}", self.cluster_name, datanode_id),
self.wal_config.clone(),
);

storage_guards.push(guard.storage_guards);
Expand All @@ -197,7 +213,6 @@ impl GreptimeDbClusterBuilder {
opts
};
opts.node_id = Some(datanode_id);
opts.mode = Mode::Distributed;

let datanode = self.create_datanode(opts, meta_srv.clone()).await;

Expand Down
2 changes: 1 addition & 1 deletion tests-integration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ mod otlp;
mod prom_store;
pub mod test_util;

mod standalone;
pub mod standalone;
#[cfg(test)]
mod tests;

Expand Down
19 changes: 16 additions & 3 deletions tests-integration/src/standalone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::sync::Arc;
use cmd::options::MixOptions;
use common_base::Plugins;
use common_catalog::consts::MIN_USER_TABLE_ID;
use common_config::KvBackendConfig;
use common_config::{KvBackendConfig, WalConfig};
use common_meta::cache_invalidator::DummyCacheInvalidator;
use common_meta::ddl::table_meta::TableMetadataAllocator;
use common_meta::ddl_manager::DdlManager;
Expand All @@ -32,6 +32,7 @@ use datanode::datanode::DatanodeBuilder;
use frontend::frontend::FrontendOptions;
use frontend::instance::builder::FrontendBuilder;
use frontend::instance::{FrontendInstance, Instance, StandaloneDatanodeManager};
use servers::Mode;

use crate::test_util::{self, create_tmp_dir_and_datanode_opts, StorageType, TestGuard};

Expand All @@ -44,6 +45,7 @@ pub struct GreptimeDbStandalone {

pub struct GreptimeDbStandaloneBuilder {
instance_name: String,
wal_config: WalConfig,
store_providers: Option<Vec<StorageType>>,
default_store: Option<StorageType>,
plugin: Option<Plugins>,
Expand All @@ -56,6 +58,7 @@ impl GreptimeDbStandaloneBuilder {
store_providers: None,
plugin: None,
default_store: None,
wal_config: WalConfig::default(),
}
}

Expand All @@ -82,12 +85,22 @@ impl GreptimeDbStandaloneBuilder {
}
}

pub fn with_wal_config(mut self, wal_config: WalConfig) -> Self {
self.wal_config = wal_config;
self
}

pub async fn build(self) -> GreptimeDbStandalone {
let default_store_type = self.default_store.unwrap_or(StorageType::File);
let store_types = self.store_providers.unwrap_or_default();

let (opts, guard) =
create_tmp_dir_and_datanode_opts(default_store_type, store_types, &self.instance_name);
let (opts, guard) = create_tmp_dir_and_datanode_opts(
Mode::Standalone,
default_store_type,
store_types,
&self.instance_name,
self.wal_config.clone(),
);

let procedure_config = ProcedureConfig::default();
let kv_backend_config = KvBackendConfig::default();
Expand Down
10 changes: 8 additions & 2 deletions tests-integration/src/test_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use std::time::Duration;
use auth::UserProviderRef;
use axum::Router;
use catalog::kvbackend::KvBackendCatalogManager;
use common_config::WalConfig;
use common_meta::key::catalog_name::CatalogNameKey;
use common_meta::key::schema_name::SchemaNameKey;
use common_query::Output;
Expand Down Expand Up @@ -294,9 +295,11 @@ impl TestGuard {
}

pub fn create_tmp_dir_and_datanode_opts(
mode: Mode,
default_store_type: StorageType,
store_provider_types: Vec<StorageType>,
name: &str,
wal_config: WalConfig,
) -> (DatanodeOptions, TestGuard) {
let home_tmp_dir = create_temp_dir(&format!("gt_data_{name}"));
let home_dir = home_tmp_dir.path().to_str().unwrap().to_string();
Expand All @@ -314,7 +317,7 @@ pub fn create_tmp_dir_and_datanode_opts(
store_providers.push(store);
storage_guards.push(StorageGuard(data_tmp_dir))
}
let opts = create_datanode_opts(default_store, store_providers, home_dir);
let opts = create_datanode_opts(mode, default_store, store_providers, home_dir, wal_config);

(
opts,
Expand All @@ -326,9 +329,11 @@ pub fn create_tmp_dir_and_datanode_opts(
}

pub(crate) fn create_datanode_opts(
mode: Mode,
default_store: ObjectStoreConfig,
providers: Vec<ObjectStoreConfig>,
home_dir: String,
wal_config: WalConfig,
) -> DatanodeOptions {
DatanodeOptions {
node_id: Some(0),
Expand All @@ -339,7 +344,8 @@ pub(crate) fn create_datanode_opts(
store: default_store,
..Default::default()
},
mode: Mode::Standalone,
mode,
wal: wal_config,
..Default::default()
}
}
Expand Down

0 comments on commit 757cbb6

Please sign in to comment.