Skip to content

Conversation

@Ahoo-Wang
Copy link
Contributor

Fixes #14047.

Changes proposed in this pull request:

  • add CosIdSnowflakeKeyGenerateAlgorithm
  • add CosIdSnowflakeIntervalShardingAlgorithm

@codecov-commenter
Copy link

Codecov Report

Merging #15067 (8a20ff6) into master (26b7850) will increase coverage by 0.01%.
The diff coverage is 81.63%.

Impacted file tree graph

@@             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 Coverage Δ
...shardingsphere/infra/instance/InstanceContext.java 0.00% <0.00%> (ø)
...cosid/CosIdSnowflakeIntervalShardingAlgorithm.java 52.94% <52.94%> (ø)
...sharding/cosid/CosIdIntervalShardingAlgorithm.java 60.00% <58.33%> (-27.50%) ⬇️
...thm/keygen/CosIdSnowflakeKeyGenerateAlgorithm.java 85.71% <85.71%> (ø)
...rding/cosid/AbstractIntervalShardingAlgorithm.java 97.43% <97.43%> (ø)
...ng/algorithm/keygen/CosIdKeyGenerateAlgorithm.java 91.66% <100.00%> (+13.09%) ⬆️
...rding/algorithm/sharding/cosid/PropertiesUtil.java 66.66% <100.00%> (ø)
...ral/common/CommonDistSQLBackendHandlerFactory.java 38.46% <0.00%> (-7.00%) ⬇️
...ite/parameter/EncryptParameterRewriterBuilder.java 80.00% <0.00%> (-6.37%) ⬇️
...te/context/ShardingSQLRewriteContextDecorator.java 68.75% <0.00%> (-6.25%) ⬇️
... and 21 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 26b7850...8a20ff6. Read the comment docs.

public final class CosIdKeyGenerateAlgorithm implements KeyGenerateAlgorithm {

public static final String TYPE = CosId.COSID.toUpperCase();
Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor Author

@Ahoo-Wang Ahoo-Wang Jan 27, 2022

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?
image

Copy link
Member

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? image

@Ahoo-Wang Sorry, I was wrong, this is a requirement for code conduct——Keep indents consistent with the previous one.

Copy link
Contributor Author

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 {
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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.

String asStringStr = getProps().getProperty(AS_STRING_KEY, Boolean.FALSE.toString());
asString = Boolean.parseBoolean(asStringStr);
long workerId = 0;
if (instanceContext != null) {
Copy link
Member

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.

Copy link
Contributor Author

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;
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • 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 .

Copy link
Member

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;
}

Copy link
Member

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.

Copy link
Contributor Author

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")
Copy link
Member

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?

Copy link
Contributor Author

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 {
Copy link
Member

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();
Copy link
Member

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

Copy link
Member

@strongduanmu strongduanmu left a 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();
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok.

@menghaoranss menghaoranss merged commit 679e04b into apache:master Jan 27, 2022
@Ahoo-Wang Ahoo-Wang deleted the 14047 branch January 29, 2022 01:55
@menghaoranss menghaoranss modified the milestones: 5.1.1, 5.1.0 Feb 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IntervalShardingAlgorithm performance is too bad

4 participants