You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by ch...@apache.org on 2024/10/17 06:00:14 UTC
(shardingsphere) branch master updated: Add query parameters and check for mysql kill processId (#33274)
This is an automated email from the ASF dual-hosted git repository.
chengzhang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new b5d0294bb03 Add query parameters and check for mysql kill processId (#33274)
b5d0294bb03 is described below
commit b5d0294bb03b1b95d6c3f49382666487d15a7664
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
---
RELEASE-NOTES.md | 14 ++++++++++++++
.../visitor/statement/type/MySQLDALStatementVisitor.java | 6 ++++++
.../parser/statement/core/statement/dal/KillStatement.java | 2 ++
.../mysql/handler/admin/executor/KillProcessExecutor.java | 6 ++++++
4 files changed, 28 insertions(+)
diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md
index 2149e344e71..58d2eee17f5 100644
--- a/RELEASE-NOTES.md
+++ b/RELEASE-NOTES.md
@@ -1,3 +1,17 @@
+## Release 5.5.2-SNAPSHOT
+
+### API Change
+
+### New Feature
+
+### Enhancement
+1. Proxy: Add query parameters and check for mysql kill processId - [#33274](https://github.com/apache/shardingsphere/pull/33274)
+
+### Bug Fix
+
+### Change Log
+1. [MILESTONE](https://github.com/apache/shardingsphere/milestone/30)
+
## Release 5.5.1-SNAPSHOT
### API Change
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 71f24332f42..99ce94601c2 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/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/dal/KillStatement.java b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/dal/KillStatement.java
index 16134a95050..b7b81c232e2 100644
--- a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/dal/KillStatement.java
+++ b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/dal/KillStatement.java
@@ -29,4 +29,6 @@ import org.apache.shardingsphere.sql.parser.statement.core.statement.AbstractSQL
public abstract class KillStatement extends AbstractSQLStatement implements DALStatement {
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 fdc2280f438..8fe70daa26c 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,6 +18,8 @@
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.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseAdminExecutor;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
@@ -31,6 +33,8 @@ import java.sql.SQLException;
@RequiredArgsConstructor
public final class KillProcessExecutor implements DatabaseAdminExecutor {
+ private static final String QUERY_SCOPE = "QUERY";
+
private final KillStatement killStatement;
/**
@@ -40,6 +44,8 @@ public final class KillProcessExecutor implements DatabaseAdminExecutor {
*/
@Override
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().getPersistServiceFacade().getProcessPersistService().killProcess(processId);
}