This is an automated email from the ASF dual-hosted git repository.
zhangliang 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 4ffff70396f Refactor UnlockClusterStatement (#38034)
4ffff70396f is described below
commit 4ffff70396f9b60138d1983a010c77debcf6c3bf
Author: Liang Zhang <[email protected]>
AuthorDate: Sat Feb 14 00:40:37 2026 +0800
Refactor UnlockClusterStatement (#38034)
* Refactor UnlockClusterStatement
* Refactor UnlockClusterStatement
---
.../parser/core/kernel/KernelDistSQLStatementVisitor.java | 7 ++++---
.../type/ral/updatable/UnlockClusterStatement.java | 15 +++++----------
.../distsql/ral/updatable/lock/UnlockClusterExecutor.java | 2 +-
.../ral/updatable/lock/UnlockClusterExecutorTest.java | 2 +-
4 files changed, 11 insertions(+), 15 deletions(-)
diff --git
a/parser/distsql/engine/src/main/java/org/apache/shardingsphere/distsql/parser/core/kernel/KernelDistSQLStatementVisitor.java
b/parser/distsql/engine/src/main/java/org/apache/shardingsphere/distsql/parser/core/kernel/KernelDistSQLStatementVisitor.java
index 20eb588e066..442e0bdc269 100644
---
a/parser/distsql/engine/src/main/java/org/apache/shardingsphere/distsql/parser/core/kernel/KernelDistSQLStatementVisitor.java
+++
b/parser/distsql/engine/src/main/java/org/apache/shardingsphere/distsql/parser/core/kernel/KernelDistSQLStatementVisitor.java
@@ -329,14 +329,15 @@ public final class KernelDistSQLStatementVisitor extends
KernelDistSQLStatementB
@Override
public ASTNode visitLockCluster(final LockClusterContext ctx) {
- String value = IdentifierValueUtils.getValue(ctx.INT_());
+ String timeoutMillis = IdentifierValueUtils.getValue(ctx.INT_());
AlgorithmSegment algorithmSegment = (AlgorithmSegment)
visitAlgorithmDefinition(ctx.lockStrategy().algorithmDefinition());
- return null == value ? new LockClusterStatement(algorithmSegment) :
new LockClusterStatement(algorithmSegment, Long.parseLong(value));
+ return null == timeoutMillis ? new
LockClusterStatement(algorithmSegment) : new
LockClusterStatement(algorithmSegment, Long.parseLong(timeoutMillis));
}
@Override
public ASTNode visitUnlockCluster(final UnlockClusterContext ctx) {
- return new
UnlockClusterStatement(Long.parseLong(IdentifierValueUtils.getValue(ctx.INT_())));
+ String timeoutMillis = IdentifierValueUtils.getValue(ctx.INT_());
+ return null == timeoutMillis ? new UnlockClusterStatement() : new
UnlockClusterStatement(Long.parseLong(timeoutMillis));
}
@Override
diff --git
a/parser/distsql/statement/src/main/java/org/apache/shardingsphere/distsql/statement/type/ral/updatable/UnlockClusterStatement.java
b/parser/distsql/statement/src/main/java/org/apache/shardingsphere/distsql/statement/type/ral/updatable/UnlockClusterStatement.java
index 05027f08561..4c09e358df2 100644
---
a/parser/distsql/statement/src/main/java/org/apache/shardingsphere/distsql/statement/type/ral/updatable/UnlockClusterStatement.java
+++
b/parser/distsql/statement/src/main/java/org/apache/shardingsphere/distsql/statement/type/ral/updatable/UnlockClusterStatement.java
@@ -17,24 +17,19 @@
package org.apache.shardingsphere.distsql.statement.type.ral.updatable;
+import lombok.Getter;
import lombok.RequiredArgsConstructor;
-import java.util.Optional;
-
/**
* Unlock cluster statement.
*/
@RequiredArgsConstructor
+@Getter
public final class UnlockClusterStatement extends UpdatableRALStatement {
- private final Long timeoutMillis;
+ private final long timeoutMillis;
- /**
- * Get lock timeout milliseconds.
- *
- * @return lock timeout milliseconds
- */
- public Optional<Long> getTimeoutMillis() {
- return Optional.of(timeoutMillis);
+ public UnlockClusterStatement() {
+ this(3000L);
}
}
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/lock/UnlockClusterExecutor.java
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/lock/UnlockClusterExecutor.java
index a50c3bdb1fc..ecfed775b11 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/lock/UnlockClusterExecutor.java
+++
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/lock/UnlockClusterExecutor.java
@@ -36,7 +36,7 @@ public final class UnlockClusterExecutor implements
DistSQLUpdateExecutor<Unlock
@Override
public void executeUpdate(final UnlockClusterStatement sqlStatement, final
ContextManager contextManager) throws SQLException {
checkState(contextManager);
- long timeoutMillis = sqlStatement.getTimeoutMillis().orElse(3000L);
+ long timeoutMillis = sqlStatement.getTimeoutMillis();
contextManager.getExclusiveOperatorEngine().operate(new
LockClusterOperation(), timeoutMillis, () -> {
checkState(contextManager);
contextManager.getPersistServiceFacade().getStateService().update(ShardingSphereState.OK);
diff --git
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/lock/UnlockClusterExecutorTest.java
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/lock/UnlockClusterExecutorTest.java
index 45096341bf6..3eea0a400c2 100644
---
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/lock/UnlockClusterExecutorTest.java
+++
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/lock/UnlockClusterExecutorTest.java
@@ -40,7 +40,7 @@ class UnlockClusterExecutorTest {
void assertExecuteUpdateWithNotLockedCluster() {
ContextManager contextManager = mock(ContextManager.class,
RETURNS_DEEP_STUBS);
when(contextManager.getStateContext().getState()).thenReturn(ShardingSphereState.OK);
- assertThrows(NotLockedClusterException.class, () ->
executor.executeUpdate(new UnlockClusterStatement(null), contextManager));
+ assertThrows(NotLockedClusterException.class, () ->
executor.executeUpdate(new UnlockClusterStatement(), contextManager));
}
@Test