From 953682dec356c61dc90fb5ec81897593acc8ebdf Mon Sep 17 00:00:00 2001 From: tristaZero Date: Thu, 6 Jun 2019 15:19:14 +0800 Subject: [PATCH] add worker.id setting --- .../strategy/keygen/SnowflakeShardingKeyGeneratorTest.java | 1 + .../src/test/resources/yaml/sharding-rule.yaml | 2 ++ .../src/test/resources/yaml/optimize-rule.yaml | 6 ++++++ .../src/test/resources/yaml/parse-rule.yaml | 2 ++ .../src/test/resources/yaml/rewrite-rule.yaml | 4 ++++ .../src/test/resources/yaml/unit/sharding.yaml | 4 ++++ .../internal/registry/RegistryCenterServiceLoader.java | 2 +- .../src/test/resources/application-sharding.properties | 2 ++ .../src/test/resources/application-sharding.properties | 2 ++ 9 files changed, 24 insertions(+), 1 deletion(-) diff --git a/sharding-core/sharding-core-common/src/test/java/org/apache/shardingsphere/core/strategy/keygen/SnowflakeShardingKeyGeneratorTest.java b/sharding-core/sharding-core-common/src/test/java/org/apache/shardingsphere/core/strategy/keygen/SnowflakeShardingKeyGeneratorTest.java index ae1be6ce05..dab4042627 100644 --- a/sharding-core/sharding-core-common/src/test/java/org/apache/shardingsphere/core/strategy/keygen/SnowflakeShardingKeyGeneratorTest.java +++ b/sharding-core/sharding-core-common/src/test/java/org/apache/shardingsphere/core/strategy/keygen/SnowflakeShardingKeyGeneratorTest.java @@ -49,6 +49,7 @@ public final class SnowflakeShardingKeyGeneratorTest { ExecutorService executor = Executors.newFixedThreadPool(threadNumber); int taskNumber = threadNumber << 2; final SnowflakeShardingKeyGenerator keyGenerator = new SnowflakeShardingKeyGenerator(); + keyGenerator.setProperties(new Properties()); Set> actual = new HashSet<>(); for (int i = 0; i < taskNumber; i++) { diff --git a/sharding-core/sharding-core-common/src/test/resources/yaml/sharding-rule.yaml b/sharding-core/sharding-core-common/src/test/resources/yaml/sharding-rule.yaml index af9ec92ec2..8160226163 100644 --- a/sharding-core/sharding-core-common/src/test/resources/yaml/sharding-rule.yaml +++ b/sharding-core/sharding-core-common/src/test/resources/yaml/sharding-rule.yaml @@ -81,6 +81,8 @@ shardingRule: keyGenerator: type: SNOWFLAKE column: order_id + props: + worker.id: 123 logicIndex: order_index t_order_item: actualDataNodes: ds_${0..1}.t_order_item_${0..1} diff --git a/sharding-core/sharding-core-optimize/src/test/resources/yaml/optimize-rule.yaml b/sharding-core/sharding-core-optimize/src/test/resources/yaml/optimize-rule.yaml index 0af7fbd9cc..1530650dd1 100644 --- a/sharding-core/sharding-core-optimize/src/test/resources/yaml/optimize-rule.yaml +++ b/sharding-core/sharding-core-optimize/src/test/resources/yaml/optimize-rule.yaml @@ -42,6 +42,8 @@ shardingRule: keyGenerator: type: SNOWFLAKE column: order_id + props: + worker.id: 123 logicIndex: order_index t_encrypt: actualDataNodes: ds_${0..1}.t_encrypt_${0..1} @@ -56,6 +58,8 @@ shardingRule: keyGenerator: type: SNOWFLAKE column: order_id + props: + worker.id: 123 t_encrypt_query: actualDataNodes: ds_${0..1}.t_encrypt_query${0..1} databaseStrategy: @@ -69,6 +73,8 @@ shardingRule: keyGenerator: type: SNOWFLAKE column: order_id + props: + worker.id: 123 encryptRule: encryptors: t_encryptor: diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-test/src/test/resources/yaml/parse-rule.yaml b/sharding-core/sharding-core-parse/sharding-core-parse-test/src/test/resources/yaml/parse-rule.yaml index 220a2344e2..66449a5b24 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-test/src/test/resources/yaml/parse-rule.yaml +++ b/sharding-core/sharding-core-parse/sharding-core-parse-test/src/test/resources/yaml/parse-rule.yaml @@ -45,6 +45,8 @@ shardingRule: keyGenerator: type: SNOWFLAKE column: item_id + props: + worker.id: 123 t_place: actualDataNodes: db${0..1}.t_place tableStrategy: diff --git a/sharding-core/sharding-core-rewrite/src/test/resources/yaml/rewrite-rule.yaml b/sharding-core/sharding-core-rewrite/src/test/resources/yaml/rewrite-rule.yaml index 9e3247c6a4..7f12c3640e 100644 --- a/sharding-core/sharding-core-rewrite/src/test/resources/yaml/rewrite-rule.yaml +++ b/sharding-core/sharding-core-rewrite/src/test/resources/yaml/rewrite-rule.yaml @@ -34,6 +34,8 @@ shardingRule: keyGenerator: type: SNOWFLAKE column: id + props: + worker.id: 123 logicIndex: logic_index table_y: actualDataNodes: db${0..1}.table_y @@ -47,6 +49,8 @@ shardingRule: keyGenerator: type: SNOWFLAKE column: id + props: + worker.id: 123 bindingTables: - table_x, table_y encryptRule: diff --git a/sharding-jdbc/sharding-jdbc-orchestration/src/test/resources/yaml/unit/sharding.yaml b/sharding-jdbc/sharding-jdbc-orchestration/src/test/resources/yaml/unit/sharding.yaml index eb40e09b88..f2bd814334 100644 --- a/sharding-jdbc/sharding-jdbc-orchestration/src/test/resources/yaml/unit/sharding.yaml +++ b/sharding-jdbc/sharding-jdbc-orchestration/src/test/resources/yaml/unit/sharding.yaml @@ -42,6 +42,8 @@ shardingRule: keyGenerator: type: SNOWFLAKE column: order_id + props: + worker.id: 123 t_order_item: actualDataNodes: ds_ms.t_order_item_${0..1} tableStrategy: @@ -51,6 +53,8 @@ shardingRule: keyGenerator: type: SNOWFLAKE column: order_item_id + props: + worker.id: 123 bindingTables: - t_order,t_order_item masterSlaveRules: diff --git a/sharding-orchestration/sharding-orchestration-core/src/main/java/org/apache/shardingsphere/orchestration/internal/registry/RegistryCenterServiceLoader.java b/sharding-orchestration/sharding-orchestration-core/src/main/java/org/apache/shardingsphere/orchestration/internal/registry/RegistryCenterServiceLoader.java index 09c79a7c1b..3929bf6e52 100644 --- a/sharding-orchestration/sharding-orchestration-core/src/main/java/org/apache/shardingsphere/orchestration/internal/registry/RegistryCenterServiceLoader.java +++ b/sharding-orchestration/sharding-orchestration-core/src/main/java/org/apache/shardingsphere/orchestration/internal/registry/RegistryCenterServiceLoader.java @@ -37,7 +37,7 @@ public final class RegistryCenterServiceLoader extends TypeBasedSPIServiceLoader NewInstanceServiceLoader.register(RegistryCenter.class); } - RegistryCenterServiceLoader() { + public RegistryCenterServiceLoader() { super(RegistryCenter.class); } diff --git a/sharding-spring/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/src/test/resources/application-sharding.properties b/sharding-spring/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/src/test/resources/application-sharding.properties index c2d1237454..d9240246f8 100644 --- a/sharding-spring/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/src/test/resources/application-sharding.properties +++ b/sharding-spring/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/src/test/resources/application-sharding.properties @@ -45,11 +45,13 @@ spring.shardingsphere.sharding.tables.t_order.table-strategy.inline.sharding-col spring.shardingsphere.sharding.tables.t_order.table-strategy.inline.algorithm-expression=t_order_${order_id % 2} spring.shardingsphere.sharding.tables.t_order.key-generator.type=SNOWFLAKE spring.shardingsphere.sharding.tables.t_order.key-generator.column=order_id +spring.shardingsphere.sharding.tables.t_order.key-generator.props.worker.id=123 spring.shardingsphere.sharding.tables.t_order_item.actual-data-nodes=ds_${0..1}.t_order_item_${0..1} spring.shardingsphere.sharding.tables.t_order_item.table-strategy.inline.sharding-column=order_id spring.shardingsphere.sharding.tables.t_order_item.table-strategy.inline.algorithm-expression=t_order_item_${order_id % 2} spring.shardingsphere.sharding.tables.t_order_item.key-generator.type=SNOWFLAKE spring.shardingsphere.sharding.tables.t_order_item.key-generator.column=order_item_id +spring.shardingsphere.sharding.tables.t_order_item.key-generator.props.worker.id=123 spring.shardingsphere.sharding.binding-tables=t_order,t_order_item spring.shardingsphere.sharding.broadcast-tables=t_config diff --git a/sharding-spring/sharding-jdbc-spring/sharding-jdbc-spring-boot-starter/src/test/resources/application-sharding.properties b/sharding-spring/sharding-jdbc-spring/sharding-jdbc-spring-boot-starter/src/test/resources/application-sharding.properties index 63fa2de5ab..d96bfd4986 100644 --- a/sharding-spring/sharding-jdbc-spring/sharding-jdbc-spring-boot-starter/src/test/resources/application-sharding.properties +++ b/sharding-spring/sharding-jdbc-spring/sharding-jdbc-spring-boot-starter/src/test/resources/application-sharding.properties @@ -45,11 +45,13 @@ spring.shardingsphere.sharding.tables.t_order.table-strategy.inline.sharding-col spring.shardingsphere.sharding.tables.t_order.table-strategy.inline.algorithm-expression=t_order_${order_id % 2} spring.shardingsphere.sharding.tables.t_order.key-generator.type=SNOWFLAKE spring.shardingsphere.sharding.tables.t_order.key-generator.column=order_id +spring.shardingsphere.sharding.tables.t_order.key-generator.props.worker.id=123 spring.shardingsphere.sharding.tables.t_order_item.actual-data-nodes=ds_${0..1}.t_order_item_${0..1} spring.shardingsphere.sharding.tables.t_order_item.table-strategy.inline.sharding-column=order_id spring.shardingsphere.sharding.tables.t_order_item.table-strategy.inline.algorithm-expression=t_order_item_${order_id % 2} spring.shardingsphere.sharding.tables.t_order_item.key-generator.type=SNOWFLAKE spring.shardingsphere.sharding.tables.t_order_item.key-generator.column=order_item_id +spring.shardingsphere.sharding.tables.t_order_item.key-generator.props.worker.id=123 spring.shardingsphere.sharding.binding-tables=t_order,t_order_item spring.shardingsphere.sharding.broadcast-tables=t_config spring.shardingsphere.sharding.encryptRule.encryptors.order_encrypt.qualifiedColumns=t_order.pwd1,t_order.pwd2 -- GitLab