Skip to content

Commit

Permalink
refactor!: add '&mut Plugins' argument in plugins setup api and remov…
Browse files Browse the repository at this point in the history
…e unnecessary mut

Signed-off-by: zyy17 <[email protected]>
  • Loading branch information
zyy17 committed Jul 18, 2024
1 parent 0b13ac6 commit 2823aa0
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 34 deletions.
5 changes: 3 additions & 2 deletions src/cmd/src/datanode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,9 @@ impl StartCommand {
info!("Datanode start command: {:#?}", self);
info!("Datanode options: {:#?}", opts);

let mut opts = opts.component;
let plugins = plugins::setup_datanode_plugins(&mut opts)
let opts = opts.component;
let mut plugins = common_base::Plugins::new();
plugins::setup_datanode_plugins(&mut plugins, &opts)
.await
.context(StartDatanodeSnafu)?;

Expand Down
14 changes: 8 additions & 6 deletions src/cmd/src/frontend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,9 @@ impl StartCommand {
info!("Frontend start command: {:#?}", self);
info!("Frontend options: {:#?}", opts);

let mut opts = opts.component;
#[allow(clippy::unnecessary_mut_passed)]
let plugins = plugins::setup_frontend_plugins(&mut opts)
let opts = opts.component;
let mut plugins = common_base::Plugins::new();
plugins::setup_frontend_plugins(&mut plugins, &opts)
.await
.context(StartFrontendSnafu)?;

Expand Down Expand Up @@ -458,7 +458,7 @@ mod tests {

#[tokio::test]
async fn test_try_from_start_command_to_anymap() {
let mut fe_opts = frontend::frontend::FrontendOptions {
let fe_opts = frontend::frontend::FrontendOptions {
http: HttpOptions {
disable_dashboard: false,
..Default::default()
Expand All @@ -467,8 +467,10 @@ mod tests {
..Default::default()
};

#[allow(clippy::unnecessary_mut_passed)]
let plugins = plugins::setup_frontend_plugins(&mut fe_opts).await.unwrap();
let mut plugins = common_base::Plugins::new();
plugins::setup_frontend_plugins(&mut plugins, &fe_opts)
.await
.unwrap();

let provider = plugins.get::<UserProviderRef>().unwrap();
let result = provider
Expand Down
6 changes: 4 additions & 2 deletions src/cmd/src/metasrv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use std::time::Duration;

use async_trait::async_trait;
use clap::Parser;
use common_base::Plugins;
use common_config::Configurable;
use common_telemetry::info;
use common_telemetry::logging::TracingOptions;
Expand Down Expand Up @@ -238,8 +239,9 @@ impl StartCommand {
info!("Metasrv start command: {:#?}", self);
info!("Metasrv options: {:#?}", opts);

let mut opts = opts.component;
let plugins = plugins::setup_metasrv_plugins(&mut opts)
let opts = opts.component;
let mut plugins = Plugins::new();
plugins::setup_metasrv_plugins(&mut plugins, &opts)
.await
.context(StartMetaServerSnafu)?;

Expand Down
28 changes: 17 additions & 11 deletions src/cmd/src/standalone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,14 +418,18 @@ impl StartCommand {
info!("Standalone start command: {:#?}", self);
info!("Standalone options: {opts:#?}");

let mut plugins = common_base::Plugins::new();
let opts = opts.component;
let mut fe_opts = opts.frontend_options();
#[allow(clippy::unnecessary_mut_passed)]
let fe_plugins = plugins::setup_frontend_plugins(&mut fe_opts) // mut ref is MUST, DO NOT change it
let fe_opts = opts.frontend_options();
let dn_opts = opts.datanode_options();

plugins::setup_frontend_plugins(&mut plugins, &fe_opts)
.await
.context(StartFrontendSnafu)?;

let dn_opts = opts.datanode_options();
plugins::setup_datanode_plugins(&mut plugins, &dn_opts)
.await
.context(StartDatanodeSnafu)?;

set_default_timezone(fe_opts.default_timezone.as_deref()).context(InitTimezoneSnafu)?;

Expand Down Expand Up @@ -464,15 +468,15 @@ impl StartCommand {
let table_metadata_manager =
Self::create_table_metadata_manager(kv_backend.clone()).await?;

let datanode = DatanodeBuilder::new(dn_opts, fe_plugins.clone())
let datanode = DatanodeBuilder::new(dn_opts, plugins.clone())
.with_kv_backend(kv_backend.clone())
.build()
.await
.context(StartDatanodeSnafu)?;

let flow_builder = FlownodeBuilder::new(
Default::default(),
fe_plugins.clone(),
plugins.clone(),
table_metadata_manager.clone(),
catalog_manager.clone(),
);
Expand Down Expand Up @@ -533,7 +537,7 @@ impl StartCommand {
node_manager.clone(),
ddl_task_executor.clone(),
)
.with_plugin(fe_plugins.clone())
.with_plugin(plugins.clone())
.try_build()
.await
.context(StartFrontendSnafu)?;
Expand All @@ -554,7 +558,7 @@ impl StartCommand {

let (tx, _rx) = broadcast::channel(1);

let servers = Services::new(fe_opts, Arc::new(frontend.clone()), fe_plugins)
let servers = Services::new(fe_opts, Arc::new(frontend.clone()), plugins)
.build()
.await
.context(StartFrontendSnafu)?;
Expand Down Expand Up @@ -636,13 +640,15 @@ mod tests {

#[tokio::test]
async fn test_try_from_start_command_to_anymap() {
let mut fe_opts = FrontendOptions {
let fe_opts = FrontendOptions {
user_provider: Some("static_user_provider:cmd:test=test".to_string()),
..Default::default()
};

#[allow(clippy::unnecessary_mut_passed)]
let plugins = plugins::setup_frontend_plugins(&mut fe_opts).await.unwrap();
let mut plugins = common_base::Plugins::new();
plugins::setup_frontend_plugins(&mut plugins, &fe_opts)
.await
.unwrap();

let provider = plugins.get::<UserProviderRef>().unwrap();
let result = provider
Expand Down
12 changes: 9 additions & 3 deletions src/plugins/src/datanode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,16 @@ use common_base::Plugins;
use datanode::config::DatanodeOptions;
use datanode::error::Result;

pub async fn setup_datanode_plugins(_opts: &mut DatanodeOptions) -> Result<Plugins> {
Ok(Plugins::new())
#[allow(unused_variables)]
#[allow(unused_mut)]
pub async fn setup_datanode_plugins(
plugins: &mut Plugins,
dn_opts: &DatanodeOptions,
) -> Result<()> {
Ok(())
}

pub async fn start_datanode_plugins(_plugins: Plugins) -> Result<()> {
#[allow(unused_variables)]
pub async fn start_datanode_plugins(plugins: Plugins) -> Result<()> {
Ok(())
}
17 changes: 10 additions & 7 deletions src/plugins/src/frontend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,21 @@ use frontend::error::{IllegalAuthConfigSnafu, Result};
use frontend::frontend::FrontendOptions;
use snafu::ResultExt;

pub async fn setup_frontend_plugins(opts: &FrontendOptions) -> Result<Plugins> {
let plugins = Plugins::new();

if let Some(user_provider) = opts.user_provider.as_ref() {
#[allow(unused_variables)]
#[allow(unused_mut)]
pub async fn setup_frontend_plugins(
plugins: &mut Plugins,
fe_opts: &FrontendOptions,
) -> Result<()> {
if let Some(user_provider) = fe_opts.user_provider.as_ref() {
let provider =
auth::user_provider_from_option(user_provider).context(IllegalAuthConfigSnafu)?;
plugins.insert::<UserProviderRef>(provider);
}

Ok(plugins)
Ok(())
}

pub async fn start_frontend_plugins(_plugins: Plugins) -> Result<()> {
#[allow(unused_variables)]
pub async fn start_frontend_plugins(plugins: Plugins) -> Result<()> {
Ok(())
}
12 changes: 9 additions & 3 deletions src/plugins/src/meta_srv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,16 @@ use common_base::Plugins;
use meta_srv::error::Result;
use meta_srv::metasrv::MetasrvOptions;

pub async fn setup_metasrv_plugins(_opts: &mut MetasrvOptions) -> Result<Plugins> {
Ok(Plugins::new())
#[allow(unused_variables)]
#[allow(unused_mut)]
pub async fn setup_metasrv_plugins(
plugins: &mut Plugins,
metasrv_opts: &MetasrvOptions,
) -> Result<()> {
Ok(())
}

pub async fn start_metasrv_plugins(_plugins: Plugins) -> Result<()> {
#[allow(unused_variables)]
pub async fn start_metasrv_plugins(plugins: Plugins) -> Result<()> {
Ok(())
}

0 comments on commit 2823aa0

Please sign in to comment.