This is an automated email from the ASF dual-hosted git repository.
zhaojinchao 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 f1bd3cf85f9 Refactor AlterReadwriteSplittingStorageUnitStatusExecutor
(#30198)
f1bd3cf85f9 is described below
commit f1bd3cf85f90eecb310365aa16a1e5aeaaffa0c0
Author: Raigor <[email protected]>
AuthorDate: Mon Feb 19 18:37:50 2024 +0800
Refactor AlterReadwriteSplittingStorageUnitStatusExecutor (#30198)
* Refactor AlterReadwriteSplittingStorageUnitStatusExecutor
* Fix code style
---
.../ReadwriteSplittingRuleStatementChecker.java | 2 +-
.../InvalidStorageUnitStatusException.java | 26 ++--
.../MissingRequiredReadStorageUnitException.java | 26 ++--
...eadwriteSplittingStorageUnitStatusExecutor.java | 155 ++++-----------------
.../antlr4/imports/readwrite-splitting/BaseRule.g4 | 2 +-
.../imports/readwrite-splitting/RALStatement.g4 | 4 +-
.../imports/readwrite-splitting/RDLStatement.g4 | 4 -
.../ReadwriteSplittingDistSQLStatementVisitor.java | 11 +-
...adwriteSplittingStorageUnitStatusStatement.java | 6 +-
.../storage/service/StorageNodeStatusService.java | 9 +-
.../ral/impl/UpdatableRALStatementAssert.java | 2 +-
...eSplittingStorageUnitStatusStatementAssert.java | 6 +-
...plittingStorageUnitStatusStatementTestCase.java | 8 +-
.../src/main/resources/case/ral/updatable.xml | 4 +-
14 files changed, 70 insertions(+), 195 deletions(-)
diff --git
a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/checker/ReadwriteSplittingRuleStatementChecker.java
b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/checker/ReadwriteSplittingRuleStatementChecker.java
index 83d82367a2b..0eb3b17fc0f 100644
---
a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/checker/ReadwriteSplittingRuleStatementChecker.java
+++
b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/checker/ReadwriteSplittingRuleStatementChecker.java
@@ -90,7 +90,7 @@ public final class ReadwriteSplittingRuleStatementChecker {
Collection<String> requiredRuleNames =
segments.stream().map(ReadwriteSplittingRuleSegment::getName).collect(Collectors.toList());
Collection<String> currentRuleNames =
currentRuleConfig.getDataSources().stream().map(ReadwriteSplittingDataSourceRuleConfiguration::getName).collect(Collectors.toList());
Collection<String> notExistedRuleNames =
requiredRuleNames.stream().filter(each ->
!currentRuleNames.contains(each)).collect(Collectors.toSet());
- ShardingSpherePreconditions.checkState(notExistedRuleNames.isEmpty(),
() -> new MissingRequiredRuleException(databaseName, notExistedRuleNames));
+ ShardingSpherePreconditions.checkState(notExistedRuleNames.isEmpty(),
() -> new MissingRequiredRuleException("Readwrite-splitting", databaseName,
notExistedRuleNames));
}
private static void checkDuplicateRuleNames(final ShardingSphereDatabase
database,
diff --git
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/ral/AlterReadwriteSplittingStorageUnitStatusStatementTestCase.java
b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/exception/InvalidStorageUnitStatusException.java
similarity index 53%
copy from
test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/ral/AlterReadwriteSplittingStorageUnitStatusStatementTestCase.java
copy to
features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/exception/InvalidStorageUnitStatusException.java
index 3a618a27909..66e323fdca8 100644
---
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/ral/AlterReadwriteSplittingStorageUnitStatusStatementTestCase.java
+++
b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/exception/InvalidStorageUnitStatusException.java
@@ -15,27 +15,19 @@
* limitations under the License.
*/
-package
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ral;
+package org.apache.shardingsphere.readwritesplitting.distsql.handler.exception;
-import lombok.Getter;
-import lombok.Setter;
-import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.DatabaseContainedTestCase;
-
-import javax.xml.bind.annotation.XmlAttribute;
+import
org.apache.shardingsphere.distsql.handler.exception.storageunit.StorageUnitDefinitionViolationException;
+import
org.apache.shardingsphere.infra.exception.core.external.sql.sqlstate.XOpenSQLState;
/**
- * Alter readwrite-splitting storage unit status statement test case.
+ * Invalid storage unit status exception.
*/
-@Getter
-@Setter
-public final class AlterReadwriteSplittingStorageUnitStatusStatementTestCase
extends DatabaseContainedTestCase {
-
- @XmlAttribute(name = "group-name")
- private String groupName;
+public final class InvalidStorageUnitStatusException extends
StorageUnitDefinitionViolationException {
- @XmlAttribute(name = "storage-unit-name")
- private String storageUnitName;
+ private static final long serialVersionUID = 4029749233439176539L;
- @XmlAttribute(name = "status")
- private String status;
+ public InvalidStorageUnitStatusException(final String errorMessages) {
+ super(XOpenSQLState.CHECK_OPTION_VIOLATION, 5, "Invalid storage unit
status, error message is: %s", errorMessages);
+ }
}
diff --git
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/ral/AlterReadwriteSplittingStorageUnitStatusStatementTestCase.java
b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/exception/MissingRequiredReadStorageUnitException.java
similarity index 51%
copy from
test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/ral/AlterReadwriteSplittingStorageUnitStatusStatementTestCase.java
copy to
features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/exception/MissingRequiredReadStorageUnitException.java
index 3a618a27909..7c1f218a3d5 100644
---
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/ral/AlterReadwriteSplittingStorageUnitStatusStatementTestCase.java
+++
b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/exception/MissingRequiredReadStorageUnitException.java
@@ -15,27 +15,19 @@
* limitations under the License.
*/
-package
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ral;
+package org.apache.shardingsphere.readwritesplitting.distsql.handler.exception;
-import lombok.Getter;
-import lombok.Setter;
-import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.DatabaseContainedTestCase;
-
-import javax.xml.bind.annotation.XmlAttribute;
+import
org.apache.shardingsphere.distsql.handler.exception.storageunit.StorageUnitDefinitionViolationException;
+import
org.apache.shardingsphere.infra.exception.core.external.sql.sqlstate.XOpenSQLState;
/**
- * Alter readwrite-splitting storage unit status statement test case.
+ * Missing required read storage unit exception.
*/
-@Getter
-@Setter
-public final class AlterReadwriteSplittingStorageUnitStatusStatementTestCase
extends DatabaseContainedTestCase {
-
- @XmlAttribute(name = "group-name")
- private String groupName;
+public final class MissingRequiredReadStorageUnitException extends
StorageUnitDefinitionViolationException {
- @XmlAttribute(name = "storage-unit-name")
- private String storageUnitName;
+ private static final long serialVersionUID = -4252553422332603648L;
- @XmlAttribute(name = "status")
- private String status;
+ public MissingRequiredReadStorageUnitException(final String ruleName,
final String storageUnitName) {
+ super(XOpenSQLState.CHECK_OPTION_VIOLATION, 6, "Read storage unit `%s`
does not exist in rule `%s`.", storageUnitName, ruleName);
+ }
}
diff --git
a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingStorageUnitStatusExecutor.java
b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingStorageUnitStatusExecutor.java
index fca40a12425..274b2a01a47 100644
---
a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingStorageUnitStatusExecutor.java
+++
b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingStorageUnitStatusExecutor.java
@@ -17,37 +17,24 @@
package org.apache.shardingsphere.readwritesplitting.distsql.handler.update;
-import com.google.common.base.Splitter;
-import com.google.common.base.Strings;
import lombok.Setter;
import
org.apache.shardingsphere.distsql.handler.aware.DistSQLExecutorDatabaseAware;
import
org.apache.shardingsphere.distsql.handler.aware.DistSQLExecutorRuleAware;
-import
org.apache.shardingsphere.distsql.handler.exception.storageunit.MissingRequiredStorageUnitsException;
-import
org.apache.shardingsphere.distsql.handler.required.DistSQLExecutorClusterModeRequired;
import
org.apache.shardingsphere.distsql.handler.engine.update.DistSQLUpdateExecutor;
+import
org.apache.shardingsphere.distsql.handler.exception.rule.MissingRequiredRuleException;
+import
org.apache.shardingsphere.distsql.handler.required.DistSQLExecutorClusterModeRequired;
import
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
-import
org.apache.shardingsphere.infra.exception.core.external.sql.type.generic.UnsupportedSQLOperationException;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import
org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDatabase;
-import
org.apache.shardingsphere.infra.rule.identifier.type.exportable.RuleExportEngine;
-import
org.apache.shardingsphere.infra.rule.identifier.type.exportable.constant.ExportableConstants;
-import
org.apache.shardingsphere.infra.rule.identifier.type.exportable.constant.ExportableItemConstants;
import org.apache.shardingsphere.infra.state.datasource.DataSourceState;
-import org.apache.shardingsphere.metadata.persist.MetaDataBasedPersistService;
-import org.apache.shardingsphere.mode.event.storage.StorageNodeDataSource;
-import org.apache.shardingsphere.mode.event.storage.StorageNodeRole;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.storage.service.StorageNodeStatusService;
-import
org.apache.shardingsphere.readwritesplitting.distsql.statement.status.AlterReadwriteSplittingStorageUnitStatusStatement;
+import
org.apache.shardingsphere.readwritesplitting.distsql.handler.exception.InvalidStorageUnitStatusException;
+import
org.apache.shardingsphere.readwritesplitting.distsql.handler.exception.MissingRequiredReadStorageUnitException;
+import
org.apache.shardingsphere.readwritesplitting.distsql.statement.AlterReadwriteSplittingStorageUnitStatusStatement;
+import
org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingDataSourceRule;
import
org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingRule;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.stream.Collectors;
+import java.util.Optional;
/**
* Alter readwrite-splitting storage unit status executor.
@@ -60,126 +47,34 @@ public final class
AlterReadwriteSplittingStorageUnitStatusExecutor
DistSQLExecutorDatabaseAware,
DistSQLExecutorRuleAware<ReadwriteSplittingRule> {
- private static final String DISABLE = "DISABLE";
-
private ShardingSphereDatabase database;
private ReadwriteSplittingRule rule;
@Override
public void executeUpdate(final
AlterReadwriteSplittingStorageUnitStatusStatement sqlStatement, final
ContextManager contextManager) {
- String toBeUpdatedStorageUnit = sqlStatement.getStorageUnitName();
- Map<String, Map<String, String>> exportedData = getExportedData();
- Map<String, String> replicaStorageUnits =
getReplicaResources(exportedData);
- Map<String, String> disabledStorageUnits =
getDisabledResources(contextManager);
- Map<String, String> autoAwareResources =
getAutoAwareResources(exportedData);
- boolean isDisable = DISABLE.equals(sqlStatement.getStatus());
- if (isDisable) {
- checkDisable(disabledStorageUnits.keySet(),
toBeUpdatedStorageUnit, replicaStorageUnits);
- } else {
- checkEnable(disabledStorageUnits, toBeUpdatedStorageUnit);
- }
- Collection<String> groupNames = getGroupNames(toBeUpdatedStorageUnit,
replicaStorageUnits, disabledStorageUnits, autoAwareResources);
- String groupName = sqlStatement.getGroupName();
- if (Strings.isNullOrEmpty(groupName)) {
- updateStatus(contextManager, database.getName(), groupNames,
toBeUpdatedStorageUnit, isDisable);
+ checkBeforeUpdate(sqlStatement);
+ updateStatus(contextManager, sqlStatement);
+ }
+
+ private void checkBeforeUpdate(final
AlterReadwriteSplittingStorageUnitStatusStatement sqlStatement) {
+ Optional<ReadwriteSplittingDataSourceRule> dataSourceRule =
rule.getDataSourceRules().values().stream().filter(each ->
each.getName().equalsIgnoreCase(sqlStatement.getRuleName())).findAny();
+ ShardingSpherePreconditions.checkState(dataSourceRule.isPresent(), ()
-> new MissingRequiredRuleException("Readwrite-splitting", database.getName(),
sqlStatement.getRuleName()));
+
ShardingSpherePreconditions.checkState(dataSourceRule.get().getReadwriteSplittingGroup().getReadDataSources().contains(sqlStatement.getStorageUnitName()),
+ () -> new
MissingRequiredReadStorageUnitException(dataSourceRule.get().getName(),
sqlStatement.getStorageUnitName()));
+ if (sqlStatement.isEnable()) {
+
ShardingSpherePreconditions.checkState(dataSourceRule.get().getDisabledDataSourceNames().contains(sqlStatement.getStorageUnitName()),
+ () -> new InvalidStorageUnitStatusException("the storage
unit is not disabled"));
} else {
- checkGroupName(groupNames, groupName);
- updateStatus(contextManager, database.getName(),
Collections.singleton(groupName), toBeUpdatedStorageUnit, isDisable);
+
ShardingSpherePreconditions.checkState(!dataSourceRule.get().getDisabledDataSourceNames().contains(sqlStatement.getStorageUnitName()),
+ () -> new InvalidStorageUnitStatusException("the storage
unit is already disabled"));
}
}
- @SuppressWarnings({"unchecked", "rawtypes"})
- private Map<String, Map<String, String>> getExportedData() {
- Map<String, Map<String, String>> result = new HashMap<>();
- Map<String, Object> exportedData = new RuleExportEngine(rule).export(
-
Arrays.asList(ExportableConstants.EXPORT_DYNAMIC_READWRITE_SPLITTING_RULE,
ExportableConstants.EXPORT_STATIC_READWRITE_SPLITTING_RULE));
- result.putAll((Map)
exportedData.getOrDefault(ExportableConstants.EXPORT_DYNAMIC_READWRITE_SPLITTING_RULE,
Collections.emptyMap()));
- result.putAll((Map)
exportedData.getOrDefault(ExportableConstants.EXPORT_STATIC_READWRITE_SPLITTING_RULE,
Collections.emptyMap()));
- return result;
- }
-
- private Map<String, String> getReplicaResources(final Map<String,
Map<String, String>> exportedData) {
- Map<String, String> result = new HashMap<>();
- exportedData.entrySet().stream().filter(entry ->
!entry.getValue().isEmpty()).forEach(entry -> addReplicaResource(result,
entry));
- return result;
- }
-
- private void addReplicaResource(final Map<String, String>
replicaStorageUnits, final Entry<String, Map<String, String>> exportedData) {
- exportedData.getValue().entrySet().stream().filter(entry ->
ExportableItemConstants.REPLICA_DATA_SOURCE_NAMES.equals(entry.getKey()))
- .map(entry ->
Arrays.asList(entry.getValue().split(","))).flatMap(Collection::stream).forEach(each
-> put(replicaStorageUnits, each, exportedData.getKey()));
- }
-
- private Map<String, String> getDisabledResources(final ContextManager
contextManager) {
- return
getDisabledStorageNodes(contextManager.getMetaDataContexts().getPersistService()).stream()
-
.collect(Collectors.toMap(QualifiedDatabase::getDataSourceName,
QualifiedDatabase::getGroupName, (value1, value2) -> String.join(",", value1,
value2)));
- }
-
- private Collection<QualifiedDatabase> getDisabledStorageNodes(final
MetaDataBasedPersistService persistService) {
- Map<String, StorageNodeDataSource> storageNodes = new
StorageNodeStatusService(persistService.getRepository()).loadStorageNodes();
- return storageNodes.entrySet().stream().filter(each ->
DataSourceState.DISABLED == each.getValue().getStatus())
- .map(each -> new QualifiedDatabase(each.getKey())).filter(each
->
database.getName().equalsIgnoreCase(each.getDatabaseName())).collect(Collectors.toList());
- }
-
- private Map<String, String> getAutoAwareResources(final Map<String,
Map<String, String>> exportedData) {
- Map<String, String> result = new HashMap<>();
- exportedData.values().stream().filter(each ->
each.containsKey(ExportableItemConstants.AUTO_AWARE_DATA_SOURCE_NAME)).forEach(each
-> Splitter.on(",")
-
.splitToList(each.get(ExportableItemConstants.REPLICA_DATA_SOURCE_NAMES)).forEach(each1
-> put(result, each1,
each.get(ExportableItemConstants.AUTO_AWARE_DATA_SOURCE_NAME))));
- return result;
- }
-
- private void checkDisable(final Collection<String> disabledStorageUnits,
final String toBeDisabledStorageUnit, final Map<String, String>
replicaResources) {
- checkResourceExists(toBeDisabledStorageUnit);
- checkIsDisabled(replicaResources, disabledStorageUnits,
toBeDisabledStorageUnit);
- checkIsReplicaResource(replicaResources, toBeDisabledStorageUnit);
- }
-
- private void checkIsDisabled(final Map<String, String> replicaResources,
final Collection<String> disabledStorageUnits, final String
toBeDisabledStorageUnit) {
- String toBeDisableResourceRuleNames =
replicaResources.get(toBeDisabledStorageUnit);
-
ShardingSpherePreconditions.checkState(!Strings.isNullOrEmpty(toBeDisableResourceRuleNames)
|| !disabledStorageUnits.contains(toBeDisabledStorageUnit),
- () -> new UnsupportedSQLOperationException(String.format("`%s`
has been disabled", toBeDisabledStorageUnit)));
- }
-
- private void checkIsReplicaResource(final Map<String, String>
replicaStorageUnits, final String toBeDisabledStorageUnit) {
-
ShardingSpherePreconditions.checkState(replicaStorageUnits.containsKey(toBeDisabledStorageUnit),
- () -> new UnsupportedSQLOperationException(String.format("`%s`
is not used as a read storage unit by any read-write separation rules,cannot be
disabled", toBeDisabledStorageUnit)));
- }
-
- private void checkGroupName(final Collection<String> groupNames, final
String groupName) {
- ShardingSpherePreconditions.checkState(groupNames.contains(groupName),
- () -> new UnsupportedSQLOperationException(String.format("The
current database does not exist the group `%s`", groupName)));
- }
-
- private void checkEnable(final Map<String, String> disabledResources,
final String toBeEnabledResource) {
- checkResourceExists(toBeEnabledResource);
- checkIsNotDisabled(disabledResources.keySet(), toBeEnabledResource);
- }
-
- private void checkResourceExists(final String toBeDisabledResource) {
- Collection<String> notExistedResources =
database.getResourceMetaData().getNotExistedDataSources(Collections.singleton(toBeDisabledResource));
- ShardingSpherePreconditions.checkState(notExistedResources.isEmpty(),
() -> new MissingRequiredStorageUnitsException(database.getName(),
Collections.singleton(toBeDisabledResource)));
- }
-
- private void checkIsNotDisabled(final Collection<String>
disabledResources, final String toBeEnabledResource) {
-
ShardingSpherePreconditions.checkState(disabledResources.contains(toBeEnabledResource),
() -> new UnsupportedSQLOperationException(String.format("`%s` is not
disabled", toBeEnabledResource)));
- }
-
- private Collection<String> getGroupNames(final String
toBeDisableStorageUnit, final Map<String, String> replicaStorageUnits,
- final Map<String, String>
disabledStorageUnits, final Map<String, String> autoAwareResources) {
- String groupNames =
autoAwareResources.getOrDefault(toBeDisableStorageUnit,
replicaStorageUnits.getOrDefault(toBeDisableStorageUnit,
disabledStorageUnits.get(toBeDisableStorageUnit)));
- return Splitter.on(",").splitToList(groupNames);
- }
-
- private void updateStatus(final ContextManager contextManager, final
String databaseName, final Collection<String> groupNames, final String
toBeDisableStorageUnit, final boolean isDisable) {
- groupNames.forEach(each -> {
- StorageNodeDataSource storageNodeDataSource = new
StorageNodeDataSource(StorageNodeRole.MEMBER, isDisable ?
DataSourceState.DISABLED : DataSourceState.ENABLED);
- new
StorageNodeStatusService(contextManager.getMetaDataContexts().getPersistService().getRepository())
- .changeStorageNodeStatus(databaseName, each,
toBeDisableStorageUnit, storageNodeDataSource);
- });
- }
-
- private void put(final Map<String, String> map, final String key, final
String value) {
- map.put(key, map.containsKey(key) ? String.join(",", map.get(key),
value) : value);
+ private void updateStatus(final ContextManager contextManager, final
AlterReadwriteSplittingStorageUnitStatusStatement sqlStatement) {
+ DataSourceState status = sqlStatement.isEnable() ?
DataSourceState.ENABLED : DataSourceState.DISABLED;
+ new
StorageNodeStatusService(contextManager.getMetaDataContexts().getPersistService().getRepository())
+ .changeMemberStorageNodeStatus(database.getName(),
sqlStatement.getRuleName(), sqlStatement.getStorageUnitName(), status);
}
@Override
diff --git
a/features/readwrite-splitting/distsql/parser/src/main/antlr4/imports/readwrite-splitting/BaseRule.g4
b/features/readwrite-splitting/distsql/parser/src/main/antlr4/imports/readwrite-splitting/BaseRule.g4
index 8b23e50147a..0551a45949f 100644
---
a/features/readwrite-splitting/distsql/parser/src/main/antlr4/imports/readwrite-splitting/BaseRule.g4
+++
b/features/readwrite-splitting/distsql/parser/src/main/antlr4/imports/readwrite-splitting/BaseRule.g4
@@ -53,7 +53,7 @@ databaseName
: IDENTIFIER_
;
-groupName
+ruleName
: IDENTIFIER_
;
diff --git
a/features/readwrite-splitting/distsql/parser/src/main/antlr4/imports/readwrite-splitting/RALStatement.g4
b/features/readwrite-splitting/distsql/parser/src/main/antlr4/imports/readwrite-splitting/RALStatement.g4
index ecf2df35e0c..0d62feac8c8 100644
---
a/features/readwrite-splitting/distsql/parser/src/main/antlr4/imports/readwrite-splitting/RALStatement.g4
+++
b/features/readwrite-splitting/distsql/parser/src/main/antlr4/imports/readwrite-splitting/RALStatement.g4
@@ -20,11 +20,11 @@ grammar RALStatement;
import BaseRule;
alterReadwriteSplittingStorageUnitStatus
- : ALTER READWRITE_SPLITTING RULE (groupName)? (ENABLE | DISABLE)
storageUnitName (FROM databaseName)?
+ : ALTER READWRITE_SPLITTING RULE ruleName (ENABLE | DISABLE)
storageUnitName (FROM databaseName)?
;
showStatusFromReadwriteSplittingRules
- : SHOW STATUS FROM READWRITE_SPLITTING (RULES | RULE groupName) (FROM
databaseName)?
+ : SHOW STATUS FROM READWRITE_SPLITTING (RULES | RULE ruleName) (FROM
databaseName)?
;
showReadQueryLoadBalanceAlgorithmPlugins
diff --git
a/features/readwrite-splitting/distsql/parser/src/main/antlr4/imports/readwrite-splitting/RDLStatement.g4
b/features/readwrite-splitting/distsql/parser/src/main/antlr4/imports/readwrite-splitting/RDLStatement.g4
index 0b49507f937..6ebd57405bb 100644
---
a/features/readwrite-splitting/distsql/parser/src/main/antlr4/imports/readwrite-splitting/RDLStatement.g4
+++
b/features/readwrite-splitting/distsql/parser/src/main/antlr4/imports/readwrite-splitting/RDLStatement.g4
@@ -39,10 +39,6 @@ dataSourceDefinition
: writeStorageUnit COMMA_ readStorageUnits
;
-ruleName
- : IDENTIFIER_
- ;
-
writeStorageUnit
: WRITE_STORAGE_UNIT EQ_ writeStorageUnitName
;
diff --git
a/features/readwrite-splitting/distsql/parser/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/parser/core/ReadwriteSplittingDistSQLStatementVisitor.java
b/features/readwrite-splitting/distsql/parser/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/parser/core/ReadwriteSplittingDistSQLStatementVisitor.java
index 480c63ef948..1757c64145c 100644
---
a/features/readwrite-splitting/distsql/parser/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/parser/core/ReadwriteSplittingDistSQLStatementVisitor.java
+++
b/features/readwrite-splitting/distsql/parser/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/parser/core/ReadwriteSplittingDistSQLStatementVisitor.java
@@ -41,7 +41,7 @@ import
org.apache.shardingsphere.readwritesplitting.distsql.statement.CreateRead
import
org.apache.shardingsphere.readwritesplitting.distsql.statement.DropReadwriteSplittingRuleStatement;
import
org.apache.shardingsphere.readwritesplitting.distsql.statement.ShowReadwriteSplittingRulesStatement;
import
org.apache.shardingsphere.readwritesplitting.distsql.statement.ShowStatusFromReadwriteSplittingRulesStatement;
-import
org.apache.shardingsphere.readwritesplitting.distsql.statement.status.AlterReadwriteSplittingStorageUnitStatusStatement;
+import
org.apache.shardingsphere.readwritesplitting.distsql.statement.AlterReadwriteSplittingStorageUnitStatusStatement;
import org.apache.shardingsphere.sql.parser.api.ASTNode;
import org.apache.shardingsphere.sql.parser.api.visitor.SQLVisitor;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.DatabaseSegment;
@@ -74,10 +74,7 @@ public final class ReadwriteSplittingDistSQLStatementVisitor
extends ReadwriteSp
@Override
public ASTNode visitAlterReadwriteSplittingStorageUnitStatus(final
AlterReadwriteSplittingStorageUnitStatusContext ctx) {
DatabaseSegment databaseSegment = null == ctx.databaseName() ? null :
(DatabaseSegment) visit(ctx.databaseName());
- String groupName = getIdentifierValue(ctx.groupName());
- String status = null == ctx.ENABLE() ?
ctx.DISABLE().getText().toUpperCase() : ctx.ENABLE().getText().toUpperCase();
- String storageUnitName = getIdentifierValue(ctx.storageUnitName());
- return new
AlterReadwriteSplittingStorageUnitStatusStatement(databaseSegment, groupName,
storageUnitName, status);
+ return new
AlterReadwriteSplittingStorageUnitStatusStatement(databaseSegment,
getIdentifierValue(ctx.ruleName()), getIdentifierValue(ctx.storageUnitName()),
null == ctx.DISABLE());
}
@Override
@@ -107,8 +104,8 @@ public final class
ReadwriteSplittingDistSQLStatementVisitor extends ReadwriteSp
@Override
public ASTNode visitShowStatusFromReadwriteSplittingRules(final
ShowStatusFromReadwriteSplittingRulesContext ctx) {
DatabaseSegment databaseSegment = null == ctx.databaseName() ? null :
(DatabaseSegment) visit(ctx.databaseName());
- String groupName = getIdentifierValue(ctx.groupName());
- return new
ShowStatusFromReadwriteSplittingRulesStatement(databaseSegment, groupName);
+ String ruleName = getIdentifierValue(ctx.ruleName());
+ return new
ShowStatusFromReadwriteSplittingRulesStatement(databaseSegment, ruleName);
}
private String getIdentifierValue(final ParseTree context) {
diff --git
a/features/readwrite-splitting/distsql/statement/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/statement/status/AlterReadwriteSplittingStorageUnitStatusStatement.java
b/features/readwrite-splitting/distsql/statement/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/statement/AlterReadwriteSplittingStorageUnitStatusStatement.java
similarity index 95%
rename from
features/readwrite-splitting/distsql/statement/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/statement/status/AlterReadwriteSplittingStorageUnitStatusStatement.java
rename to
features/readwrite-splitting/distsql/statement/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/statement/AlterReadwriteSplittingStorageUnitStatusStatement.java
index f87e9926651..baea6656d4a 100644
---
a/features/readwrite-splitting/distsql/statement/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/statement/status/AlterReadwriteSplittingStorageUnitStatusStatement.java
+++
b/features/readwrite-splitting/distsql/statement/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/statement/AlterReadwriteSplittingStorageUnitStatusStatement.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.readwritesplitting.distsql.statement.status;
+package org.apache.shardingsphere.readwritesplitting.distsql.statement;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
@@ -34,11 +34,11 @@ public final class
AlterReadwriteSplittingStorageUnitStatusStatement extends Upd
private final DatabaseSegment database;
- private final String groupName;
+ private final String ruleName;
private final String storageUnitName;
- private final String status;
+ private final boolean enable;
@Override
public Optional<DatabaseSegment> getDatabase() {
diff --git
a/mode/core/src/main/java/org/apache/shardingsphere/mode/storage/service/StorageNodeStatusService.java
b/mode/core/src/main/java/org/apache/shardingsphere/mode/storage/service/StorageNodeStatusService.java
index ce765e67cbd..f352bf30c11 100644
---
a/mode/core/src/main/java/org/apache/shardingsphere/mode/storage/service/StorageNodeStatusService.java
+++
b/mode/core/src/main/java/org/apache/shardingsphere/mode/storage/service/StorageNodeStatusService.java
@@ -20,8 +20,10 @@ package org.apache.shardingsphere.mode.storage.service;
import com.google.common.base.Strings;
import lombok.RequiredArgsConstructor;
import
org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDatabase;
+import org.apache.shardingsphere.infra.state.datasource.DataSourceState;
import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
import org.apache.shardingsphere.mode.event.storage.StorageNodeDataSource;
+import org.apache.shardingsphere.mode.event.storage.StorageNodeRole;
import org.apache.shardingsphere.mode.spi.PersistRepository;
import org.apache.shardingsphere.mode.storage.node.StorageNode;
import org.apache.shardingsphere.mode.storage.yaml.YamlStorageNodeDataSource;
@@ -57,14 +59,15 @@ public final class StorageNodeStatusService {
}
/**
- * Change storage node status.
+ * Change member storage node status.
*
* @param databaseName database name
* @param groupName group name
* @param storageUnitName storage unit name
- * @param storageNodeDataSource storage node data source
+ * @param dataSourceState data source state
*/
- public void changeStorageNodeStatus(final String databaseName, final
String groupName, final String storageUnitName, final StorageNodeDataSource
storageNodeDataSource) {
+ public void changeMemberStorageNodeStatus(final String databaseName, final
String groupName, final String storageUnitName, final DataSourceState
dataSourceState) {
+ StorageNodeDataSource storageNodeDataSource = new
StorageNodeDataSource(StorageNodeRole.MEMBER, dataSourceState);
repository.persist(StorageNode.getStorageNodeDataSourcePath(new
QualifiedDatabase(databaseName, groupName, storageUnitName)),
YamlEngine.marshal(new
YamlStorageNodeDataSourceSwapper().swapToYamlConfiguration(storageNodeDataSource)));
}
diff --git
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ral/impl/UpdatableRALStatementAssert.java
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ral/impl/UpdatableRALStatementAssert.java
index 1b7cac49047..d084d91e49e 100644
---
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ral/impl/UpdatableRALStatementAssert.java
+++
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ral/impl/UpdatableRALStatementAssert.java
@@ -28,7 +28,7 @@ import
org.apache.shardingsphere.distsql.statement.ral.updatable.LockClusterStat
import
org.apache.shardingsphere.distsql.statement.ral.updatable.RefreshTableMetaDataStatement;
import
org.apache.shardingsphere.distsql.statement.ral.updatable.SetDistVariableStatement;
import
org.apache.shardingsphere.distsql.statement.ral.updatable.UnlabelComputeNodeStatement;
-import
org.apache.shardingsphere.readwritesplitting.distsql.statement.status.AlterReadwriteSplittingStorageUnitStatusStatement;
+import
org.apache.shardingsphere.readwritesplitting.distsql.statement.AlterReadwriteSplittingStorageUnitStatusStatement;
import
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.SQLCaseAssertContext;
import
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.ral.impl.updatable.AlterComputeNodeStatementAssert;
import
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.ral.impl.updatable.AlterReadwriteSplittingStorageUnitStatusStatementAssert;
diff --git
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ral/impl/updatable/AlterReadwriteSplittingStorageUnitStatusStatementAssert.java
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ral/impl/updatable/AlterReadwriteSplittingStorageUnitStatusStatementAssert.java
index 9a56b7bdbb2..e84bf09fef4 100644
---
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ral/impl/updatable/AlterReadwriteSplittingStorageUnitStatusStatementAssert.java
+++
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ral/impl/updatable/AlterReadwriteSplittingStorageUnitStatusStatementAssert.java
@@ -19,7 +19,7 @@ package
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
-import
org.apache.shardingsphere.readwritesplitting.distsql.statement.status.AlterReadwriteSplittingStorageUnitStatusStatement;
+import
org.apache.shardingsphere.readwritesplitting.distsql.statement.AlterReadwriteSplittingStorageUnitStatusStatement;
import
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.SQLCaseAssertContext;
import
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.segment.database.DatabaseAssert;
import
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.ExistingAssert;
@@ -44,9 +44,9 @@ public final class
AlterReadwriteSplittingStorageUnitStatusStatementAssert {
public static void assertIs(final SQLCaseAssertContext assertContext,
final AlterReadwriteSplittingStorageUnitStatusStatement actual,
final
AlterReadwriteSplittingStorageUnitStatusStatementTestCase expected) {
if (ExistingAssert.assertIs(assertContext, actual, expected)) {
- assertThat(actual.getGroupName(), is(expected.getGroupName()));
+ assertThat(actual.getRuleName(), is(expected.getRuleName()));
assertThat(actual.getStorageUnitName(),
is(expected.getStorageUnitName()));
- assertThat(actual.getStatus(), is(expected.getStatus()));
+ assertThat(actual.isEnable(), is(expected.isEnable()));
assertIs(assertContext, actual, (DatabaseContainedTestCase)
expected);
}
}
diff --git
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/ral/AlterReadwriteSplittingStorageUnitStatusStatementTestCase.java
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/ral/AlterReadwriteSplittingStorageUnitStatusStatementTestCase.java
index 3a618a27909..a9334effec4 100644
---
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/ral/AlterReadwriteSplittingStorageUnitStatusStatementTestCase.java
+++
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/ral/AlterReadwriteSplittingStorageUnitStatusStatementTestCase.java
@@ -30,12 +30,12 @@ import javax.xml.bind.annotation.XmlAttribute;
@Setter
public final class AlterReadwriteSplittingStorageUnitStatusStatementTestCase
extends DatabaseContainedTestCase {
- @XmlAttribute(name = "group-name")
- private String groupName;
+ @XmlAttribute(name = "rule-name")
+ private String ruleName;
@XmlAttribute(name = "storage-unit-name")
private String storageUnitName;
- @XmlAttribute(name = "status")
- private String status;
+ @XmlAttribute(name = "enable")
+ private boolean enable;
}
diff --git a/test/it/parser/src/main/resources/case/ral/updatable.xml
b/test/it/parser/src/main/resources/case/ral/updatable.xml
index 0726fbd4dd0..33f158f08b0 100644
--- a/test/it/parser/src/main/resources/case/ral/updatable.xml
+++ b/test/it/parser/src/main/resources/case/ral/updatable.xml
@@ -76,11 +76,11 @@
<file-path>/json/exported-metadata.json</file-path>
</import-metadata>
- <alter-readwrite-splitting-storage-unit-status-enable
sql-case-id="alter-readwrite-splitting-storage-unit-status-enable"
group-name="group_1" storage-unit-name="read_ds_0" status="ENABLE">
+ <alter-readwrite-splitting-storage-unit-status-enable
sql-case-id="alter-readwrite-splitting-storage-unit-status-enable"
rule-name="group_1" storage-unit-name="read_ds_0" enable="true">
<database name="read_write" start-index="61" stop-index="70" />
</alter-readwrite-splitting-storage-unit-status-enable>
- <alter-readwrite-splitting-storage-unit-status-disable
sql-case-id="alter-readwrite-splitting-storage-unit-status-disable"
group-name="group_1" storage-unit-name="read_ds_0" status="DISABLE">
+ <alter-readwrite-splitting-storage-unit-status-disable
sql-case-id="alter-readwrite-splitting-storage-unit-status-disable"
rule-name="group_1" storage-unit-name="read_ds_0" enable="false">
<database name="read_write" start-index="62" stop-index="71" />
</alter-readwrite-splitting-storage-unit-status-disable>
</sql-parser-test-cases>