mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-07-08 23:10:39 +00:00
feat: introduce plugin setup functions with richer context (#8256)
feat: enrich plugin setup context
This commit is contained in:
@@ -46,7 +46,12 @@ impl InstanceBuilder {
|
||||
) -> Result<Self> {
|
||||
let guard = Self::init(&mut opts, &mut plugins).await?;
|
||||
|
||||
let datanode_builder = Self::datanode_builder(&opts, plugins).await?;
|
||||
let mut datanode_builder = Self::datanode_builder(&opts, &plugins).await?;
|
||||
|
||||
plugins::setup_datanode_plugins_post_build(&mut plugins, &opts.plugins, &datanode_builder)
|
||||
.await
|
||||
.context(StartDatanodeSnafu)?;
|
||||
datanode_builder.set_plugins(plugins);
|
||||
|
||||
Ok(Self {
|
||||
guard,
|
||||
@@ -71,7 +76,7 @@ impl InstanceBuilder {
|
||||
maybe_activate_heap_profile(&dn_opts.memory);
|
||||
create_resource_limit_metrics(APP_NAME);
|
||||
|
||||
plugins::setup_datanode_plugins(plugins, &opts.plugins, dn_opts)
|
||||
plugins::setup_datanode_plugins_pre_build(plugins, &opts.plugins, dn_opts)
|
||||
.await
|
||||
.context(StartDatanodeSnafu)?;
|
||||
|
||||
@@ -81,7 +86,10 @@ impl InstanceBuilder {
|
||||
Ok(guard)
|
||||
}
|
||||
|
||||
async fn datanode_builder(opts: &DatanodeOptions, plugins: Plugins) -> Result<DatanodeBuilder> {
|
||||
async fn datanode_builder(
|
||||
opts: &DatanodeOptions,
|
||||
plugins: &Plugins,
|
||||
) -> Result<DatanodeBuilder> {
|
||||
let dn_opts = &opts.component;
|
||||
|
||||
let member_id = dn_opts
|
||||
@@ -93,7 +101,7 @@ impl InstanceBuilder {
|
||||
let client = meta_client::create_meta_client(
|
||||
MetaClientType::Datanode { member_id },
|
||||
meta_client_options,
|
||||
Some(&plugins),
|
||||
Some(plugins),
|
||||
None,
|
||||
)
|
||||
.await
|
||||
|
||||
@@ -278,7 +278,7 @@ impl StartCommand {
|
||||
opts.grpc.detect_server_addr();
|
||||
|
||||
let mut plugins = Plugins::new();
|
||||
plugins::setup_flownode_plugins(&mut plugins, &plugin_opts, &opts)
|
||||
plugins::setup_flownode_plugins_pre_build(&mut plugins, &plugin_opts, &opts)
|
||||
.await
|
||||
.context(StartFlownodeSnafu)?;
|
||||
|
||||
@@ -376,7 +376,7 @@ impl StartCommand {
|
||||
)
|
||||
.context(StartFlownodeSnafu)?;
|
||||
let frontend_client = Arc::new(frontend_client);
|
||||
let flownode_builder = FlownodeBuilder::new(
|
||||
let mut flownode_builder = FlownodeBuilder::new(
|
||||
opts.clone(),
|
||||
plugins.clone(),
|
||||
table_metadata_manager,
|
||||
@@ -386,6 +386,11 @@ impl StartCommand {
|
||||
)
|
||||
.with_heartbeat_task(heartbeat_task);
|
||||
|
||||
plugins::setup_flownode_plugins_post_build(&mut plugins, &plugin_opts, &flownode_builder)
|
||||
.await
|
||||
.context(StartFlownodeSnafu)?;
|
||||
flownode_builder.set_plugins(plugins.clone());
|
||||
|
||||
let mut flownode = flownode_builder.build().await.context(StartFlownodeSnafu)?;
|
||||
|
||||
let builder =
|
||||
|
||||
@@ -52,7 +52,6 @@ use plugins::PluginOptions;
|
||||
use plugins::frontend::context::{
|
||||
CatalogManagerConfigureContext, DistributedCatalogManagerConfigureContext,
|
||||
};
|
||||
use plugins::frontend::setup_frontend_dynamic_plugins;
|
||||
use plugins::options::PluginOptionsDeserializerImpl;
|
||||
use servers::addrs;
|
||||
use servers::grpc::GrpcOptions;
|
||||
@@ -354,10 +353,6 @@ impl StartCommand {
|
||||
let plugin_opts = opts.plugins;
|
||||
let mut opts = opts.component;
|
||||
opts.grpc.detect_server_addr();
|
||||
let mut plugins = Plugins::new();
|
||||
plugins::setup_frontend_plugins(&mut plugins, &plugin_opts, &opts)
|
||||
.await
|
||||
.context(error::StartFrontendSnafu)?;
|
||||
|
||||
set_default_timezone(opts.default_timezone.as_deref()).context(error::InitTimezoneSnafu)?;
|
||||
set_default_prefix(opts.default_column_prefix.as_deref())
|
||||
@@ -375,6 +370,29 @@ impl StartCommand {
|
||||
let cache_ttl = meta_client_options.metadata_cache_ttl;
|
||||
let cache_tti = meta_client_options.metadata_cache_tti;
|
||||
|
||||
let meta_config: Vec<PluginOptions> = meta_client::create_meta_client(
|
||||
MetaClientType::Frontend,
|
||||
meta_client_options,
|
||||
None,
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.context(error::MetaClientInitSnafu)?
|
||||
.pull_config(PluginOptionsDeserializerImpl)
|
||||
.await
|
||||
.context(error::MetaClientInitSnafu)?;
|
||||
|
||||
let mut plugins = Plugins::new();
|
||||
plugins::setup_frontend_plugins_pre_build(
|
||||
&mut plugins,
|
||||
&plugin_opts,
|
||||
&opts,
|
||||
Some(&meta_config),
|
||||
)
|
||||
.await
|
||||
.context(error::StartFrontendSnafu)?;
|
||||
|
||||
// now initialize the meta_client with plugins
|
||||
let meta_client = meta_client::create_meta_client(
|
||||
MetaClientType::Frontend,
|
||||
meta_client_options,
|
||||
@@ -384,14 +402,6 @@ impl StartCommand {
|
||||
.await
|
||||
.context(error::MetaClientInitSnafu)?;
|
||||
|
||||
let meta_config: Vec<PluginOptions> = meta_client
|
||||
.pull_config(PluginOptionsDeserializerImpl)
|
||||
.await
|
||||
.context(error::MetaClientInitSnafu)?;
|
||||
setup_frontend_dynamic_plugins(meta_config, &mut plugins)
|
||||
.await
|
||||
.context(error::StartFrontendSnafu)?;
|
||||
|
||||
let readonly_meta_backend = new_read_only_meta_kv_backend(meta_client.clone());
|
||||
|
||||
// TODO(discord9): add helper function to ease the creation of cache registry&such
|
||||
@@ -470,7 +480,7 @@ impl StartCommand {
|
||||
};
|
||||
let catalog_manager = builder.build();
|
||||
|
||||
let instance = FrontendBuilder::new(
|
||||
let builder = FrontendBuilder::new(
|
||||
opts.clone(),
|
||||
cached_meta_backend.clone(),
|
||||
layered_cache_registry.clone(),
|
||||
@@ -478,12 +488,18 @@ impl StartCommand {
|
||||
client,
|
||||
meta_client.clone(),
|
||||
process_manager,
|
||||
)
|
||||
.with_plugin(plugins.clone())
|
||||
.with_local_cache_invalidator(layered_cache_registry)
|
||||
.try_build()
|
||||
.await
|
||||
.context(error::StartFrontendSnafu)?;
|
||||
);
|
||||
|
||||
plugins::setup_frontend_plugins_post_build(&mut plugins, &plugin_opts, &builder)
|
||||
.await
|
||||
.context(error::StartFrontendSnafu)?;
|
||||
|
||||
let instance = builder
|
||||
.with_plugin(plugins.clone())
|
||||
.with_local_cache_invalidator(layered_cache_registry)
|
||||
.try_build()
|
||||
.await
|
||||
.context(error::StartFrontendSnafu)?;
|
||||
|
||||
let heartbeat_task = Some(create_heartbeat_task(&opts, meta_client, &instance));
|
||||
|
||||
@@ -638,7 +654,7 @@ mod tests {
|
||||
};
|
||||
|
||||
let mut plugins = Plugins::new();
|
||||
plugins::setup_frontend_plugins(&mut plugins, &[], &fe_opts)
|
||||
plugins::setup_frontend_plugins_pre_build(&mut plugins, &[], &fe_opts, None)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
|
||||
@@ -342,14 +342,23 @@ impl StartCommand {
|
||||
info!("Metasrv options: {:#?}", opts);
|
||||
|
||||
let mut plugins = Plugins::new();
|
||||
plugins::setup_metasrv_plugins(&mut plugins, &plugin_opts, &opts)
|
||||
plugins::setup_metasrv_plugins_pre_build(&mut plugins, &plugin_opts, &opts)
|
||||
.await
|
||||
.context(StartMetaServerSnafu)?;
|
||||
|
||||
let builder = metasrv_builder(&opts, plugins, None)
|
||||
let builder = metasrv_builder(&opts, &plugins, None)
|
||||
.await
|
||||
.context(error::BuildMetaServerSnafu)?;
|
||||
|
||||
plugins::setup_metasrv_plugins_post_build(&mut plugins, &plugin_opts, &builder)
|
||||
.await
|
||||
.context(StartMetaServerSnafu)?;
|
||||
|
||||
let metasrv = builder
|
||||
.plugins(plugins)
|
||||
.build()
|
||||
.await
|
||||
.context(error::BuildMetaServerSnafu)?;
|
||||
let metasrv = builder.build().await.context(error::BuildMetaServerSnafu)?;
|
||||
|
||||
let instance = MetasrvInstance::new(metasrv)
|
||||
.await
|
||||
|
||||
@@ -380,11 +380,11 @@ impl StartCommand {
|
||||
let node_id = dn_opts.node_id;
|
||||
let init_regions_parallelism = dn_opts.init_regions_parallelism;
|
||||
|
||||
plugins::setup_frontend_plugins(&mut plugins, &plugin_opts, &fe_opts)
|
||||
plugins::setup_frontend_plugins_pre_build(&mut plugins, &plugin_opts, &fe_opts, None)
|
||||
.await
|
||||
.context(error::StartFrontendSnafu)?;
|
||||
|
||||
plugins::setup_datanode_plugins(&mut plugins, &plugin_opts, &dn_opts)
|
||||
plugins::setup_datanode_plugins_pre_build(&mut plugins, &plugin_opts, &dn_opts)
|
||||
.await
|
||||
.context(error::StartDatanodeSnafu)?;
|
||||
|
||||
@@ -429,6 +429,12 @@ impl StartCommand {
|
||||
if let Some(writable) = creator.open_regions_writable_override {
|
||||
builder.with_open_regions_writable_override(writable);
|
||||
}
|
||||
|
||||
plugins::setup_datanode_plugins_post_build(&mut plugins, &plugin_opts, &builder)
|
||||
.await
|
||||
.context(error::StartDatanodeSnafu)?;
|
||||
builder.set_plugins(plugins.clone());
|
||||
|
||||
let datanode = builder.build().await.context(error::StartDatanodeSnafu)?;
|
||||
|
||||
let information_extension = Arc::new(StandaloneInformationExtension::new(
|
||||
@@ -478,7 +484,7 @@ impl StartCommand {
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let flow_builder = FlownodeBuilder::new(
|
||||
let mut flow_builder = FlownodeBuilder::new(
|
||||
flownode_options,
|
||||
plugins.clone(),
|
||||
table_metadata_manager.clone(),
|
||||
@@ -486,6 +492,12 @@ impl StartCommand {
|
||||
flow_metadata_manager.clone(),
|
||||
frontend_client.clone(),
|
||||
);
|
||||
|
||||
plugins::setup_flownode_plugins_post_build(&mut plugins, &plugin_opts, &flow_builder)
|
||||
.await
|
||||
.context(error::StartFlownodeSnafu)?;
|
||||
flow_builder.set_plugins(plugins.clone());
|
||||
|
||||
let flownode = flow_builder
|
||||
.build()
|
||||
.await
|
||||
@@ -578,11 +590,17 @@ impl StartCommand {
|
||||
node_manager.clone(),
|
||||
procedure_executor.clone(),
|
||||
process_manager,
|
||||
)
|
||||
.with_plugin(plugins.clone())
|
||||
.try_build()
|
||||
.await
|
||||
.context(error::StartFrontendSnafu)?;
|
||||
);
|
||||
|
||||
plugins::setup_frontend_plugins_post_build(&mut plugins, &plugin_opts, &fe_instance)
|
||||
.await
|
||||
.context(error::StartFrontendSnafu)?;
|
||||
|
||||
let fe_instance = fe_instance
|
||||
.with_plugin(plugins.clone())
|
||||
.try_build()
|
||||
.await
|
||||
.context(error::StartFrontendSnafu)?;
|
||||
let fe_instance = Arc::new(fe_instance);
|
||||
|
||||
// set the frontend client for flownode
|
||||
@@ -959,7 +977,7 @@ mod tests {
|
||||
|
||||
let mut plugins = Plugins::new();
|
||||
plugins.insert(StandaloneFlag);
|
||||
plugins::setup_frontend_plugins(&mut plugins, &[], &fe_opts)
|
||||
plugins::setup_frontend_plugins_pre_build(&mut plugins, &[], &fe_opts, None)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user