You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2023/02/28 01:47:22 UTC
[shardingsphere] branch master updated: Fix set worker-id does not take effect with Standalone mode (#24360)
This is an automated email from the ASF dual-hosted git repository.
panjuan 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 45795c0bcf7 Fix set worker-id does not take effect with Standalone mode (#24360)
45795c0bcf7 is described below
commit 45795c0bcf72c062d2fb799e3ea8b80a8d6b342a
Author: zhaojinchao <zh...@apache.org>
AuthorDate: Tue Feb 28 09:47:14 2023 +0800
Fix set worker-id does not take effect with Standalone mode (#24360)
* Fix set worker-id does not take effect with Standalone mode
* Fix unit test
* Adjustment assert file
* Update
* Revise
---
.../shardingsphere/sharding/rule/ShardingRule.java | 2 +-
.../query/ShowShardingTableNodesExecutorTest.java | 3 ++-
.../e2e/fixture/ITKeyGenerateAlgorithmFixture.java | 20 +++++++++++++++++++-
.../dataset/empty_rules/show_sharding_table_rule.xml | 4 ++--
.../standalone/show_compute_node_info.xml | 2 +-
.../empty_rules/standalone/show_compute_nodes.xml | 2 +-
.../proxy/conf/mysql/config-empty-rules.yaml | 2 ++
.../proxy/conf/opengauss/config-empty-rules.yaml | 4 +++-
.../proxy/conf/postgresql/config-empty-rules.yaml | 4 +++-
9 files changed, 34 insertions(+), 9 deletions(-)
diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
index 6fb1c6cae99..b2cc5f0d82f 100644
--- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
+++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
@@ -136,7 +136,7 @@ public final class ShardingRule implements DatabaseRule, DataNodeContainedRule,
ruleConfig.getBindingTableGroups(), broadcastTables, defaultDatabaseShardingStrategyConfig, defaultTableShardingStrategyConfig, defaultShardingColumn)),
InvalidBindingTablesException::new);
keyGenerators.values().stream().filter(each -> each instanceof InstanceContextAware).forEach(each -> ((InstanceContextAware) each).setInstanceContext(instanceContext));
- if (defaultKeyGenerateAlgorithm instanceof InstanceContextAware) {
+ if (defaultKeyGenerateAlgorithm instanceof InstanceContextAware && -1 == instanceContext.getWorkerId()) {
((InstanceContextAware) defaultKeyGenerateAlgorithm).setInstanceContext(instanceContext);
}
}
diff --git a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableNodesExecutorTest.java b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableNodesExecutorTest.java
index 9e3ef4d310b..0a80d5bbaed 100644
--- a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableNodesExecutorTest.java
+++ b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableNodesExecutorTest.java
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.sharding.distsql.query;
import lombok.SneakyThrows;
import org.apache.shardingsphere.distsql.handler.query.RQLExecutor;
+import org.apache.shardingsphere.infra.instance.InstanceContext;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
@@ -66,7 +67,7 @@ public final class ShowShardingTableNodesExecutorTest {
YamlRootConfiguration yamlRootConfig = YamlEngine.unmarshal(new File(url.getFile()), YamlRootConfiguration.class);
ShardingRuleConfiguration shardingRuleConfig = ShardingRuleConfigurationConverter.findAndConvertShardingRuleConfiguration(yamlRootConfig.getRules())
.orElseThrow(ShardingRuleNotFoundException::new);
- return new ShardingRule(shardingRuleConfig, Arrays.asList("ds_1", "ds_2", "ds_3"), null);
+ return new ShardingRule(shardingRuleConfig, Arrays.asList("ds_1", "ds_2", "ds_3"), mock(InstanceContext.class));
}
private void assertOrder(final ShardingSphereDatabase database) {
diff --git a/test/e2e/fixture/src/test/java/org/apache/shardingsphere/test/e2e/fixture/ITKeyGenerateAlgorithmFixture.java b/test/e2e/fixture/src/test/java/org/apache/shardingsphere/test/e2e/fixture/ITKeyGenerateAlgorithmFixture.java
index 42c756895e6..8bc4fd2825e 100644
--- a/test/e2e/fixture/src/test/java/org/apache/shardingsphere/test/e2e/fixture/ITKeyGenerateAlgorithmFixture.java
+++ b/test/e2e/fixture/src/test/java/org/apache/shardingsphere/test/e2e/fixture/ITKeyGenerateAlgorithmFixture.java
@@ -17,9 +17,20 @@
package org.apache.shardingsphere.test.e2e.fixture;
+import org.apache.shardingsphere.infra.instance.InstanceContext;
+import org.apache.shardingsphere.infra.instance.InstanceContextAware;
import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;
-public final class ITKeyGenerateAlgorithmFixture implements KeyGenerateAlgorithm {
+import java.util.Properties;
+
+public final class ITKeyGenerateAlgorithmFixture implements KeyGenerateAlgorithm, InstanceContextAware {
+
+ private Properties props;
+
+ @Override
+ public void init(final Properties props) {
+ this.props = props;
+ }
@Override
public Long generateKey() {
@@ -30,4 +41,11 @@ public final class ITKeyGenerateAlgorithmFixture implements KeyGenerateAlgorithm
public String getType() {
return "IT.FIXTURE";
}
+
+ @Override
+ public void setInstanceContext(final InstanceContext instanceContext) {
+ if (null != instanceContext) {
+ instanceContext.generateWorkerId(props);
+ }
+ }
}
diff --git a/test/e2e/suite/src/test/resources/cases/ral/dataset/empty_rules/show_sharding_table_rule.xml b/test/e2e/suite/src/test/resources/cases/ral/dataset/empty_rules/show_sharding_table_rule.xml
index 555adf6caad..1e916cfe462 100644
--- a/test/e2e/suite/src/test/resources/cases/ral/dataset/empty_rules/show_sharding_table_rule.xml
+++ b/test/e2e/suite/src/test/resources/cases/ral/dataset/empty_rules/show_sharding_table_rule.xml
@@ -34,6 +34,6 @@
<column name="auditor_types" />
<column name="allow_hint_disable" />
</metadata>
- <row values="t_user| | write_ds_${0..9}| | | | | STANDARD| user_id| MOD| sharding-count=40| user_id| IT.FIXTURE|| IT.AUDITOR.FIXTURE| true" />
- <row values="t_user_item| | write_ds_${0..9}| | | | |STANDARD| user_id| MOD| sharding-count=40| user_id| IT.FIXTURE| | |" />
+ <row values="t_user| | write_ds_${0..9}| | | | | STANDARD| user_id| MOD| sharding-count=40| user_id| IT.FIXTURE| worker-id=1 | IT.AUDITOR.FIXTURE| true" />
+ <row values="t_user_item| | write_ds_${0..9}| | | | |STANDARD| user_id| MOD| sharding-count=40| user_id| IT.FIXTURE| worker-id=1 | |" />
</dataset>
diff --git a/test/e2e/suite/src/test/resources/cases/ral/dataset/empty_rules/standalone/show_compute_node_info.xml b/test/e2e/suite/src/test/resources/cases/ral/dataset/empty_rules/standalone/show_compute_node_info.xml
index 12e5b672b84..e3266e14386 100644
--- a/test/e2e/suite/src/test/resources/cases/ral/dataset/empty_rules/standalone/show_compute_node_info.xml
+++ b/test/e2e/suite/src/test/resources/cases/ral/dataset/empty_rules/standalone/show_compute_node_info.xml
@@ -26,5 +26,5 @@
<column name="labels" />
<column name="version" assertion="false"/>
</metadata>
- <row values=" | | 3307| OK| Standalone| 0| |" />
+ <row values=" | | 3307| OK| Standalone| 1| |" />
</dataset>
diff --git a/test/e2e/suite/src/test/resources/cases/ral/dataset/empty_rules/standalone/show_compute_nodes.xml b/test/e2e/suite/src/test/resources/cases/ral/dataset/empty_rules/standalone/show_compute_nodes.xml
index 12e5b672b84..e3266e14386 100644
--- a/test/e2e/suite/src/test/resources/cases/ral/dataset/empty_rules/standalone/show_compute_nodes.xml
+++ b/test/e2e/suite/src/test/resources/cases/ral/dataset/empty_rules/standalone/show_compute_nodes.xml
@@ -26,5 +26,5 @@
<column name="labels" />
<column name="version" assertion="false"/>
</metadata>
- <row values=" | | 3307| OK| Standalone| 0| |" />
+ <row values=" | | 3307| OK| Standalone| 1| |" />
</dataset>
diff --git a/test/e2e/suite/src/test/resources/env/scenario/empty_rules/proxy/conf/mysql/config-empty-rules.yaml b/test/e2e/suite/src/test/resources/env/scenario/empty_rules/proxy/conf/mysql/config-empty-rules.yaml
index 57f56dd2877..c152d3bb572 100644
--- a/test/e2e/suite/src/test/resources/env/scenario/empty_rules/proxy/conf/mysql/config-empty-rules.yaml
+++ b/test/e2e/suite/src/test/resources/env/scenario/empty_rules/proxy/conf/mysql/config-empty-rules.yaml
@@ -243,6 +243,8 @@ rules:
keyGenerators:
constant:
type: IT.FIXTURE
+ props:
+ worker-id: 1
auditors:
auditor_constant:
diff --git a/test/e2e/suite/src/test/resources/env/scenario/empty_rules/proxy/conf/opengauss/config-empty-rules.yaml b/test/e2e/suite/src/test/resources/env/scenario/empty_rules/proxy/conf/opengauss/config-empty-rules.yaml
index b916e9ea974..de89875b1b7 100644
--- a/test/e2e/suite/src/test/resources/env/scenario/empty_rules/proxy/conf/opengauss/config-empty-rules.yaml
+++ b/test/e2e/suite/src/test/resources/env/scenario/empty_rules/proxy/conf/opengauss/config-empty-rules.yaml
@@ -239,10 +239,12 @@ rules:
type: MOD
props:
sharding-count: 40
-
+
keyGenerators:
constant:
type: IT.FIXTURE
+ props:
+ worker-id: 1
auditors:
auditor_constant:
diff --git a/test/e2e/suite/src/test/resources/env/scenario/empty_rules/proxy/conf/postgresql/config-empty-rules.yaml b/test/e2e/suite/src/test/resources/env/scenario/empty_rules/proxy/conf/postgresql/config-empty-rules.yaml
index 8b830475ced..951b20fcf2e 100644
--- a/test/e2e/suite/src/test/resources/env/scenario/empty_rules/proxy/conf/postgresql/config-empty-rules.yaml
+++ b/test/e2e/suite/src/test/resources/env/scenario/empty_rules/proxy/conf/postgresql/config-empty-rules.yaml
@@ -239,10 +239,12 @@ rules:
type: MOD
props:
sharding-count: 40
-
+
keyGenerators:
constant:
type: IT.FIXTURE
+ props:
+ worker-id: 1
auditors:
auditor_constant: