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/04/28 05:39:20 UTC
[GitHub] [shardingsphere] VeejaLiu opened a new issue, #17169: Error when using DistSQL to add a custom ID generation algorithm
VeejaLiu opened a new issue, #17169:
URL: https://github.com/apache/shardingsphere/issues/17169
## Bug Report
I write a Class implements KeyGenerateAlgorithm:
```
package com.hireez;
import com.google.common.base.Preconditions;
import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereInstanceRequiredAlgorithm;
import org.apache.shardingsphere.infra.instance.InstanceContext;
import org.apache.shardingsphere.sharding.algorithm.keygen.TimeService;
import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;
import java.util.Calendar;
import java.util.Properties;
public class ShortSnowflakeGeneratorAlgorithm implements KeyGenerateAlgorithm, ShardingSphereInstanceRequiredAlgorithm {
public ShortSnowflakeGeneratorAlgorithm(){
}
@Override
public Comparable<?> generateKey() {
...
}
@Override
public void init() {
System.out.println("ShortSnowflakeGeneratorAlgorithm Init()...");
}
@Override
public String getType() {
return "HIREEZ_SNOWFLAKE";
}
@Override
public Properties getProps() {
return this.props;
}
@Override
public void setProps(Properties props) {
this.props = props;
}
@Override
public boolean isDefault() {
return true;
}
@Override
public void setInstanceContext(InstanceContext instanceContext) {
this.instanceContext = instanceContext;
}
}
```
And I create a file in resource to register class:
<img width="1025" alt="image" src="https://user-images.githubusercontent.com/22064617/165682703-c252d47d-692e-4cb3-a35a-eb6eeb66a419.png">
Then maven install into a .jar:
<img width="387" alt="image" src="https://user-images.githubusercontent.com/22064617/165683048-21176b36-99fb-472f-b326-06a7dfe0b1ab.png">
THen put it into proxy server:
<img width="564" alt="image" src="https://user-images.githubusercontent.com/22064617/165683265-378e94f7-c348-447f-a686-bc195a0d0b8c.png">
When I use the DistSQL to create a new ID generator:
```
Database changed
MySQL [hireez_sharding_db]> CREATE SHARDING KEY GENERATOR hireez_key_generator(TYPE(NAME=HIREEZ_SNOWFLAKE));
ERROR 1114 (C1114): Invalid sharding algorithms [HIREEZ_SNOWFLAKE].
MySQL [hireez_sharding_db]>
```
And error stack:
```
[ERROR] 2022-04-28 05:36:51.852 [ShardingSphere-Command-8] o.a.s.p.f.c.CommandExecutorTask - Exception occur:
org.apache.shardingsphere.infra.distsql.exception.rule.InvalidAlgorithmConfigurationException: Invalid sharding algorithms [HIREEZ_SNOWFLAKE].
at org.apache.shardingsphere.sharding.distsql.handler.update.CreateShardingKeyGeneratorStatementUpdater.lambda$checkKeyGeneratorAlgorithm$7(CreateShardingKeyGeneratorStatementUpdater.java:76)
at org.apache.shardingsphere.infra.distsql.exception.DistSQLException.predictionThrow(DistSQLException.java:43)
at org.apache.shardingsphere.sharding.distsql.handler.update.CreateShardingKeyGeneratorStatementUpdater.checkKeyGeneratorAlgorithm(CreateShardingKeyGeneratorStatementUpdater.java:76)
at org.apache.shardingsphere.sharding.distsql.handler.update.CreateShardingKeyGeneratorStatementUpdater.checkSQLStatement(CreateShardingKeyGeneratorStatementUpdater.java:50)
at org.apache.shardingsphere.sharding.distsql.handler.update.CreateShardingKeyGeneratorStatementUpdater.checkSQLStatement(CreateShardingKeyGeneratorStatementUpdater.java:44)
at org.apache.shardingsphere.proxy.backend.text.distsql.rdl.rule.RuleDefinitionBackendHandler.execute(RuleDefinitionBackendHandler.java:82)
at org.apache.shardingsphere.proxy.backend.text.distsql.rdl.rule.RuleDefinitionBackendHandler.execute(RuleDefinitionBackendHandler.java:60)
at org.apache.shardingsphere.proxy.backend.text.SchemaRequiredBackendHandler.execute(SchemaRequiredBackendHandler.java:51)
at org.apache.shardingsphere.proxy.frontend.mysql.command.query.text.query.MySQLComQueryPacketExecutor.execute(MySQLComQueryPacketExecutor.java:97)
at org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask.executeCommand(CommandExecutorTask.java:100)
at org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask.run(CommandExecutorTask.java:72)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:830)
```
Who can tell me how I should solve this mistake?
Or tell me what ideas to solve this problem?
--
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.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] VeejaLiu commented on issue #17169: Error when using DistSQL to add a custom ID generation algorithm
Posted by GitBox <gi...@apache.org>.
VeejaLiu commented on issue #17169:
URL: https://github.com/apache/shardingsphere/issues/17169#issuecomment-1111978920
I finally found the problem.
I didn't understand the rules of SPI.
The file name in `META-INF/services` is the fully qualified class name of the **interface**, and the content in it is the fully qualified class name of the **implementation class**.
I made a mistake about this.
<img width="1389" alt="image" src="https://user-images.githubusercontent.com/22064617/165723963-868e8aa1-e348-4b36-9162-f843bb5f0029.png">
Maybe it can give some inspiration to later people!
--
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] VeejaLiu commented on issue #17169: Error when using DistSQL to add a custom ID generation algorithm
Posted by GitBox <gi...@apache.org>.
VeejaLiu commented on issue #17169:
URL: https://github.com/apache/shardingsphere/issues/17169#issuecomment-1111948956
Maybe here:
<img width="2429" alt="image" src="https://user-images.githubusercontent.com/22064617/165718217-a8ac4fa6-bb14-4425-ab63-9608f7ed68a1.png">
--
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] VeejaLiu closed issue #17169: Error when using DistSQL to add a custom ID generation algorithm
Posted by GitBox <gi...@apache.org>.
VeejaLiu closed issue #17169: Error when using DistSQL to add a custom ID generation algorithm
URL: https://github.com/apache/shardingsphere/issues/17169
--
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