diff --git a/src/common/license/src/license_manager.rs b/src/common/license/src/license_manager.rs index 2f82424330fb..1d8c4a19b265 100644 --- a/src/common/license/src/license_manager.rs +++ b/src/common/license/src/license_manager.rs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +use std::ops::Deref; use std::sync::Arc; use databend_common_base::base::GlobalInstance; @@ -58,21 +59,34 @@ pub trait LicenseManager: Sync + Send { fn get_storage_quota(&self, license_key: String) -> Result; } -pub struct LicenseManagerWrapper { - pub manager: Box, +pub struct LicenseManagerSwitch { + manager: Box, +} + +impl LicenseManagerSwitch { + pub fn create(manager: Box) -> LicenseManagerSwitch { + LicenseManagerSwitch { manager } + } + + pub fn instance() -> Arc { + GlobalInstance::get() + } +} + +impl Deref for LicenseManagerSwitch { + type Target = dyn LicenseManager; + + fn deref(&self) -> &Self::Target { + self.manager.as_ref() + } } -unsafe impl Send for LicenseManagerWrapper {} -unsafe impl Sync for LicenseManagerWrapper {} pub struct OssLicenseManager {} impl LicenseManager for OssLicenseManager { fn init(_tenant: String) -> Result<()> { let rm = OssLicenseManager {}; - let wrapper = LicenseManagerWrapper { - manager: Box::new(rm), - }; - GlobalInstance::set(Arc::new(wrapper)); + GlobalInstance::set(Arc::new(LicenseManagerSwitch::create(Box::new(rm)))); Ok(()) } @@ -97,7 +111,3 @@ impl LicenseManager for OssLicenseManager { Ok(StorageQuota::default()) } } - -pub fn get_license_manager() -> Arc { - GlobalInstance::get() -} diff --git a/src/query/ee/src/background_service/background_service_handler.rs b/src/query/ee/src/background_service/background_service_handler.rs index 6bd2df0ded50..06d9220c1e31 100644 --- a/src/query/ee/src/background_service/background_service_handler.rs +++ b/src/query/ee/src/background_service/background_service_handler.rs @@ -23,7 +23,7 @@ use databend_common_config::InnerConfig; use databend_common_exception::ErrorCode; use databend_common_exception::Result; use databend_common_license::license::Feature; -use databend_common_license::license_manager::get_license_manager; +use databend_common_license::license_manager::LicenseManagerSwitch; use databend_common_meta_api::BackgroundApi; use databend_common_meta_app::background::BackgroundJobIdent; use databend_common_meta_app::background::BackgroundJobInfo; @@ -275,7 +275,7 @@ impl RealBackgroundService { let settings = session.get_settings(); // check for valid license - get_license_manager().manager.check_enterprise_enabled( + LicenseManagerSwitch::instance().check_enterprise_enabled( unsafe { settings.get_enterprise_license().unwrap_or_default() }, Feature::BackgroundService, ) diff --git a/src/query/ee/src/license/license_mgr.rs b/src/query/ee/src/license/license_mgr.rs index b13e504a32af..66daeb09b98d 100644 --- a/src/query/ee/src/license/license_mgr.rs +++ b/src/query/ee/src/license/license_mgr.rs @@ -23,7 +23,7 @@ use databend_common_license::license::Feature; use databend_common_license::license::LicenseInfo; use databend_common_license::license::StorageQuota; use databend_common_license::license_manager::LicenseManager; -use databend_common_license::license_manager::LicenseManagerWrapper; +use databend_common_license::license_manager::LicenseManagerSwitch; use jwt_simple::algorithms::ES256PublicKey; use jwt_simple::claims::JWTClaims; use jwt_simple::prelude::Clock; @@ -49,10 +49,8 @@ impl LicenseManager for RealLicenseManager { cache: DashMap::new(), public_key: LICENSE_PUBLIC_KEY.to_string(), }; - let wrapper = LicenseManagerWrapper { - manager: Box::new(rm), - }; - GlobalInstance::set(Arc::new(wrapper)); + + GlobalInstance::set(Arc::new(LicenseManagerSwitch::create(Box::new(rm)))); Ok(()) } diff --git a/src/query/ee/src/storage_encryption/handler.rs b/src/query/ee/src/storage_encryption/handler.rs index c766a13cd519..9513e6294731 100644 --- a/src/query/ee/src/storage_encryption/handler.rs +++ b/src/query/ee/src/storage_encryption/handler.rs @@ -18,7 +18,7 @@ use databend_common_base::base::GlobalInstance; use databend_common_config::InnerConfig; use databend_common_exception::Result; use databend_common_license::license::Feature; -use databend_common_license::license_manager::get_license_manager; +use databend_common_license::license_manager::LicenseManagerSwitch; use databend_enterprise_storage_encryption::StorageEncryptionHandler; use databend_enterprise_storage_encryption::StorageEncryptionHandlerWrapper; use databend_query::sessions::SessionManager; @@ -40,7 +40,7 @@ impl StorageEncryptionHandler for RealStorageEncryptionHandler { let settings = session.get_settings(); // check for valid license - get_license_manager().manager.check_enterprise_enabled( + LicenseManagerSwitch::instance().check_enterprise_enabled( unsafe { settings.get_enterprise_license().unwrap_or_default() }, Feature::StorageEncryption, ) diff --git a/src/query/ee/src/storage_quota/handler.rs b/src/query/ee/src/storage_quota/handler.rs index e02fc882f4b4..92bf068fb5cf 100644 --- a/src/query/ee/src/storage_quota/handler.rs +++ b/src/query/ee/src/storage_quota/handler.rs @@ -18,7 +18,7 @@ use databend_common_base::base::GlobalInstance; use databend_common_config::InnerConfig; use databend_common_exception::Result; use databend_common_license::license::StorageQuota; -use databend_common_license::license_manager::get_license_manager; +use databend_common_license::license_manager::LicenseManagerSwitch; use databend_enterprise_storage_quota::StorageQuotaHandler; use databend_enterprise_storage_quota::StorageQuotaHandlerWrapper; use databend_query::sessions::SessionManager; @@ -39,8 +39,7 @@ impl StorageQuotaHandler for RealStorageQuotaHandler { let settings = session.get_settings(); // check for valid license - get_license_manager() - .manager + LicenseManagerSwitch::instance() .get_storage_quota(unsafe { settings.get_enterprise_license().unwrap_or_default() }) } } diff --git a/src/query/ee/src/test_kits/mock_services.rs b/src/query/ee/src/test_kits/mock_services.rs index 1b7169d23899..198581d52f51 100644 --- a/src/query/ee/src/test_kits/mock_services.rs +++ b/src/query/ee/src/test_kits/mock_services.rs @@ -17,7 +17,7 @@ use std::sync::Arc; use databend_common_base::base::GlobalInstance; use databend_common_config::InnerConfig; use databend_common_exception::Result; -use databend_common_license::license_manager::LicenseManagerWrapper; +use databend_common_license::license_manager::LicenseManagerSwitch; use crate::aggregating_index::RealAggregatingIndexHandler; use crate::data_mask::RealDatamaskHandler; @@ -32,10 +32,7 @@ impl MockServices { #[async_backtrace::framed] pub async fn init(cfg: &InnerConfig, public_key: String) -> Result<()> { let rm = RealLicenseManager::new(cfg.query.tenant_id.tenant_name().to_string(), public_key); - let wrapper = LicenseManagerWrapper { - manager: Box::new(rm), - }; - GlobalInstance::set(Arc::new(wrapper)); + GlobalInstance::set(Arc::new(LicenseManagerSwitch::create(Box::new(rm)))); RealVacuumHandler::init()?; RealAggregatingIndexHandler::init()?; RealDatamaskHandler::init()?; diff --git a/src/query/service/src/interpreters/common/stream.rs b/src/query/service/src/interpreters/common/stream.rs index 11e7819582c8..f2e952aa4cb8 100644 --- a/src/query/service/src/interpreters/common/stream.rs +++ b/src/query/service/src/interpreters/common/stream.rs @@ -19,7 +19,7 @@ use chrono::Utc; use databend_common_exception::ErrorCode; use databend_common_exception::Result; use databend_common_license::license::Feature; -use databend_common_license::license_manager::get_license_manager; +use databend_common_license::license_manager::LicenseManagerSwitch; use databend_common_meta_app::schema::TableInfo; use databend_common_meta_app::schema::UpdateStreamMetaReq; use databend_common_meta_app::schema::UpdateTableMetaReq; @@ -49,9 +49,7 @@ pub async fn dml_build_update_stream_req( return Ok(vec![]); } - let license_manager = get_license_manager(); - license_manager - .manager + LicenseManagerSwitch::instance() .check_enterprise_enabled(ctx.get_license_key(), Feature::Stream)?; let mut reqs = Vec::with_capacity(tables.len()); @@ -134,9 +132,7 @@ pub async fn query_build_update_stream_req( return Ok(None); } - let license_manager = get_license_manager(); - license_manager - .manager + LicenseManagerSwitch::instance() .check_enterprise_enabled(ctx.get_license_key(), Feature::Stream)?; let cap = streams.len(); diff --git a/src/query/service/src/interpreters/hook/vacuum_hook.rs b/src/query/service/src/interpreters/hook/vacuum_hook.rs index 4357027826fc..35d0682bba30 100644 --- a/src/query/service/src/interpreters/hook/vacuum_hook.rs +++ b/src/query/service/src/interpreters/hook/vacuum_hook.rs @@ -19,7 +19,7 @@ use databend_common_base::runtime::GlobalIORuntime; use databend_common_catalog::table_context::TableContext; use databend_common_exception::Result; use databend_common_license::license::Feature::Vacuum; -use databend_common_license::license_manager::get_license_manager; +use databend_common_license::license_manager::LicenseManagerSwitch; use databend_common_pipeline_core::query_spill_prefix; use databend_common_storage::DataOperator; use databend_enterprise_vacuum_handler::get_vacuum_handler; @@ -31,13 +31,11 @@ pub fn hook_vacuum_temp_files(query_ctx: &Arc) -> Result<()> { let tenant = query_ctx.get_tenant(); let settings = query_ctx.get_settings(); let spill_prefix = query_spill_prefix(tenant.tenant_name(), &query_ctx.get_id()); - let license_manager = get_license_manager(); let vacuum_limit = settings.get_max_vacuum_temp_files_after_query()?; // disable all s3 operator if vacuum limit = 0 if vacuum_limit != 0 - && license_manager - .manager + && LicenseManagerSwitch::instance() .check_enterprise_enabled(query_ctx.get_license_key(), Vacuum) .is_ok() { diff --git a/src/query/service/src/interpreters/interpreter_data_mask_create.rs b/src/query/service/src/interpreters/interpreter_data_mask_create.rs index 6d5fa733841e..0b0bb4bece45 100644 --- a/src/query/service/src/interpreters/interpreter_data_mask_create.rs +++ b/src/query/service/src/interpreters/interpreter_data_mask_create.rs @@ -16,7 +16,7 @@ use std::sync::Arc; use databend_common_exception::Result; use databend_common_license::license::Feature; -use databend_common_license::license_manager::get_license_manager; +use databend_common_license::license_manager::LicenseManagerSwitch; use databend_common_sql::plans::CreateDatamaskPolicyPlan; use databend_common_users::UserApiProvider; use databend_enterprise_data_mask_feature::get_datamask_handler; @@ -49,9 +49,7 @@ impl Interpreter for CreateDataMaskInterpreter { #[async_backtrace::framed] async fn execute2(&self) -> Result { - let license_manager = get_license_manager(); - license_manager - .manager + LicenseManagerSwitch::instance() .check_enterprise_enabled(self.ctx.get_license_key(), Feature::DataMask)?; let meta_api = UserApiProvider::instance().get_meta_store_client(); let handler = get_datamask_handler(); diff --git a/src/query/service/src/interpreters/interpreter_data_mask_desc.rs b/src/query/service/src/interpreters/interpreter_data_mask_desc.rs index da5a75790631..d048c18805fa 100644 --- a/src/query/service/src/interpreters/interpreter_data_mask_desc.rs +++ b/src/query/service/src/interpreters/interpreter_data_mask_desc.rs @@ -20,7 +20,7 @@ use databend_common_expression::types::StringType; use databend_common_expression::DataBlock; use databend_common_expression::FromData; use databend_common_license::license::Feature; -use databend_common_license::license_manager::get_license_manager; +use databend_common_license::license_manager::LicenseManagerSwitch; use databend_common_sql::plans::DescDatamaskPolicyPlan; use databend_common_users::UserApiProvider; use databend_enterprise_data_mask_feature::get_datamask_handler; @@ -54,9 +54,7 @@ impl Interpreter for DescDataMaskInterpreter { #[async_backtrace::framed] async fn execute2(&self) -> Result { - let license_manager = get_license_manager(); - license_manager - .manager + LicenseManagerSwitch::instance() .check_enterprise_enabled(self.ctx.get_license_key(), Feature::DataMask)?; let meta_api = UserApiProvider::instance().get_meta_store_client(); let handler = get_datamask_handler(); diff --git a/src/query/service/src/interpreters/interpreter_data_mask_drop.rs b/src/query/service/src/interpreters/interpreter_data_mask_drop.rs index 8a9a4587e941..2306c7e578db 100644 --- a/src/query/service/src/interpreters/interpreter_data_mask_drop.rs +++ b/src/query/service/src/interpreters/interpreter_data_mask_drop.rs @@ -16,7 +16,7 @@ use std::sync::Arc; use databend_common_exception::Result; use databend_common_license::license::Feature; -use databend_common_license::license_manager::get_license_manager; +use databend_common_license::license_manager::LicenseManagerSwitch; use databend_common_sql::plans::DropDatamaskPolicyPlan; use databend_common_users::UserApiProvider; use databend_enterprise_data_mask_feature::get_datamask_handler; @@ -49,9 +49,7 @@ impl Interpreter for DropDataMaskInterpreter { #[async_backtrace::framed] async fn execute2(&self) -> Result { - let license_manager = get_license_manager(); - license_manager - .manager + LicenseManagerSwitch::instance() .check_enterprise_enabled(self.ctx.get_license_key(), Feature::DataMask)?; let meta_api = UserApiProvider::instance().get_meta_store_client(); let handler = get_datamask_handler(); diff --git a/src/query/service/src/interpreters/interpreter_index_create.rs b/src/query/service/src/interpreters/interpreter_index_create.rs index c22d459e6cfa..5dbee26e6e70 100644 --- a/src/query/service/src/interpreters/interpreter_index_create.rs +++ b/src/query/service/src/interpreters/interpreter_index_create.rs @@ -18,7 +18,7 @@ use chrono::Utc; use databend_common_exception::ErrorCode; use databend_common_exception::Result; use databend_common_license::license::Feature; -use databend_common_license::license_manager::get_license_manager; +use databend_common_license::license_manager::LicenseManagerSwitch; use databend_common_meta_app::schema::CreateIndexReq; use databend_common_meta_app::schema::IndexMeta; use databend_common_meta_app::schema::IndexNameIdent; @@ -56,9 +56,7 @@ impl Interpreter for CreateIndexInterpreter { async fn execute2(&self) -> Result { let tenant = self.ctx.get_tenant(); - let license_manager = get_license_manager(); - license_manager - .manager + LicenseManagerSwitch::instance() .check_enterprise_enabled(self.ctx.get_license_key(), Feature::AggregateIndex)?; let index_name = self.plan.index_name.clone(); diff --git a/src/query/service/src/interpreters/interpreter_index_drop.rs b/src/query/service/src/interpreters/interpreter_index_drop.rs index 9f27d27aa860..cdf4eb4b843c 100644 --- a/src/query/service/src/interpreters/interpreter_index_drop.rs +++ b/src/query/service/src/interpreters/interpreter_index_drop.rs @@ -16,7 +16,7 @@ use std::sync::Arc; use databend_common_exception::Result; use databend_common_license::license::Feature; -use databend_common_license::license_manager::get_license_manager; +use databend_common_license::license_manager::LicenseManagerSwitch; use databend_common_meta_app::schema::DropIndexReq; use databend_common_meta_app::schema::IndexNameIdent; use databend_common_sql::plans::DropIndexPlan; @@ -52,9 +52,7 @@ impl Interpreter for DropIndexInterpreter { async fn execute2(&self) -> Result { let tenant = self.ctx.get_tenant(); - let license_manager = get_license_manager(); - license_manager - .manager + LicenseManagerSwitch::instance() .check_enterprise_enabled(self.ctx.get_license_key(), Feature::AggregateIndex)?; let index_name = self.plan.index.clone(); diff --git a/src/query/service/src/interpreters/interpreter_index_refresh.rs b/src/query/service/src/interpreters/interpreter_index_refresh.rs index 94022966a006..ee4147d52ee1 100644 --- a/src/query/service/src/interpreters/interpreter_index_refresh.rs +++ b/src/query/service/src/interpreters/interpreter_index_refresh.rs @@ -27,7 +27,7 @@ use databend_common_expression::TableField; use databend_common_expression::TableSchema; use databend_common_expression::BLOCK_NAME_COL_NAME; use databend_common_license::license::Feature; -use databend_common_license::license_manager::get_license_manager; +use databend_common_license::license_manager::LicenseManagerSwitch; use databend_common_meta_app::schema::IndexMeta; use databend_common_meta_app::schema::UpdateIndexReq; use databend_common_pipeline_core::ExecutionInfo; @@ -214,9 +214,7 @@ impl Interpreter for RefreshIndexInterpreter { #[async_backtrace::framed] async fn execute2(&self) -> Result { - let license_manager = get_license_manager(); - license_manager - .manager + LicenseManagerSwitch::instance() .check_enterprise_enabled(self.ctx.get_license_key(), Feature::AggregateIndex)?; let (mut query_plan, output_schema, select_columns) = match self.plan.query_plan.as_ref() { Plan::Query { diff --git a/src/query/service/src/interpreters/interpreter_stream_create.rs b/src/query/service/src/interpreters/interpreter_stream_create.rs index cc0da500020d..016e3d98f085 100644 --- a/src/query/service/src/interpreters/interpreter_stream_create.rs +++ b/src/query/service/src/interpreters/interpreter_stream_create.rs @@ -16,7 +16,7 @@ use std::sync::Arc; use databend_common_exception::Result; use databend_common_license::license::Feature; -use databend_common_license::license_manager::get_license_manager; +use databend_common_license::license_manager::LicenseManagerSwitch; use databend_common_sql::plans::CreateStreamPlan; use databend_common_storages_fuse::TableContext; use databend_enterprise_stream_handler::get_stream_handler; @@ -48,9 +48,7 @@ impl Interpreter for CreateStreamInterpreter { #[async_backtrace::framed] async fn execute2(&self) -> Result { - let license_manager = get_license_manager(); - license_manager - .manager + LicenseManagerSwitch::instance() .check_enterprise_enabled(self.ctx.get_license_key(), Feature::Stream)?; let handler = get_stream_handler(); diff --git a/src/query/service/src/interpreters/interpreter_stream_drop.rs b/src/query/service/src/interpreters/interpreter_stream_drop.rs index 11e88ce6f82c..a47a3f3572a1 100644 --- a/src/query/service/src/interpreters/interpreter_stream_drop.rs +++ b/src/query/service/src/interpreters/interpreter_stream_drop.rs @@ -16,7 +16,7 @@ use std::sync::Arc; use databend_common_exception::Result; use databend_common_license::license::Feature; -use databend_common_license::license_manager::get_license_manager; +use databend_common_license::license_manager::LicenseManagerSwitch; use databend_common_sql::plans::DropStreamPlan; use databend_enterprise_stream_handler::get_stream_handler; @@ -48,9 +48,7 @@ impl Interpreter for DropStreamInterpreter { #[async_backtrace::framed] async fn execute2(&self) -> Result { - let license_manager = get_license_manager(); - license_manager - .manager + LicenseManagerSwitch::instance() .check_enterprise_enabled(self.ctx.get_license_key(), Feature::Stream)?; let handler = get_stream_handler(); diff --git a/src/query/service/src/interpreters/interpreter_table_add_column.rs b/src/query/service/src/interpreters/interpreter_table_add_column.rs index b8a122fc56b2..e2493d9d3438 100644 --- a/src/query/service/src/interpreters/interpreter_table_add_column.rs +++ b/src/query/service/src/interpreters/interpreter_table_add_column.rs @@ -19,7 +19,7 @@ use databend_common_catalog::table::TableExt; use databend_common_exception::ErrorCode; use databend_common_exception::Result; use databend_common_license::license::Feature::ComputedColumn; -use databend_common_license::license_manager::get_license_manager; +use databend_common_license::license_manager::LicenseManagerSwitch; use databend_common_meta_app::schema::DatabaseType; use databend_common_meta_app::schema::TableMeta; use databend_common_meta_app::schema::UpdateTableMetaReq; @@ -94,9 +94,7 @@ impl Interpreter for AddTableColumnInterpreter { let mut new_table_meta = table_info.meta.clone(); let field = self.plan.field.clone(); if field.computed_expr().is_some() { - let license_manager = get_license_manager(); - license_manager - .manager + LicenseManagerSwitch::instance() .check_enterprise_enabled(self.ctx.get_license_key(), ComputedColumn)?; } diff --git a/src/query/service/src/interpreters/interpreter_table_create.rs b/src/query/service/src/interpreters/interpreter_table_create.rs index 34926d39b9ef..5f941e9318fd 100644 --- a/src/query/service/src/interpreters/interpreter_table_create.rs +++ b/src/query/service/src/interpreters/interpreter_table_create.rs @@ -31,7 +31,7 @@ use databend_common_io::constants::DEFAULT_MIN_TABLE_LEVEL_DATA_RETENTION_PERIOD use databend_common_license::license::Feature; use databend_common_license::license::Feature::ComputedColumn; use databend_common_license::license::Feature::InvertedIndex; -use databend_common_license::license_manager::get_license_manager; +use databend_common_license::license_manager::LicenseManagerSwitch; use databend_common_management::RoleApi; use databend_common_meta_app::principal::OwnershipObject; use databend_common_meta_app::schema::CommitTableMetaReq; @@ -122,15 +122,11 @@ impl Interpreter for CreateTableInterpreter { .iter() .any(|f| f.computed_expr().is_some()); if has_computed_column { - let license_manager = get_license_manager(); - license_manager - .manager + LicenseManagerSwitch::instance() .check_enterprise_enabled(self.ctx.get_license_key(), ComputedColumn)?; } if self.plan.inverted_indexes.is_some() { - let license_manager = get_license_manager(); - license_manager - .manager + LicenseManagerSwitch::instance() .check_enterprise_enabled(self.ctx.get_license_key(), InvertedIndex)?; } @@ -447,9 +443,7 @@ impl CreateTableInterpreter { } async fn build_attach_request(&self, storage_prefix: &str) -> Result { - let license_manager = get_license_manager(); - license_manager - .manager + LicenseManagerSwitch::instance() .check_enterprise_enabled(self.ctx.get_license_key(), Feature::AttacheTable)?; let handler = get_attach_table_handler(); diff --git a/src/query/service/src/interpreters/interpreter_table_index_create.rs b/src/query/service/src/interpreters/interpreter_table_index_create.rs index f50c99be85cc..75d5f40be5e2 100644 --- a/src/query/service/src/interpreters/interpreter_table_index_create.rs +++ b/src/query/service/src/interpreters/interpreter_table_index_create.rs @@ -16,7 +16,7 @@ use std::sync::Arc; use databend_common_exception::Result; use databend_common_license::license::Feature; -use databend_common_license::license_manager::get_license_manager; +use databend_common_license::license_manager::LicenseManagerSwitch; use databend_common_meta_app::schema::CreateTableIndexReq; use databend_common_sql::plans::CreateTableIndexPlan; use databend_common_storages_fuse::TableContext; @@ -49,9 +49,7 @@ impl Interpreter for CreateTableIndexInterpreter { #[async_backtrace::framed] async fn execute2(&self) -> Result { - let license_manager = get_license_manager(); - license_manager - .manager + LicenseManagerSwitch::instance() .check_enterprise_enabled(self.ctx.get_license_key(), Feature::InvertedIndex)?; let index_name = self.plan.index_name.clone(); diff --git a/src/query/service/src/interpreters/interpreter_table_index_drop.rs b/src/query/service/src/interpreters/interpreter_table_index_drop.rs index 1f8acea0ab3e..383c9db435fc 100644 --- a/src/query/service/src/interpreters/interpreter_table_index_drop.rs +++ b/src/query/service/src/interpreters/interpreter_table_index_drop.rs @@ -16,7 +16,7 @@ use std::sync::Arc; use databend_common_exception::Result; use databend_common_license::license::Feature; -use databend_common_license::license_manager::get_license_manager; +use databend_common_license::license_manager::LicenseManagerSwitch; use databend_common_meta_app::schema::DropTableIndexReq; use databend_common_sql::plans::DropTableIndexPlan; use databend_common_storages_fuse::TableContext; @@ -49,9 +49,7 @@ impl Interpreter for DropTableIndexInterpreter { #[async_backtrace::framed] async fn execute2(&self) -> Result { - let license_manager = get_license_manager(); - license_manager - .manager + LicenseManagerSwitch::instance() .check_enterprise_enabled(self.ctx.get_license_key(), Feature::InvertedIndex)?; let index_name = self.plan.index_name.clone(); diff --git a/src/query/service/src/interpreters/interpreter_table_index_refresh.rs b/src/query/service/src/interpreters/interpreter_table_index_refresh.rs index f178397d99ec..caa3001290c8 100644 --- a/src/query/service/src/interpreters/interpreter_table_index_refresh.rs +++ b/src/query/service/src/interpreters/interpreter_table_index_refresh.rs @@ -19,7 +19,7 @@ use databend_common_exception::ErrorCode; use databend_common_exception::Result; use databend_common_expression::TableSchemaRefExt; use databend_common_license::license::Feature; -use databend_common_license::license_manager::get_license_manager; +use databend_common_license::license_manager::LicenseManagerSwitch; use databend_common_sql::plans::RefreshTableIndexPlan; use databend_common_storages_fuse::FuseTable; use databend_common_storages_fuse::TableContext; @@ -51,9 +51,7 @@ impl Interpreter for RefreshTableIndexInterpreter { #[async_backtrace::framed] async fn execute2(&self) -> Result { - let license_manager = get_license_manager(); - license_manager - .manager + LicenseManagerSwitch::instance() .check_enterprise_enabled(self.ctx.get_license_key(), Feature::InvertedIndex)?; let table = self diff --git a/src/query/service/src/interpreters/interpreter_table_modify_column.rs b/src/query/service/src/interpreters/interpreter_table_modify_column.rs index 6cd7eb141e56..958988527b63 100644 --- a/src/query/service/src/interpreters/interpreter_table_modify_column.rs +++ b/src/query/service/src/interpreters/interpreter_table_modify_column.rs @@ -26,7 +26,7 @@ use databend_common_expression::TableField; use databend_common_expression::TableSchema; use databend_common_license::license::Feature::ComputedColumn; use databend_common_license::license::Feature::DataMask; -use databend_common_license::license_manager::get_license_manager; +use databend_common_license::license_manager::LicenseManagerSwitch; use databend_common_meta_app::schema::DatabaseType; use databend_common_meta_app::schema::SetTableColumnMaskPolicyAction; use databend_common_meta_app::schema::SetTableColumnMaskPolicyReq; @@ -75,9 +75,7 @@ impl ModifyTableColumnInterpreter { column: String, mask_name: String, ) -> Result { - let license_manager = get_license_manager(); - license_manager - .manager + LicenseManagerSwitch::instance() .check_enterprise_enabled(self.ctx.get_license_key(), DataMask)?; if table.is_temp() { @@ -418,9 +416,7 @@ impl ModifyTableColumnInterpreter { table: Arc, column: String, ) -> Result { - let license_manager = get_license_manager(); - license_manager - .manager + LicenseManagerSwitch::instance() .check_enterprise_enabled(self.ctx.get_license_key(), DataMask)?; let table_info = table.get_table_info(); @@ -456,9 +452,7 @@ impl ModifyTableColumnInterpreter { table_meta: TableMeta, column: String, ) -> Result { - let license_manager = get_license_manager(); - license_manager - .manager + LicenseManagerSwitch::instance() .check_enterprise_enabled(self.ctx.get_license_key(), ComputedColumn)?; let table_info = table.get_table_info(); diff --git a/src/query/service/src/interpreters/interpreter_table_vacuum.rs b/src/query/service/src/interpreters/interpreter_table_vacuum.rs index 74043239ba3f..8f4f9860865e 100644 --- a/src/query/service/src/interpreters/interpreter_table_vacuum.rs +++ b/src/query/service/src/interpreters/interpreter_table_vacuum.rs @@ -21,7 +21,7 @@ use databend_common_expression::types::UInt64Type; use databend_common_expression::DataBlock; use databend_common_expression::FromData; use databend_common_license::license::Feature::Vacuum; -use databend_common_license::license_manager::get_license_manager; +use databend_common_license::license_manager::LicenseManagerSwitch; use databend_common_sql::plans::VacuumTablePlan; use databend_common_storages_fuse::FuseTable; use databend_common_storages_fuse::FUSE_TBL_BLOCK_PREFIX; @@ -106,9 +106,7 @@ impl Interpreter for VacuumTableInterpreter { #[async_backtrace::framed] async fn execute2(&self) -> Result { - let license_manager = get_license_manager(); - license_manager - .manager + LicenseManagerSwitch::instance() .check_enterprise_enabled(self.ctx.get_license_key(), Vacuum)?; let catalog_name = self.plan.catalog.clone(); diff --git a/src/query/service/src/interpreters/interpreter_vacuum_drop_tables.rs b/src/query/service/src/interpreters/interpreter_vacuum_drop_tables.rs index 6b59eb3974a8..643122f0599c 100644 --- a/src/query/service/src/interpreters/interpreter_vacuum_drop_tables.rs +++ b/src/query/service/src/interpreters/interpreter_vacuum_drop_tables.rs @@ -24,7 +24,7 @@ use databend_common_expression::types::UInt64Type; use databend_common_expression::DataBlock; use databend_common_expression::FromData; use databend_common_license::license::Feature::Vacuum; -use databend_common_license::license_manager::get_license_manager; +use databend_common_license::license_manager::LicenseManagerSwitch; use databend_common_meta_app::schema::database_name_ident::DatabaseNameIdent; use databend_common_meta_app::schema::DroppedId; use databend_common_meta_app::schema::GcDroppedTableReq; @@ -112,9 +112,7 @@ impl Interpreter for VacuumDropTablesInterpreter { #[async_backtrace::framed] async fn execute2(&self) -> Result { - let license_manager = get_license_manager(); - license_manager - .manager + LicenseManagerSwitch::instance() .check_enterprise_enabled(self.ctx.get_license_key(), Vacuum)?; let ctx = self.ctx.clone(); diff --git a/src/query/service/src/interpreters/interpreter_vacuum_temporary_files.rs b/src/query/service/src/interpreters/interpreter_vacuum_temporary_files.rs index 208265bfff17..322958dd614d 100644 --- a/src/query/service/src/interpreters/interpreter_vacuum_temporary_files.rs +++ b/src/query/service/src/interpreters/interpreter_vacuum_temporary_files.rs @@ -19,7 +19,7 @@ use databend_common_expression::types::UInt64Type; use databend_common_expression::DataBlock; use databend_common_expression::FromData; use databend_common_license::license::Feature::Vacuum; -use databend_common_license::license_manager::get_license_manager; +use databend_common_license::license_manager::LicenseManagerSwitch; use databend_common_pipeline_core::query_spill_prefix; use databend_common_sql::plans::VacuumTemporaryFilesPlan; use databend_enterprise_vacuum_handler::get_vacuum_handler; @@ -52,9 +52,7 @@ impl Interpreter for VacuumTemporaryFilesInterpreter { #[async_backtrace::framed] async fn execute2(&self) -> Result { - let license_manager = get_license_manager(); - license_manager - .manager + LicenseManagerSwitch::instance() .check_enterprise_enabled(self.ctx.get_license_key(), Vacuum)?; let handler = get_vacuum_handler(); diff --git a/src/query/service/src/interpreters/interpreter_virtual_column_alter.rs b/src/query/service/src/interpreters/interpreter_virtual_column_alter.rs index c616112c6375..5584de3c6c77 100644 --- a/src/query/service/src/interpreters/interpreter_virtual_column_alter.rs +++ b/src/query/service/src/interpreters/interpreter_virtual_column_alter.rs @@ -17,7 +17,7 @@ use std::sync::Arc; use databend_common_catalog::table::TableExt; use databend_common_exception::Result; use databend_common_license::license::Feature::VirtualColumn; -use databend_common_license::license_manager::get_license_manager; +use databend_common_license::license_manager::LicenseManagerSwitch; use databend_common_meta_app::schema::UpdateVirtualColumnReq; use databend_common_meta_app::schema::VirtualColumnIdent; use databend_common_sql::plans::AlterVirtualColumnPlan; @@ -52,9 +52,7 @@ impl Interpreter for AlterVirtualColumnInterpreter { #[async_backtrace::framed] async fn execute2(&self) -> Result { let tenant = self.ctx.get_tenant(); - let license_manager = get_license_manager(); - license_manager - .manager + LicenseManagerSwitch::instance() .check_enterprise_enabled(self.ctx.get_license_key(), VirtualColumn)?; let catalog_name = self.plan.catalog.clone(); diff --git a/src/query/service/src/interpreters/interpreter_virtual_column_create.rs b/src/query/service/src/interpreters/interpreter_virtual_column_create.rs index 15c20a127529..5e673406a17d 100644 --- a/src/query/service/src/interpreters/interpreter_virtual_column_create.rs +++ b/src/query/service/src/interpreters/interpreter_virtual_column_create.rs @@ -17,7 +17,7 @@ use std::sync::Arc; use databend_common_catalog::table::TableExt; use databend_common_exception::Result; use databend_common_license::license::Feature::VirtualColumn; -use databend_common_license::license_manager::get_license_manager; +use databend_common_license::license_manager::LicenseManagerSwitch; use databend_common_meta_app::schema::CreateVirtualColumnReq; use databend_common_meta_app::schema::VirtualColumnIdent; use databend_common_sql::plans::CreateVirtualColumnPlan; @@ -52,9 +52,7 @@ impl Interpreter for CreateVirtualColumnInterpreter { #[async_backtrace::framed] async fn execute2(&self) -> Result { let tenant = self.ctx.get_tenant(); - let license_manager = get_license_manager(); - license_manager - .manager + LicenseManagerSwitch::instance() .check_enterprise_enabled(self.ctx.get_license_key(), VirtualColumn)?; let catalog_name = self.plan.catalog.clone(); diff --git a/src/query/service/src/interpreters/interpreter_virtual_column_drop.rs b/src/query/service/src/interpreters/interpreter_virtual_column_drop.rs index 6b29c8ab7380..668a26bc538b 100644 --- a/src/query/service/src/interpreters/interpreter_virtual_column_drop.rs +++ b/src/query/service/src/interpreters/interpreter_virtual_column_drop.rs @@ -17,7 +17,7 @@ use std::sync::Arc; use databend_common_catalog::table::TableExt; use databend_common_exception::Result; use databend_common_license::license::Feature::VirtualColumn; -use databend_common_license::license_manager::get_license_manager; +use databend_common_license::license_manager::LicenseManagerSwitch; use databend_common_meta_app::schema::DropVirtualColumnReq; use databend_common_meta_app::schema::VirtualColumnIdent; use databend_common_sql::plans::DropVirtualColumnPlan; @@ -52,9 +52,7 @@ impl Interpreter for DropVirtualColumnInterpreter { #[async_backtrace::framed] async fn execute2(&self) -> Result { let tenant = self.ctx.get_tenant(); - let license_manager = get_license_manager(); - license_manager - .manager + LicenseManagerSwitch::instance() .check_enterprise_enabled(self.ctx.get_license_key(), VirtualColumn)?; let catalog_name = self.plan.catalog.clone(); diff --git a/src/query/service/src/interpreters/interpreter_virtual_column_refresh.rs b/src/query/service/src/interpreters/interpreter_virtual_column_refresh.rs index 4865091f6cfa..89d8b420d00f 100644 --- a/src/query/service/src/interpreters/interpreter_virtual_column_refresh.rs +++ b/src/query/service/src/interpreters/interpreter_virtual_column_refresh.rs @@ -17,7 +17,7 @@ use std::sync::Arc; use databend_common_catalog::table::TableExt; use databend_common_exception::Result; use databend_common_license::license::Feature::VirtualColumn; -use databend_common_license::license_manager::get_license_manager; +use databend_common_license::license_manager::LicenseManagerSwitch; use databend_common_sql::plans::RefreshVirtualColumnPlan; use databend_common_storages_fuse::FuseTable; use databend_enterprise_virtual_column::get_virtual_column_handler; @@ -50,9 +50,7 @@ impl Interpreter for RefreshVirtualColumnInterpreter { #[async_backtrace::framed] async fn execute2(&self) -> Result { - let license_manager = get_license_manager(); - license_manager - .manager + LicenseManagerSwitch::instance() .check_enterprise_enabled(self.ctx.get_license_key(), VirtualColumn)?; let catalog_name = self.plan.catalog.clone(); diff --git a/src/query/service/src/pipelines/processors/transforms/transform_add_computed_columns.rs b/src/query/service/src/pipelines/processors/transforms/transform_add_computed_columns.rs index 19e2afb17f38..e9ea3b6fa7db 100644 --- a/src/query/service/src/pipelines/processors/transforms/transform_add_computed_columns.rs +++ b/src/query/service/src/pipelines/processors/transforms/transform_add_computed_columns.rs @@ -24,7 +24,7 @@ use databend_common_expression::DataSchemaRef; use databend_common_expression::Expr; use databend_common_functions::BUILTIN_FUNCTIONS; use databend_common_license::license::Feature::ComputedColumn; -use databend_common_license::license_manager::get_license_manager; +use databend_common_license::license_manager::LicenseManagerSwitch; use databend_common_pipeline_transforms::processors::Transform; use databend_common_sql::evaluator::BlockOperator; use databend_common_sql::evaluator::CompoundBlockOperator; @@ -45,9 +45,7 @@ where Self: Transform input_schema: DataSchemaRef, output_schema: DataSchemaRef, ) -> Result { - let license_manager = get_license_manager(); - license_manager - .manager + LicenseManagerSwitch::instance() .check_enterprise_enabled(ctx.get_license_key(), ComputedColumn)?; let mut exprs = Vec::with_capacity(output_schema.fields().len()); diff --git a/src/query/service/src/table_functions/others/license_info.rs b/src/query/service/src/table_functions/others/license_info.rs index 9307e233b27a..b4a986ad11ec 100644 --- a/src/query/service/src/table_functions/others/license_info.rs +++ b/src/query/service/src/table_functions/others/license_info.rs @@ -39,7 +39,7 @@ use databend_common_expression::TableSchemaRefExt; use databend_common_expression::Value; use databend_common_license::license::Feature; use databend_common_license::license::LicenseInfo; -use databend_common_license::license_manager::get_license_manager; +use databend_common_license::license_manager::LicenseManagerSwitch; use databend_common_meta_app::schema::TableIdent; use databend_common_meta_app::schema::TableInfo; use databend_common_meta_app::schema::TableMeta; @@ -227,12 +227,10 @@ impl AsyncSource for LicenseInfoSource { )? }; - get_license_manager() - .manager + LicenseManagerSwitch::instance() .check_enterprise_enabled(license.clone(), Feature::LicenseInfo)?; - let info = get_license_manager() - .manager + let info = LicenseManagerSwitch::instance() .parse_license(license.as_str()) .map_err_to_code(ErrorCode::LicenseKeyInvalid, || { format!( diff --git a/src/query/service/src/table_functions/others/suggested_background_tasks.rs b/src/query/service/src/table_functions/others/suggested_background_tasks.rs index c6a3cf8529e2..3aa67581400d 100644 --- a/src/query/service/src/table_functions/others/suggested_background_tasks.rs +++ b/src/query/service/src/table_functions/others/suggested_background_tasks.rs @@ -36,7 +36,7 @@ use databend_common_expression::TableField; use databend_common_expression::TableSchemaRef; use databend_common_expression::TableSchemaRefExt; use databend_common_license::license::Feature; -use databend_common_license::license_manager::get_license_manager; +use databend_common_license::license_manager::LicenseManagerSwitch; use databend_common_meta_app::schema::TableIdent; use databend_common_meta_app::schema::TableInfo; use databend_common_meta_app::schema::TableMeta; @@ -249,9 +249,7 @@ impl AsyncSource for SuggestedBackgroundTasksSource { self.done = true; let ctx = self.ctx.as_any().downcast_ref::().unwrap(); - let license_mgr = get_license_manager(); - license_mgr - .manager + LicenseManagerSwitch::instance() .check_enterprise_enabled(ctx.get_license_key(), Feature::BackgroundService)?; let suggestions = Self::all_suggestions(Arc::new(ctx.clone())).await?; diff --git a/src/query/sql/src/executor/table_read_plan.rs b/src/query/sql/src/executor/table_read_plan.rs index 13a70c4600e8..1b3c06a57751 100644 --- a/src/query/sql/src/executor/table_read_plan.rs +++ b/src/query/sql/src/executor/table_read_plan.rs @@ -34,7 +34,7 @@ use databend_common_expression::RemoteExpr; use databend_common_expression::Scalar; use databend_common_expression::TableField; use databend_common_license::license::Feature::DataMask; -use databend_common_license::license_manager::get_license_manager; +use databend_common_license::license_manager::LicenseManagerSwitch; use databend_common_meta_app::tenant::Tenant; use databend_common_settings::Settings; use databend_common_users::UserApiProvider; @@ -173,11 +173,10 @@ impl ToReadDataSourcePlan for dyn Table { let tenant = ctx.get_tenant(); if let Some(column_mask_policy) = &table_meta.column_mask_policy { - let license_manager = get_license_manager(); - let ret = license_manager - .manager - .check_enterprise_enabled(ctx.get_license_key(), DataMask); - if ret.is_err() { + if LicenseManagerSwitch::instance() + .check_enterprise_enabled(ctx.get_license_key(), DataMask) + .is_err() + { None } else { let mut mask_policy_map = BTreeMap::new(); diff --git a/src/query/sql/src/planner/binder/binder.rs b/src/query/sql/src/planner/binder/binder.rs index fc80aa40f37c..72d5ea28a2ca 100644 --- a/src/query/sql/src/planner/binder/binder.rs +++ b/src/query/sql/src/planner/binder/binder.rs @@ -37,7 +37,7 @@ use databend_common_expression::SEARCH_MATCHED_COLUMN_ID; use databend_common_expression::SEARCH_SCORE_COLUMN_ID; use databend_common_functions::BUILTIN_FUNCTIONS; use databend_common_license::license::Feature; -use databend_common_license::license_manager::get_license_manager; +use databend_common_license::license_manager::LicenseManagerSwitch; use databend_common_meta_app::principal::FileFormatOptionsReader; use databend_common_meta_app::principal::FileFormatParams; use databend_common_meta_app::principal::StageFileFormatType; @@ -922,9 +922,7 @@ impl<'a> Binder { } // check inverted index license if !bind_context.inverted_index_map.is_empty() { - let license_manager = get_license_manager(); - license_manager - .manager + LicenseManagerSwitch::instance() .check_enterprise_enabled(self.ctx.get_license_key(), Feature::InvertedIndex)?; } let bound_internal_columns = &bind_context.bound_internal_columns; diff --git a/src/query/sql/src/planner/binder/ddl/index.rs b/src/query/sql/src/planner/binder/ddl/index.rs index 5c5c8c0576de..55a9156c1ee8 100644 --- a/src/query/sql/src/planner/binder/ddl/index.rs +++ b/src/query/sql/src/planner/binder/ddl/index.rs @@ -37,7 +37,7 @@ use databend_common_expression::ColumnId; use databend_common_expression::TableDataType; use databend_common_expression::TableSchemaRef; use databend_common_license::license::Feature::AggregateIndex; -use databend_common_license::license_manager::get_license_manager; +use databend_common_license::license_manager::LicenseManagerSwitch; use databend_common_meta_app::schema::GetIndexReq; use databend_common_meta_app::schema::IndexMeta; use databend_common_meta_app::schema::IndexNameIdent; @@ -149,9 +149,8 @@ impl Binder { && table.support_index() && !matches!(table.engine(), "VIEW" | "STREAM") { - let license_manager = get_license_manager(); - if license_manager - .manager + #[allow(clippy::collapsible_if)] + if LicenseManagerSwitch::instance() .check_enterprise_enabled(self.ctx.get_license_key(), AggregateIndex) .is_ok() { diff --git a/src/query/sql/src/planner/binder/ddl/stream.rs b/src/query/sql/src/planner/binder/ddl/stream.rs index 26781afb2c0f..a18914afd761 100644 --- a/src/query/sql/src/planner/binder/ddl/stream.rs +++ b/src/query/sql/src/planner/binder/ddl/stream.rs @@ -19,7 +19,7 @@ use databend_common_ast::ast::ShowLimit; use databend_common_ast::ast::ShowStreamsStmt; use databend_common_exception::Result; use databend_common_license::license::Feature; -use databend_common_license::license_manager::get_license_manager; +use databend_common_license::license_manager::LicenseManagerSwitch; use log::debug; use crate::binder::Binder; @@ -114,9 +114,7 @@ impl Binder { bind_context: &mut BindContext, stmt: &ShowStreamsStmt, ) -> Result { - let license_manager = get_license_manager(); - license_manager - .manager + LicenseManagerSwitch::instance() .check_enterprise_enabled(self.ctx.get_license_key(), Feature::Stream)?; let ShowStreamsStmt { @@ -190,9 +188,7 @@ impl Binder { bind_context: &mut BindContext, stmt: &DescribeStreamStmt, ) -> Result { - let license_manager = get_license_manager(); - license_manager - .manager + LicenseManagerSwitch::instance() .check_enterprise_enabled(self.ctx.get_license_key(), Feature::Stream)?; let DescribeStreamStmt { diff --git a/src/query/sql/src/planner/semantic/virtual_column_rewriter.rs b/src/query/sql/src/planner/semantic/virtual_column_rewriter.rs index 7a9cec3109be..67e9412be466 100644 --- a/src/query/sql/src/planner/semantic/virtual_column_rewriter.rs +++ b/src/query/sql/src/planner/semantic/virtual_column_rewriter.rs @@ -23,7 +23,7 @@ use databend_common_expression::types::DataType; use databend_common_expression::Scalar; use databend_common_expression::TableDataType; use databend_common_license::license::Feature::VirtualColumn; -use databend_common_license::license_manager::get_license_manager; +use databend_common_license::license_manager::LicenseManagerSwitch; use databend_common_meta_app::schema::ListVirtualColumnsReq; use jsonb::keypath::parse_key_paths; use jsonb::keypath::KeyPath; @@ -66,9 +66,7 @@ impl VirtualColumnRewriter { } pub(crate) fn rewrite(&mut self, s_expr: &SExpr) -> Result { - let license_manager = get_license_manager(); - if license_manager - .manager + if LicenseManagerSwitch::instance() .check_enterprise_enabled(self.ctx.get_license_key(), VirtualColumn) .is_err() { diff --git a/src/query/storages/fuse/src/table_functions/fuse_amend.rs b/src/query/storages/fuse/src/table_functions/fuse_amend.rs index 9b9843944d9d..955d780c844d 100644 --- a/src/query/storages/fuse/src/table_functions/fuse_amend.rs +++ b/src/query/storages/fuse/src/table_functions/fuse_amend.rs @@ -26,7 +26,7 @@ use databend_common_expression::TableField; use databend_common_expression::TableSchemaRef; use databend_common_expression::TableSchemaRefExt; use databend_common_license::license::Feature; -use databend_common_license::license_manager::get_license_manager; +use databend_common_license::license_manager::LicenseManagerSwitch; use databend_enterprise_fail_safe::get_fail_safe_handler; use databend_enterprise_fail_safe::FailSafeHandlerWrapper; @@ -71,9 +71,7 @@ impl SimpleTableFunc for FuseAmendTable { ctx: &Arc, _plan: &DataSourcePlan, ) -> Result> { - let license_manager = get_license_manager(); - license_manager - .manager + LicenseManagerSwitch::instance() .check_enterprise_enabled(ctx.get_license_key(), Feature::AmendTable)?; let tenant_id = ctx.get_tenant(); let tbl = ctx