Skip to content

Commit 0204779

Browse files
authored
feat: add some configurable points (#7227)
* feat: enhance extension * fix: cr * move information schema table factories trait to standalone * fix: self cr * remove extension factory * refactor * remove extension filed from greptime options struct * refactor * minor refactor * fix: cargo check * fix: clippy * fix: license check * feat: enhance grpc and http configurator in servers crate * grpc builder configurator * remove unused file * complete the remaining expansion points. * fix: self-cr * rename * fix: typo
1 parent afefc0c commit 0204779

File tree

17 files changed

+254
-169
lines changed

17 files changed

+254
-169
lines changed

src/catalog/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ edition.workspace = true
55
license.workspace = true
66

77
[features]
8-
enterprise = []
98
testing = []
109

1110
[lints]

src/catalog/src/kvbackend.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
pub use client::{CachedKvBackend, CachedKvBackendBuilder, MetaKvBackend};
16-
1715
mod builder;
1816
mod client;
1917
mod manager;
2018
mod table_cache;
2119

22-
pub use builder::KvBackendCatalogManagerBuilder;
20+
pub use builder::{
21+
CatalogManagerConfigurator, CatalogManagerConfiguratorRef, KvBackendCatalogManagerBuilder,
22+
};
23+
pub use client::{CachedKvBackend, CachedKvBackendBuilder, MetaKvBackend};
2324
pub use manager::KvBackendCatalogManager;
2425
pub use table_cache::{TableCache, TableCacheRef, new_table_cache};

src/catalog/src/kvbackend/builder.rs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
use std::collections::HashMap;
1516
use std::sync::Arc;
1617

1718
use common_catalog::consts::DEFAULT_CATALOG_NAME;
19+
use common_error::ext::BoxedError;
1820
use common_meta::cache::LayeredCacheRegistryRef;
1921
use common_meta::key::TableMetadataManager;
2022
use common_meta::key::flow::FlowMetadataManager;
@@ -23,24 +25,34 @@ use common_procedure::ProcedureManagerRef;
2325
use moka::sync::Cache;
2426
use partition::manager::PartitionRuleManager;
2527

26-
#[cfg(feature = "enterprise")]
27-
use crate::information_schema::InformationSchemaTableFactoryRef;
28-
use crate::information_schema::{InformationExtensionRef, InformationSchemaProvider};
28+
use crate::information_schema::{
29+
InformationExtensionRef, InformationSchemaProvider, InformationSchemaTableFactoryRef,
30+
};
2931
use crate::kvbackend::KvBackendCatalogManager;
3032
use crate::kvbackend::manager::{CATALOG_CACHE_MAX_CAPACITY, SystemCatalog};
3133
use crate::process_manager::ProcessManagerRef;
3234
use crate::system_schema::numbers_table_provider::NumbersTableProvider;
3335
use crate::system_schema::pg_catalog::PGCatalogProvider;
3436

37+
/// The configurator that customizes or enhances the [`KvBackendCatalogManagerBuilder`].
38+
#[async_trait::async_trait]
39+
pub trait CatalogManagerConfigurator<C>: Send + Sync {
40+
async fn configure(
41+
&self,
42+
builder: KvBackendCatalogManagerBuilder,
43+
ctx: C,
44+
) -> std::result::Result<KvBackendCatalogManagerBuilder, BoxedError>;
45+
}
46+
47+
pub type CatalogManagerConfiguratorRef<C> = Arc<dyn CatalogManagerConfigurator<C>>;
48+
3549
pub struct KvBackendCatalogManagerBuilder {
3650
information_extension: InformationExtensionRef,
3751
backend: KvBackendRef,
3852
cache_registry: LayeredCacheRegistryRef,
3953
procedure_manager: Option<ProcedureManagerRef>,
4054
process_manager: Option<ProcessManagerRef>,
41-
#[cfg(feature = "enterprise")]
42-
extra_information_table_factories:
43-
std::collections::HashMap<String, InformationSchemaTableFactoryRef>,
55+
extra_information_table_factories: HashMap<String, InformationSchemaTableFactoryRef>,
4456
}
4557

4658
impl KvBackendCatalogManagerBuilder {
@@ -55,8 +67,7 @@ impl KvBackendCatalogManagerBuilder {
5567
cache_registry,
5668
procedure_manager: None,
5769
process_manager: None,
58-
#[cfg(feature = "enterprise")]
59-
extra_information_table_factories: std::collections::HashMap::new(),
70+
extra_information_table_factories: HashMap::new(),
6071
}
6172
}
6273

@@ -71,10 +82,9 @@ impl KvBackendCatalogManagerBuilder {
7182
}
7283

7384
/// Sets the extra information tables.
74-
#[cfg(feature = "enterprise")]
7585
pub fn with_extra_information_table_factories(
7686
mut self,
77-
factories: std::collections::HashMap<String, InformationSchemaTableFactoryRef>,
87+
factories: HashMap<String, InformationSchemaTableFactoryRef>,
7888
) -> Self {
7989
self.extra_information_table_factories = factories;
8090
self
@@ -87,7 +97,6 @@ impl KvBackendCatalogManagerBuilder {
8797
cache_registry,
8898
procedure_manager,
8999
process_manager,
90-
#[cfg(feature = "enterprise")]
91100
extra_information_table_factories,
92101
} = self;
93102
Arc::new_cyclic(|me| KvBackendCatalogManager {
@@ -111,7 +120,6 @@ impl KvBackendCatalogManagerBuilder {
111120
process_manager.clone(),
112121
backend.clone(),
113122
);
114-
#[cfg(feature = "enterprise")]
115123
let provider = provider
116124
.with_extra_table_factories(extra_information_table_factories.clone());
117125
Arc::new(provider)
@@ -123,7 +131,6 @@ impl KvBackendCatalogManagerBuilder {
123131
numbers_table_provider: NumbersTableProvider,
124132
backend,
125133
process_manager,
126-
#[cfg(feature = "enterprise")]
127134
extra_information_table_factories,
128135
},
129136
cache_registry,

src/catalog/src/kvbackend/manager.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ use crate::error::{
5353
CacheNotFoundSnafu, GetTableCacheSnafu, InvalidTableInfoInCatalogSnafu, ListCatalogsSnafu,
5454
ListSchemasSnafu, ListTablesSnafu, Result, TableMetadataManagerSnafu,
5555
};
56-
#[cfg(feature = "enterprise")]
57-
use crate::information_schema::InformationSchemaTableFactoryRef;
58-
use crate::information_schema::{InformationExtensionRef, InformationSchemaProvider};
56+
use crate::information_schema::{
57+
InformationExtensionRef, InformationSchemaProvider, InformationSchemaTableFactoryRef,
58+
};
5959
use crate::kvbackend::TableCacheRef;
6060
use crate::process_manager::ProcessManagerRef;
6161
use crate::system_schema::SystemSchemaProvider;
@@ -557,7 +557,6 @@ pub(super) struct SystemCatalog {
557557
pub(super) numbers_table_provider: NumbersTableProvider,
558558
pub(super) backend: KvBackendRef,
559559
pub(super) process_manager: Option<ProcessManagerRef>,
560-
#[cfg(feature = "enterprise")]
561560
pub(super) extra_information_table_factories:
562561
std::collections::HashMap<String, InformationSchemaTableFactoryRef>,
563562
}
@@ -628,7 +627,6 @@ impl SystemCatalog {
628627
self.process_manager.clone(),
629628
self.backend.clone(),
630629
);
631-
#[cfg(feature = "enterprise")]
632630
let provider = provider
633631
.with_extra_table_factories(self.extra_information_table_factories.clone());
634632
Arc::new(provider)

src/catalog/src/system_schema/information_schema.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ macro_rules! setup_memory_table {
117117
};
118118
}
119119

120-
#[cfg(feature = "enterprise")]
121120
pub struct MakeInformationTableRequest {
122121
pub catalog_name: String,
123122
pub catalog_manager: Weak<dyn CatalogManager>,
@@ -128,12 +127,10 @@ pub struct MakeInformationTableRequest {
128127
///
129128
/// This trait allows for extensibility of the information schema by providing
130129
/// a way to dynamically create custom information schema tables.
131-
#[cfg(feature = "enterprise")]
132130
pub trait InformationSchemaTableFactory {
133131
fn make_information_table(&self, req: MakeInformationTableRequest) -> SystemTableRef;
134132
}
135133

136-
#[cfg(feature = "enterprise")]
137134
pub type InformationSchemaTableFactoryRef = Arc<dyn InformationSchemaTableFactory + Send + Sync>;
138135

139136
/// The `information_schema` tables info provider.
@@ -143,9 +140,7 @@ pub struct InformationSchemaProvider {
143140
process_manager: Option<ProcessManagerRef>,
144141
flow_metadata_manager: Arc<FlowMetadataManager>,
145142
tables: HashMap<String, TableRef>,
146-
#[allow(dead_code)]
147143
kv_backend: KvBackendRef,
148-
#[cfg(feature = "enterprise")]
149144
extra_table_factories: HashMap<String, InformationSchemaTableFactoryRef>,
150145
}
151146

@@ -166,7 +161,6 @@ impl SystemSchemaProviderInner for InformationSchemaProvider {
166161
}
167162

168163
fn system_table(&self, name: &str) -> Option<SystemTableRef> {
169-
#[cfg(feature = "enterprise")]
170164
if let Some(factory) = self.extra_table_factories.get(name) {
171165
let req = MakeInformationTableRequest {
172166
catalog_name: self.catalog_name.clone(),
@@ -281,7 +275,6 @@ impl InformationSchemaProvider {
281275
process_manager,
282276
tables: HashMap::new(),
283277
kv_backend,
284-
#[cfg(feature = "enterprise")]
285278
extra_table_factories: HashMap::new(),
286279
};
287280

@@ -290,7 +283,6 @@ impl InformationSchemaProvider {
290283
provider
291284
}
292285

293-
#[cfg(feature = "enterprise")]
294286
pub(crate) fn with_extra_table_factories(
295287
mut self,
296288
factories: HashMap<String, InformationSchemaTableFactoryRef>,
@@ -358,7 +350,6 @@ impl InformationSchemaProvider {
358350
if let Some(process_list) = self.build_table(PROCESS_LIST) {
359351
tables.insert(PROCESS_LIST.to_string(), process_list);
360352
}
361-
#[cfg(feature = "enterprise")]
362353
for name in self.extra_table_factories.keys() {
363354
tables.insert(name.clone(), self.build_table(name).expect(name));
364355
}

src/cmd/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ default = [
1616
"meta-srv/pg_kvbackend",
1717
"meta-srv/mysql_kvbackend",
1818
]
19-
enterprise = ["common-meta/enterprise", "frontend/enterprise", "meta-srv/enterprise", "catalog/enterprise"]
19+
enterprise = ["common-meta/enterprise", "frontend/enterprise", "meta-srv/enterprise"]
2020
tokio-console = ["common-telemetry/tokio-console"]
2121

2222
[lints]

src/cmd/src/flownode.rs

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,28 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
use std::fmt::Debug;
1516
use std::path::Path;
1617
use std::sync::Arc;
1718
use std::time::Duration;
1819

1920
use cache::{build_fundamental_cache_registry, with_default_composite_cache_registry};
21+
use catalog::CatalogManagerRef;
2022
use catalog::information_extension::DistributedInformationExtension;
2123
use catalog::kvbackend::{CachedKvBackendBuilder, KvBackendCatalogManagerBuilder, MetaKvBackend};
2224
use clap::Parser;
2325
use client::client_manager::NodeClients;
2426
use common_base::Plugins;
2527
use common_config::{Configurable, DEFAULT_DATA_HOME};
2628
use common_grpc::channel_manager::ChannelConfig;
29+
use common_meta::FlownodeId;
2730
use common_meta::cache::{CacheRegistryBuilder, LayeredCacheRegistryBuilder};
2831
use common_meta::heartbeat::handler::HandlerGroupExecutor;
2932
use common_meta::heartbeat::handler::invalidate_table_cache::InvalidateCacheHandler;
3033
use common_meta::heartbeat::handler::parse_mailbox_message::ParseMailboxMessageHandler;
3134
use common_meta::key::TableMetadataManager;
3235
use common_meta::key::flow::FlowMetadataManager;
36+
use common_meta::kv_backend::KvBackendRef;
3337
use common_stat::ResourceStatImpl;
3438
use common_telemetry::info;
3539
use common_telemetry::logging::{DEFAULT_LOGGING_DIR, TracingOptions};
@@ -39,12 +43,13 @@ use flow::{
3943
get_flow_auth_options,
4044
};
4145
use meta_client::{MetaClientOptions, MetaClientType};
46+
use servers::configurator::GrpcBuilderConfiguratorRef;
4247
use snafu::{OptionExt, ResultExt, ensure};
4348
use tracing_appender::non_blocking::WorkerGuard;
4449

4550
use crate::error::{
4651
BuildCacheRegistrySnafu, InitMetadataSnafu, LoadLayeredConfigSnafu, MetaClientInitSnafu,
47-
MissingConfigSnafu, Result, ShutdownFlownodeSnafu, StartFlownodeSnafu,
52+
MissingConfigSnafu, OtherSnafu, Result, ShutdownFlownodeSnafu, StartFlownodeSnafu,
4853
};
4954
use crate::options::{GlobalOptions, GreptimeOptions};
5055
use crate::{App, create_resource_limit_metrics, log_versions, maybe_activate_heap_profile};
@@ -55,33 +60,14 @@ type FlownodeOptions = GreptimeOptions<flow::FlownodeOptions>;
5560

5661
pub struct Instance {
5762
flownode: FlownodeInstance,
58-
59-
// The components of flownode, which make it easier to expand based
60-
// on the components.
61-
#[cfg(feature = "enterprise")]
62-
components: Components,
63-
6463
// Keep the logging guard to prevent the worker from being dropped.
6564
_guard: Vec<WorkerGuard>,
6665
}
6766

68-
#[cfg(feature = "enterprise")]
69-
pub struct Components {
70-
pub catalog_manager: catalog::CatalogManagerRef,
71-
pub fe_client: Arc<FrontendClient>,
72-
pub kv_backend: common_meta::kv_backend::KvBackendRef,
73-
}
74-
7567
impl Instance {
76-
pub fn new(
77-
flownode: FlownodeInstance,
78-
#[cfg(feature = "enterprise")] components: Components,
79-
guard: Vec<WorkerGuard>,
80-
) -> Self {
68+
pub fn new(flownode: FlownodeInstance, guard: Vec<WorkerGuard>) -> Self {
8169
Self {
8270
flownode,
83-
#[cfg(feature = "enterprise")]
84-
components,
8571
_guard: guard,
8672
}
8773
}
@@ -94,11 +80,6 @@ impl Instance {
9480
pub fn flownode_mut(&mut self) -> &mut FlownodeInstance {
9581
&mut self.flownode
9682
}
97-
98-
#[cfg(feature = "enterprise")]
99-
pub fn components(&self) -> &Components {
100-
&self.components
101-
}
10283
}
10384

10485
#[async_trait::async_trait]
@@ -396,7 +377,7 @@ impl StartCommand {
396377
let frontend_client = Arc::new(frontend_client);
397378
let flownode_builder = FlownodeBuilder::new(
398379
opts.clone(),
399-
plugins,
380+
plugins.clone(),
400381
table_metadata_manager,
401382
catalog_manager.clone(),
402383
flow_metadata_manager,
@@ -405,8 +386,29 @@ impl StartCommand {
405386
.with_heartbeat_task(heartbeat_task);
406387

407388
let mut flownode = flownode_builder.build().await.context(StartFlownodeSnafu)?;
389+
390+
let builder =
391+
FlownodeServiceBuilder::grpc_server_builder(&opts, flownode.flownode_server());
392+
let builder = if let Some(configurator) =
393+
plugins.get::<GrpcBuilderConfiguratorRef<GrpcConfigureContext>>()
394+
{
395+
let context = GrpcConfigureContext {
396+
kv_backend: cached_meta_backend.clone(),
397+
fe_client: frontend_client.clone(),
398+
flownode_id: member_id,
399+
catalog_manager: catalog_manager.clone(),
400+
};
401+
configurator
402+
.configure(builder, context)
403+
.await
404+
.context(OtherSnafu)?
405+
} else {
406+
builder
407+
};
408+
let grpc_server = builder.build();
409+
408410
let services = FlownodeServiceBuilder::new(&opts)
409-
.with_default_grpc_server(flownode.flownode_server())
411+
.with_grpc_server(grpc_server)
410412
.enable_http_service()
411413
.build()
412414
.context(StartFlownodeSnafu)?;
@@ -430,16 +432,14 @@ impl StartCommand {
430432
.set_frontend_invoker(invoker)
431433
.await;
432434

433-
#[cfg(feature = "enterprise")]
434-
let components = Components {
435-
catalog_manager: catalog_manager.clone(),
436-
fe_client: frontend_client,
437-
kv_backend: cached_meta_backend,
438-
};
439-
440-
#[cfg(not(feature = "enterprise"))]
441-
return Ok(Instance::new(flownode, guard));
442-
#[cfg(feature = "enterprise")]
443-
Ok(Instance::new(flownode, components, guard))
435+
Ok(Instance::new(flownode, guard))
444436
}
445437
}
438+
439+
/// The context for [`GrpcBuilderConfiguratorRef`] in flownode.
440+
pub struct GrpcConfigureContext {
441+
pub kv_backend: KvBackendRef,
442+
pub fe_client: Arc<FrontendClient>,
443+
pub flownode_id: FlownodeId,
444+
pub catalog_manager: CatalogManagerRef,
445+
}

0 commit comments

Comments
 (0)