You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2022/01/25 14:57:42 UTC
[GitHub] [shardingsphere] Ahoo-Wang opened a new pull request #15067: add `CosIdSnowflakeKeyGenerateAlgorithm`/`CosIdSnowflakeIntervalShardingAlgorithm`
Ahoo-Wang opened a new pull request #15067:
URL: https://github.com/apache/shardingsphere/pull/15067
Fixes #14047.
Changes proposed in this pull request:
- add `CosIdSnowflakeKeyGenerateAlgorithm`
- add `CosIdSnowflakeIntervalShardingAlgorithm`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] Ahoo-Wang commented on a change in pull request #15067: add `CosIdSnowflakeKeyGenerateAlgorithm`/`CosIdSnowflakeIntervalShardingAlgorithm`
Posted by GitBox <gi...@apache.org>.
Ahoo-Wang commented on a change in pull request #15067:
URL: https://github.com/apache/shardingsphere/pull/15067#discussion_r793290808
##########
File path: shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/keygen/CosIdSnowflakeKeyGenerateAlgorithm.java
##########
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.sharding.algorithm.keygen;
+
+import lombok.Getter;
+import lombok.Setter;
+import me.ahoo.cosid.converter.Radix62IdConverter;
+import me.ahoo.cosid.snowflake.ClockSyncSnowflakeId;
+import me.ahoo.cosid.snowflake.MillisecondSnowflakeId;
+import me.ahoo.cosid.snowflake.SnowflakeId;
+import me.ahoo.cosid.snowflake.StringSnowflakeId;
+import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereInstanceRequiredAlgorithm;
+import org.apache.shardingsphere.infra.instance.InstanceContext;
+import org.apache.shardingsphere.sharding.algorithm.sharding.cosid.CosIdAlgorithm;
+import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;
+
+import java.util.Properties;
+
+/**
+ * CosId snowflake key generate algorithm.
+ */
+public final class CosIdSnowflakeKeyGenerateAlgorithm implements KeyGenerateAlgorithm, ShardingSphereInstanceRequiredAlgorithm {
+
+ public static final String TYPE = CosIdAlgorithm.TYPE_PREFIX + "SNOWFLAKE";
+
+ public static final long DEFAULT_EPOCH = SnowflakeKeyGenerateAlgorithm.EPOCH;
+
+ public static final String AS_STRING_KEY = "as-string";
+
+ public static final String EPOCH_KEY = "epoch";
+
+ private volatile InstanceContext instanceContext;
+
+ private volatile SnowflakeId snowflakeId;
+
+ private volatile boolean asString;
+
+ @Getter
+ @Setter
+ private Properties props = new Properties();
+
+ @Override
+ public Comparable<?> generateKey() {
+ if (asString) {
+ return snowflakeId.generateAsString();
+ }
+ return snowflakeId.generate();
+ }
+
+ @Override
+ public void init() {
+ String asStringStr = getProps().getProperty(AS_STRING_KEY, Boolean.FALSE.toString());
+ asString = Boolean.parseBoolean(asStringStr);
+ long workerId = 0;
+ if (null != instanceContext) {
+ workerId = instanceContext.getWorkerId();
Review comment:
ok.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] menghaoranss commented on a change in pull request #15067: add `CosIdSnowflakeKeyGenerateAlgorithm`/`CosIdSnowflakeIntervalShardingAlgorithm`
Posted by GitBox <gi...@apache.org>.
menghaoranss commented on a change in pull request #15067:
URL: https://github.com/apache/shardingsphere/pull/15067#discussion_r793268861
##########
File path: shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/keygen/CosIdSnowflakeKeyGenerateAlgorithm.java
##########
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.sharding.algorithm.keygen;
+
+import lombok.Getter;
+import lombok.Setter;
+import me.ahoo.cosid.converter.Radix62IdConverter;
+import me.ahoo.cosid.snowflake.ClockSyncSnowflakeId;
+import me.ahoo.cosid.snowflake.MillisecondSnowflakeId;
+import me.ahoo.cosid.snowflake.SnowflakeId;
+import me.ahoo.cosid.snowflake.StringSnowflakeId;
+import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereInstanceRequiredAlgorithm;
+import org.apache.shardingsphere.infra.instance.InstanceContext;
+import org.apache.shardingsphere.sharding.algorithm.sharding.cosid.CosIdAlgorithm;
+import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;
+
+import java.util.Properties;
+
+/**
+ * CosId snowflake key generate algorithm.
+ */
+public final class CosIdSnowflakeKeyGenerateAlgorithm implements KeyGenerateAlgorithm, ShardingSphereInstanceRequiredAlgorithm {
+
+ public static final String TYPE = CosIdAlgorithm.TYPE_PREFIX + "SNOWFLAKE";
+
+ public static final long DEFAULT_EPOCH = SnowflakeKeyGenerateAlgorithm.EPOCH;
+
+ public static final String AS_STRING_KEY = "as-string";
+
+ public static final String EPOCH_KEY = "epoch";
+
+ private volatile InstanceContext instanceContext;
+
+ private volatile SnowflakeId snowflakeId;
+
+ private volatile boolean asString;
+
+ @Getter
+ @Setter
+ private Properties props = new Properties();
+
+ @Override
+ public Comparable<?> generateKey() {
+ if (asString) {
+ return snowflakeId.generateAsString();
+ }
+ return snowflakeId.generate();
+ }
+
+ @Override
+ public void init() {
+ String asStringStr = getProps().getProperty(AS_STRING_KEY, Boolean.FALSE.toString());
+ asString = Boolean.parseBoolean(asStringStr);
+ long workerId = 0;
+ if (null != instanceContext) {
+ workerId = instanceContext.getWorkerId();
Review comment:
the `instanceContext` is initialized after `init()`, so it will always be null here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] Ahoo-Wang commented on a change in pull request #15067: add `CosIdSnowflakeKeyGenerateAlgorithm`/`CosIdSnowflakeIntervalShardingAlgorithm`
Posted by GitBox <gi...@apache.org>.
Ahoo-Wang commented on a change in pull request #15067:
URL: https://github.com/apache/shardingsphere/pull/15067#discussion_r792655881
##########
File path: shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/keygen/CosIdSnowflakeKeyGenerateAlgorithm.java
##########
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.sharding.algorithm.keygen;
+
+import lombok.Getter;
+import lombok.Setter;
+import me.ahoo.cosid.converter.Radix62IdConverter;
+import me.ahoo.cosid.snowflake.ClockSyncSnowflakeId;
+import me.ahoo.cosid.snowflake.MillisecondSnowflakeId;
+import me.ahoo.cosid.snowflake.SnowflakeId;
+import me.ahoo.cosid.snowflake.StringSnowflakeId;
+import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereInstanceRequiredAlgorithm;
+import org.apache.shardingsphere.infra.instance.InstanceContext;
+import org.apache.shardingsphere.sharding.algorithm.sharding.cosid.CosIdAlgorithm;
+import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;
+
+import java.util.Properties;
+
+/**
+ * CosId-Snowflake key generate algorithm.
+ */
+public final class CosIdSnowflakeKeyGenerateAlgorithm implements KeyGenerateAlgorithm, ShardingSphereInstanceRequiredAlgorithm {
+
+ public static final String TYPE = CosIdAlgorithm.TYPE_PREFIX + "SNOWFLAKE";
+
+ public static final long DEFAULT_EPOCH = SnowflakeKeyGenerateAlgorithm.EPOCH;
+
+ public static final String AS_STRING_KEY = "as-string";
+
+ public static final String EPOCH_KEY = "epoch";
+
+ private volatile InstanceContext instanceContext;
+
+ private volatile SnowflakeId snowflakeId;
+
+ private volatile boolean asString;
+
+ @Getter
+ @Setter
+ private Properties props = new Properties();
+
+ @Override
+ public Comparable<?> generateKey() {
+ if (asString) {
+ return snowflakeId.generateAsString();
+ }
+ return snowflakeId.generate();
+ }
+
+ @Override
+ public void init() {
+ String asStringStr = getProps().getProperty(AS_STRING_KEY, Boolean.FALSE.toString());
+ asString = Boolean.parseBoolean(asStringStr);
+ long workerId = 0;
+ if (instanceContext != null) {
Review comment:
ok
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] Ahoo-Wang commented on a change in pull request #15067: add `CosIdSnowflakeKeyGenerateAlgorithm`/`CosIdSnowflakeIntervalShardingAlgorithm`
Posted by GitBox <gi...@apache.org>.
Ahoo-Wang commented on a change in pull request #15067:
URL: https://github.com/apache/shardingsphere/pull/15067#discussion_r793213798
##########
File path: shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/keygen/CosIdKeyGenerateAlgorithm.java
##########
@@ -20,57 +20,47 @@
import me.ahoo.cosid.CosId;
import me.ahoo.cosid.provider.IdGeneratorProvider;
import me.ahoo.cosid.provider.LazyIdGenerator;
-import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereInstanceRequiredAlgorithm;
-import org.apache.shardingsphere.infra.instance.InstanceContext;
import org.apache.shardingsphere.sharding.algorithm.sharding.cosid.CosIdAlgorithm;
import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;
-import java.util.Optional;
import java.util.Properties;
/**
* CosId key generate algorithm.
*/
-public final class CosIdKeyGenerateAlgorithm implements KeyGenerateAlgorithm, ShardingSphereInstanceRequiredAlgorithm {
-
+public final class CosIdKeyGenerateAlgorithm implements KeyGenerateAlgorithm {
+
public static final String TYPE = CosId.COSID.toUpperCase();
-
Review comment:
@strongduanmu Ok,thanks.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] strongduanmu commented on a change in pull request #15067: add `CosIdSnowflakeKeyGenerateAlgorithm`/`CosIdSnowflakeIntervalShardingAlgorithm`
Posted by GitBox <gi...@apache.org>.
strongduanmu commented on a change in pull request #15067:
URL: https://github.com/apache/shardingsphere/pull/15067#discussion_r793184197
##########
File path: shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/keygen/CosIdKeyGenerateAlgorithm.java
##########
@@ -20,57 +20,47 @@
import me.ahoo.cosid.CosId;
import me.ahoo.cosid.provider.IdGeneratorProvider;
import me.ahoo.cosid.provider.LazyIdGenerator;
-import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereInstanceRequiredAlgorithm;
-import org.apache.shardingsphere.infra.instance.InstanceContext;
import org.apache.shardingsphere.sharding.algorithm.sharding.cosid.CosIdAlgorithm;
import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;
-import java.util.Optional;
import java.util.Properties;
/**
* CosId key generate algorithm.
*/
-public final class CosIdKeyGenerateAlgorithm implements KeyGenerateAlgorithm, ShardingSphereInstanceRequiredAlgorithm {
Review comment:
>
Thank you, I got it.
##########
File path: shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/keygen/CosIdKeyGenerateAlgorithm.java
##########
@@ -20,57 +20,47 @@
import me.ahoo.cosid.CosId;
import me.ahoo.cosid.provider.IdGeneratorProvider;
import me.ahoo.cosid.provider.LazyIdGenerator;
-import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereInstanceRequiredAlgorithm;
-import org.apache.shardingsphere.infra.instance.InstanceContext;
import org.apache.shardingsphere.sharding.algorithm.sharding.cosid.CosIdAlgorithm;
import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;
-import java.util.Optional;
import java.util.Properties;
/**
* CosId key generate algorithm.
*/
-public final class CosIdKeyGenerateAlgorithm implements KeyGenerateAlgorithm, ShardingSphereInstanceRequiredAlgorithm {
-
+public final class CosIdKeyGenerateAlgorithm implements KeyGenerateAlgorithm {
+
public static final String TYPE = CosId.COSID.toUpperCase();
-
Review comment:
> @Ahoo-Wang Please keep indents consistent with the previous one.
@Ahoo-Wang Please modify these checkstyle problem.
##########
File path: shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/keygen/CosIdSnowflakeKeyGenerateAlgorithm.java
##########
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.sharding.algorithm.keygen;
+
+import lombok.Getter;
+import lombok.Setter;
+import me.ahoo.cosid.converter.Radix62IdConverter;
+import me.ahoo.cosid.snowflake.ClockSyncSnowflakeId;
+import me.ahoo.cosid.snowflake.MillisecondSnowflakeId;
+import me.ahoo.cosid.snowflake.SnowflakeId;
+import me.ahoo.cosid.snowflake.StringSnowflakeId;
+import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereInstanceRequiredAlgorithm;
+import org.apache.shardingsphere.infra.instance.InstanceContext;
+import org.apache.shardingsphere.sharding.algorithm.sharding.cosid.CosIdAlgorithm;
+import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;
+
+import java.util.Properties;
+
+/**
+ * CosId-Snowflake key generate algorithm.
+ */
+public final class CosIdSnowflakeKeyGenerateAlgorithm implements KeyGenerateAlgorithm, ShardingSphereInstanceRequiredAlgorithm {
+
+ public static final String TYPE = CosIdAlgorithm.TYPE_PREFIX + "SNOWFLAKE";
+
+ public static final long DEFAULT_EPOCH = SnowflakeKeyGenerateAlgorithm.EPOCH;
Review comment:
>
Ok.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] codecov-commenter commented on pull request #15067: add `CosIdSnowflakeKeyGenerateAlgorithm`/`CosIdSnowflakeIntervalShardingAlgorithm`
Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on pull request #15067:
URL: https://github.com/apache/shardingsphere/pull/15067#issuecomment-1021848681
# [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/15067?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
> Merging [#15067](https://codecov.io/gh/apache/shardingsphere/pull/15067?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (8a20ff6) into [master](https://codecov.io/gh/apache/shardingsphere/commit/26b78505bf3e67129ef06e76708e27b92e0ff1a5?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (26b7850) will **increase** coverage by `0.01%`.
> The diff coverage is `81.63%`.
[](https://codecov.io/gh/apache/shardingsphere/pull/15067?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
```diff
@@ Coverage Diff @@
## master #15067 +/- ##
============================================
+ Coverage 59.67% 59.69% +0.01%
- Complexity 1897 1905 +8
============================================
Files 3151 3161 +10
Lines 47085 47153 +68
Branches 7999 8013 +14
============================================
+ Hits 28098 28147 +49
- Misses 16743 16754 +11
- Partials 2244 2252 +8
```
| [Impacted Files](https://codecov.io/gh/apache/shardingsphere/pull/15067?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
|---|---|---|
| [...shardingsphere/infra/instance/InstanceContext.java](https://codecov.io/gh/apache/shardingsphere/pull/15067/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtaW5mcmEvc2hhcmRpbmdzcGhlcmUtaW5mcmEtY29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9pbmZyYS9pbnN0YW5jZS9JbnN0YW5jZUNvbnRleHQuamF2YQ==) | `0.00% <0.00%> (ø)` | |
| [...cosid/CosIdSnowflakeIntervalShardingAlgorithm.java](https://codecov.io/gh/apache/shardingsphere/pull/15067/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtc2hhcmRpbmcvc2hhcmRpbmdzcGhlcmUtc2hhcmRpbmctY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvc2hhcmRpbmcvYWxnb3JpdGhtL3NoYXJkaW5nL2Nvc2lkL0Nvc0lkU25vd2ZsYWtlSW50ZXJ2YWxTaGFyZGluZ0FsZ29yaXRobS5qYXZh) | `52.94% <52.94%> (ø)` | |
| [...sharding/cosid/CosIdIntervalShardingAlgorithm.java](https://codecov.io/gh/apache/shardingsphere/pull/15067/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtc2hhcmRpbmcvc2hhcmRpbmdzcGhlcmUtc2hhcmRpbmctY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvc2hhcmRpbmcvYWxnb3JpdGhtL3NoYXJkaW5nL2Nvc2lkL0Nvc0lkSW50ZXJ2YWxTaGFyZGluZ0FsZ29yaXRobS5qYXZh) | `60.00% <58.33%> (-27.50%)` | :arrow_down: |
| [...thm/keygen/CosIdSnowflakeKeyGenerateAlgorithm.java](https://codecov.io/gh/apache/shardingsphere/pull/15067/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtc2hhcmRpbmcvc2hhcmRpbmdzcGhlcmUtc2hhcmRpbmctY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvc2hhcmRpbmcvYWxnb3JpdGhtL2tleWdlbi9Db3NJZFNub3dmbGFrZUtleUdlbmVyYXRlQWxnb3JpdGhtLmphdmE=) | `85.71% <85.71%> (ø)` | |
| [...rding/cosid/AbstractIntervalShardingAlgorithm.java](https://codecov.io/gh/apache/shardingsphere/pull/15067/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtc2hhcmRpbmcvc2hhcmRpbmdzcGhlcmUtc2hhcmRpbmctY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvc2hhcmRpbmcvYWxnb3JpdGhtL3NoYXJkaW5nL2Nvc2lkL0Fic3RyYWN0SW50ZXJ2YWxTaGFyZGluZ0FsZ29yaXRobS5qYXZh) | `97.43% <97.43%> (ø)` | |
| [...ng/algorithm/keygen/CosIdKeyGenerateAlgorithm.java](https://codecov.io/gh/apache/shardingsphere/pull/15067/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtc2hhcmRpbmcvc2hhcmRpbmdzcGhlcmUtc2hhcmRpbmctY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvc2hhcmRpbmcvYWxnb3JpdGhtL2tleWdlbi9Db3NJZEtleUdlbmVyYXRlQWxnb3JpdGhtLmphdmE=) | `91.66% <100.00%> (+13.09%)` | :arrow_up: |
| [...rding/algorithm/sharding/cosid/PropertiesUtil.java](https://codecov.io/gh/apache/shardingsphere/pull/15067/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtc2hhcmRpbmcvc2hhcmRpbmdzcGhlcmUtc2hhcmRpbmctY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvc2hhcmRpbmcvYWxnb3JpdGhtL3NoYXJkaW5nL2Nvc2lkL1Byb3BlcnRpZXNVdGlsLmphdmE=) | `66.66% <100.00%> (ø)` | |
| [...ral/common/CommonDistSQLBackendHandlerFactory.java](https://codecov.io/gh/apache/shardingsphere/pull/15067/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtcHJveHkvc2hhcmRpbmdzcGhlcmUtcHJveHktYmFja2VuZC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvcHJveHkvYmFja2VuZC90ZXh0L2Rpc3RzcWwvcmFsL2NvbW1vbi9Db21tb25EaXN0U1FMQmFja2VuZEhhbmRsZXJGYWN0b3J5LmphdmE=) | `38.46% <0.00%> (-7.00%)` | :arrow_down: |
| [...ite/parameter/EncryptParameterRewriterBuilder.java](https://codecov.io/gh/apache/shardingsphere/pull/15067/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtZW5jcnlwdC9zaGFyZGluZ3NwaGVyZS1lbmNyeXB0LWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2VuY3J5cHQvcmV3cml0ZS9wYXJhbWV0ZXIvRW5jcnlwdFBhcmFtZXRlclJld3JpdGVyQnVpbGRlci5qYXZh) | `80.00% <0.00%> (-6.37%)` | :arrow_down: |
| [...te/context/ShardingSQLRewriteContextDecorator.java](https://codecov.io/gh/apache/shardingsphere/pull/15067/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtc2hhcmRpbmcvc2hhcmRpbmdzcGhlcmUtc2hhcmRpbmctY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvc2hhcmRpbmcvcmV3cml0ZS9jb250ZXh0L1NoYXJkaW5nU1FMUmV3cml0ZUNvbnRleHREZWNvcmF0b3IuamF2YQ==) | `68.75% <0.00%> (-6.25%)` | :arrow_down: |
| ... and [21 more](https://codecov.io/gh/apache/shardingsphere/pull/15067/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | |
------
[Continue to review full report at Codecov](https://codecov.io/gh/apache/shardingsphere/pull/15067?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/15067?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [26b7850...8a20ff6](https://codecov.io/gh/apache/shardingsphere/pull/15067?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] Ahoo-Wang commented on a change in pull request #15067: add `CosIdSnowflakeKeyGenerateAlgorithm`/`CosIdSnowflakeIntervalShardingAlgorithm`
Posted by GitBox <gi...@apache.org>.
Ahoo-Wang commented on a change in pull request #15067:
URL: https://github.com/apache/shardingsphere/pull/15067#discussion_r792655217
##########
File path: shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/cosid/AbstractIntervalShardingAlgorithm.java
##########
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.sharding.algorithm.sharding.cosid;
+
+import com.google.common.collect.BoundType;
+import com.google.common.collect.Range;
+import lombok.Getter;
+import lombok.Setter;
+import me.ahoo.cosid.sharding.IntervalStep;
+import me.ahoo.cosid.sharding.IntervalTimeline;
+import org.apache.shardingsphere.sharding.api.sharding.standard.PreciseShardingValue;
+import org.apache.shardingsphere.sharding.api.sharding.standard.RangeShardingValue;
+import org.apache.shardingsphere.sharding.api.sharding.standard.StandardShardingAlgorithm;
+
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
+import java.time.temporal.ChronoUnit;
+import java.util.Collection;
+import java.util.Properties;
+
+/**
+ * Interval-based time range sharding algorithm.
+ */
+public abstract class AbstractIntervalShardingAlgorithm<T extends Comparable<?>> implements StandardShardingAlgorithm<T> {
+
+ public static final String DEFAULT_DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss";
+
+ public static final DateTimeFormatter DEFAULT_DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern(DEFAULT_DATE_TIME_PATTERN);
+
+ public static final String DATE_TIME_LOWER_KEY = "datetime-lower";
+
+ public static final String DATE_TIME_UPPER_KEY = "datetime-upper";
+
+ public static final String SHARDING_SUFFIX_FORMAT_KEY = "sharding-suffix-pattern";
+
+ public static final String INTERVAL_UNIT_KEY = "datetime-interval-unit";
+
+ public static final String INTERVAL_AMOUNT_KEY = "datetime-interval-amount";
+
+ public static final String ZONE_ID_KEY = "zone-id";
+
+ private volatile IntervalTimeline intervalTimeline;
+
+ private ZoneId zoneId = ZoneId.systemDefault();
+
+ @Getter
+ @Setter
+ private Properties props = new Properties();
+
+ /**
+ * get zone id.
+ *
+ * @return zone id
+ */
+ protected ZoneId getZoneId() {
+ return zoneId;
+ }
+
+ @Override
+ public void init() {
+ if (getProps().containsKey(ZONE_ID_KEY)) {
+ zoneId = ZoneId.of(getRequiredValue(ZONE_ID_KEY));
+ }
+ String logicNamePrefix = getRequiredValue(CosIdAlgorithm.LOGIC_NAME_PREFIX_KEY);
+ LocalDateTime effectiveLower = LocalDateTime.parse(getRequiredValue(DATE_TIME_LOWER_KEY), DEFAULT_DATE_TIME_FORMATTER);
+ LocalDateTime effectiveUpper = LocalDateTime.parse(getRequiredValue(DATE_TIME_UPPER_KEY), DEFAULT_DATE_TIME_FORMATTER);
+ DateTimeFormatter suffixFormatter = DateTimeFormatter.ofPattern(getRequiredValue(SHARDING_SUFFIX_FORMAT_KEY));
+ ChronoUnit stepUnit = ChronoUnit.valueOf(getRequiredValue(INTERVAL_UNIT_KEY));
+ int stepAmount = Integer.parseInt(getProps().getProperty(INTERVAL_AMOUNT_KEY, "1"));
+ intervalTimeline = new IntervalTimeline(logicNamePrefix, Range.closed(effectiveLower, effectiveUpper), IntervalStep.of(stepUnit, stepAmount), suffixFormatter);
+ }
+
+ private String getRequiredValue(final String key) {
+ return PropertiesUtil.getRequiredValue(getProps(), key);
+ }
+
+ @Override
+ public String doSharding(final Collection<String> availableTargetNames, final PreciseShardingValue<T> shardingValue) {
+ LocalDateTime shardingTime = convertShardingValue(shardingValue.getValue());
+ return this.intervalTimeline.sharding(shardingTime);
+ }
+
+ @Override
+ public Collection<String> doSharding(final Collection<String> availableTargetNames, final RangeShardingValue<T> shardingValue) {
+ Range<LocalDateTime> shardingRangeTime = convertRangeShardingValue(shardingValue.getValueRange());
+ return this.intervalTimeline.sharding(shardingRangeTime);
+ }
+
+ /**
+ * convert sharding value to {@link LocalDateTime}.
+ *
+ * @param shardingValue sharding value
+ * @return The {@link LocalDateTime} represented by the sharding value
+ */
+ protected abstract LocalDateTime convertShardingValue(T shardingValue);
+
+ private Range<LocalDateTime> convertRangeShardingValue(final Range<T> shardingValue) {
+ if (Range.all().equals(shardingValue)) {
+ return Range.all();
+ }
+ Object endpointValue = shardingValue.hasLowerBound() ? shardingValue.lowerEndpoint() : shardingValue.upperEndpoint();
+ if (endpointValue instanceof LocalDateTime) {
+ @SuppressWarnings("unchecked")
+ Range<LocalDateTime> targetRange = (Range<LocalDateTime>) shardingValue;
+ return targetRange;
+ }
+
Review comment:
ok
##########
File path: shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/cosid/AbstractIntervalShardingAlgorithm.java
##########
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.sharding.algorithm.sharding.cosid;
+
+import com.google.common.collect.BoundType;
+import com.google.common.collect.Range;
+import lombok.Getter;
+import lombok.Setter;
+import me.ahoo.cosid.sharding.IntervalStep;
+import me.ahoo.cosid.sharding.IntervalTimeline;
+import org.apache.shardingsphere.sharding.api.sharding.standard.PreciseShardingValue;
+import org.apache.shardingsphere.sharding.api.sharding.standard.RangeShardingValue;
+import org.apache.shardingsphere.sharding.api.sharding.standard.StandardShardingAlgorithm;
+
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
+import java.time.temporal.ChronoUnit;
+import java.util.Collection;
+import java.util.Properties;
+
+/**
+ * Interval-based time range sharding algorithm.
+ */
+public abstract class AbstractIntervalShardingAlgorithm<T extends Comparable<?>> implements StandardShardingAlgorithm<T> {
+
+ public static final String DEFAULT_DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss";
+
+ public static final DateTimeFormatter DEFAULT_DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern(DEFAULT_DATE_TIME_PATTERN);
+
+ public static final String DATE_TIME_LOWER_KEY = "datetime-lower";
+
+ public static final String DATE_TIME_UPPER_KEY = "datetime-upper";
+
+ public static final String SHARDING_SUFFIX_FORMAT_KEY = "sharding-suffix-pattern";
+
+ public static final String INTERVAL_UNIT_KEY = "datetime-interval-unit";
+
+ public static final String INTERVAL_AMOUNT_KEY = "datetime-interval-amount";
+
+ public static final String ZONE_ID_KEY = "zone-id";
+
+ private volatile IntervalTimeline intervalTimeline;
+
+ private ZoneId zoneId = ZoneId.systemDefault();
+
+ @Getter
+ @Setter
+ private Properties props = new Properties();
+
+ /**
+ * get zone id.
+ *
+ * @return zone id
+ */
+ protected ZoneId getZoneId() {
+ return zoneId;
+ }
+
+ @Override
+ public void init() {
+ if (getProps().containsKey(ZONE_ID_KEY)) {
+ zoneId = ZoneId.of(getRequiredValue(ZONE_ID_KEY));
+ }
+ String logicNamePrefix = getRequiredValue(CosIdAlgorithm.LOGIC_NAME_PREFIX_KEY);
+ LocalDateTime effectiveLower = LocalDateTime.parse(getRequiredValue(DATE_TIME_LOWER_KEY), DEFAULT_DATE_TIME_FORMATTER);
+ LocalDateTime effectiveUpper = LocalDateTime.parse(getRequiredValue(DATE_TIME_UPPER_KEY), DEFAULT_DATE_TIME_FORMATTER);
+ DateTimeFormatter suffixFormatter = DateTimeFormatter.ofPattern(getRequiredValue(SHARDING_SUFFIX_FORMAT_KEY));
+ ChronoUnit stepUnit = ChronoUnit.valueOf(getRequiredValue(INTERVAL_UNIT_KEY));
+ int stepAmount = Integer.parseInt(getProps().getProperty(INTERVAL_AMOUNT_KEY, "1"));
+ intervalTimeline = new IntervalTimeline(logicNamePrefix, Range.closed(effectiveLower, effectiveUpper), IntervalStep.of(stepUnit, stepAmount), suffixFormatter);
+ }
+
+ private String getRequiredValue(final String key) {
+ return PropertiesUtil.getRequiredValue(getProps(), key);
+ }
+
+ @Override
+ public String doSharding(final Collection<String> availableTargetNames, final PreciseShardingValue<T> shardingValue) {
+ LocalDateTime shardingTime = convertShardingValue(shardingValue.getValue());
+ return this.intervalTimeline.sharding(shardingTime);
+ }
+
+ @Override
+ public Collection<String> doSharding(final Collection<String> availableTargetNames, final RangeShardingValue<T> shardingValue) {
+ Range<LocalDateTime> shardingRangeTime = convertRangeShardingValue(shardingValue.getValueRange());
+ return this.intervalTimeline.sharding(shardingRangeTime);
+ }
+
+ /**
+ * convert sharding value to {@link LocalDateTime}.
+ *
+ * @param shardingValue sharding value
+ * @return The {@link LocalDateTime} represented by the sharding value
+ */
+ protected abstract LocalDateTime convertShardingValue(T shardingValue);
+
+ private Range<LocalDateTime> convertRangeShardingValue(final Range<T> shardingValue) {
+ if (Range.all().equals(shardingValue)) {
+ return Range.all();
+ }
+ Object endpointValue = shardingValue.hasLowerBound() ? shardingValue.lowerEndpoint() : shardingValue.upperEndpoint();
+ if (endpointValue instanceof LocalDateTime) {
+ @SuppressWarnings("unchecked")
Review comment:
ok
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] Ahoo-Wang commented on a change in pull request #15067: add `CosIdSnowflakeKeyGenerateAlgorithm`/`CosIdSnowflakeIntervalShardingAlgorithm`
Posted by GitBox <gi...@apache.org>.
Ahoo-Wang commented on a change in pull request #15067:
URL: https://github.com/apache/shardingsphere/pull/15067#discussion_r792684685
##########
File path: shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/keygen/CosIdKeyGenerateAlgorithm.java
##########
@@ -20,57 +20,47 @@
import me.ahoo.cosid.CosId;
import me.ahoo.cosid.provider.IdGeneratorProvider;
import me.ahoo.cosid.provider.LazyIdGenerator;
-import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereInstanceRequiredAlgorithm;
-import org.apache.shardingsphere.infra.instance.InstanceContext;
import org.apache.shardingsphere.sharding.algorithm.sharding.cosid.CosIdAlgorithm;
import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;
-import java.util.Optional;
import java.util.Properties;
/**
* CosId key generate algorithm.
*/
-public final class CosIdKeyGenerateAlgorithm implements KeyGenerateAlgorithm, ShardingSphereInstanceRequiredAlgorithm {
Review comment:
Because the `SegmentId` algorithm and `SegmentChainId` algorithm of `CosId` do not need to depend on `WorkerId`, so I added `CosIdSnowflakeKeyGenerateAlgorithm`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] Ahoo-Wang commented on a change in pull request #15067: add `CosIdSnowflakeKeyGenerateAlgorithm`/`CosIdSnowflakeIntervalShardingAlgorithm`
Posted by GitBox <gi...@apache.org>.
Ahoo-Wang commented on a change in pull request #15067:
URL: https://github.com/apache/shardingsphere/pull/15067#discussion_r792697848
##########
File path: pom.xml
##########
@@ -57,7 +57,7 @@
<guava.version>30.0-jre</guava.version>
<gson.version>2.8.6</gson.version>
<slf4j.version>1.7.7</slf4j.version>
- <cosid.version>1.7.6</cosid.version>
+ <cosid.version>1.8.4</cosid.version>
Review comment:
ok
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] Ahoo-Wang commented on a change in pull request #15067: add `CosIdSnowflakeKeyGenerateAlgorithm`/`CosIdSnowflakeIntervalShardingAlgorithm`
Posted by GitBox <gi...@apache.org>.
Ahoo-Wang commented on a change in pull request #15067:
URL: https://github.com/apache/shardingsphere/pull/15067#discussion_r793202029
##########
File path: shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/keygen/CosIdKeyGenerateAlgorithm.java
##########
@@ -20,57 +20,47 @@
import me.ahoo.cosid.CosId;
import me.ahoo.cosid.provider.IdGeneratorProvider;
import me.ahoo.cosid.provider.LazyIdGenerator;
-import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereInstanceRequiredAlgorithm;
-import org.apache.shardingsphere.infra.instance.InstanceContext;
import org.apache.shardingsphere.sharding.algorithm.sharding.cosid.CosIdAlgorithm;
import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;
-import java.util.Optional;
import java.util.Properties;
/**
* CosId key generate algorithm.
*/
-public final class CosIdKeyGenerateAlgorithm implements KeyGenerateAlgorithm, ShardingSphereInstanceRequiredAlgorithm {
-
+public final class CosIdKeyGenerateAlgorithm implements KeyGenerateAlgorithm {
+
public static final String TYPE = CosId.COSID.toUpperCase();
-
Review comment:
@strongduanmu I'm sorry I didn't find the question about indentation.Do you mean the indentation of empty lines?

--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] Ahoo-Wang commented on a change in pull request #15067: add `CosIdSnowflakeKeyGenerateAlgorithm`/`CosIdSnowflakeIntervalShardingAlgorithm`
Posted by GitBox <gi...@apache.org>.
Ahoo-Wang commented on a change in pull request #15067:
URL: https://github.com/apache/shardingsphere/pull/15067#discussion_r793202029
##########
File path: shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/keygen/CosIdKeyGenerateAlgorithm.java
##########
@@ -20,57 +20,47 @@
import me.ahoo.cosid.CosId;
import me.ahoo.cosid.provider.IdGeneratorProvider;
import me.ahoo.cosid.provider.LazyIdGenerator;
-import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereInstanceRequiredAlgorithm;
-import org.apache.shardingsphere.infra.instance.InstanceContext;
import org.apache.shardingsphere.sharding.algorithm.sharding.cosid.CosIdAlgorithm;
import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;
-import java.util.Optional;
import java.util.Properties;
/**
* CosId key generate algorithm.
*/
-public final class CosIdKeyGenerateAlgorithm implements KeyGenerateAlgorithm, ShardingSphereInstanceRequiredAlgorithm {
-
+public final class CosIdKeyGenerateAlgorithm implements KeyGenerateAlgorithm {
+
public static final String TYPE = CosId.COSID.toUpperCase();
-
Review comment:
I'm sorry I didn't find the question about indentation.Do you mean the indentation of empty lines?

--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] menghaoranss merged pull request #15067: add `CosIdSnowflakeKeyGenerateAlgorithm`/`CosIdSnowflakeIntervalShardingAlgorithm`
Posted by GitBox <gi...@apache.org>.
menghaoranss merged pull request #15067:
URL: https://github.com/apache/shardingsphere/pull/15067
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] strongduanmu commented on a change in pull request #15067: add `CosIdSnowflakeKeyGenerateAlgorithm`/`CosIdSnowflakeIntervalShardingAlgorithm`
Posted by GitBox <gi...@apache.org>.
strongduanmu commented on a change in pull request #15067:
URL: https://github.com/apache/shardingsphere/pull/15067#discussion_r793210254
##########
File path: shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/keygen/CosIdKeyGenerateAlgorithm.java
##########
@@ -20,57 +20,47 @@
import me.ahoo.cosid.CosId;
import me.ahoo.cosid.provider.IdGeneratorProvider;
import me.ahoo.cosid.provider.LazyIdGenerator;
-import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereInstanceRequiredAlgorithm;
-import org.apache.shardingsphere.infra.instance.InstanceContext;
import org.apache.shardingsphere.sharding.algorithm.sharding.cosid.CosIdAlgorithm;
import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;
-import java.util.Optional;
import java.util.Properties;
/**
* CosId key generate algorithm.
*/
-public final class CosIdKeyGenerateAlgorithm implements KeyGenerateAlgorithm, ShardingSphereInstanceRequiredAlgorithm {
-
+public final class CosIdKeyGenerateAlgorithm implements KeyGenerateAlgorithm {
+
public static final String TYPE = CosId.COSID.toUpperCase();
-
Review comment:
> @strongduanmu I'm sorry I didn't find the question about indentation.Do you mean the indentation of empty lines? 
@Ahoo-Wang Sorry, I was wrong, this is a requirement for `code conduct`——Keep indents consistent with the previous one.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] strongduanmu commented on a change in pull request #15067: add `CosIdSnowflakeKeyGenerateAlgorithm`/`CosIdSnowflakeIntervalShardingAlgorithm`
Posted by GitBox <gi...@apache.org>.
strongduanmu commented on a change in pull request #15067:
URL: https://github.com/apache/shardingsphere/pull/15067#discussion_r792328133
##########
File path: shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/keygen/CosIdKeyGenerateAlgorithm.java
##########
@@ -20,57 +20,47 @@
import me.ahoo.cosid.CosId;
import me.ahoo.cosid.provider.IdGeneratorProvider;
import me.ahoo.cosid.provider.LazyIdGenerator;
-import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereInstanceRequiredAlgorithm;
-import org.apache.shardingsphere.infra.instance.InstanceContext;
import org.apache.shardingsphere.sharding.algorithm.sharding.cosid.CosIdAlgorithm;
import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;
-import java.util.Optional;
import java.util.Properties;
/**
* CosId key generate algorithm.
*/
-public final class CosIdKeyGenerateAlgorithm implements KeyGenerateAlgorithm, ShardingSphereInstanceRequiredAlgorithm {
-
+public final class CosIdKeyGenerateAlgorithm implements KeyGenerateAlgorithm {
+
public static final String TYPE = CosId.COSID.toUpperCase();
-
Review comment:
@Ahoo-Wang Please keep indents consistent with the previous one.
##########
File path: shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/cosid/AbstractIntervalShardingAlgorithm.java
##########
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.sharding.algorithm.sharding.cosid;
+
+import com.google.common.collect.BoundType;
+import com.google.common.collect.Range;
+import lombok.Getter;
+import lombok.Setter;
+import me.ahoo.cosid.sharding.IntervalStep;
+import me.ahoo.cosid.sharding.IntervalTimeline;
+import org.apache.shardingsphere.sharding.api.sharding.standard.PreciseShardingValue;
+import org.apache.shardingsphere.sharding.api.sharding.standard.RangeShardingValue;
+import org.apache.shardingsphere.sharding.api.sharding.standard.StandardShardingAlgorithm;
+
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
+import java.time.temporal.ChronoUnit;
+import java.util.Collection;
+import java.util.Properties;
+
+/**
+ * Interval-based time range sharding algorithm.
+ */
+public abstract class AbstractIntervalShardingAlgorithm<T extends Comparable<?>> implements StandardShardingAlgorithm<T> {
+
+ public static final String DEFAULT_DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss";
+
+ public static final DateTimeFormatter DEFAULT_DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern(DEFAULT_DATE_TIME_PATTERN);
+
+ public static final String DATE_TIME_LOWER_KEY = "datetime-lower";
+
+ public static final String DATE_TIME_UPPER_KEY = "datetime-upper";
+
+ public static final String SHARDING_SUFFIX_FORMAT_KEY = "sharding-suffix-pattern";
+
+ public static final String INTERVAL_UNIT_KEY = "datetime-interval-unit";
+
+ public static final String INTERVAL_AMOUNT_KEY = "datetime-interval-amount";
+
+ public static final String ZONE_ID_KEY = "zone-id";
+
+ private volatile IntervalTimeline intervalTimeline;
+
+ private ZoneId zoneId = ZoneId.systemDefault();
+
+ @Getter
+ @Setter
+ private Properties props = new Properties();
+
+ /**
+ * get zone id.
+ *
+ * @return zone id
+ */
+ protected ZoneId getZoneId() {
+ return zoneId;
+ }
+
+ @Override
+ public void init() {
+ if (getProps().containsKey(ZONE_ID_KEY)) {
+ zoneId = ZoneId.of(getRequiredValue(ZONE_ID_KEY));
+ }
+ String logicNamePrefix = getRequiredValue(CosIdAlgorithm.LOGIC_NAME_PREFIX_KEY);
+ LocalDateTime effectiveLower = LocalDateTime.parse(getRequiredValue(DATE_TIME_LOWER_KEY), DEFAULT_DATE_TIME_FORMATTER);
+ LocalDateTime effectiveUpper = LocalDateTime.parse(getRequiredValue(DATE_TIME_UPPER_KEY), DEFAULT_DATE_TIME_FORMATTER);
+ DateTimeFormatter suffixFormatter = DateTimeFormatter.ofPattern(getRequiredValue(SHARDING_SUFFIX_FORMAT_KEY));
+ ChronoUnit stepUnit = ChronoUnit.valueOf(getRequiredValue(INTERVAL_UNIT_KEY));
+ int stepAmount = Integer.parseInt(getProps().getProperty(INTERVAL_AMOUNT_KEY, "1"));
+ intervalTimeline = new IntervalTimeline(logicNamePrefix, Range.closed(effectiveLower, effectiveUpper), IntervalStep.of(stepUnit, stepAmount), suffixFormatter);
+ }
+
+ private String getRequiredValue(final String key) {
+ return PropertiesUtil.getRequiredValue(getProps(), key);
+ }
+
+ @Override
+ public String doSharding(final Collection<String> availableTargetNames, final PreciseShardingValue<T> shardingValue) {
+ LocalDateTime shardingTime = convertShardingValue(shardingValue.getValue());
+ return this.intervalTimeline.sharding(shardingTime);
+ }
+
+ @Override
+ public Collection<String> doSharding(final Collection<String> availableTargetNames, final RangeShardingValue<T> shardingValue) {
+ Range<LocalDateTime> shardingRangeTime = convertRangeShardingValue(shardingValue.getValueRange());
+ return this.intervalTimeline.sharding(shardingRangeTime);
+ }
+
+ /**
+ * convert sharding value to {@link LocalDateTime}.
+ *
+ * @param shardingValue sharding value
+ * @return The {@link LocalDateTime} represented by the sharding value
+ */
+ protected abstract LocalDateTime convertShardingValue(T shardingValue);
+
+ private Range<LocalDateTime> convertRangeShardingValue(final Range<T> shardingValue) {
+ if (Range.all().equals(shardingValue)) {
+ return Range.all();
+ }
+ Object endpointValue = shardingValue.hasLowerBound() ? shardingValue.lowerEndpoint() : shardingValue.upperEndpoint();
+ if (endpointValue instanceof LocalDateTime) {
+ @SuppressWarnings("unchecked")
+ Range<LocalDateTime> targetRange = (Range<LocalDateTime>) shardingValue;
+ return targetRange;
+ }
+
Review comment:
Please remove useless blank line.
##########
File path: pom.xml
##########
@@ -57,7 +57,7 @@
<guava.version>30.0-jre</guava.version>
<gson.version>2.8.6</gson.version>
<slf4j.version>1.7.7</slf4j.version>
- <cosid.version>1.7.6</cosid.version>
+ <cosid.version>1.8.4</cosid.version>
Review comment:
@Ahoo-Wang Please update `cosid-core` version in LICENSE file.
##########
File path: shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/keygen/CosIdKeyGenerateAlgorithm.java
##########
@@ -20,57 +20,47 @@
import me.ahoo.cosid.CosId;
import me.ahoo.cosid.provider.IdGeneratorProvider;
import me.ahoo.cosid.provider.LazyIdGenerator;
-import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereInstanceRequiredAlgorithm;
-import org.apache.shardingsphere.infra.instance.InstanceContext;
import org.apache.shardingsphere.sharding.algorithm.sharding.cosid.CosIdAlgorithm;
import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;
-import java.util.Optional;
import java.util.Properties;
/**
* CosId key generate algorithm.
*/
-public final class CosIdKeyGenerateAlgorithm implements KeyGenerateAlgorithm, ShardingSphereInstanceRequiredAlgorithm {
Review comment:
@Ahoo-Wang Why remove ShardingSphereInstanceRequiredAlgorithm interface?
##########
File path: shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/keygen/CosIdSnowflakeKeyGenerateAlgorithm.java
##########
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.sharding.algorithm.keygen;
+
+import lombok.Getter;
+import lombok.Setter;
+import me.ahoo.cosid.converter.Radix62IdConverter;
+import me.ahoo.cosid.snowflake.ClockSyncSnowflakeId;
+import me.ahoo.cosid.snowflake.MillisecondSnowflakeId;
+import me.ahoo.cosid.snowflake.SnowflakeId;
+import me.ahoo.cosid.snowflake.StringSnowflakeId;
+import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereInstanceRequiredAlgorithm;
+import org.apache.shardingsphere.infra.instance.InstanceContext;
+import org.apache.shardingsphere.sharding.algorithm.sharding.cosid.CosIdAlgorithm;
+import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;
+
+import java.util.Properties;
+
+/**
+ * CosId-Snowflake key generate algorithm.
+ */
+public final class CosIdSnowflakeKeyGenerateAlgorithm implements KeyGenerateAlgorithm, ShardingSphereInstanceRequiredAlgorithm {
+
+ public static final String TYPE = CosIdAlgorithm.TYPE_PREFIX + "SNOWFLAKE";
+
+ public static final long DEFAULT_EPOCH = SnowflakeKeyGenerateAlgorithm.EPOCH;
Review comment:
Can we change these public field to private?
##########
File path: shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/cosid/AbstractIntervalShardingAlgorithm.java
##########
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.sharding.algorithm.sharding.cosid;
+
+import com.google.common.collect.BoundType;
+import com.google.common.collect.Range;
+import lombok.Getter;
+import lombok.Setter;
+import me.ahoo.cosid.sharding.IntervalStep;
+import me.ahoo.cosid.sharding.IntervalTimeline;
+import org.apache.shardingsphere.sharding.api.sharding.standard.PreciseShardingValue;
+import org.apache.shardingsphere.sharding.api.sharding.standard.RangeShardingValue;
+import org.apache.shardingsphere.sharding.api.sharding.standard.StandardShardingAlgorithm;
+
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
+import java.time.temporal.ChronoUnit;
+import java.util.Collection;
+import java.util.Properties;
+
+/**
+ * Interval-based time range sharding algorithm.
+ */
+public abstract class AbstractIntervalShardingAlgorithm<T extends Comparable<?>> implements StandardShardingAlgorithm<T> {
+
+ public static final String DEFAULT_DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss";
+
+ public static final DateTimeFormatter DEFAULT_DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern(DEFAULT_DATE_TIME_PATTERN);
+
+ public static final String DATE_TIME_LOWER_KEY = "datetime-lower";
+
+ public static final String DATE_TIME_UPPER_KEY = "datetime-upper";
+
+ public static final String SHARDING_SUFFIX_FORMAT_KEY = "sharding-suffix-pattern";
+
+ public static final String INTERVAL_UNIT_KEY = "datetime-interval-unit";
+
+ public static final String INTERVAL_AMOUNT_KEY = "datetime-interval-amount";
+
+ public static final String ZONE_ID_KEY = "zone-id";
+
+ private volatile IntervalTimeline intervalTimeline;
+
+ private ZoneId zoneId = ZoneId.systemDefault();
+
+ @Getter
+ @Setter
+ private Properties props = new Properties();
+
+ /**
+ * get zone id.
+ *
+ * @return zone id
+ */
+ protected ZoneId getZoneId() {
+ return zoneId;
+ }
+
+ @Override
+ public void init() {
+ if (getProps().containsKey(ZONE_ID_KEY)) {
+ zoneId = ZoneId.of(getRequiredValue(ZONE_ID_KEY));
+ }
+ String logicNamePrefix = getRequiredValue(CosIdAlgorithm.LOGIC_NAME_PREFIX_KEY);
+ LocalDateTime effectiveLower = LocalDateTime.parse(getRequiredValue(DATE_TIME_LOWER_KEY), DEFAULT_DATE_TIME_FORMATTER);
+ LocalDateTime effectiveUpper = LocalDateTime.parse(getRequiredValue(DATE_TIME_UPPER_KEY), DEFAULT_DATE_TIME_FORMATTER);
+ DateTimeFormatter suffixFormatter = DateTimeFormatter.ofPattern(getRequiredValue(SHARDING_SUFFIX_FORMAT_KEY));
+ ChronoUnit stepUnit = ChronoUnit.valueOf(getRequiredValue(INTERVAL_UNIT_KEY));
+ int stepAmount = Integer.parseInt(getProps().getProperty(INTERVAL_AMOUNT_KEY, "1"));
+ intervalTimeline = new IntervalTimeline(logicNamePrefix, Range.closed(effectiveLower, effectiveUpper), IntervalStep.of(stepUnit, stepAmount), suffixFormatter);
+ }
+
+ private String getRequiredValue(final String key) {
+ return PropertiesUtil.getRequiredValue(getProps(), key);
+ }
+
+ @Override
+ public String doSharding(final Collection<String> availableTargetNames, final PreciseShardingValue<T> shardingValue) {
+ LocalDateTime shardingTime = convertShardingValue(shardingValue.getValue());
+ return this.intervalTimeline.sharding(shardingTime);
+ }
+
+ @Override
+ public Collection<String> doSharding(final Collection<String> availableTargetNames, final RangeShardingValue<T> shardingValue) {
+ Range<LocalDateTime> shardingRangeTime = convertRangeShardingValue(shardingValue.getValueRange());
+ return this.intervalTimeline.sharding(shardingRangeTime);
+ }
+
+ /**
+ * convert sharding value to {@link LocalDateTime}.
+ *
+ * @param shardingValue sharding value
+ * @return The {@link LocalDateTime} represented by the sharding value
+ */
+ protected abstract LocalDateTime convertShardingValue(T shardingValue);
+
+ private Range<LocalDateTime> convertRangeShardingValue(final Range<T> shardingValue) {
+ if (Range.all().equals(shardingValue)) {
+ return Range.all();
+ }
+ Object endpointValue = shardingValue.hasLowerBound() ? shardingValue.lowerEndpoint() : shardingValue.upperEndpoint();
+ if (endpointValue instanceof LocalDateTime) {
+ @SuppressWarnings("unchecked")
Review comment:
@Ahoo-Wang Move this annotation to method?
##########
File path: shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/keygen/CosIdSnowflakeKeyGenerateAlgorithm.java
##########
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.sharding.algorithm.keygen;
+
+import lombok.Getter;
+import lombok.Setter;
+import me.ahoo.cosid.converter.Radix62IdConverter;
+import me.ahoo.cosid.snowflake.ClockSyncSnowflakeId;
+import me.ahoo.cosid.snowflake.MillisecondSnowflakeId;
+import me.ahoo.cosid.snowflake.SnowflakeId;
+import me.ahoo.cosid.snowflake.StringSnowflakeId;
+import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereInstanceRequiredAlgorithm;
+import org.apache.shardingsphere.infra.instance.InstanceContext;
+import org.apache.shardingsphere.sharding.algorithm.sharding.cosid.CosIdAlgorithm;
+import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;
+
+import java.util.Properties;
+
+/**
+ * CosId-Snowflake key generate algorithm.
+ */
+public final class CosIdSnowflakeKeyGenerateAlgorithm implements KeyGenerateAlgorithm, ShardingSphereInstanceRequiredAlgorithm {
+
+ public static final String TYPE = CosIdAlgorithm.TYPE_PREFIX + "SNOWFLAKE";
+
+ public static final long DEFAULT_EPOCH = SnowflakeKeyGenerateAlgorithm.EPOCH;
+
+ public static final String AS_STRING_KEY = "as-string";
+
+ public static final String EPOCH_KEY = "epoch";
+
+ private volatile InstanceContext instanceContext;
+
+ private volatile SnowflakeId snowflakeId;
+
+ private volatile boolean asString;
+
+ @Getter
+ @Setter
+ private Properties props = new Properties();
+
+ @Override
+ public Comparable<?> generateKey() {
+ if (asString) {
+ return snowflakeId.generateAsString();
+ }
+ return snowflakeId.generate();
+ }
+
+ @Override
+ public void init() {
+ String asStringStr = getProps().getProperty(AS_STRING_KEY, Boolean.FALSE.toString());
+ asString = Boolean.parseBoolean(asStringStr);
+ long workerId = 0;
+ if (instanceContext != null) {
Review comment:
@Ahoo-Wang Please put null on the left condition.
##########
File path: shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/keygen/CosIdSnowflakeKeyGenerateAlgorithm.java
##########
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.sharding.algorithm.keygen;
+
+import lombok.Getter;
+import lombok.Setter;
+import me.ahoo.cosid.converter.Radix62IdConverter;
+import me.ahoo.cosid.snowflake.ClockSyncSnowflakeId;
+import me.ahoo.cosid.snowflake.MillisecondSnowflakeId;
+import me.ahoo.cosid.snowflake.SnowflakeId;
+import me.ahoo.cosid.snowflake.StringSnowflakeId;
+import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereInstanceRequiredAlgorithm;
+import org.apache.shardingsphere.infra.instance.InstanceContext;
+import org.apache.shardingsphere.sharding.algorithm.sharding.cosid.CosIdAlgorithm;
+import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;
+
+import java.util.Properties;
+
+/**
+ * CosId-Snowflake key generate algorithm.
Review comment:
`CosId snowflake key generate algorithm.` may be better.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] Ahoo-Wang commented on a change in pull request #15067: add `CosIdSnowflakeKeyGenerateAlgorithm`/`CosIdSnowflakeIntervalShardingAlgorithm`
Posted by GitBox <gi...@apache.org>.
Ahoo-Wang commented on a change in pull request #15067:
URL: https://github.com/apache/shardingsphere/pull/15067#discussion_r792694164
##########
File path: shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/keygen/CosIdSnowflakeKeyGenerateAlgorithm.java
##########
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.sharding.algorithm.keygen;
+
+import lombok.Getter;
+import lombok.Setter;
+import me.ahoo.cosid.converter.Radix62IdConverter;
+import me.ahoo.cosid.snowflake.ClockSyncSnowflakeId;
+import me.ahoo.cosid.snowflake.MillisecondSnowflakeId;
+import me.ahoo.cosid.snowflake.SnowflakeId;
+import me.ahoo.cosid.snowflake.StringSnowflakeId;
+import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereInstanceRequiredAlgorithm;
+import org.apache.shardingsphere.infra.instance.InstanceContext;
+import org.apache.shardingsphere.sharding.algorithm.sharding.cosid.CosIdAlgorithm;
+import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;
+
+import java.util.Properties;
+
+/**
+ * CosId-Snowflake key generate algorithm.
+ */
+public final class CosIdSnowflakeKeyGenerateAlgorithm implements KeyGenerateAlgorithm, ShardingSphereInstanceRequiredAlgorithm {
+
+ public static final String TYPE = CosIdAlgorithm.TYPE_PREFIX + "SNOWFLAKE";
+
+ public static final long DEFAULT_EPOCH = SnowflakeKeyGenerateAlgorithm.EPOCH;
Review comment:
- `DEFAULT_EPOCH` should be informed to users.just like `SnowflakeKeyGenerateAlgorithm#EPOCH`.
- `TYPE` is public to users like documentation conventions.
So I suggest to define as public .
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org