mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-09-05 04:58:59 +00:00
feat: introduce plugin setup functions with richer context (#8256)
feat: enrich plugin setup context
This commit is contained in:
@@ -14,14 +14,15 @@
|
||||
|
||||
use common_base::Plugins;
|
||||
use datanode::config::DatanodeOptions;
|
||||
use datanode::datanode::Datanode;
|
||||
use datanode::datanode::{Datanode, DatanodeBuilder};
|
||||
use datanode::error::Result;
|
||||
|
||||
use crate::options::PluginOptions;
|
||||
|
||||
/// Sets up datanode plugins before the [`DatanodeBuilder`] is constructed.
|
||||
#[allow(unused_variables)]
|
||||
#[allow(unused_mut)]
|
||||
pub async fn setup_datanode_plugins(
|
||||
pub async fn setup_datanode_plugins_pre_build(
|
||||
plugins: &mut Plugins,
|
||||
plugin_options: &[PluginOptions],
|
||||
dn_opts: &DatanodeOptions,
|
||||
@@ -29,6 +30,21 @@ pub async fn setup_datanode_plugins(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Sets up datanode plugins after the [`DatanodeBuilder`] is constructed
|
||||
/// but before [`DatanodeBuilder::build()`].
|
||||
///
|
||||
/// Plugins can read context from the builder (e.g., kv_backend, options)
|
||||
/// and insert additional plugins. After this call, [`DatanodeBuilder::set_plugins()`]
|
||||
/// should be called to sync plugins into the builder.
|
||||
#[allow(unused_variables)]
|
||||
pub async fn setup_datanode_plugins_post_build(
|
||||
plugins: &mut Plugins,
|
||||
plugin_options: &[PluginOptions],
|
||||
builder: &DatanodeBuilder,
|
||||
) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn start_datanode_plugins(_instance: &Datanode) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -14,19 +14,35 @@
|
||||
|
||||
use common_base::Plugins;
|
||||
use flow::error::Result;
|
||||
use flow::{FlownodeInstance, FlownodeOptions};
|
||||
use flow::{FlownodeBuilder, FlownodeInstance, FlownodeOptions};
|
||||
|
||||
use crate::options::PluginOptions;
|
||||
|
||||
#[allow(unused_mut)]
|
||||
pub async fn setup_flownode_plugins(
|
||||
_plugins: &mut Plugins,
|
||||
_plugin_options: &[PluginOptions],
|
||||
/// Sets up flownode plugins before the [`FlownodeBuilder`] is constructed.
|
||||
#[allow(unused_mut, unused_variables)]
|
||||
pub async fn setup_flownode_plugins_pre_build(
|
||||
plugins: &mut Plugins,
|
||||
plugin_options: &[PluginOptions],
|
||||
_fn_opts: &FlownodeOptions,
|
||||
) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Sets up flownode plugins after the [`FlownodeBuilder`] is constructed
|
||||
/// but before [`FlownodeBuilder::build()`].
|
||||
///
|
||||
/// Plugins can read context from the builder (e.g., opts, catalog_manager, flow_metadata_manager)
|
||||
/// and insert additional plugins. After this call, [`FlownodeBuilder::set_plugins()`]
|
||||
/// should be called to sync plugins into the builder.
|
||||
#[allow(unused_variables)]
|
||||
pub async fn setup_flownode_plugins_post_build(
|
||||
plugins: &mut Plugins,
|
||||
plugin_options: &[PluginOptions],
|
||||
builder: &FlownodeBuilder,
|
||||
) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn start_flownode_plugins(_instance: &FlownodeInstance) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -18,15 +18,27 @@ use common_meta::cache::CacheRegistryBuilder;
|
||||
use frontend::error::{IllegalAuthConfigSnafu, Result};
|
||||
use frontend::frontend::FrontendOptions;
|
||||
use frontend::instance::Instance;
|
||||
use frontend::instance::builder::FrontendBuilder;
|
||||
use snafu::ResultExt;
|
||||
|
||||
use crate::options::PluginOptions;
|
||||
|
||||
/// Sets up frontend plugins before the [`FrontendBuilder`] is constructed.
|
||||
///
|
||||
/// This is where "infrastructure configurators" are registered — plugins that the builder
|
||||
/// consumes during construction (e.g., `CatalogManagerConfiguratorRef`, cache invalidators).
|
||||
///
|
||||
/// In distributed mode this is called twice:
|
||||
/// 1. First without meta config (before `create_meta_client`), for plugins needed by the meta client.
|
||||
/// 2. Second with meta config pulled from metasrv, for dynamic configurators.
|
||||
///
|
||||
/// In standalone mode it is called once with `None`.
|
||||
#[allow(unused_mut)]
|
||||
pub async fn setup_frontend_plugins(
|
||||
pub async fn setup_frontend_plugins_pre_build(
|
||||
plugins: &mut Plugins,
|
||||
_plugin_options: &[PluginOptions],
|
||||
fe_opts: &FrontendOptions,
|
||||
_meta_config: Option<&[PluginOptions]>,
|
||||
) -> Result<()> {
|
||||
if let Some(user_provider) = fe_opts.user_provider.as_ref() {
|
||||
let provider =
|
||||
@@ -39,15 +51,15 @@ pub async fn setup_frontend_plugins(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Setup dynamic plugins based on the meta config in frontend.
|
||||
/// This is called after the `setup_frontend_plugins` because the meta client needs to be created first.
|
||||
/// Sets up frontend plugins after the [`FrontendBuilder`] is constructed
|
||||
/// but before [`FrontendBuilder::try_build()`] and [`FrontendBuilder::with_plugin()`].
|
||||
///
|
||||
/// For those configs/plugins which are corresponding with the metasrv's config,
|
||||
/// we pull from metasrv first, then create/override the current config/plugin.
|
||||
/// Note: make sure the override works as expected.
|
||||
pub async fn setup_frontend_dynamic_plugins(
|
||||
_meta_config: Vec<PluginOptions>,
|
||||
/// This is where "feature plugins" are registered — plugins that consume builder context
|
||||
/// (e.g., `KvBackendRef`, `CatalogManagerRef`) to construct themselves.
|
||||
pub async fn setup_frontend_plugins_post_build(
|
||||
_plugins: &mut Plugins,
|
||||
_plugin_options: &[PluginOptions],
|
||||
_builder: &FrontendBuilder,
|
||||
) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
+12
-4
@@ -21,9 +21,17 @@ pub mod options;
|
||||
pub mod standalone;
|
||||
|
||||
pub use cli::SubCommand;
|
||||
pub use datanode::{setup_datanode_plugins, start_datanode_plugins};
|
||||
pub use flownode::{setup_flownode_plugins, start_flownode_plugins};
|
||||
pub use frontend::{setup_frontend_plugins, start_frontend_plugins};
|
||||
pub use meta_srv::{setup_metasrv_plugins, start_metasrv_plugins};
|
||||
pub use datanode::{
|
||||
setup_datanode_plugins_post_build, setup_datanode_plugins_pre_build, start_datanode_plugins,
|
||||
};
|
||||
pub use flownode::{
|
||||
setup_flownode_plugins_post_build, setup_flownode_plugins_pre_build, start_flownode_plugins,
|
||||
};
|
||||
pub use frontend::{
|
||||
setup_frontend_plugins_post_build, setup_frontend_plugins_pre_build, start_frontend_plugins,
|
||||
};
|
||||
pub use meta_srv::{
|
||||
setup_metasrv_plugins_post_build, setup_metasrv_plugins_pre_build, start_metasrv_plugins,
|
||||
};
|
||||
pub use options::PluginOptions;
|
||||
pub use standalone::setup_standalone_plugins;
|
||||
|
||||
@@ -16,14 +16,34 @@ use common_base::Plugins;
|
||||
use meta_srv::bootstrap::MetasrvInstance;
|
||||
use meta_srv::error::Result;
|
||||
use meta_srv::metasrv::MetasrvOptions;
|
||||
use meta_srv::metasrv::builder::MetasrvBuilder;
|
||||
|
||||
use crate::options::PluginOptions;
|
||||
|
||||
/// Sets up metasrv plugins before the [`MetasrvBuilder`] is constructed.
|
||||
///
|
||||
/// Plugins registered here are available during builder construction
|
||||
/// (e.g., `SelectorFactoryRef`).
|
||||
#[allow(unused_variables)]
|
||||
pub async fn setup_metasrv_plugins(
|
||||
_plugins: &mut Plugins,
|
||||
pub async fn setup_metasrv_plugins_pre_build(
|
||||
plugins: &mut Plugins,
|
||||
plugin_options: &[PluginOptions],
|
||||
metasrv_opts: &MetasrvOptions,
|
||||
_metasrv_opts: &MetasrvOptions,
|
||||
) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Sets up metasrv plugins after the [`MetasrvBuilder`] is constructed
|
||||
/// but before [`MetasrvBuilder::build()`].
|
||||
///
|
||||
/// Plugins can read context from the builder (e.g., kv_backend, options)
|
||||
/// and insert additional plugins. After this call, [`MetasrvBuilder::plugins()`]
|
||||
/// should be called to set plugins on the builder.
|
||||
#[allow(unused_variables)]
|
||||
pub async fn setup_metasrv_plugins_post_build(
|
||||
plugins: &mut Plugins,
|
||||
plugin_options: &[PluginOptions],
|
||||
builder: &MetasrvBuilder,
|
||||
) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user