This is an automated email from the ASF dual-hosted git repository.
jianglongtao 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 1aff934 DistSQL add instance circuit breaker (#12687)
1aff934 is described below
commit 1aff934000da85d441583812ae912bb22fdc7183
Author: lanchengx <[email protected]>
AuthorDate: Sun Sep 26 03:20:26 2021 -0500
DistSQL add instance circuit breaker (#12687)
* Circuit breaker.
* Reformat.
* Reformat.
* Update g4.
* Update visitor.
---
.../src/main/antlr4/imports/Keyword.g4 | 16 +++++++++
.../src/main/antlr4/imports/RALStatement.g4 | 16 +++++++++
.../parser/autogen/CommonDistSQLStatement.g4 | 2 ++
.../core/common/CommonDistSQLStatementVisitor.java | 13 ++++++++
...tement.java => SetInstanceStatusStatement.java} | 19 +++--------
.../ReadwriteSplittingDistSQLStatementVisitor.java | 6 ++--
.../SetReadwriteSplittingStatusStatement.java | 8 ++---
.../common/set/SetStatementExecutorFactory.java | 13 +++++---
...xecutor.java => SetInstanceStatusExecutor.java} | 39 +++++-----------------
...va => SetReadwriteSplittingStatusExecutor.java} | 20 +++--------
.../set/SetStatementExecutorFactoryTest.java | 18 +++++++---
11 files changed, 92 insertions(+), 78 deletions(-)
diff --git
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/Keyword.g4
b/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/Keyword.g4
index 3473f71..ab033ce 100644
---
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/Keyword.g4
+++
b/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/Keyword.g4
@@ -98,3 +98,19 @@ VARIABLE
HINT
: H I N T
;
+
+ENABLE
+ : E N A B L E
+ ;
+
+DISABLE
+ : D I S A B L E
+ ;
+
+INSTANCE
+ : I N S T A N C E
+ ;
+
+IP
+ : I P
+ ;
diff --git
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/RALStatement.g4
b/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/RALStatement.g4
index e942427..30a15e8 100644
---
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/RALStatement.g4
+++
b/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/RALStatement.g4
@@ -27,6 +27,14 @@ showVariable
: SHOW VARIABLE variableName
;
+enableInstance
+ :ENABLE INSTANCE IP EQ ip COMMA PORT EQ port
+ ;
+
+disableInstance
+ :DISABLE INSTANCE IP EQ ip COMMA PORT EQ port
+ ;
+
clearHint
: CLEAR HINT
;
@@ -38,3 +46,11 @@ variableName
variableValue
: IDENTIFIER
;
+
+ip
+ : IDENTIFIER | NUMBER+
+ ;
+
+port
+ : INT
+ ;
diff --git
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/CommonDistSQLStatement.g4
b/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/CommonDistSQLStatement.g4
index 4598f99..935c608 100644
---
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/CommonDistSQLStatement.g4
+++
b/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/CommonDistSQLStatement.g4
@@ -27,5 +27,7 @@ execute
| setVariable
| showVariable
| clearHint
+ | enableInstance
+ | disableInstance
) SEMI?
;
diff --git
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/java/org/apache/shardingsphere/distsql/parser/core/common/CommonDistSQLStatementVisitor.java
b/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/java/org/apache/shardingsphere/distsql/parser/core/common/CommonDistSQLStatementVisitor.java
index fb6bb72..3d82e4f 100644
---
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/java/org/apache/shardingsphere/distsql/parser/core/common/CommonDistSQLStatementVisitor.java
+++
b/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/java/org/apache/shardingsphere/distsql/parser/core/common/CommonDistSQLStatementVisitor.java
@@ -23,7 +23,9 @@ import
org.apache.shardingsphere.distsql.parser.autogen.CommonDistSQLStatementPa
import
org.apache.shardingsphere.distsql.parser.autogen.CommonDistSQLStatementParser.AlterResourceContext;
import
org.apache.shardingsphere.distsql.parser.autogen.CommonDistSQLStatementParser.ClearHintContext;
import
org.apache.shardingsphere.distsql.parser.autogen.CommonDistSQLStatementParser.DataSourceContext;
+import
org.apache.shardingsphere.distsql.parser.autogen.CommonDistSQLStatementParser.DisableInstanceContext;
import
org.apache.shardingsphere.distsql.parser.autogen.CommonDistSQLStatementParser.DropResourceContext;
+import
org.apache.shardingsphere.distsql.parser.autogen.CommonDistSQLStatementParser.EnableInstanceContext;
import
org.apache.shardingsphere.distsql.parser.autogen.CommonDistSQLStatementParser.PoolPropertiesContext;
import
org.apache.shardingsphere.distsql.parser.autogen.CommonDistSQLStatementParser.PoolPropertyContext;
import
org.apache.shardingsphere.distsql.parser.autogen.CommonDistSQLStatementParser.SchemaNameContext;
@@ -32,6 +34,7 @@ import
org.apache.shardingsphere.distsql.parser.autogen.CommonDistSQLStatementPa
import
org.apache.shardingsphere.distsql.parser.autogen.CommonDistSQLStatementParser.ShowVariableContext;
import org.apache.shardingsphere.distsql.parser.segment.DataSourceSegment;
import
org.apache.shardingsphere.distsql.parser.statement.ral.common.hint.ClearHintStatement;
+import
org.apache.shardingsphere.distsql.parser.statement.ral.common.status.SetInstanceStatusStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.common.variable.SetVariableStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.common.variable.ShowVariableStatement;
import
org.apache.shardingsphere.distsql.parser.statement.rdl.alter.AlterResourceStatement;
@@ -80,6 +83,16 @@ public final class CommonDistSQLStatementVisitor extends
CommonDistSQLStatementB
null == ctx.poolProperties() ? new Properties() :
getPoolProperties(ctx.poolProperties()));
}
+ @Override
+ public ASTNode visitEnableInstance(final EnableInstanceContext ctx) {
+ return new
SetInstanceStatusStatement(ctx.ENABLE().getText().toUpperCase(), new
IdentifierValue(ctx.ip().getText()).getValue(), ctx.port().getText());
+ }
+
+ @Override
+ public ASTNode visitDisableInstance(final DisableInstanceContext ctx) {
+ return new
SetInstanceStatusStatement(ctx.DISABLE().getText().toUpperCase(), new
IdentifierValue(ctx.ip().getText()).getValue(), ctx.port().getText());
+ }
+
private Properties getPoolProperties(final PoolPropertiesContext ctx) {
Properties result = new Properties();
for (PoolPropertyContext each : ctx.poolProperty()) {
diff --git
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/ral/common/status/SetStatusStatement.java
b/shardingsphere-distsql-parser/shardingsphere-distsql-parser-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/ral/common/status/SetInstanceStatusStatement.java
similarity index 66%
copy from
shardingsphere-distsql-parser/shardingsphere-distsql-parser-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/ral/common/status/SetStatusStatement.java
copy to
shardingsphere-distsql-parser/shardingsphere-distsql-parser-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/ral/common/status/SetInstanceStatusStatement.java
index a3b6e1a..3817f7d 100644
---
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/ral/common/status/SetStatusStatement.java
+++
b/shardingsphere-distsql-parser/shardingsphere-distsql-parser-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/ral/common/status/SetInstanceStatusStatement.java
@@ -20,28 +20,17 @@ package
org.apache.shardingsphere.distsql.parser.statement.ral.common.status;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import
org.apache.shardingsphere.distsql.parser.statement.ral.common.SetDistSQLStatement;
-import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.SchemaSegment;
-import
org.apache.shardingsphere.sql.parser.sql.common.statement.available.FromSchemaAvailable;
-
-import java.util.Optional;
/**
- * Set status statement.
+ * Set instance status statement.
*/
@Getter
@RequiredArgsConstructor
-public class SetStatusStatement extends SetDistSQLStatement implements
FromSchemaAvailable {
-
- private final String featureName;
+public class SetInstanceStatusStatement extends SetDistSQLStatement {
private final String status;
- private final String resourceName;
-
- private final SchemaSegment schema;
+ private final String ip;
- @Override
- public Optional<SchemaSegment> getSchema() {
- return Optional.ofNullable(schema);
- }
+ private final String port;
}
diff --git
a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-parser/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/parser/core/ReadwriteSplittingDistSQLStatementVisitor.java
b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-parser/src/main/java/org/apache/shardingsphere/readwrit
[...]
index 76ec689..deafd1c 100644
---
a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-parser/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/parser/core/ReadwriteSplittingDistSQLStatementVisitor.java
+++
b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-parser/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/parser/core/ReadwriteSplittingDistSQLStatementVisitor.java
@@ -35,7 +35,7 @@ import
org.apache.shardingsphere.distsql.parser.autogen.ReadwriteSplittingDistSQ
import
org.apache.shardingsphere.distsql.parser.autogen.ReadwriteSplittingDistSQLStatementParser.ShowReadwriteSplittingRulesContext;
import
org.apache.shardingsphere.distsql.parser.autogen.ReadwriteSplittingDistSQLStatementParser.StaticReadwriteSplittingRuleDefinitionContext;
import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
-import
org.apache.shardingsphere.distsql.parser.statement.ral.common.status.SetStatusStatement;
+import
org.apache.shardingsphere.readwritesplitting.distsql.parser.statement.status.SetReadwriteSplittingStatusStatement;
import
org.apache.shardingsphere.readwritesplitting.distsql.parser.segment.ReadwriteSplittingRuleSegment;
import
org.apache.shardingsphere.readwritesplitting.distsql.parser.statement.AlterReadwriteSplittingRuleStatement;
import
org.apache.shardingsphere.readwritesplitting.distsql.parser.statement.CreateReadwriteSplittingRuleStatement;
@@ -76,13 +76,13 @@ public final class
ReadwriteSplittingDistSQLStatementVisitor extends ReadwriteSp
@Override
public ASTNode visitEnableReadDataSource(final EnableReadDataSourceContext
ctx) {
SchemaSegment schemaSegment = Objects.nonNull(ctx.schemaName()) ?
(SchemaSegment) visit(ctx.schemaName()) : null;
- return new SetStatusStatement(ctx.READWRITE_SPLITTING().getText(),
ctx.ENABLE().getText(), new
IdentifierValue(ctx.resourceName().getText()).getValue(), schemaSegment);
+ return new
SetReadwriteSplittingStatusStatement(ctx.ENABLE().getText().toUpperCase(), new
IdentifierValue(ctx.resourceName().getText()).getValue(), schemaSegment);
}
@Override
public ASTNode visitDisableReadDataSource(final
DisableReadDataSourceContext ctx) {
SchemaSegment schemaSegment = Objects.nonNull(ctx.schemaName()) ?
(SchemaSegment) visit(ctx.schemaName()) : null;
- return new SetStatusStatement(ctx.READWRITE_SPLITTING().getText(),
ctx.DISABLE().getText(), new
IdentifierValue(ctx.resourceName().getText()).getValue(), schemaSegment);
+ return new
SetReadwriteSplittingStatusStatement(ctx.DISABLE().getText().toUpperCase(), new
IdentifierValue(ctx.resourceName().getText()).getValue(), schemaSegment);
}
@Override
diff --git
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/ral/common/status/SetStatusStatement.java
b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-statement/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/parser/statement/status/SetReadwriteSplittingStatusStatement.java
similarity index 85%
rename from
shardingsphere-distsql-parser/shardingsphere-distsql-parser-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/ral/common/status/SetStatusStatement.java
rename to
shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-statement/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/parser/statement/status/SetReadwriteSplittingStatusStatement.java
index a3b6e1a..5fe49a5 100644
---
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/ral/common/status/SetStatusStatement.java
+++
b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-statement/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/parser/statement/status/SetReadwriteSplittingStatusStatement.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.distsql.parser.statement.ral.common.status;
+package
org.apache.shardingsphere.readwritesplitting.distsql.parser.statement.status;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
@@ -26,13 +26,11 @@ import
org.apache.shardingsphere.sql.parser.sql.common.statement.available.FromS
import java.util.Optional;
/**
- * Set status statement.
+ * Set readwrite-splitting status statement.
*/
@Getter
@RequiredArgsConstructor
-public class SetStatusStatement extends SetDistSQLStatement implements
FromSchemaAvailable {
-
- private final String featureName;
+public class SetReadwriteSplittingStatusStatement extends SetDistSQLStatement
implements FromSchemaAvailable {
private final String status;
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/set/SetStatementExecutorFactory.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/set/SetStatementExecutorFactory.java
index 90c69e0..1d576b9 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/set/SetStatementExecutorFactory.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/set/SetStatementExecutorFactory.java
@@ -19,11 +19,13 @@ package
org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.set;
import com.mchange.v1.db.sql.UnsupportedTypeException;
import
org.apache.shardingsphere.distsql.parser.statement.ral.common.SetDistSQLStatement;
-import
org.apache.shardingsphere.distsql.parser.statement.ral.common.status.SetStatusStatement;
+import
org.apache.shardingsphere.distsql.parser.statement.ral.common.status.SetInstanceStatusStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.common.variable.SetVariableStatement;
import
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
-import
org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.set.excutor.SetStatusExecutor;
+import
org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.set.excutor.SetInstanceStatusExecutor;
+import
org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.set.excutor.SetReadwriteSplittingStatusExecutor;
import
org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.set.excutor.SetVariableExecutor;
+import
org.apache.shardingsphere.readwritesplitting.distsql.parser.statement.status.SetReadwriteSplittingStatusStatement;
import java.sql.SQLException;
@@ -44,8 +46,11 @@ public final class SetStatementExecutorFactory {
if (sqlStatement instanceof SetVariableStatement) {
return new SetVariableExecutor((SetVariableStatement)
sqlStatement, backendConnection);
}
- if (sqlStatement instanceof SetStatusStatement) {
- return new SetStatusExecutor((SetStatusStatement) sqlStatement,
backendConnection);
+ if (sqlStatement instanceof SetReadwriteSplittingStatusStatement) {
+ return new
SetReadwriteSplittingStatusExecutor((SetReadwriteSplittingStatusStatement)
sqlStatement, backendConnection);
+ }
+ if (sqlStatement instanceof SetInstanceStatusStatement) {
+ return new SetInstanceStatusExecutor((SetInstanceStatusStatement)
sqlStatement, backendConnection);
}
throw new
UnsupportedTypeException(sqlStatement.getClass().getCanonicalName());
}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/set/excutor/SetStatusExecutor.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/set/excutor/SetInstanceStatusExecutor.java
similarity index 52%
copy from
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/set/excutor/SetStatusExecutor.java
copy to
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/set/excutor/SetInstanceStatusExecutor.java
index 78cdc5f..715d43c 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/set/excutor/SetStatusExecutor.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/set/excutor/SetInstanceStatusExecutor.java
@@ -18,56 +18,33 @@
package
org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.set.excutor;
import lombok.AllArgsConstructor;
-import
org.apache.shardingsphere.distsql.parser.statement.ral.common.status.SetStatusStatement;
+import
org.apache.shardingsphere.distsql.parser.statement.ral.common.status.SetInstanceStatusStatement;
import org.apache.shardingsphere.infra.distsql.exception.DistSQLException;
-import
org.apache.shardingsphere.infra.distsql.exception.resource.RequiredResourceMissedException;
-import org.apache.shardingsphere.infra.exception.SchemaNotExistedException;
import org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistService;
import
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-import
org.apache.shardingsphere.proxy.backend.exception.NoDatabaseSelectedException;
import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
import
org.apache.shardingsphere.proxy.backend.response.header.update.UpdateResponseHeader;
import
org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.set.SetStatementExecutor;
-import java.util.Collection;
-import java.util.Collections;
import java.util.Optional;
/**
- * Set status statement executor.
+ * Set instance status executor.
*/
@AllArgsConstructor
-public final class SetStatusExecutor implements SetStatementExecutor {
+public final class SetInstanceStatusExecutor implements SetStatementExecutor {
- private static final String READWRITE_SPLITTING = "READWRITE_SPLITTING";
-
- private final SetStatusStatement sqlStatement;
+ private final SetInstanceStatusStatement sqlStatement;
private final BackendConnection backendConnection;
@Override
public ResponseHeader execute() throws DistSQLException {
- String schemaName = sqlStatement.getSchema().isPresent() ?
sqlStatement.getSchema().get().getIdentifier().getValue() :
backendConnection.getSchemaName();
- if (null == schemaName) {
- throw new NoDatabaseSelectedException();
- }
- if
(!ProxyContext.getInstance().getAllSchemaNames().contains(schemaName)) {
- throw new SchemaNotExistedException(schemaName);
- }
- String resourceName = sqlStatement.getResourceName();
- Collection<String> notExistedResources =
ProxyContext.getInstance().getMetaData(schemaName).getResource().getNotExistedResources(Collections.singleton(resourceName));
- DistSQLException.predictionThrow(notExistedResources.isEmpty(), new
RequiredResourceMissedException(schemaName,
Collections.singleton(resourceName)));
- if
(sqlStatement.getFeatureName().equalsIgnoreCase(READWRITE_SPLITTING)) {
- handleReadwriteSplitting(schemaName, resourceName);
- } else {
- throw new
UnsupportedOperationException(sqlStatement.getFeatureName());
- }
- return new UpdateResponseHeader(sqlStatement);
- }
-
- private void handleReadwriteSplitting(final String schemaName, final
String resourceName) {
+ String ip = sqlStatement.getIp();
+ String port = sqlStatement.getPort();
Optional<MetaDataPersistService> persistService =
ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaDataPersistService();
- //TODO Need to disable slave data source API support
+ //TODO Need to circuit breaker API support.
+ return new UpdateResponseHeader(sqlStatement);
}
}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/set/excutor/SetStatusExecutor.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/set/excutor/SetReadwriteSplittingStatusExecutor.java
similarity index 81%
rename from
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/set/excutor/SetStatusExecutor.java
rename to
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/set/excutor/SetReadwriteSplittingStatusExecutor.java
index 78cdc5f..08f3ad9 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/set/excutor/SetStatusExecutor.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/set/excutor/SetReadwriteSplittingStatusExecutor.java
@@ -18,7 +18,6 @@
package
org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.set.excutor;
import lombok.AllArgsConstructor;
-import
org.apache.shardingsphere.distsql.parser.statement.ral.common.status.SetStatusStatement;
import org.apache.shardingsphere.infra.distsql.exception.DistSQLException;
import
org.apache.shardingsphere.infra.distsql.exception.resource.RequiredResourceMissedException;
import org.apache.shardingsphere.infra.exception.SchemaNotExistedException;
@@ -29,20 +28,19 @@ import
org.apache.shardingsphere.proxy.backend.exception.NoDatabaseSelectedExcep
import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
import
org.apache.shardingsphere.proxy.backend.response.header.update.UpdateResponseHeader;
import
org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.set.SetStatementExecutor;
+import
org.apache.shardingsphere.readwritesplitting.distsql.parser.statement.status.SetReadwriteSplittingStatusStatement;
import java.util.Collection;
import java.util.Collections;
import java.util.Optional;
/**
- * Set status statement executor.
+ * Set readwrite-splitting status executor.
*/
@AllArgsConstructor
-public final class SetStatusExecutor implements SetStatementExecutor {
+public final class SetReadwriteSplittingStatusExecutor implements
SetStatementExecutor {
- private static final String READWRITE_SPLITTING = "READWRITE_SPLITTING";
-
- private final SetStatusStatement sqlStatement;
+ private final SetReadwriteSplittingStatusStatement sqlStatement;
private final BackendConnection backendConnection;
@@ -58,16 +56,8 @@ public final class SetStatusExecutor implements
SetStatementExecutor {
String resourceName = sqlStatement.getResourceName();
Collection<String> notExistedResources =
ProxyContext.getInstance().getMetaData(schemaName).getResource().getNotExistedResources(Collections.singleton(resourceName));
DistSQLException.predictionThrow(notExistedResources.isEmpty(), new
RequiredResourceMissedException(schemaName,
Collections.singleton(resourceName)));
- if
(sqlStatement.getFeatureName().equalsIgnoreCase(READWRITE_SPLITTING)) {
- handleReadwriteSplitting(schemaName, resourceName);
- } else {
- throw new
UnsupportedOperationException(sqlStatement.getFeatureName());
- }
- return new UpdateResponseHeader(sqlStatement);
- }
-
- private void handleReadwriteSplitting(final String schemaName, final
String resourceName) {
Optional<MetaDataPersistService> persistService =
ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaDataPersistService();
//TODO Need to disable slave data source API support
+ return new UpdateResponseHeader(sqlStatement);
}
}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/set/SetStatementExecutorFactoryTest.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/set/SetStatementExecutorFactoryTest.java
index ed29ac1..1e3811a 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/set/SetStatementExecutorFactoryTest.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/set/SetStatementExecutorFactoryTest.java
@@ -18,11 +18,13 @@
package org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.set;
import
org.apache.shardingsphere.distsql.parser.statement.ral.common.SetDistSQLStatement;
-import
org.apache.shardingsphere.distsql.parser.statement.ral.common.status.SetStatusStatement;
+import
org.apache.shardingsphere.distsql.parser.statement.ral.common.status.SetInstanceStatusStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.common.variable.SetVariableStatement;
import
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
-import
org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.set.excutor.SetStatusExecutor;
+import
org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.set.excutor.SetInstanceStatusExecutor;
+import
org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.set.excutor.SetReadwriteSplittingStatusExecutor;
import
org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.set.excutor.SetVariableExecutor;
+import
org.apache.shardingsphere.readwritesplitting.distsql.parser.statement.status.SetReadwriteSplittingStatusStatement;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -47,8 +49,14 @@ public final class SetStatementExecutorFactoryTest {
}
@Test
- public void assertSetStatusExecutor() throws SQLException {
- SetDistSQLStatement sqlStatement = mock(SetStatusStatement.class);
- assertThat(SetStatementExecutorFactory.newInstance(sqlStatement,
backendConnection), instanceOf(SetStatusExecutor.class));
+ public void assertSetReadwriteSplittingStatusExecutor() throws
SQLException {
+ SetDistSQLStatement sqlStatement =
mock(SetReadwriteSplittingStatusStatement.class);
+ assertThat(SetStatementExecutorFactory.newInstance(sqlStatement,
backendConnection), instanceOf(SetReadwriteSplittingStatusExecutor.class));
+ }
+
+ @Test
+ public void assertSetInstanceStatusExecutor() throws SQLException {
+ SetDistSQLStatement sqlStatement =
mock(SetInstanceStatusStatement.class);
+ assertThat(SetStatementExecutorFactory.newInstance(sqlStatement,
backendConnection), instanceOf(SetInstanceStatusExecutor.class));
}
}