Skip to content

Commit 198a47e

Browse files
committed
- SystemPlan is only produced by the SQL binder and that binder always runs in a QueryContext whose tenant is fixed to GlobalConfig::instance().query.tenant_id unless the server
is in management mode. When management mode is enabled, ManagementModeAccess blocks Plan::System altogether so no user query can ever build a system action with a different tenant. As a result, the tenant field inside SystemPlan was guaranteed to equal the global config tenant and provided no extra routing information anywhere else in the stack. - All flight actions (system_action, kill_query, set_priority, truncate_table) run inside a query server whose GlobalConfig already defines a single tenant. There is no supported deployment where a single query process serves multiple tenants concurrently over flight RPC. Therefore, the create_session helper in src/query/service/src/servers/flight/v1/actions/mod.rs can safely derive the tenant from GlobalConfig every time; the optional parameter was never used to switch context to another tenant. - Because both ends (planner and flight handler) collapse to the same static tenant, the tenant field in SystemPlan and the Option<Tenant> parameter to create_session were redundant wiring that couldn't change behavior. Removing them simplifies the code without affecting any observable semantics and makes it clear that system/flight actions always run under the server's configured tenant.
1 parent bf7eb5e commit 198a47e

File tree

8 files changed

+8
-14
lines changed

8 files changed

+8
-14
lines changed

src/meta/app/src/tenant/tenant.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::app_error::TenantIsEmpty;
2424
/// Tenant is not stored directly in meta-store.
2525
///
2626
/// It is just a type for use on the client side.
27-
#[derive(Clone, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
27+
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
2828
pub struct Tenant {
2929
// TODO: consider using NonEmptyString?
3030
pub tenant: String,

src/query/service/src/servers/flight/v1/actions/kill_query.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::servers::flight::v1::actions::create_session;
2424
pub static KILL_QUERY: &str = "/actions/kill_query";
2525

2626
pub async fn kill_query(plan: KillPlan) -> Result<bool> {
27-
let session = create_session(None)?;
27+
let session = create_session()?;
2828
let version = GlobalConfig::version();
2929
let query_context = session.create_query_context(version).await?;
3030
let interpreter = KillInterpreter::from_flight(query_context, plan)?;

src/query/service/src/servers/flight/v1/actions/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ use std::sync::Arc;
2727
use databend_common_catalog::session_type::SessionType;
2828
use databend_common_config::GlobalConfig;
2929
use databend_common_exception::Result;
30-
use databend_common_meta_app::tenant::Tenant;
3130
use databend_common_settings::Settings;
3231
pub use flight_actions::flight_actions;
3332
pub use flight_actions::FlightActions;
@@ -44,10 +43,10 @@ pub use truncate_table::TRUNCATE_TABLE;
4443
use crate::sessions::Session;
4544
use crate::sessions::SessionManager;
4645

47-
pub(crate) fn create_session(tenant: Option<Tenant>) -> Result<Arc<Session>> {
46+
pub(crate) fn create_session() -> Result<Arc<Session>> {
4847
let config = GlobalConfig::instance();
49-
let tenant_id = tenant.unwrap_or(config.query.tenant_id.clone());
50-
let settings = Settings::create(tenant_id.clone());
48+
let tenant_id = config.query.tenant_id.clone();
49+
let settings = Settings::create(tenant_id);
5150
match SessionManager::instance().create_with_settings(SessionType::FlightRPC, settings, None) {
5251
Err(cause) => Err(cause),
5352
Ok(session) => Ok(Arc::new(session)),

src/query/service/src/servers/flight/v1/actions/set_priority.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::servers::flight::v1::actions::create_session;
2424
pub static SET_PRIORITY: &str = "/actions/set_priority";
2525

2626
pub async fn set_priority(plan: SetPriorityPlan) -> Result<bool> {
27-
let session = create_session(None)?;
27+
let session = create_session()?;
2828
let version = GlobalConfig::version();
2929
let query_context = session.create_query_context(version).await?;
3030
let interpreter = SetPriorityInterpreter::from_flight(query_context, plan)?;

src/query/service/src/servers/flight/v1/actions/system_action.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use crate::servers::flight::v1::actions::create_session;
2323
pub static SYSTEM_ACTION: &str = "/actions/system_action";
2424

2525
pub async fn system_action(plan: SystemPlan) -> Result<()> {
26-
let session = create_session(Some(plan.clone().tenant))?;
26+
let session = create_session()?;
2727
let version = GlobalConfig::version();
2828
let query_context = session.create_query_context(version).await?;
2929
let interpreter = SystemActionInterpreter::from_flight(query_context, plan)?;

src/query/service/src/servers/flight/v1/actions/truncate_table.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use crate::servers::flight::v1::actions::create_session;
2323
pub static TRUNCATE_TABLE: &str = "/actions/truncate_table";
2424

2525
pub async fn truncate_table(plan: TruncateTablePlan) -> Result<()> {
26-
let session = create_session(None)?;
26+
let session = create_session()?;
2727
let version = GlobalConfig::version();
2828
let query_context = session.create_query_context(version).await?;
2929
let interpreter = TruncateTableInterpreter::from_flight(query_context, plan)?;

src/query/sql/src/planner/binder/system.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,12 @@ impl Binder {
2525
#[async_backtrace::framed]
2626
pub(super) async fn bind_system(&mut self, stmt: &SystemStmt) -> Result<Plan> {
2727
let SystemStmt { action } = stmt;
28-
let tenant = self.ctx.get_tenant();
2928
match action {
3029
AstSystemAction::Backtrace(switch) => Ok(Plan::System(Box::new(SystemPlan {
3130
action: SystemAction::Backtrace(*switch),
32-
tenant,
3331
}))),
3432
AstSystemAction::FlushPrivileges => Ok(Plan::System(Box::new(SystemPlan {
3533
action: SystemAction::FlushPrivileges,
36-
tenant,
3734
}))),
3835
}
3936
}

src/query/sql/src/planner/plans/system.rs

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

15-
use databend_common_meta_app::tenant::Tenant;
1615
use serde::Deserialize;
1716
use serde::Serialize;
1817

1918
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)]
2019
pub struct SystemPlan {
2120
pub action: SystemAction,
22-
pub tenant: Tenant,
2321
}
2422

2523
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]

0 commit comments

Comments
 (0)