You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by ji...@apache.org on 2024/10/22 05:58:18 UTC
(shardingsphere) 42/43: Add query parameters and check for mysql kill processId (#33274)
This is an automated email from the ASF dual-hosted git repository.
jianglongtao pushed a commit to branch fix-33341
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
commit c20ebff163393e8d7bdc3c1aff9d9d8d5a79f255
Author: ZhangCheng <ch...@apache.org>
AuthorDate: Thu Oct 17 14:00:07 2024 +0800
Add query parameters and check for mysql kill processId (#33274)
* Support mysql kill query processId
* Support mysql kill query processId
* Support mysql kill query processId
* Support mysql kill query processId
(cherry picked from commit b5d0294bb03b1b95d6c3f49382666487d15a7664)
---
.../visitor/statement/type/MySQLDALStatementVisitor.java | 6 ++++++
.../sql/dialect/statement/mysql/dal/MySQLKillStatement.java | 2 ++
.../mysql/handler/admin/executor/KillProcessExecutor.java | 12 ++++++++++--
3 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/parser/sql/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/type/MySQLDALStatementVisitor.java b/parser/sql/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/type/MySQLDALStatementVisitor.java
index 0c6e3365c13..f5b9c3ba49b 100644
--- a/parser/sql/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/type/MySQLDALStatementVisitor.java
+++ b/parser/sql/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/type/MySQLDALStatementVisitor.java
@@ -479,6 +479,12 @@ public final class MySQLDALStatementVisitor extends MySQLStatementVisitor implem
} else {
result.setProcessId(ctx.IDENTIFIER_().getText());
}
+ if (null != ctx.QUERY()) {
+ result.setScope(ctx.QUERY().getText());
+ }
+ if (null != ctx.CONNECTION()) {
+ result.setScope(ctx.CONNECTION().getText());
+ }
return result;
}
diff --git a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/mysql/dal/MySQLKillStatement.java b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/mysql/dal/MySQLKillStatement.java
index 404087b1acf..46028b5a3bf 100644
--- a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/mysql/dal/MySQLKillStatement.java
+++ b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/mysql/dal/MySQLKillStatement.java
@@ -31,4 +31,6 @@ import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.MySQLSta
public final class MySQLKillStatement extends AbstractSQLStatement implements DALStatement, MySQLStatement {
private String processId;
+
+ private String scope;
}
diff --git a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/KillProcessExecutor.java b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/KillProcessExecutor.java
index 4f1bc47e2ee..4e670f9ea2f 100644
--- a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/KillProcessExecutor.java
+++ b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/KillProcessExecutor.java
@@ -18,18 +18,24 @@
package org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor;
import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
+import org.apache.shardingsphere.infra.exception.generic.UnsupportedSQLOperationException;
import org.apache.shardingsphere.mode.process.event.KillProcessRequestEvent;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseAdminExecutor;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLKillStatement;
+import java.sql.SQLException;
+
/**
* Kill process executor.
*/
@RequiredArgsConstructor
public final class KillProcessExecutor implements DatabaseAdminExecutor {
-
+
+ private static final String QUERY_SCOPE = "QUERY";
+
private final MySQLKillStatement killStatement;
/**
@@ -38,7 +44,9 @@ public final class KillProcessExecutor implements DatabaseAdminExecutor {
* @param connectionSession connection session
*/
@Override
- public void execute(final ConnectionSession connectionSession) {
+ public void execute(final ConnectionSession connectionSession) throws SQLException {
+ ShardingSpherePreconditions.checkState(QUERY_SCOPE.equalsIgnoreCase(killStatement.getScope()),
+ () -> new UnsupportedSQLOperationException("Only `KILL QUERY <processId>` SQL syntax is supported"));
String processId = killStatement.getProcessId();
ProxyContext.getInstance().getContextManager().getInstanceContext().getEventBusContext().post(new KillProcessRequestEvent(processId));
}