Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: expose DatanodeBuilder::build_object_store_manager() and MitoConfig::sanitize() #4212

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 16 additions & 17 deletions src/datanode/src/datanode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ use store_api::storage::RegionId;
use tokio::fs;
use tokio::sync::Notify;

use crate::config::{DatanodeOptions, RegionEngineConfig};
use crate::config::{DatanodeOptions, RegionEngineConfig, StorageConfig};
use crate::error::{
self, BuildMitoEngineSnafu, CreateDirSnafu, GetMetadataSnafu, MissingKvBackendSnafu,
MissingNodeIdSnafu, OpenLogStoreSnafu, Result, RuntimeResourceSnafu, ShutdownInstanceSnafu,
Expand Down Expand Up @@ -270,6 +270,20 @@ impl DatanodeBuilder {
})
}

/// Builds [ObjectStoreManager] from [StorageConfig].
pub async fn build_object_store_manager(cfg: &StorageConfig) -> Result<ObjectStoreManagerRef> {
let object_store = store::new_object_store(cfg.store.clone(), &cfg.data_home).await?;
let default_name = cfg.store.name();
let mut object_store_manager = ObjectStoreManager::new(default_name, object_store);
for store in &cfg.providers {
object_store_manager.add(
store.name(),
store::new_object_store(store.clone(), &cfg.data_home).await?,
);
}
Ok(Arc::new(object_store_manager))
}

#[cfg(test)]
/// Open all regions belong to this datanode.
async fn initialize_region_server(
Expand Down Expand Up @@ -329,7 +343,7 @@ impl DatanodeBuilder {
table_provider_factory,
);

let object_store_manager = Self::build_object_store_manager(opts).await?;
let object_store_manager = Self::build_object_store_manager(&opts.storage).await?;
let engines = Self::build_store_engines(opts, object_store_manager).await?;
for engine in engines {
region_server.register_engine(engine);
Expand Down Expand Up @@ -432,21 +446,6 @@ impl DatanodeBuilder {
.context(OpenLogStoreSnafu)
.map(Arc::new)
}

/// Builds [ObjectStoreManager]
async fn build_object_store_manager(opts: &DatanodeOptions) -> Result<ObjectStoreManagerRef> {
let object_store =
store::new_object_store(opts.storage.store.clone(), &opts.storage.data_home).await?;
let default_name = opts.storage.store.name();
let mut object_store_manager = ObjectStoreManager::new(default_name, object_store);
for store in &opts.storage.providers {
object_store_manager.add(
store.name(),
store::new_object_store(store.clone(), &opts.storage.data_home).await?,
);
}
Ok(Arc::new(object_store_manager))
}
}

/// Open all regions belong to this datanode.
Expand Down
2 changes: 1 addition & 1 deletion src/mito2/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ impl MitoConfig {
/// Sanitize incorrect configurations.
///
/// Returns an error if there is a configuration that unable to sanitize.
pub(crate) fn sanitize(&mut self, data_home: &str) -> Result<()> {
pub fn sanitize(&mut self, data_home: &str) -> Result<()> {
// Use default value if `num_workers` is 0.
if self.num_workers == 0 {
self.num_workers = divide_num_cpus(2);
Expand Down