You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by su...@apache.org on 2024/05/09 11:45:46 UTC
(shardingsphere) branch master updated: Rename StorageNodeDataSource to QualifiedDataSourceStatus (#31184)
This is an automated email from the ASF dual-hosted git repository.
sunnianjun 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 b2800005964 Rename StorageNodeDataSource to QualifiedDataSourceStatus (#31184)
b2800005964 is described below
commit b2800005964334d2f9b1fc68e580ca71bb2365c6
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Thu May 9 19:45:39 2024 +0800
Rename StorageNodeDataSource to QualifiedDataSourceStatus (#31184)
* Rename StorageNodeDataSource to QualifiedDataSourceStatus
* Rename StorageNodeDataSource to QualifiedDataSourceStatus
---
...eadwriteSplittingStorageUnitStatusExecutor.java | 4 ++--
.../mode/metadata/MetaDataContextsFactory.java | 18 +++++++--------
...aSource.java => QualifiedDataSourceStatus.java} | 4 ++--
....java => QualifiedDataSourceStatusService.java} | 26 +++++++++++-----------
...rce.java => YamlQualifiedDataSourceStatus.java} | 4 ++--
...a => YamlQualifiedDataSourceStatusSwapper.java} | 16 ++++++-------
.../cluster/ClusterContextManagerBuilder.java | 3 ++-
.../cluster/coordinator/RegistryCenter.java | 6 ++---
.../storage/event/StorageNodeChangedEvent.java | 4 ++--
...java => QualifiedDataSourceChangedWatcher.java} | 14 ++++++------
.../subscriber/StateChangedSubscriber.java | 4 ++--
....cluster.coordinator.registry.GovernanceWatcher | 2 +-
...a => QualifiedDataSourceStatusServiceTest.java} | 6 ++---
... => QualifiedDataSourceChangedWatcherTest.java} | 22 +++++++++---------
.../subscriber/StateChangedSubscriberTest.java | 8 +++----
15 files changed, 71 insertions(+), 70 deletions(-)
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 661a71e7a1f..a3d4a755b54 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
@@ -28,7 +28,7 @@ import org.apache.shardingsphere.infra.exception.kernel.metadata.rule.MissingReq
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.state.datasource.DataSourceState;
import org.apache.shardingsphere.mode.manager.ContextManager;
-import org.apache.shardingsphere.mode.storage.service.StorageNodeStatusService;
+import org.apache.shardingsphere.mode.storage.service.QualifiedDataSourceStatusService;
import org.apache.shardingsphere.readwritesplitting.constant.ReadwriteSplittingDataSourceType;
import org.apache.shardingsphere.readwritesplitting.distsql.statement.AlterReadwriteSplittingStorageUnitStatusStatement;
import org.apache.shardingsphere.readwritesplitting.exception.ReadwriteSplittingRuleExceptionIdentifier;
@@ -77,7 +77,7 @@ public final class AlterReadwriteSplittingStorageUnitStatusExecutor
private void updateStatus(final ContextManager contextManager, final AlterReadwriteSplittingStorageUnitStatusStatement sqlStatement) {
DataSourceState status = sqlStatement.isEnable() ? DataSourceState.ENABLED : DataSourceState.DISABLED;
- new StorageNodeStatusService(contextManager.getMetaDataContexts().getPersistService().getRepository())
+ new QualifiedDataSourceStatusService(contextManager.getMetaDataContexts().getPersistService().getRepository())
.changeMemberQualifiedDataSourceStatus(database.getName(), sqlStatement.getRuleName(), sqlStatement.getStorageUnitName(), status);
}
diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContextsFactory.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContextsFactory.java
index 0b55ecc021d..7a2535420cf 100644
--- a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContextsFactory.java
+++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContextsFactory.java
@@ -39,7 +39,7 @@ import org.apache.shardingsphere.infra.state.datasource.DataSourceStateManager;
import org.apache.shardingsphere.metadata.factory.ExternalMetaDataFactory;
import org.apache.shardingsphere.metadata.factory.InternalMetaDataFactory;
import org.apache.shardingsphere.metadata.persist.MetaDataPersistService;
-import org.apache.shardingsphere.mode.storage.StorageNodeDataSource;
+import org.apache.shardingsphere.mode.storage.QualifiedDataSourceStatus;
import org.apache.shardingsphere.mode.manager.ContextManagerBuilderParameter;
import javax.sql.DataSource;
@@ -78,17 +78,17 @@ public final class MetaDataContextsFactory {
* @param persistService persist service
* @param param context manager builder parameter
* @param instanceContext instance context
- * @param storageNodes storage nodes
+ * @param statusMap qualified data source status map
* @return meta data contexts
* @throws SQLException SQL exception
*/
public static MetaDataContexts create(final MetaDataPersistService persistService, final ContextManagerBuilderParameter param,
- final InstanceContext instanceContext, final Map<String, StorageNodeDataSource> storageNodes) throws SQLException {
+ final InstanceContext instanceContext, final Map<String, QualifiedDataSourceStatus> statusMap) throws SQLException {
boolean isDatabaseMetaDataExisted = !persistService.getDatabaseMetaDataService().loadAllDatabaseNames().isEmpty();
Map<String, DatabaseConfiguration> effectiveDatabaseConfigs = isDatabaseMetaDataExisted
? createEffectiveDatabaseConfigurations(getDatabaseNames(instanceContext, param.getDatabaseConfigs(), persistService), param.getDatabaseConfigs(), persistService)
: param.getDatabaseConfigs();
- checkDataSourceStates(effectiveDatabaseConfigs, storageNodes, param.isForce());
+ checkDataSourceStates(effectiveDatabaseConfigs, statusMap, param.isForce());
// TODO load global data sources from persist service
Map<String, DataSource> globalDataSources = param.getGlobalDataSources();
Collection<RuleConfiguration> globalRuleConfigs = isDatabaseMetaDataExisted ? persistService.getGlobalRuleService().load() : param.getGlobalRuleConfigs();
@@ -130,8 +130,8 @@ public final class MetaDataContextsFactory {
}
}
- private static void checkDataSourceStates(final Map<String, DatabaseConfiguration> databaseConfigs, final Map<String, StorageNodeDataSource> storageNodes, final boolean force) {
- Map<String, DataSourceState> storageDataSourceStates = getStorageDataSourceStates(storageNodes);
+ private static void checkDataSourceStates(final Map<String, DatabaseConfiguration> databaseConfigs, final Map<String, QualifiedDataSourceStatus> statusMap, final boolean force) {
+ Map<String, DataSourceState> storageDataSourceStates = getStorageDataSourceStates(statusMap);
databaseConfigs.forEach((key, value) -> {
if (!value.getStorageUnits().isEmpty()) {
DataSourceStateManager.getInstance().initStates(key, value.getStorageUnits(), storageDataSourceStates, force);
@@ -139,9 +139,9 @@ public final class MetaDataContextsFactory {
});
}
- private static Map<String, DataSourceState> getStorageDataSourceStates(final Map<String, StorageNodeDataSource> storageDataSourceStates) {
- Map<String, DataSourceState> result = new HashMap<>(storageDataSourceStates.size(), 1F);
- storageDataSourceStates.forEach((key, value) -> {
+ private static Map<String, DataSourceState> getStorageDataSourceStates(final Map<String, QualifiedDataSourceStatus> statusMap) {
+ Map<String, DataSourceState> result = new HashMap<>(statusMap.size(), 1F);
+ statusMap.forEach((key, value) -> {
List<String> values = Splitter.on(".").splitToList(key);
Preconditions.checkArgument(3 == values.size(), "Illegal data source of storage node.");
String databaseName = values.get(0);
diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/storage/StorageNodeDataSource.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/storage/QualifiedDataSourceStatus.java
similarity index 93%
rename from mode/core/src/main/java/org/apache/shardingsphere/mode/storage/StorageNodeDataSource.java
rename to mode/core/src/main/java/org/apache/shardingsphere/mode/storage/QualifiedDataSourceStatus.java
index 364d06464a4..fdffe12439c 100644
--- a/mode/core/src/main/java/org/apache/shardingsphere/mode/storage/StorageNodeDataSource.java
+++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/storage/QualifiedDataSourceStatus.java
@@ -22,11 +22,11 @@ import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.infra.state.datasource.DataSourceState;
/**
- * Storage node data source.
+ * Qualified data source status.
*/
@RequiredArgsConstructor
@Getter
-public final class StorageNodeDataSource {
+public final class QualifiedDataSourceStatus {
private final Role role;
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/QualifiedDataSourceStatusService.java
similarity index 69%
rename from mode/core/src/main/java/org/apache/shardingsphere/mode/storage/service/StorageNodeStatusService.java
rename to mode/core/src/main/java/org/apache/shardingsphere/mode/storage/service/QualifiedDataSourceStatusService.java
index ab34e512304..7f993b5616a 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/QualifiedDataSourceStatusService.java
@@ -23,36 +23,36 @@ import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDataSou
import org.apache.shardingsphere.infra.state.datasource.DataSourceState;
import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
import org.apache.shardingsphere.mode.spi.PersistRepository;
-import org.apache.shardingsphere.mode.storage.StorageNodeDataSource;
-import org.apache.shardingsphere.mode.storage.StorageNodeDataSource.Role;
+import org.apache.shardingsphere.mode.storage.QualifiedDataSourceStatus;
+import org.apache.shardingsphere.mode.storage.QualifiedDataSourceStatus.Role;
import org.apache.shardingsphere.mode.storage.node.QualifiedDataSourceNode;
-import org.apache.shardingsphere.mode.storage.yaml.YamlStorageNodeDataSource;
-import org.apache.shardingsphere.mode.storage.yaml.YamlStorageNodeDataSourceSwapper;
+import org.apache.shardingsphere.mode.storage.yaml.YamlQualifiedDataSourceStatus;
+import org.apache.shardingsphere.mode.storage.yaml.YamlQualifiedDataSourceStatusSwapper;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
/**
- * Storage node status service.
+ * Qualified data source status service.
*/
@RequiredArgsConstructor
-public final class StorageNodeStatusService {
+public final class QualifiedDataSourceStatusService {
private final PersistRepository repository;
/**
- * Load storage node names.
+ * Load qualified data source status.
*
- * @return loaded storage node names
+ * @return qualified data source status
*/
- public Map<String, StorageNodeDataSource> loadStorageNodes() {
+ public Map<String, QualifiedDataSourceStatus> loadQualifiedDataSourceStatus() {
Collection<String> qualifiedDataSourceNodes = repository.getChildrenKeys(QualifiedDataSourceNode.getRootPath());
- Map<String, StorageNodeDataSource> result = new HashMap<>(qualifiedDataSourceNodes.size(), 1F);
+ Map<String, QualifiedDataSourceStatus> result = new HashMap<>(qualifiedDataSourceNodes.size(), 1F);
qualifiedDataSourceNodes.forEach(each -> {
String yamlContent = repository.getDirectly(QualifiedDataSourceNode.getQualifiedDataSourceNodePath(new QualifiedDataSource(each)));
if (!Strings.isNullOrEmpty(yamlContent)) {
- result.put(each, new YamlStorageNodeDataSourceSwapper().swapToObject(YamlEngine.unmarshal(yamlContent, YamlStorageNodeDataSource.class)));
+ result.put(each, new YamlQualifiedDataSourceStatusSwapper().swapToObject(YamlEngine.unmarshal(yamlContent, YamlQualifiedDataSourceStatus.class)));
}
});
return result;
@@ -67,8 +67,8 @@ public final class StorageNodeStatusService {
* @param dataSourceState data source state
*/
public void changeMemberQualifiedDataSourceStatus(final String databaseName, final String groupName, final String storageUnitName, final DataSourceState dataSourceState) {
- StorageNodeDataSource storageNodeDataSource = new StorageNodeDataSource(Role.MEMBER, dataSourceState);
+ QualifiedDataSourceStatus status = new QualifiedDataSourceStatus(Role.MEMBER, dataSourceState);
repository.persist(QualifiedDataSourceNode.getQualifiedDataSourceNodePath(new QualifiedDataSource(databaseName, groupName, storageUnitName)),
- YamlEngine.marshal(new YamlStorageNodeDataSourceSwapper().swapToYamlConfiguration(storageNodeDataSource)));
+ YamlEngine.marshal(new YamlQualifiedDataSourceStatusSwapper().swapToYamlConfiguration(status)));
}
}
diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/storage/yaml/YamlStorageNodeDataSource.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/storage/yaml/YamlQualifiedDataSourceStatus.java
similarity index 90%
rename from mode/core/src/main/java/org/apache/shardingsphere/mode/storage/yaml/YamlStorageNodeDataSource.java
rename to mode/core/src/main/java/org/apache/shardingsphere/mode/storage/yaml/YamlQualifiedDataSourceStatus.java
index 9182a398abf..754a3817b2d 100644
--- a/mode/core/src/main/java/org/apache/shardingsphere/mode/storage/yaml/YamlStorageNodeDataSource.java
+++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/storage/yaml/YamlQualifiedDataSourceStatus.java
@@ -22,11 +22,11 @@ import lombok.Setter;
import org.apache.shardingsphere.infra.util.yaml.YamlConfiguration;
/**
- * YAML storage node data source.
+ * YAML qualified data source status.
*/
@Getter
@Setter
-public final class YamlStorageNodeDataSource implements YamlConfiguration {
+public final class YamlQualifiedDataSourceStatus implements YamlConfiguration {
private String role;
diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/storage/yaml/YamlStorageNodeDataSourceSwapper.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/storage/yaml/YamlQualifiedDataSourceStatusSwapper.java
similarity index 60%
rename from mode/core/src/main/java/org/apache/shardingsphere/mode/storage/yaml/YamlStorageNodeDataSourceSwapper.java
rename to mode/core/src/main/java/org/apache/shardingsphere/mode/storage/yaml/YamlQualifiedDataSourceStatusSwapper.java
index 4ec210ae7ed..c8c12924755 100644
--- a/mode/core/src/main/java/org/apache/shardingsphere/mode/storage/yaml/YamlStorageNodeDataSourceSwapper.java
+++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/storage/yaml/YamlQualifiedDataSourceStatusSwapper.java
@@ -19,24 +19,24 @@ package org.apache.shardingsphere.mode.storage.yaml;
import org.apache.shardingsphere.infra.state.datasource.DataSourceState;
import org.apache.shardingsphere.infra.util.yaml.swapper.YamlConfigurationSwapper;
-import org.apache.shardingsphere.mode.storage.StorageNodeDataSource;
-import org.apache.shardingsphere.mode.storage.StorageNodeDataSource.Role;
+import org.apache.shardingsphere.mode.storage.QualifiedDataSourceStatus;
+import org.apache.shardingsphere.mode.storage.QualifiedDataSourceStatus.Role;
/**
- * YAML storage node data source swapper.
+ * YAML qualified data source status swapper.
*/
-public final class YamlStorageNodeDataSourceSwapper implements YamlConfigurationSwapper<YamlStorageNodeDataSource, StorageNodeDataSource> {
+public final class YamlQualifiedDataSourceStatusSwapper implements YamlConfigurationSwapper<YamlQualifiedDataSourceStatus, QualifiedDataSourceStatus> {
@Override
- public YamlStorageNodeDataSource swapToYamlConfiguration(final StorageNodeDataSource data) {
- YamlStorageNodeDataSource result = new YamlStorageNodeDataSource();
+ public YamlQualifiedDataSourceStatus swapToYamlConfiguration(final QualifiedDataSourceStatus data) {
+ YamlQualifiedDataSourceStatus result = new YamlQualifiedDataSourceStatus();
result.setRole(data.getRole().name());
result.setStatus(data.getStatus().name());
return result;
}
@Override
- public StorageNodeDataSource swapToObject(final YamlStorageNodeDataSource yamlConfig) {
- return new StorageNodeDataSource(Role.valueOf(yamlConfig.getRole()), DataSourceState.valueOf(yamlConfig.getStatus()));
+ public QualifiedDataSourceStatus swapToObject(final YamlQualifiedDataSourceStatus yamlConfig) {
+ return new QualifiedDataSourceStatus(Role.valueOf(yamlConfig.getRole()), DataSourceState.valueOf(yamlConfig.getStatus()));
}
}
diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
index 16966cf98fc..16ed52f69da 100644
--- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
+++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
@@ -54,7 +54,8 @@ public final class ClusterContextManagerBuilder implements ContextManagerBuilder
((InstanceContextAware) registryCenter.getRepository()).setInstanceContext(instanceContext);
}
MetaDataPersistService persistService = new MetaDataPersistService(repository);
- MetaDataContexts metaDataContexts = MetaDataContextsFactory.create(persistService, param, instanceContext, registryCenter.getStorageNodeStatusService().loadStorageNodes());
+ MetaDataContexts metaDataContexts = MetaDataContextsFactory.create(
+ persistService, param, instanceContext, registryCenter.getQualifiedDataSourceStatusService().loadQualifiedDataSourceStatus());
ContextManager result = new ContextManager(metaDataContexts, instanceContext);
setContextManagerAware(result);
registerOnline(registryCenter, param, result);
diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/RegistryCenter.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/RegistryCenter.java
index 4b4d6c7cc10..d7a476112ab 100644
--- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/RegistryCenter.java
+++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/RegistryCenter.java
@@ -34,7 +34,7 @@ import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.statu
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.cluster.subscriber.ClusterStatusSubscriber;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.service.ComputeNodeStatusService;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.subscriber.ComputeNodeStatusSubscriber;
-import org.apache.shardingsphere.mode.storage.service.StorageNodeStatusService;
+import org.apache.shardingsphere.mode.storage.service.QualifiedDataSourceStatusService;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.storage.subscriber.QualifiedDataSourceStatusSubscriber;
import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository;
import org.apache.shardingsphere.mode.repository.cluster.lock.holder.DistributedLockHolder;
@@ -52,7 +52,7 @@ public final class RegistryCenter {
private final ClusterPersistRepository repository;
@Getter
- private final StorageNodeStatusService storageNodeStatusService;
+ private final QualifiedDataSourceStatusService qualifiedDataSourceStatusService;
@Getter
private final ClusterStatusService clusterStatusService;
@@ -78,7 +78,7 @@ public final class RegistryCenter {
this.eventBusContext = eventBusContext;
this.instanceMetaData = instanceMetaData;
this.databaseConfigs = databaseConfigs;
- storageNodeStatusService = new StorageNodeStatusService(repository);
+ qualifiedDataSourceStatusService = new QualifiedDataSourceStatusService(repository);
clusterStatusService = new ClusterStatusService(repository);
computeNodeStatusService = new ComputeNodeStatusService(repository);
globalLockPersistService = new GlobalLockPersistService(initDistributedLockHolder(repository));
diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/event/StorageNodeChangedEvent.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/event/StorageNodeChangedEvent.java
index 1f1f029e7bc..c045e408c53 100644
--- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/event/StorageNodeChangedEvent.java
+++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/event/StorageNodeChangedEvent.java
@@ -21,7 +21,7 @@ import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.infra.rule.event.GovernanceEvent;
import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDataSource;
-import org.apache.shardingsphere.mode.storage.StorageNodeDataSource;
+import org.apache.shardingsphere.mode.storage.QualifiedDataSourceStatus;
/**
* Storage node changed event.
@@ -32,5 +32,5 @@ public final class StorageNodeChangedEvent implements GovernanceEvent {
private final QualifiedDataSource qualifiedDataSource;
- private final StorageNodeDataSource dataSource;
+ private final QualifiedDataSourceStatus status;
}
diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/watcher/StorageNodeStateChangedWatcher.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/watcher/QualifiedDataSourceChangedWatcher.java
similarity index 80%
rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/watcher/StorageNodeStateChangedWatcher.java
rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/watcher/QualifiedDataSourceChangedWatcher.java
index 332684c7f2e..05f2451f0ca 100644
--- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/watcher/StorageNodeStateChangedWatcher.java
+++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/watcher/QualifiedDataSourceChangedWatcher.java
@@ -24,9 +24,9 @@ import org.apache.shardingsphere.infra.rule.event.GovernanceEvent;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.GovernanceWatcher;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.storage.event.StorageNodeChangedEvent;
import org.apache.shardingsphere.mode.storage.node.QualifiedDataSourceNode;
-import org.apache.shardingsphere.mode.storage.yaml.YamlStorageNodeDataSource;
-import org.apache.shardingsphere.mode.storage.yaml.YamlStorageNodeDataSourceSwapper;
-import org.apache.shardingsphere.mode.storage.StorageNodeDataSource;
+import org.apache.shardingsphere.mode.storage.yaml.YamlQualifiedDataSourceStatus;
+import org.apache.shardingsphere.mode.storage.yaml.YamlQualifiedDataSourceStatusSwapper;
+import org.apache.shardingsphere.mode.storage.QualifiedDataSourceStatus;
import org.apache.shardingsphere.mode.event.DataChangedEvent;
import org.apache.shardingsphere.mode.event.DataChangedEvent.Type;
@@ -36,9 +36,9 @@ import java.util.Collections;
import java.util.Optional;
/**
- * Storage node state changed watcher.
+ * Qualified data source changed watcher.
*/
-public final class StorageNodeStateChangedWatcher implements GovernanceWatcher<GovernanceEvent> {
+public final class QualifiedDataSourceChangedWatcher implements GovernanceWatcher<GovernanceEvent> {
@Override
public Collection<String> getWatchingKeys(final String databaseName) {
@@ -57,8 +57,8 @@ public final class StorageNodeStateChangedWatcher implements GovernanceWatcher<G
}
Optional<QualifiedDataSource> qualifiedDataSource = QualifiedDataSourceNode.extractQualifiedDataSource(event.getKey());
if (qualifiedDataSource.isPresent()) {
- StorageNodeDataSource storageNodeDataSource = new YamlStorageNodeDataSourceSwapper().swapToObject(YamlEngine.unmarshal(event.getValue(), YamlStorageNodeDataSource.class));
- return Optional.of(new StorageNodeChangedEvent(qualifiedDataSource.get(), storageNodeDataSource));
+ QualifiedDataSourceStatus status = new YamlQualifiedDataSourceStatusSwapper().swapToObject(YamlEngine.unmarshal(event.getValue(), YamlQualifiedDataSourceStatus.class));
+ return Optional.of(new StorageNodeChangedEvent(qualifiedDataSource.get(), status));
}
return Optional.empty();
}
diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StateChangedSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StateChangedSubscriber.java
index 4cbdb49f595..c7559e4d2da 100644
--- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StateChangedSubscriber.java
+++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StateChangedSubscriber.java
@@ -63,10 +63,10 @@ public final class StateChangedSubscriber {
if (!contextManager.getMetaDataContexts().getMetaData().containsDatabase(qualifiedDataSource.getDatabaseName())) {
return;
}
- DataSourceStateManager.getInstance().updateState(qualifiedDataSource, DataSourceState.valueOf(event.getDataSource().getStatus().name()));
+ DataSourceStateManager.getInstance().updateState(qualifiedDataSource, DataSourceState.valueOf(event.getStatus().getStatus().name()));
ShardingSphereDatabase database = contextManager.getMetaDataContexts().getMetaData().getDatabase(qualifiedDataSource.getDatabaseName());
for (StaticDataSourceRuleAttribute each : database.getRuleMetaData().getAttributes(StaticDataSourceRuleAttribute.class)) {
- each.updateStatus(qualifiedDataSource, event.getDataSource().getStatus());
+ each.updateStatus(qualifiedDataSource, event.getStatus().getStatus());
}
}
diff --git a/mode/type/cluster/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.GovernanceWatcher b/mode/type/cluster/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.GovernanceWatcher
index 93d03cd1ce8..ef200deff89 100644
--- a/mode/type/cluster/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.GovernanceWatcher
+++ b/mode/type/cluster/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.GovernanceWatcher
@@ -15,7 +15,7 @@
# limitations under the License.
#
-org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.storage.watcher.StorageNodeStateChangedWatcher
+org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.storage.watcher.QualifiedDataSourceChangedWatcher
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.watcher.ComputeNodeStateChangedWatcher
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.cluster.watcher.ClusterStateChangedWatcher
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.data.ShardingSphereDataChangedWatcher
diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/service/StorageNodeStatusServiceTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/service/QualifiedDataSourceStatusServiceTest.java
similarity index 87%
rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/service/StorageNodeStatusServiceTest.java
rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/service/QualifiedDataSourceStatusServiceTest.java
index a5f6f72f697..fee16f70bd0 100644
--- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/service/StorageNodeStatusServiceTest.java
+++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/service/QualifiedDataSourceStatusServiceTest.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.storage.service;
import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository;
-import org.apache.shardingsphere.mode.storage.service.StorageNodeStatusService;
+import org.apache.shardingsphere.mode.storage.service.QualifiedDataSourceStatusService;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
@@ -32,7 +32,7 @@ import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
-class StorageNodeStatusServiceTest {
+class QualifiedDataSourceStatusServiceTest {
@Mock
private ClusterPersistRepository repository;
@@ -41,6 +41,6 @@ class StorageNodeStatusServiceTest {
void assertLoadDisabledDataSources() {
List<String> disabledDataSources = Arrays.asList("replica_query_db.readwrite_ds.replica_ds_0", "other_schema.other_ds.other_ds0");
when(repository.getChildrenKeys(anyString())).thenReturn(disabledDataSources);
- assertDoesNotThrow(() -> new StorageNodeStatusService(repository).loadStorageNodes());
+ assertDoesNotThrow(() -> new QualifiedDataSourceStatusService(repository).loadQualifiedDataSourceStatus());
}
}
diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/watcher/StorageNodeStateChangedWatcherTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/watcher/QualifiedDataSourceChangedWatcherTest.java
similarity index 77%
rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/watcher/StorageNodeStateChangedWatcherTest.java
rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/watcher/QualifiedDataSourceChangedWatcherTest.java
index 072f0d56531..94e16fc64ba 100644
--- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/watcher/StorageNodeStateChangedWatcherTest.java
+++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/watcher/QualifiedDataSourceChangedWatcherTest.java
@@ -22,7 +22,7 @@ import org.apache.shardingsphere.infra.state.datasource.DataSourceState;
import org.apache.shardingsphere.mode.event.DataChangedEvent;
import org.apache.shardingsphere.mode.event.DataChangedEvent.Type;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.storage.event.StorageNodeChangedEvent;
-import org.apache.shardingsphere.mode.storage.StorageNodeDataSource.Role;
+import org.apache.shardingsphere.mode.storage.QualifiedDataSourceStatus.Role;
import org.junit.jupiter.api.Test;
import java.util.Optional;
@@ -32,37 +32,37 @@ import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
-class StorageNodeStateChangedWatcherTest {
+class QualifiedDataSourceChangedWatcherTest {
@Test
- void assertCreateEnabledStorageNodeChangedEvent() {
- Optional<GovernanceEvent> actual = new StorageNodeStateChangedWatcher().createGovernanceEvent(
+ void assertCreateEnabledQualifiedDataSourceChangedEvent() {
+ Optional<GovernanceEvent> actual = new QualifiedDataSourceChangedWatcher().createGovernanceEvent(
new DataChangedEvent("/nodes/storage_nodes/replica_query_db.readwrite_ds.replica_ds_0", "role: MEMBER\nstatus: ENABLED\n", Type.ADDED));
assertTrue(actual.isPresent());
StorageNodeChangedEvent actualEvent = (StorageNodeChangedEvent) actual.get();
assertThat(actualEvent.getQualifiedDataSource().getDatabaseName(), is("replica_query_db"));
assertThat(actualEvent.getQualifiedDataSource().getGroupName(), is("readwrite_ds"));
assertThat(actualEvent.getQualifiedDataSource().getDataSourceName(), is("replica_ds_0"));
- assertThat(actualEvent.getDataSource().getRole(), is(Role.MEMBER));
- assertThat(actualEvent.getDataSource().getStatus(), is(DataSourceState.ENABLED));
+ assertThat(actualEvent.getStatus().getRole(), is(Role.MEMBER));
+ assertThat(actualEvent.getStatus().getStatus(), is(DataSourceState.ENABLED));
}
@Test
- void assertCreateDisabledStorageNodeChangedEvent() {
- Optional<GovernanceEvent> actual = new StorageNodeStateChangedWatcher().createGovernanceEvent(
+ void assertCreateDisabledQualifiedDataSourceChangedEvent() {
+ Optional<GovernanceEvent> actual = new QualifiedDataSourceChangedWatcher().createGovernanceEvent(
new DataChangedEvent("/nodes/storage_nodes/replica_query_db.readwrite_ds.replica_ds_0", "role: MEMBER\nstatus: DISABLED\n", Type.DELETED));
assertTrue(actual.isPresent());
StorageNodeChangedEvent actualEvent = (StorageNodeChangedEvent) actual.get();
assertThat(actualEvent.getQualifiedDataSource().getDatabaseName(), is("replica_query_db"));
assertThat(actualEvent.getQualifiedDataSource().getGroupName(), is("readwrite_ds"));
assertThat(actualEvent.getQualifiedDataSource().getDataSourceName(), is("replica_ds_0"));
- assertThat(actualEvent.getDataSource().getRole(), is(Role.MEMBER));
- assertThat(actualEvent.getDataSource().getStatus(), is(DataSourceState.DISABLED));
+ assertThat(actualEvent.getStatus().getRole(), is(Role.MEMBER));
+ assertThat(actualEvent.getStatus().getStatus(), is(DataSourceState.DISABLED));
}
@Test
void assertCreateEmptyEvent() {
- Optional<GovernanceEvent> actual = new StorageNodeStateChangedWatcher().createGovernanceEvent(
+ Optional<GovernanceEvent> actual = new QualifiedDataSourceChangedWatcher().createGovernanceEvent(
new DataChangedEvent("/nodes/storage_nodes/replica_query_db.readwrite_ds.replica_ds_0", "", Type.ADDED));
assertFalse(actual.isPresent());
}
diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StateChangedSubscriberTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StateChangedSubscriberTest.java
index a3cf669c849..e910f01d052 100644
--- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StateChangedSubscriberTest.java
+++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StateChangedSubscriberTest.java
@@ -48,8 +48,8 @@ import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.statu
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository;
import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepositoryConfiguration;
-import org.apache.shardingsphere.mode.storage.StorageNodeDataSource;
-import org.apache.shardingsphere.mode.storage.StorageNodeDataSource.Role;
+import org.apache.shardingsphere.mode.storage.QualifiedDataSourceStatus;
+import org.apache.shardingsphere.mode.storage.QualifiedDataSourceStatus.Role;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -114,11 +114,11 @@ class StateChangedSubscriberTest {
void assertRenewForDisableStateChanged() {
StaticDataSourceRuleAttribute ruleAttribute = mock(StaticDataSourceRuleAttribute.class);
when(database.getRuleMetaData().getAttributes(StaticDataSourceRuleAttribute.class)).thenReturn(Collections.singleton(ruleAttribute));
- StorageNodeChangedEvent event = new StorageNodeChangedEvent(new QualifiedDataSource("db.readwrite_ds.ds_0"), new StorageNodeDataSource(Role.MEMBER, DataSourceState.DISABLED));
+ StorageNodeChangedEvent event = new StorageNodeChangedEvent(new QualifiedDataSource("db.readwrite_ds.ds_0"), new QualifiedDataSourceStatus(Role.MEMBER, DataSourceState.DISABLED));
subscriber.renew(event);
verify(ruleAttribute).updateStatus(
argThat(qualifiedDataSource -> Objects.equals(event.getQualifiedDataSource(), qualifiedDataSource)),
- argThat(dataSourceState -> Objects.equals(event.getDataSource().getStatus(), dataSourceState)));
+ argThat(dataSourceState -> Objects.equals(event.getStatus().getStatus(), dataSourceState)));
}
@Test