Skip to content

Commit c20e715

Browse files
committed
feat: add explicit FLUSH PRIVILEGES to refresh role cache for query node
1 parent 7836cc0 commit c20e715

File tree

14 files changed

+39
-14
lines changed

14 files changed

+39
-14
lines changed

src/query/ast/src/ast/statements/system_action.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ impl Display for SystemStmt {
3232
#[derive(Debug, Clone, PartialEq, Eq, Drive, DriveMut)]
3333
pub enum SystemAction {
3434
Backtrace(bool),
35+
FlushPrivileges,
3536
}
3637

3738
impl Display for SystemAction {
@@ -41,6 +42,7 @@ impl Display for SystemAction {
4142
true => write!(f, "ENABLE EXCEPTION_BACKTRACE"),
4243
false => write!(f, "DISABLE EXCEPTION_BACKTRACE"),
4344
},
45+
SystemAction::FlushPrivileges => write!(f, "FLUSH PRIVILEGES"),
4446
}
4547
}
4648
}

src/query/ast/src/parser/statement.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5007,15 +5007,21 @@ pub fn priority(i: Input) -> IResult<Priority> {
50075007
}
50085008

50095009
pub fn action(i: Input) -> IResult<SystemAction> {
5010-
let mut backtrace = parser_fn(map(
5010+
let backtrace = parser_fn(map(
50115011
rule! {
50125012
#switch ~ EXCEPTION_BACKTRACE
50135013
},
50145014
|(switch, _)| SystemAction::Backtrace(switch),
50155015
));
5016+
let flush_privileges = parser_fn(map(
5017+
rule! {
5018+
FLUSH ~ PRIVILEGES
5019+
},
5020+
|_| SystemAction::FlushPrivileges,
5021+
));
50165022
// add other system action type here
50175023
rule!(
5018-
#backtrace
5024+
#backtrace | #flush_privileges
50195025
)
50205026
.parse(i)
50215027
}

src/query/ast/src/parser/token.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,8 @@ pub enum TokenKind {
683683
FORMAT_NAME,
684684
#[token("FORMATS", ignore(ascii_case))]
685685
FORMATS,
686+
#[token("FLUSH", ignore(ascii_case))]
687+
FLUSH,
686688
#[token("FRAGMENTS", ignore(ascii_case))]
687689
FRAGMENTS,
688690
#[token("FRIDAY", ignore(ascii_case))]

src/query/service/src/interpreters/interpreter_system_action.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use databend_common_exception::set_backtrace;
2020
use databend_common_exception::Result;
2121
use databend_common_sql::plans::SystemAction;
2222
use databend_common_sql::plans::SystemPlan;
23+
use databend_common_users::RoleCacheManager;
2324

2425
use crate::clusters::ClusterHelper;
2526
use crate::clusters::FlightParams;
@@ -90,6 +91,10 @@ impl Interpreter for SystemActionInterpreter {
9091
SystemAction::Backtrace(switch) => {
9192
set_backtrace(switch);
9293
}
94+
SystemAction::FlushPrivileges => {
95+
let tenant = self.ctx.get_tenant();
96+
RoleCacheManager::instance().force_reload(&tenant).await?;
97+
}
9398
}
9499
Ok(PipelineBuildResult::create())
95100
}

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()?;
27+
let session = create_session(Some(plan.tenant.as_str()))?;
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: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,12 @@ pub use truncate_table::TRUNCATE_TABLE;
4343
use crate::sessions::Session;
4444
use crate::sessions::SessionManager;
4545

46-
pub(crate) fn create_session() -> Result<Arc<Session>> {
46+
pub(crate) fn create_session(tenant: Option<&str>) -> Result<Arc<Session>> {
4747
let config = GlobalConfig::instance();
48-
let settings = Settings::create(config.query.tenant_id.clone());
48+
let tenant_id = tenant.unwrap_or(&config.query.tenant_id);
49+
let settings = Settings::create(tenant_id.clone());
4950
match SessionManager::instance().create_with_settings(SessionType::FlightRPC, settings, None) {
5051
Err(cause) => Err(cause),
5152
Ok(session) => Ok(Arc::new(session)),
5253
}
53-
}
54+
}

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()?;
27+
let session = create_session(Some(plan.tenant.as_str()))?;
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()?;
26+
let session = create_session(Some(plan.tenant.as_str()))?;
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()?;
26+
let session = create_session(Some(plan.tenant.as_str()))?;
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/ddl/table.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1457,7 +1457,7 @@ impl Binder {
14571457
Ok(Plan::TruncateTable(Box::new(TruncateTablePlan {
14581458
catalog,
14591459
database,
1460-
table,
1460+
table
14611461
})))
14621462
}
14631463

0 commit comments

Comments
 (0)