From 3d37a84cb39959450607dc1eb2df19198999baf2 Mon Sep 17 00:00:00 2001 From: Liang Zhang Date: Wed, 22 May 2024 21:40:54 +0800 Subject: [PATCH 1/6] Refactor MetaDataVersion (#31348) --- .../infra/metadata/version/MetaDataVersion.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/version/MetaDataVersion.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/version/MetaDataVersion.java index 156ffc4e9f179..c2c3b254aac4f 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/version/MetaDataVersion.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/version/MetaDataVersion.java @@ -38,9 +38,7 @@ public final class MetaDataVersion { private final String nextActiveVersion; public MetaDataVersion(final String key) { - this.key = key; - currentActiveVersion = ""; - nextActiveVersion = ""; + this(key, "", ""); } /** From 87db43c43b7c40b3414b2fc68102fd6645a40e34 Mon Sep 17 00:00:00 2001 From: Liang Zhang Date: Wed, 22 May 2024 22:00:02 +0800 Subject: [PATCH 2/6] Add AutoCloseable on PersistRepository (#31349) * Refactor MetaDataVersion * Add AutoCloseable on PersistRepository --- .../shardingsphere/mode/spi/PersistRepository.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/mode/api/src/main/java/org/apache/shardingsphere/mode/spi/PersistRepository.java b/mode/api/src/main/java/org/apache/shardingsphere/mode/spi/PersistRepository.java index b6d1c0cb1e099..66c56758f2d4e 100644 --- a/mode/api/src/main/java/org/apache/shardingsphere/mode/spi/PersistRepository.java +++ b/mode/api/src/main/java/org/apache/shardingsphere/mode/spi/PersistRepository.java @@ -24,7 +24,7 @@ /** * Persist repository. */ -public interface PersistRepository extends TypedSPI { +public interface PersistRepository extends TypedSPI, AutoCloseable { /** * Path separator. @@ -48,10 +48,10 @@ public interface PersistRepository extends TypedSPI { List getChildrenKeys(String key); /** - * Judge node is exist or not. + * Judge node is existed or not. * * @param key key - * @return node is exist or not + * @return node is existed or not */ boolean isExisted(String key); @@ -87,8 +87,6 @@ default void persistEphemeral(String key, String value) { */ void delete(String key); - /** - * Close. - */ + @Override void close(); } From 62fc079a81b9fbed58200864d2bea3b6d91f06c9 Mon Sep 17 00:00:00 2001 From: Liang Zhang Date: Wed, 22 May 2024 23:39:31 +0800 Subject: [PATCH 3/6] Rename PersistRepository.getDirectly to query (#31353) --- ...ipelineJobItemErrorMessageGovernanceRepository.java | 2 +- .../PipelineJobItemProcessGovernanceRepository.java | 2 +- .../job/PipelineJobCheckGovernanceRepository.java | 4 ++-- .../PipelineJobConfigurationGovernanceRepository.java | 2 +- .../job/PipelineJobOffsetGovernanceRepository.java | 2 +- ...PipelineMetaDataDataSourceGovernanceRepository.java | 2 +- ...taDataProcessConfigurationGovernanceRepository.java | 2 +- .../service/config/RepositoryTuplePersistService.java | 4 ++-- .../datasource/DataSourceNodePersistService.java | 8 ++++---- .../datasource/DataSourceUnitPersistService.java | 8 ++++---- .../database/rule/DatabaseRulePersistService.java | 2 +- .../config/global/GlobalRulePersistService.java | 4 ++-- .../config/global/PropertiesPersistService.java | 4 ++-- .../ShardingSphereTableRowDataPersistService.java | 2 +- .../service/schema/TableMetaDataPersistService.java | 6 +++--- .../service/schema/ViewMetaDataPersistService.java | 6 +++--- .../service/version/MetaDataVersionPersistService.java | 4 ++-- .../shardingsphere/mode/spi/PersistRepository.java | 8 ++++---- .../mode/service/ComputeNodePersistService.java | 10 +++++----- .../shardingsphere/mode/state/StatePersistService.java | 2 +- .../service/QualifiedDataSourceStatusService.java | 2 +- .../mode/service/ComputeNodePersistServiceTest.java | 10 +++++----- .../mode/state/StatePersistServiceTest.java | 2 +- .../process/subscriber/ClusterProcessSubscriber.java | 4 ++-- .../fixture/ClusterPersistRepositoryFixture.java | 6 +----- .../ProcessListClusterPersistRepositoryFixture.java | 2 +- .../subscriber/ClusterProcessSubscriberTest.java | 2 +- .../generator/ClusterWorkerIdGeneratorTest.java | 2 +- .../mode/repository/cluster/etcd/EtcdRepository.java | 2 +- .../repository/cluster/etcd/EtcdRepositoryTest.java | 9 ++++----- .../cluster/zookeeper/ZookeeperRepository.java | 2 +- .../fixture/StandalonePersistRepositoryFixture.java | 2 +- .../repository/standalone/jdbc/JDBCRepository.java | 6 +++--- .../repository/standalone/jdbc/JDBCRepositoryTest.java | 4 ++-- .../proxy/fixture/ClusterPersistRepositoryFixture.java | 2 +- 35 files changed, 68 insertions(+), 73 deletions(-) diff --git a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/registrycenter/repository/item/PipelineJobItemErrorMessageGovernanceRepository.java b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/registrycenter/repository/item/PipelineJobItemErrorMessageGovernanceRepository.java index 7410efb617fcc..f234294972bb8 100644 --- a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/registrycenter/repository/item/PipelineJobItemErrorMessageGovernanceRepository.java +++ b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/registrycenter/repository/item/PipelineJobItemErrorMessageGovernanceRepository.java @@ -61,6 +61,6 @@ public void clean(final String jobId, final int shardingItem) { * @return error msg */ public String load(final String jobId, final int shardingItem) { - return Optional.ofNullable(repository.getDirectly(PipelineMetaDataNode.getJobItemErrorMessagePath(jobId, shardingItem))).orElse(""); + return Optional.ofNullable(repository.query(PipelineMetaDataNode.getJobItemErrorMessagePath(jobId, shardingItem))).orElse(""); } } diff --git a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/registrycenter/repository/item/PipelineJobItemProcessGovernanceRepository.java b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/registrycenter/repository/item/PipelineJobItemProcessGovernanceRepository.java index 9a19023c08e1d..9cc6df628a2f4 100644 --- a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/registrycenter/repository/item/PipelineJobItemProcessGovernanceRepository.java +++ b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/registrycenter/repository/item/PipelineJobItemProcessGovernanceRepository.java @@ -62,7 +62,7 @@ public void update(final String jobId, final int shardingItem, final String prog * @return job item progress */ public Optional load(final String jobId, final int shardingItem) { - String text = repository.getDirectly(PipelineMetaDataNode.getJobOffsetItemPath(jobId, shardingItem)); + String text = repository.query(PipelineMetaDataNode.getJobOffsetItemPath(jobId, shardingItem)); return Strings.isNullOrEmpty(text) ? Optional.empty() : Optional.of(text); } } diff --git a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/registrycenter/repository/job/PipelineJobCheckGovernanceRepository.java b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/registrycenter/repository/job/PipelineJobCheckGovernanceRepository.java index acaf37791396a..4fda2a3ef6f9a 100644 --- a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/registrycenter/repository/job/PipelineJobCheckGovernanceRepository.java +++ b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/registrycenter/repository/job/PipelineJobCheckGovernanceRepository.java @@ -50,7 +50,7 @@ public final class PipelineJobCheckGovernanceRepository { * @return check job id */ public Optional findLatestCheckJobId(final String parentJobId) { - return Optional.ofNullable(repository.getDirectly(PipelineMetaDataNode.getLatestCheckJobIdPath(parentJobId))); + return Optional.ofNullable(repository.query(PipelineMetaDataNode.getLatestCheckJobIdPath(parentJobId))); } /** @@ -91,7 +91,7 @@ public void deleteLatestCheckJobId(final String parentJobId) { */ @SuppressWarnings("unchecked") public Map getCheckJobResult(final String parentJobId, final String checkJobId) { - String yamlCheckResultMapText = repository.getDirectly(PipelineMetaDataNode.getCheckJobResultPath(parentJobId, checkJobId)); + String yamlCheckResultMapText = repository.query(PipelineMetaDataNode.getCheckJobResultPath(parentJobId, checkJobId)); if (Strings.isNullOrEmpty(yamlCheckResultMapText)) { return Collections.emptyMap(); } diff --git a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/registrycenter/repository/job/PipelineJobConfigurationGovernanceRepository.java b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/registrycenter/repository/job/PipelineJobConfigurationGovernanceRepository.java index cead2383479b4..9e0445a39bcc8 100644 --- a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/registrycenter/repository/job/PipelineJobConfigurationGovernanceRepository.java +++ b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/registrycenter/repository/job/PipelineJobConfigurationGovernanceRepository.java @@ -38,7 +38,7 @@ public final class PipelineJobConfigurationGovernanceRepository { * @return pipeline job configuration exists or not */ public boolean isExisted(final String jobId) { - return null != repository.getDirectly(PipelineMetaDataNode.getJobConfigurationPath(jobId)); + return null != repository.query(PipelineMetaDataNode.getJobConfigurationPath(jobId)); } /** diff --git a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/registrycenter/repository/job/PipelineJobOffsetGovernanceRepository.java b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/registrycenter/repository/job/PipelineJobOffsetGovernanceRepository.java index 421534e218cf7..77a41c5935ec6 100644 --- a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/registrycenter/repository/job/PipelineJobOffsetGovernanceRepository.java +++ b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/registrycenter/repository/job/PipelineJobOffsetGovernanceRepository.java @@ -51,7 +51,7 @@ public void persist(final String jobId, final JobOffsetInfo jobOffsetInfo) { * @return job offset info */ public JobOffsetInfo load(final String jobId) { - String value = repository.getDirectly(PipelineMetaDataNode.getJobOffsetPath(jobId)); + String value = repository.query(PipelineMetaDataNode.getJobOffsetPath(jobId)); return new YamlJobOffsetInfoSwapper().swapToObject(Strings.isNullOrEmpty(value) ? new YamlJobOffsetInfo() : YamlEngine.unmarshal(value, YamlJobOffsetInfo.class)); } } diff --git a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/registrycenter/repository/metadata/PipelineMetaDataDataSourceGovernanceRepository.java b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/registrycenter/repository/metadata/PipelineMetaDataDataSourceGovernanceRepository.java index 0c7cfafec1a99..8d27e90174c75 100644 --- a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/registrycenter/repository/metadata/PipelineMetaDataDataSourceGovernanceRepository.java +++ b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/registrycenter/repository/metadata/PipelineMetaDataDataSourceGovernanceRepository.java @@ -46,6 +46,6 @@ public void persist(final String jobType, final String metaDataDataSources) { * @return data source properties */ public String load(final String jobType) { - return repository.getDirectly(PipelineMetaDataNode.getMetaDataDataSourcesPath(jobType)); + return repository.query(PipelineMetaDataNode.getMetaDataDataSourcesPath(jobType)); } } diff --git a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/registrycenter/repository/metadata/PipelineMetaDataProcessConfigurationGovernanceRepository.java b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/registrycenter/repository/metadata/PipelineMetaDataProcessConfigurationGovernanceRepository.java index f286dddf5532b..e88d245c335e9 100644 --- a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/registrycenter/repository/metadata/PipelineMetaDataProcessConfigurationGovernanceRepository.java +++ b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/registrycenter/repository/metadata/PipelineMetaDataProcessConfigurationGovernanceRepository.java @@ -46,6 +46,6 @@ public void persist(final String jobType, final String processConfigYamlText) { * @return process configuration YAML text */ public String load(final String jobType) { - return repository.getDirectly(PipelineMetaDataNode.getMetaDataProcessConfigPath(jobType)); + return repository.query(PipelineMetaDataNode.getMetaDataProcessConfigPath(jobType)); } } diff --git a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/RepositoryTuplePersistService.java b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/RepositoryTuplePersistService.java index bffaa8258eece..5bbd555209b0a 100644 --- a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/RepositoryTuplePersistService.java +++ b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/RepositoryTuplePersistService.java @@ -69,7 +69,7 @@ private void loadNodes(final String toBeLoadedNode, final Collection loa } private RepositoryTuple getRepositoryTuple(final String node) { - String activeRuleKey = node.replace(ACTIVE_VERSION_PATH, VERSIONS_PATH) + "/" + repository.getDirectly(node); - return new RepositoryTuple(activeRuleKey, repository.getDirectly(activeRuleKey)); + String activeRuleKey = node.replace(ACTIVE_VERSION_PATH, VERSIONS_PATH) + "/" + repository.query(node); + return new RepositoryTuple(activeRuleKey, repository.query(activeRuleKey)); } } diff --git a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/database/datasource/DataSourceNodePersistService.java b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/database/datasource/DataSourceNodePersistService.java index 370c8501793ce..b20032be6b5f6 100644 --- a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/database/datasource/DataSourceNodePersistService.java +++ b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/database/datasource/DataSourceNodePersistService.java @@ -63,7 +63,7 @@ public void persist(final String databaseName, final Map load(final String databaseName) { Map result = new LinkedHashMap<>(); for (String each : repository.getChildrenKeys(DataSourceMetaDataNode.getDataSourceNodesNode(databaseName))) { - String dataSourceValue = repository.getDirectly(DataSourceMetaDataNode.getDataSourceNodeVersionNode(databaseName, each, getDataSourceActiveVersion(databaseName, each))); + String dataSourceValue = repository.query(DataSourceMetaDataNode.getDataSourceNodeVersionNode(databaseName, each, getDataSourceActiveVersion(databaseName, each))); if (!Strings.isNullOrEmpty(dataSourceValue)) { result.put(each, new YamlDataSourceConfigurationSwapper().swapToDataSourcePoolProperties(YamlEngine.unmarshal(dataSourceValue, Map.class))); } @@ -74,8 +74,8 @@ public Map load(final String databaseName) { @SuppressWarnings("unchecked") @Override public Map load(final String databaseName, final String name) { - Map result = new LinkedHashMap<>(); - String dataSourceValue = repository.getDirectly(DataSourceMetaDataNode.getDataSourceNodeVersionNode(databaseName, name, getDataSourceActiveVersion(databaseName, name))); + Map result = new LinkedHashMap<>(1, 1F); + String dataSourceValue = repository.query(DataSourceMetaDataNode.getDataSourceNodeVersionNode(databaseName, name, getDataSourceActiveVersion(databaseName, name))); if (!Strings.isNullOrEmpty(dataSourceValue)) { result.put(name, new YamlDataSourceConfigurationSwapper().swapToDataSourcePoolProperties(YamlEngine.unmarshal(dataSourceValue, Map.class))); } @@ -115,6 +115,6 @@ public Collection persistConfigurations(final String databaseNa } private String getDataSourceActiveVersion(final String databaseName, final String dataSourceName) { - return repository.getDirectly(DataSourceMetaDataNode.getDataSourceNodeActiveVersionNode(databaseName, dataSourceName)); + return repository.query(DataSourceMetaDataNode.getDataSourceNodeActiveVersionNode(databaseName, dataSourceName)); } } diff --git a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/database/datasource/DataSourceUnitPersistService.java b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/database/datasource/DataSourceUnitPersistService.java index b18ab364fcadc..4c5fb9a60e27f 100644 --- a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/database/datasource/DataSourceUnitPersistService.java +++ b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/database/datasource/DataSourceUnitPersistService.java @@ -63,7 +63,7 @@ public void persist(final String databaseName, final Map load(final String databaseName) { Map result = new LinkedHashMap<>(); for (String each : repository.getChildrenKeys(DataSourceMetaDataNode.getDataSourceUnitsNode(databaseName))) { - String dataSourceValue = repository.getDirectly(DataSourceMetaDataNode.getDataSourceUnitVersionNode(databaseName, each, getDataSourceActiveVersion(databaseName, each))); + String dataSourceValue = repository.query(DataSourceMetaDataNode.getDataSourceUnitVersionNode(databaseName, each, getDataSourceActiveVersion(databaseName, each))); if (!Strings.isNullOrEmpty(dataSourceValue)) { result.put(each, new YamlDataSourceConfigurationSwapper().swapToDataSourcePoolProperties(YamlEngine.unmarshal(dataSourceValue, Map.class))); } @@ -74,8 +74,8 @@ public Map load(final String databaseName) { @SuppressWarnings("unchecked") @Override public Map load(final String databaseName, final String name) { - Map result = new LinkedHashMap<>(); - String dataSourceValue = repository.getDirectly(DataSourceMetaDataNode.getDataSourceUnitVersionNode(databaseName, name, getDataSourceActiveVersion(databaseName, name))); + Map result = new LinkedHashMap<>(1, 1F); + String dataSourceValue = repository.query(DataSourceMetaDataNode.getDataSourceUnitVersionNode(databaseName, name, getDataSourceActiveVersion(databaseName, name))); if (!Strings.isNullOrEmpty(dataSourceValue)) { result.put(name, new YamlDataSourceConfigurationSwapper().swapToDataSourcePoolProperties(YamlEngine.unmarshal(dataSourceValue, Map.class))); } @@ -115,6 +115,6 @@ public Collection persistConfigurations(final String databaseNa } private String getDataSourceActiveVersion(final String databaseName, final String dataSourceName) { - return repository.getDirectly(DataSourceMetaDataNode.getDataSourceUnitActiveVersionNode(databaseName, dataSourceName)); + return repository.query(DataSourceMetaDataNode.getDataSourceUnitActiveVersionNode(databaseName, dataSourceName)); } } diff --git a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/database/rule/DatabaseRulePersistService.java b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/database/rule/DatabaseRulePersistService.java index 3266c98e9ab9c..602550d062c41 100644 --- a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/database/rule/DatabaseRulePersistService.java +++ b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/database/rule/DatabaseRulePersistService.java @@ -128,6 +128,6 @@ private Collection deleteRepositoryTuples(final String database } private String getActiveVersion(final String databaseName, final String ruleName, final String key) { - return repository.getDirectly(DatabaseRuleMetaDataNode.getDatabaseRuleActiveVersionNode(databaseName, ruleName, key)); + return repository.query(DatabaseRuleMetaDataNode.getDatabaseRuleActiveVersionNode(databaseName, ruleName, key)); } } diff --git a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/global/GlobalRulePersistService.java b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/global/GlobalRulePersistService.java index cf705688dc0f4..3980aee1f150c 100644 --- a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/global/GlobalRulePersistService.java +++ b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/global/GlobalRulePersistService.java @@ -72,10 +72,10 @@ private Collection persistTuples(final Collection versions = repository.getChildrenKeys(GlobalNode.getGlobalRuleVersionsNode(each.getKey())); String nextActiveVersion = versions.isEmpty() ? DEFAULT_VERSION : String.valueOf(Integer.parseInt(versions.get(0)) + 1); repository.persist(GlobalNode.getGlobalRuleVersionNode(each.getKey(), nextActiveVersion), each.getValue()); - if (Strings.isNullOrEmpty(repository.getDirectly(GlobalNode.getGlobalRuleActiveVersionNode(each.getKey())))) { + if (Strings.isNullOrEmpty(repository.query(GlobalNode.getGlobalRuleActiveVersionNode(each.getKey())))) { repository.persist(GlobalNode.getGlobalRuleActiveVersionNode(each.getKey()), DEFAULT_VERSION); } - result.add(new MetaDataVersion(GlobalNode.getGlobalRuleNode(each.getKey()), repository.getDirectly(GlobalNode.getGlobalRuleActiveVersionNode(each.getKey())), nextActiveVersion)); + result.add(new MetaDataVersion(GlobalNode.getGlobalRuleNode(each.getKey()), repository.query(GlobalNode.getGlobalRuleActiveVersionNode(each.getKey())), nextActiveVersion)); } return result; } diff --git a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/global/PropertiesPersistService.java b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/global/PropertiesPersistService.java index e38cf6c3fbf44..6abb939ed97cd 100644 --- a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/global/PropertiesPersistService.java +++ b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/global/PropertiesPersistService.java @@ -55,11 +55,11 @@ public void persist(final Properties props) { @Override public Properties load() { - String yamlContent = repository.getDirectly(GlobalNode.getPropsVersionNode(getActiveVersion())); + String yamlContent = repository.query(GlobalNode.getPropsVersionNode(getActiveVersion())); return Strings.isNullOrEmpty(yamlContent) ? new Properties() : YamlEngine.unmarshal(yamlContent, Properties.class); } private String getActiveVersion() { - return repository.getDirectly(GlobalNode.getPropsActiveVersionNode()); + return repository.query(GlobalNode.getPropsActiveVersionNode()); } } diff --git a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/schema/ShardingSphereTableRowDataPersistService.java b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/schema/ShardingSphereTableRowDataPersistService.java index e357bd10d0774..423d30b378265 100644 --- a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/schema/ShardingSphereTableRowDataPersistService.java +++ b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/schema/ShardingSphereTableRowDataPersistService.java @@ -85,7 +85,7 @@ public ShardingSphereTableData load(final String databaseName, final String sche ShardingSphereTableData result = new ShardingSphereTableData(tableName); YamlShardingSphereRowDataSwapper swapper = new YamlShardingSphereRowDataSwapper(new ArrayList<>(table.getColumnValues())); for (String each : repository.getChildrenKeys(ShardingSphereDataNode.getTablePath(databaseName, schemaName, tableName))) { - String yamlRow = repository.getDirectly(ShardingSphereDataNode.getTableRowPath(databaseName, schemaName, tableName, each)); + String yamlRow = repository.query(ShardingSphereDataNode.getTableRowPath(databaseName, schemaName, tableName, each)); if (!Strings.isNullOrEmpty(yamlRow)) { result.getRows().add(swapper.swapToObject(YamlEngine.unmarshal(yamlRow, YamlShardingSphereRowData.class))); } diff --git a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/schema/TableMetaDataPersistService.java b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/schema/TableMetaDataPersistService.java index c31477671222b..bdbf2a73514d4 100644 --- a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/schema/TableMetaDataPersistService.java +++ b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/schema/TableMetaDataPersistService.java @@ -66,7 +66,7 @@ public void persist(final String databaseName, final String schemaName, final Ma } private String getActiveVersion(final String databaseName, final String schemaName, final String tableName) { - return repository.getDirectly(TableMetaDataNode.getTableActiveVersionNode(databaseName, schemaName, tableName)); + return repository.query(TableMetaDataNode.getTableActiveVersionNode(databaseName, schemaName, tableName)); } @Override @@ -83,8 +83,8 @@ public Map load(final String databaseName, final St private Map getTableMetaDataByTableNames(final String databaseName, final String schemaName, final Collection tableNames) { Map result = new LinkedHashMap<>(tableNames.size(), 1F); tableNames.forEach(each -> { - String table = repository.getDirectly(TableMetaDataNode.getTableVersionNode(databaseName, schemaName, each, - repository.getDirectly(TableMetaDataNode.getTableActiveVersionNode(databaseName, schemaName, each)))); + String table = repository.query(TableMetaDataNode.getTableVersionNode(databaseName, schemaName, each, + repository.query(TableMetaDataNode.getTableActiveVersionNode(databaseName, schemaName, each)))); if (!Strings.isNullOrEmpty(table)) { result.put(each.toLowerCase(), new YamlTableSwapper().swapToObject(YamlEngine.unmarshal(table, YamlShardingSphereTable.class))); } diff --git a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/schema/ViewMetaDataPersistService.java b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/schema/ViewMetaDataPersistService.java index e97fbde82ea5d..ec497b773593e 100644 --- a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/schema/ViewMetaDataPersistService.java +++ b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/schema/ViewMetaDataPersistService.java @@ -66,7 +66,7 @@ public void persist(final String databaseName, final String schemaName, final Ma } private String getActiveVersion(final String databaseName, final String schemaName, final String viewName) { - return repository.getDirectly(ViewMetaDataNode.getViewActiveVersionNode(databaseName, schemaName, viewName)); + return repository.query(ViewMetaDataNode.getViewActiveVersionNode(databaseName, schemaName, viewName)); } @Override @@ -83,8 +83,8 @@ public Map load(final String databaseName, final Str private Map getViewMetaDataByViewNames(final String databaseName, final String schemaName, final Collection viewNames) { Map result = new LinkedHashMap<>(viewNames.size(), 1F); viewNames.forEach(each -> { - String view = repository.getDirectly(ViewMetaDataNode.getViewVersionNode(databaseName, schemaName, each, - repository.getDirectly(ViewMetaDataNode.getViewActiveVersionNode(databaseName, schemaName, each)))); + String view = repository.query(ViewMetaDataNode.getViewVersionNode(databaseName, schemaName, each, + repository.query(ViewMetaDataNode.getViewActiveVersionNode(databaseName, schemaName, each)))); if (!Strings.isNullOrEmpty(view)) { result.put(each.toLowerCase(), new YamlViewSwapper().swapToObject(YamlEngine.unmarshal(view, YamlShardingSphereView.class))); } diff --git a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/version/MetaDataVersionPersistService.java b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/version/MetaDataVersionPersistService.java index 15d1824519251..b6d4c56921ab5 100644 --- a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/version/MetaDataVersionPersistService.java +++ b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/version/MetaDataVersionPersistService.java @@ -45,11 +45,11 @@ public void switchActiveVersion(final Collection metaDataVersio @Override public String getActiveVersionByFullPath(final String fullPath) { - return repository.getDirectly(fullPath); + return repository.query(fullPath); } @Override public String getVersionPathByActiveVersion(final String path, final String activeVersion) { - return repository.getDirectly(DatabaseMetaDataNode.getVersionNodeByActiveVersionPath(path, activeVersion)); + return repository.query(DatabaseMetaDataNode.getVersionNodeByActiveVersionPath(path, activeVersion)); } } diff --git a/mode/api/src/main/java/org/apache/shardingsphere/mode/spi/PersistRepository.java b/mode/api/src/main/java/org/apache/shardingsphere/mode/spi/PersistRepository.java index 66c56758f2d4e..2f6e654012196 100644 --- a/mode/api/src/main/java/org/apache/shardingsphere/mode/spi/PersistRepository.java +++ b/mode/api/src/main/java/org/apache/shardingsphere/mode/spi/PersistRepository.java @@ -32,12 +32,12 @@ public interface PersistRepository extends TypedSPI, AutoCloseable { String PATH_SEPARATOR = "/"; /** - * Get value from registry center directly. + * Query data. * - * @param key key - * @return value + * @param key key to be queried + * @return queryed data */ - String getDirectly(String key); + String query(String key); /** * Get names of sub-node. diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/service/ComputeNodePersistService.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/service/ComputeNodePersistService.java index 8eea3693aa51e..5fdeb7323b781 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/service/ComputeNodePersistService.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/service/ComputeNodePersistService.java @@ -87,7 +87,7 @@ public void persistInstanceWorkerId(final String instanceId, final int workerId) */ @SuppressWarnings("unchecked") public Collection loadInstanceLabels(final String instanceId) { - String yamlContent = repository.getDirectly(ComputeNode.getInstanceLabelsNodePath(instanceId)); + String yamlContent = repository.query(ComputeNode.getInstanceLabelsNodePath(instanceId)); return Strings.isNullOrEmpty(yamlContent) ? new LinkedList<>() : YamlEngine.unmarshal(yamlContent, Collection.class); } @@ -98,7 +98,7 @@ public Collection loadInstanceLabels(final String instanceId) { * @return state */ public String loadComputeNodeState(final String instanceId) { - return repository.getDirectly(ComputeNode.getComputeNodeStateNodePath(instanceId)); + return repository.query(ComputeNode.getComputeNodeStateNodePath(instanceId)); } /** @@ -109,7 +109,7 @@ public String loadComputeNodeState(final String instanceId) { */ public Optional loadInstanceWorkerId(final String instanceId) { try { - String workerId = repository.getDirectly(ComputeNode.getInstanceWorkerIdNodePath(instanceId)); + String workerId = repository.query(ComputeNode.getInstanceWorkerIdNodePath(instanceId)); return Strings.isNullOrEmpty(workerId) ? Optional.empty() : Optional.of(Integer.valueOf(workerId)); } catch (final NumberFormatException ex) { log.error("Invalid worker id for instance: {}", instanceId); @@ -133,7 +133,7 @@ public Collection loadAllComputeNodeInstances() { private Collection loadComputeNodeInstances(final InstanceType instanceType) { Collection result = new LinkedList<>(); for (String each : repository.getChildrenKeys(ComputeNode.getOnlineNodePath(instanceType))) { - String value = repository.getDirectly(ComputeNode.getOnlineInstanceNodePath(each, instanceType)); + String value = repository.query(ComputeNode.getOnlineInstanceNodePath(each, instanceType)); if (Strings.isNullOrEmpty(value)) { continue; } @@ -166,7 +166,7 @@ public Collection getAssignedWorkerIds() { Collection childrenKeys = repository.getChildrenKeys(ComputeNode.getInstanceWorkerIdRootNodePath()); Collection result = new LinkedHashSet<>(childrenKeys.size(), 1F); for (String each : childrenKeys) { - String workerId = repository.getDirectly(ComputeNode.getInstanceWorkerIdNodePath(each)); + String workerId = repository.query(ComputeNode.getInstanceWorkerIdNodePath(each)); if (null != workerId) { result.add(Integer.parseInt(workerId)); } diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/state/StatePersistService.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/state/StatePersistService.java index 0dfa95215a368..04478f846d873 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/state/StatePersistService.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/state/StatePersistService.java @@ -48,7 +48,7 @@ public void updateClusterState(final ClusterState state) { * @return cluster state */ public Optional loadClusterState() { - String value = repository.getDirectly(ComputeNode.getClusterStateNodePath()); + String value = repository.query(ComputeNode.getClusterStateNodePath()); return Strings.isNullOrEmpty(value) ? Optional.empty() : Optional.of(ClusterState.valueOf(value)); } } diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/storage/service/QualifiedDataSourceStatusService.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/storage/service/QualifiedDataSourceStatusService.java index c1399b6face40..d02e0d4e18b52 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/storage/service/QualifiedDataSourceStatusService.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/storage/service/QualifiedDataSourceStatusService.java @@ -49,7 +49,7 @@ public Map loadStatus() { Collection qualifiedDataSourceNodes = repository.getChildrenKeys(QualifiedDataSourceNode.getRootPath()); Map result = new HashMap<>(qualifiedDataSourceNodes.size(), 1F); qualifiedDataSourceNodes.forEach(each -> { - String yamlContent = repository.getDirectly(QualifiedDataSourceNode.getQualifiedDataSourceNodePath(new QualifiedDataSource(each))); + String yamlContent = repository.query(QualifiedDataSourceNode.getQualifiedDataSourceNodePath(new QualifiedDataSource(each))); if (!Strings.isNullOrEmpty(yamlContent)) { result.put(each, new YamlQualifiedDataSourceStatusSwapper().swapToObject(YamlEngine.unmarshal(yamlContent, YamlQualifiedDataSourceStatus.class))); } diff --git a/mode/core/src/test/java/org/apache/shardingsphere/mode/service/ComputeNodePersistServiceTest.java b/mode/core/src/test/java/org/apache/shardingsphere/mode/service/ComputeNodePersistServiceTest.java index fb7e065f33311..1184caecea7de 100644 --- a/mode/core/src/test/java/org/apache/shardingsphere/mode/service/ComputeNodePersistServiceTest.java +++ b/mode/core/src/test/java/org/apache/shardingsphere/mode/service/ComputeNodePersistServiceTest.java @@ -86,7 +86,7 @@ void assertLoadInstanceLabels() { InstanceMetaData instanceMetaData = new ProxyInstanceMetaData("foo_instance_id", 3307); final String instanceId = instanceMetaData.getId(); new ComputeNodePersistService(repository).loadInstanceLabels(instanceId); - verify(repository).getDirectly(ComputeNode.getInstanceLabelsNodePath(instanceId)); + verify(repository).query(ComputeNode.getInstanceLabelsNodePath(instanceId)); } @Test @@ -94,7 +94,7 @@ void assertLoadComputeNodeState() { InstanceMetaData instanceMetaData = new ProxyInstanceMetaData("foo_instance_id", 3307); final String instanceId = instanceMetaData.getId(); new ComputeNodePersistService(repository).loadComputeNodeState(instanceId); - verify(repository).getDirectly(ComputeNode.getComputeNodeStateNodePath(instanceId)); + verify(repository).query(ComputeNode.getComputeNodeStateNodePath(instanceId)); } @Test @@ -102,7 +102,7 @@ void assertLoadInstanceWorkerId() { InstanceMetaData instanceMetaData = new ProxyInstanceMetaData("foo_instance_id", 3307); final String instanceId = instanceMetaData.getId(); new ComputeNodePersistService(repository).loadInstanceWorkerId(instanceId); - verify(repository).getDirectly(ComputeNode.getInstanceWorkerIdNodePath(instanceId)); + verify(repository).query(ComputeNode.getInstanceWorkerIdNodePath(instanceId)); } @Test @@ -112,11 +112,11 @@ void assertLoadAllComputeNodeInstances() { YamlComputeNodeData yamlComputeNodeData0 = new YamlComputeNodeData(); yamlComputeNodeData0.setAttribute("127.0.0.1@3307"); yamlComputeNodeData0.setVersion("foo_version"); - when(repository.getDirectly("/nodes/compute_nodes/online/jdbc/foo_instance_3307")).thenReturn(YamlEngine.marshal(yamlComputeNodeData0)); + when(repository.query("/nodes/compute_nodes/online/jdbc/foo_instance_3307")).thenReturn(YamlEngine.marshal(yamlComputeNodeData0)); YamlComputeNodeData yamlComputeNodeData1 = new YamlComputeNodeData(); yamlComputeNodeData1.setAttribute("127.0.0.1@3308"); yamlComputeNodeData1.setVersion("foo_version"); - when(repository.getDirectly("/nodes/compute_nodes/online/proxy/foo_instance_3308")).thenReturn(YamlEngine.marshal(yamlComputeNodeData1)); + when(repository.query("/nodes/compute_nodes/online/proxy/foo_instance_3308")).thenReturn(YamlEngine.marshal(yamlComputeNodeData1)); List actual = new ArrayList<>(new ComputeNodePersistService(repository).loadAllComputeNodeInstances()); assertThat(actual.size(), is(2)); assertThat(actual.get(0).getMetaData().getId(), is("foo_instance_3307")); diff --git a/mode/core/src/test/java/org/apache/shardingsphere/mode/state/StatePersistServiceTest.java b/mode/core/src/test/java/org/apache/shardingsphere/mode/state/StatePersistServiceTest.java index ca3b4994cb2b1..261d49586a73e 100644 --- a/mode/core/src/test/java/org/apache/shardingsphere/mode/state/StatePersistServiceTest.java +++ b/mode/core/src/test/java/org/apache/shardingsphere/mode/state/StatePersistServiceTest.java @@ -43,6 +43,6 @@ void assertUpdateClusterStateClusterStateWithoutPath() { @Test void assertLoadClusterStateClusterState() { new StatePersistService(repository).loadClusterState(); - verify(repository).getDirectly(ComputeNode.getClusterStateNodePath()); + verify(repository).query(ComputeNode.getClusterStateNodePath()); } } diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/process/subscriber/ClusterProcessSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/process/subscriber/ClusterProcessSubscriber.java index ca7219b50bb85..440d8e22dc9b6 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/process/subscriber/ClusterProcessSubscriber.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/process/subscriber/ClusterProcessSubscriber.java @@ -73,7 +73,7 @@ public void postShowProcessListData(final ShowProcessListRequestEvent event) { private void postShowProcessListData(final String taskId) { YamlProcessList yamlProcessList = new YamlProcessList(); for (String each : repository.getChildrenKeys(ProcessNode.getProcessIdPath(taskId)).stream() - .map(each -> repository.getDirectly(ProcessNode.getProcessListInstancePath(taskId, each))).collect(Collectors.toList())) { + .map(each -> repository.query(ProcessNode.getProcessListInstancePath(taskId, each))).collect(Collectors.toList())) { yamlProcessList.getProcesses().addAll(YamlEngine.unmarshal(each, YamlProcessList.class).getProcesses()); } eventBusContext.post(new ShowProcessListResponseEvent(swapper.swapToObject(yamlProcessList))); @@ -86,7 +86,7 @@ private Collection getShowProcessListTriggerPaths(final String taskId) { } private boolean isReady(final Collection paths) { - return paths.stream().noneMatch(each -> null != repository.getDirectly(each)); + return paths.stream().noneMatch(each -> null != repository.query(each)); } @Override diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/fixture/ClusterPersistRepositoryFixture.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/fixture/ClusterPersistRepositoryFixture.java index ccdf17cc44eb6..66e0ae464929a 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/fixture/ClusterPersistRepositoryFixture.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/fixture/ClusterPersistRepositoryFixture.java @@ -32,7 +32,7 @@ public void init(final ClusterPersistRepositoryConfiguration config) { } @Override - public String getDirectly(final String key) { + public String query(final String key) { return ""; } @@ -54,10 +54,6 @@ public void persist(final String key, final String value) { public void update(final String key, final String value) { } - @Override - public void persistEphemeral(final String key, final String value) { - } - @Override public boolean persistExclusiveEphemeral(final String key, final String value) { return true; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/process/ProcessListClusterPersistRepositoryFixture.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/process/ProcessListClusterPersistRepositoryFixture.java index 37ec0c2e1352c..c4b40c487008d 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/process/ProcessListClusterPersistRepositoryFixture.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/process/ProcessListClusterPersistRepositoryFixture.java @@ -36,7 +36,7 @@ public void init(final ClusterPersistRepositoryConfiguration config) { } @Override - public String getDirectly(final String key) { + public String query(final String key) { return REGISTRY_DATA.get(key); } diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/process/subscriber/ClusterProcessSubscriberTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/process/subscriber/ClusterProcessSubscriberTest.java index 6f3ce36b9c632..5fc60d3e80597 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/process/subscriber/ClusterProcessSubscriberTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/process/subscriber/ClusterProcessSubscriberTest.java @@ -53,7 +53,7 @@ void setUp() { void assertPostShowProcessListData() { when(repository.getChildrenKeys(ComputeNode.getOnlineNodePath(InstanceType.JDBC))).thenReturn(Collections.emptyList()); when(repository.getChildrenKeys(ComputeNode.getOnlineNodePath(InstanceType.PROXY))).thenReturn(Collections.singletonList("abc")); - when(repository.getDirectly(any())).thenReturn(null); + when(repository.query(any())).thenReturn(null); clusterProcessListSubscriber.postShowProcessListData(new ShowProcessListRequestEvent()); verify(repository).persist(any(), any()); } diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/workerid/generator/ClusterWorkerIdGeneratorTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/workerid/generator/ClusterWorkerIdGeneratorTest.java index a82c3e800f4cf..184dd83b77108 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/workerid/generator/ClusterWorkerIdGeneratorTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/workerid/generator/ClusterWorkerIdGeneratorTest.java @@ -37,7 +37,7 @@ class ClusterWorkerIdGeneratorTest { @Test void assertGenerateWithExistedWorkerId() { ClusterPersistRepository repository = mock(ClusterPersistRepository.class); - when(repository.getDirectly("/nodes/compute_nodes/worker_id/foo_id")).thenReturn("10"); + when(repository.query("/nodes/compute_nodes/worker_id/foo_id")).thenReturn("10"); assertThat(new ClusterWorkerIdGenerator(repository, "foo_id").generate(PropertiesBuilder.build(new Property(WorkerIdGenerator.WORKER_ID_KEY, "1"))), is(10)); } diff --git a/mode/type/cluster/repository/provider/etcd/src/main/java/org/apache/shardingsphere/mode/repository/cluster/etcd/EtcdRepository.java b/mode/type/cluster/repository/provider/etcd/src/main/java/org/apache/shardingsphere/mode/repository/cluster/etcd/EtcdRepository.java index 6f565f297df4b..71ef640546700 100644 --- a/mode/type/cluster/repository/provider/etcd/src/main/java/org/apache/shardingsphere/mode/repository/cluster/etcd/EtcdRepository.java +++ b/mode/type/cluster/repository/provider/etcd/src/main/java/org/apache/shardingsphere/mode/repository/cluster/etcd/EtcdRepository.java @@ -79,7 +79,7 @@ public void init(final ClusterPersistRepositoryConfiguration config) { @SneakyThrows({InterruptedException.class, ExecutionException.class}) @Override - public String getDirectly(final String key) { + public String query(final String key) { List keyValues = client.getKVClient().get(ByteSequence.from(key, StandardCharsets.UTF_8)).get().getKvs(); return keyValues.isEmpty() ? null : keyValues.iterator().next().getValue().toString(StandardCharsets.UTF_8); } diff --git a/mode/type/cluster/repository/provider/etcd/src/test/java/org/apache/shardingsphere/mode/repository/cluster/etcd/EtcdRepositoryTest.java b/mode/type/cluster/repository/provider/etcd/src/test/java/org/apache/shardingsphere/mode/repository/cluster/etcd/EtcdRepositoryTest.java index 2c9e8b1245aa7..995afdc6cca19 100644 --- a/mode/type/cluster/repository/provider/etcd/src/test/java/org/apache/shardingsphere/mode/repository/cluster/etcd/EtcdRepositoryTest.java +++ b/mode/type/cluster/repository/provider/etcd/src/test/java/org/apache/shardingsphere/mode/repository/cluster/etcd/EtcdRepositoryTest.java @@ -119,7 +119,7 @@ private void setProperties() { @SuppressWarnings("unchecked") @SneakyThrows({InterruptedException.class, ExecutionException.class}) - private Client mockClient() { + private void mockClient() { when(client.getKVClient()).thenReturn(kv); when(kv.get(any(ByteSequence.class))).thenReturn(getFuture); when(kv.get(any(ByteSequence.class), any(GetOption.class))).thenReturn(getFuture); @@ -131,12 +131,11 @@ private Client mockClient() { when(leaseFuture.get()).thenReturn(leaseGrantResponse); when(leaseGrantResponse.getID()).thenReturn(123L); when(client.getWatchClient()).thenReturn(watch); - return client; } @Test void assertGetKey() { - repository.getDirectly("key"); + repository.query("key"); verify(kv).get(ByteSequence.from("key", StandardCharsets.UTF_8)); verify(getResponse).getKvs(); } @@ -226,7 +225,7 @@ void assertClose() { void assertGetKeyWhenThrowInterruptedException() throws ExecutionException, InterruptedException { doThrow(InterruptedException.class).when(getFuture).get(); try { - repository.getDirectly("key"); + repository.query("key"); // CHECKSTYLE:OFF } catch (final Exception ex) { // CHECKSTYLE:ON @@ -238,7 +237,7 @@ void assertGetKeyWhenThrowInterruptedException() throws ExecutionException, Inte void assertGetKeyWhenThrowExecutionException() throws ExecutionException, InterruptedException { doThrow(ExecutionException.class).when(getFuture).get(); try { - repository.getDirectly("key"); + repository.query("key"); // CHECKSTYLE:OFF } catch (final Exception ex) { // CHECKSTYLE:ON diff --git a/mode/type/cluster/repository/provider/zookeeper/src/main/java/org/apache/shardingsphere/mode/repository/cluster/zookeeper/ZookeeperRepository.java b/mode/type/cluster/repository/provider/zookeeper/src/main/java/org/apache/shardingsphere/mode/repository/cluster/zookeeper/ZookeeperRepository.java index 3b4b4d7e2cd1c..8edc93f0508d8 100644 --- a/mode/type/cluster/repository/provider/zookeeper/src/main/java/org/apache/shardingsphere/mode/repository/cluster/zookeeper/ZookeeperRepository.java +++ b/mode/type/cluster/repository/provider/zookeeper/src/main/java/org/apache/shardingsphere/mode/repository/cluster/zookeeper/ZookeeperRepository.java @@ -167,7 +167,7 @@ public void update(final String key, final String value) { } @Override - public String getDirectly(final String key) { + public String query(final String key) { try { return new String(client.getData().forPath(key), StandardCharsets.UTF_8); // CHECKSTYLE:OFF diff --git a/mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/fixture/StandalonePersistRepositoryFixture.java b/mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/fixture/StandalonePersistRepositoryFixture.java index 37587c0751dde..db4f32fa8e10a 100644 --- a/mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/fixture/StandalonePersistRepositoryFixture.java +++ b/mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/fixture/StandalonePersistRepositoryFixture.java @@ -29,7 +29,7 @@ public final class StandalonePersistRepositoryFixture implements StandalonePersi private final Map persistMap = new HashMap<>(); @Override - public String getDirectly(final String key) { + public String query(final String key) { return persistMap.get(key); } diff --git a/mode/type/standalone/repository/provider/jdbc/src/main/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/JDBCRepository.java b/mode/type/standalone/repository/provider/jdbc/src/main/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/JDBCRepository.java index 71a2de1a4e735..7d15cf6c5304a 100644 --- a/mode/type/standalone/repository/provider/jdbc/src/main/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/JDBCRepository.java +++ b/mode/type/standalone/repository/provider/jdbc/src/main/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/JDBCRepository.java @@ -79,7 +79,7 @@ public void init(final Properties props) { } @Override - public String getDirectly(final String key) { + public String query(final String key) { try ( Connection connection = dataSource.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(repositorySQL.getSelectByKeySQL())) { @@ -122,7 +122,7 @@ public List getChildrenKeys(final String key) { @Override public boolean isExisted(final String key) { - return !Strings.isNullOrEmpty(getDirectly(key)); + return !Strings.isNullOrEmpty(query(key)); } @Override @@ -138,7 +138,7 @@ public void persist(final String key, final String value) { // Create key level directory recursively. for (int i = 0; i < paths.length - 1; i++) { String tempKey = tempPrefix + SEPARATOR + paths[i]; - String tempKeyVal = getDirectly(tempKey); + String tempKeyVal = query(tempKey); if (Strings.isNullOrEmpty(tempKeyVal)) { insert(tempKey, "", parent); } diff --git a/mode/type/standalone/repository/provider/jdbc/src/test/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/JDBCRepositoryTest.java b/mode/type/standalone/repository/provider/jdbc/src/test/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/JDBCRepositoryTest.java index d136b41fd1069..3a7d283020539 100644 --- a/mode/type/standalone/repository/provider/jdbc/src/test/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/JDBCRepositoryTest.java +++ b/mode/type/standalone/repository/provider/jdbc/src/test/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/JDBCRepositoryTest.java @@ -104,7 +104,7 @@ void assertGet() throws SQLException { when(mockPreparedStatement.executeQuery()).thenReturn(mockResultSet); when(mockResultSet.next()).thenReturn(true); when(mockResultSet.getString("value")).thenReturn(value); - String actual = repository.getDirectly(key); + String actual = repository.query(key); verify(mockPreparedStatement).setString(1, key); assertThat(actual, is(value)); } @@ -114,7 +114,7 @@ void assertGetFailure() throws SQLException { when(mockJdbcConnection.prepareStatement(repositorySQL.getSelectByKeySQL())).thenReturn(mockPreparedStatement); when(mockPreparedStatement.executeQuery()).thenReturn(mockResultSet); when(mockResultSet.next()).thenReturn(false); - String actual = repository.getDirectly("key"); + String actual = repository.query("key"); assertThat(actual, is("")); } diff --git a/proxy/bootstrap/src/test/java/org/apache/shardingsphere/proxy/fixture/ClusterPersistRepositoryFixture.java b/proxy/bootstrap/src/test/java/org/apache/shardingsphere/proxy/fixture/ClusterPersistRepositoryFixture.java index 3b4328eb33d5a..497530abe6905 100644 --- a/proxy/bootstrap/src/test/java/org/apache/shardingsphere/proxy/fixture/ClusterPersistRepositoryFixture.java +++ b/proxy/bootstrap/src/test/java/org/apache/shardingsphere/proxy/fixture/ClusterPersistRepositoryFixture.java @@ -36,7 +36,7 @@ public void init(final ClusterPersistRepositoryConfiguration config) { } @Override - public String getDirectly(final String key) { + public String query(final String key) { return REGISTRY_DATA.get(key); } From 5ec12538540f3d51c5748ea3b777c846aef4fe51 Mon Sep 17 00:00:00 2001 From: Liang Zhang Date: Wed, 22 May 2024 23:59:48 +0800 Subject: [PATCH 4/6] Refactor ZookeeperRepository.query() (#31354) --- .../repository/cluster/zookeeper/ZookeeperRepository.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mode/type/cluster/repository/provider/zookeeper/src/main/java/org/apache/shardingsphere/mode/repository/cluster/zookeeper/ZookeeperRepository.java b/mode/type/cluster/repository/provider/zookeeper/src/main/java/org/apache/shardingsphere/mode/repository/cluster/zookeeper/ZookeeperRepository.java index 8edc93f0508d8..a33513e4624e1 100644 --- a/mode/type/cluster/repository/provider/zookeeper/src/main/java/org/apache/shardingsphere/mode/repository/cluster/zookeeper/ZookeeperRepository.java +++ b/mode/type/cluster/repository/provider/zookeeper/src/main/java/org/apache/shardingsphere/mode/repository/cluster/zookeeper/ZookeeperRepository.java @@ -34,6 +34,7 @@ import org.apache.shardingsphere.mode.event.DataChangedEvent.Type; import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository; import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepositoryConfiguration; +import org.apache.shardingsphere.mode.repository.cluster.exception.ClusterPersistRepositoryException; import org.apache.shardingsphere.mode.repository.cluster.listener.DataChangedEventListener; import org.apache.shardingsphere.mode.repository.cluster.lock.holder.DistributedLockHolder; import org.apache.shardingsphere.mode.repository.cluster.zookeeper.handler.ZookeeperExceptionHandler; @@ -41,6 +42,7 @@ import org.apache.shardingsphere.mode.repository.cluster.zookeeper.props.ZookeeperProperties; import org.apache.shardingsphere.mode.repository.cluster.zookeeper.props.ZookeeperPropertyKey; import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; import org.apache.zookeeper.KeeperException.NodeExistsException; import org.apache.zookeeper.KeeperException.OperationTimeoutException; import org.apache.zookeeper.ZooDefs; @@ -170,11 +172,12 @@ public void update(final String key, final String value) { public String query(final String key) { try { return new String(client.getData().forPath(key), StandardCharsets.UTF_8); + } catch (final KeeperException.NoNodeException ex) { + return null; // CHECKSTYLE:OFF } catch (final Exception ex) { // CHECKSTYLE:ON - ZookeeperExceptionHandler.handleException(ex); - return null; + throw new ClusterPersistRepositoryException(ex); } } From 045708012aaab681bbdfac82ee8b0d3a4eb0c2fc Mon Sep 17 00:00:00 2001 From: LJ <97254796+DIDA-lJ@users.noreply.github.com> Date: Thu, 23 May 2024 00:11:03 +0800 Subject: [PATCH 5/6] Modify the document format and adapt the Chinese and English documents. (#31351) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update limitations.cn.md * Update limitations.en.md:The adaptation of the content and format of Chinese documents. --- .../document/content/features/shadow/limitations.cn.md | 10 +++++----- .../document/content/features/shadow/limitations.en.md | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/document/content/features/shadow/limitations.cn.md b/docs/document/content/features/shadow/limitations.cn.md index fc330b06c45b7..7842a9ccb639e 100644 --- a/docs/document/content/features/shadow/limitations.cn.md +++ b/docs/document/content/features/shadow/limitations.cn.md @@ -4,14 +4,14 @@ weight = 2 +++ ## 基于 Hint 的影子算法 - -* 无。 +* 无 ## 基于列的影子算法 +SQL 不支持列表: +* 不支持 DDL +* 不支持范围、分组和子查询,如:BETWEEN、GROUP BY ... HAVING 等 -* 不支持 DDL; -* 不支持范围、分组和子查询,如:BETWEEN、GROUP BY ... HAVING 等。 - SQL 支持列表: +SQL 支持列表: - INSERT | *SQL* | *是否支持* | diff --git a/docs/document/content/features/shadow/limitations.en.md b/docs/document/content/features/shadow/limitations.en.md index c8aa1101cd66d..f6356cf798f7f 100644 --- a/docs/document/content/features/shadow/limitations.en.md +++ b/docs/document/content/features/shadow/limitations.en.md @@ -8,10 +8,10 @@ weight = 2 No ## Column based shadow algorithm +SQL does not support lists: +- Does not support DDL. -Does not support DDL. - -Does not support scope, group, subqueries such as BETWEEN, GROUP BY ... HAVING, etc. +- Does not support scope, group, subqueries such as BETWEEN, GROUP BY ... HAVING, etc. SQL support list From bae03f1b8a800efa10f30ae937d02f2668f3a204 Mon Sep 17 00:00:00 2001 From: LJ <97254796+DIDA-lJ@users.noreply.github.com> Date: Thu, 23 May 2024 00:11:54 +0800 Subject: [PATCH 6/6] Update 2022_05_24_Your_Guide_to_DistSQL_Cluster_Governance_Capability_Apache_ShardingSphere_Feature_Update.en.md (#31336) Modify the unreasonable parts in the document: the fonts in the document are not displayed normally. Modify the bold Markdown syntax to make them display normally. --- ..._Capability_Apache_ShardingSphere_Feature_Update.en.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/blog/content/material/2022_05_24_Your_Guide_to_DistSQL_Cluster_Governance_Capability_Apache_ShardingSphere_Feature_Update.en.md b/docs/blog/content/material/2022_05_24_Your_Guide_to_DistSQL_Cluster_Governance_Capability_Apache_ShardingSphere_Feature_Update.en.md index 856a0d9606c97..3ce265dea9c9c 100644 --- a/docs/blog/content/material/2022_05_24_Your_Guide_to_DistSQL_Cluster_Governance_Capability_Apache_ShardingSphere_Feature_Update.en.md +++ b/docs/blog/content/material/2022_05_24_Your_Guide_to_DistSQL_Cluster_Governance_Capability_Apache_ShardingSphere_Feature_Update.en.md @@ -418,13 +418,13 @@ New issue Have a question about this project? Sign up for a free GitHub account github.com ## Reference -**1. ShardingSphere-Proxy Quickstart: **[https://shardingsphere.apache.org/document/5.1.0/cn/quick-start/shardingsphere-proxy-quick-start/](https://shardingsphere.apache.org/document/5.1.0/en/quick-start/shardingsphere-proxy-quick-start/) +**1. ShardingSphere-Proxy Quickstart:** [https://shardingsphere.apache.org/document/5.1.0/cn/quick-start/shardingsphere-proxy-quick-start/](https://shardingsphere.apache.org/document/5.1.0/en/quick-start/shardingsphere-proxy-quick-start/) -**2.DistSQL RDL:**https://shardingsphere.apache.org/document/current/en/user-manual/shardingsphere-proxy/distsql/syntax/rdl/resource-definition/ +**2.DistSQL RDL**https://shardingsphere.apache.org/document/current/en/user-manual/shardingsphere-proxy/distsql/syntax/rdl/resource-definition/ -**3.DistSQL RQL:**https://shardingsphere.apache.org/document/current/en/user-manual/shardingsphere-proxy/distsql/syntax/rql/resource-query/ +**3.DistSQL RQL**https://shardingsphere.apache.org/document/current/en/user-manual/shardingsphere-proxy/distsql/syntax/rql/resource-query/ -**4.DistSQL RAL:**https://shardingsphere.apache.org/document/current/en/user-manual/shardingsphere-proxy/distsql/syntax/ral/ +**4.DistSQL RAL**https://shardingsphere.apache.org/document/current/en/user-manual/shardingsphere-proxy/distsql/syntax/ral/ **Apache ShardingSphere Project Links:** [ShardingSphere Github](https://github.com/apache/shardingsphere/issues?page=1&q=is%3Aopen+is%3Aissue+label%3A%22project%3A+OpenForce+2022%22)