-
Notifications
You must be signed in to change notification settings - Fork 6.9k
add CosIdSnowflakeKeyGenerateAlgorithm/CosIdSnowflakeIntervalShardingAlgorithm
#15067
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- add `CosIdSnowflakeIntervalShardingAlgorithm`
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
| public final class CosIdKeyGenerateAlgorithm implements KeyGenerateAlgorithm { | ||
|
|
||
| public static final String TYPE = CosId.COSID.toUpperCase(); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Ahoo-Wang Please keep indents consistent with the previous one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Ahoo-Wang Please keep indents consistent with the previous one.
@Ahoo-Wang Please modify these checkstyle problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@strongduanmu I'm sorry I didn't find the question about indentation.Do you mean the indentation of empty lines?

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@strongduanmu Ok,thanks.
| /** | ||
| * CosId key generate algorithm. | ||
| */ | ||
| public final class CosIdKeyGenerateAlgorithm implements KeyGenerateAlgorithm, ShardingSphereInstanceRequiredAlgorithm { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Ahoo-Wang Why remove ShardingSphereInstanceRequiredAlgorithm interface?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the SegmentId algorithm and SegmentChainId algorithm of CosId do not need to depend on WorkerId, so I added CosIdSnowflakeKeyGenerateAlgorithm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, I got it.
.../org/apache/shardingsphere/sharding/algorithm/keygen/CosIdSnowflakeKeyGenerateAlgorithm.java
Outdated
Show resolved
Hide resolved
| String asStringStr = getProps().getProperty(AS_STRING_KEY, Boolean.FALSE.toString()); | ||
| asString = Boolean.parseBoolean(asStringStr); | ||
| long workerId = 0; | ||
| if (instanceContext != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Ahoo-Wang Please put null on the left condition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
|
|
||
| public static final String TYPE = CosIdAlgorithm.TYPE_PREFIX + "SNOWFLAKE"; | ||
|
|
||
| public static final long DEFAULT_EPOCH = SnowflakeKeyGenerateAlgorithm.EPOCH; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we change these public field to private?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DEFAULT_EPOCHshould be informed to users.just likeSnowflakeKeyGenerateAlgorithm#EPOCH.TYPEis public to users like documentation conventions.
So I suggest to define as public .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok.
| Range<LocalDateTime> targetRange = (Range<LocalDateTime>) shardingValue; | ||
| return targetRange; | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove useless blank line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
| } | ||
| Object endpointValue = shardingValue.hasLowerBound() ? shardingValue.lowerEndpoint() : shardingValue.upperEndpoint(); | ||
| if (endpointValue instanceof LocalDateTime) { | ||
| @SuppressWarnings("unchecked") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Ahoo-Wang Move this annotation to method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
- upgrade to CosId 1.8.6
| /** | ||
| * CosId key generate algorithm. | ||
| */ | ||
| public final class CosIdKeyGenerateAlgorithm implements KeyGenerateAlgorithm, ShardingSphereInstanceRequiredAlgorithm { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, I got it.
| public final class CosIdKeyGenerateAlgorithm implements KeyGenerateAlgorithm { | ||
|
|
||
| public static final String TYPE = CosId.COSID.toUpperCase(); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Ahoo-Wang Please keep indents consistent with the previous one.
@Ahoo-Wang Please modify these checkstyle problem.
|
|
||
| public static final String TYPE = CosIdAlgorithm.TYPE_PREFIX + "SNOWFLAKE"; | ||
|
|
||
| public static final long DEFAULT_EPOCH = SnowflakeKeyGenerateAlgorithm.EPOCH; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok.
strongduanmu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Ahoo-Wang Thank you for your contribution, this pr looks good to me, @menghaoranss Can you help double check this pr?
| asString = Boolean.parseBoolean(asStringStr); | ||
| long workerId = 0; | ||
| if (null != instanceContext) { | ||
| workerId = instanceContext.getWorkerId(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the instanceContext is initialized after init(), so it will always be null here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok.
Fixes #14047.
Changes proposed in this pull request:
CosIdSnowflakeKeyGenerateAlgorithmCosIdSnowflakeIntervalShardingAlgorithm