ICALLYOU opened a new issue, #24392:
URL: https://github.com/apache/shardingsphere/issues/24392
(shardingsphere-proxy5.3.1)I had a question about a custom compound sharding
algorithm. After editing the shard algorithm, the middleware prompt does not
implement the interface, but the interface is implemented in the program.
Error message is as follows
Exception in thread "main" java.lang.AbstractMethodError: Receiver class
com.mysql.sharding.proxy.complex.OrderTableComplex does not define or inherit
an implementation of the resolved method 'abstract void
init(java.util.Properties)' of interface
org.apache.shardingsphere.infra.util.spi.lifecycle.SPIPostProcessor.
at
org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry.findRegisteredService(TypedSPIRegistry.java:66)
at
org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry.getRegisteredService(TypedSPIRegistry.java:113)
at
org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory.createAlgorithm(ShardingSphereAlgorithmFactory.java:41)
at
org.apache.shardingsphere.sharding.rule.ShardingRule.lambda$new$0(ShardingRule.java:120)
at java.base/java.util.LinkedHashMap.forEach(LinkedHashMap.java:721)
at
org.apache.shardingsphere.sharding.rule.ShardingRule.(ShardingRule.java:120)
at
org.apache.shardingsphere.sharding.rule.builder.ShardingRuleBuilder.build(ShardingRuleBuilder.java:41)
at
org.apache.shardingsphere.sharding.rule.builder.ShardingRuleBuilder.build(ShardingRuleBuilder.java:35)
at
org.apache.shardingsphere.infra.rule.builder.database.DatabaseRulesBuilder.build(DatabaseRulesBuilder.java:64)
at
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase.create(ShardingSphereDatabase.java:87)
at
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabasesFactory.createGenericDatabases(ShardingSphereDatabasesFactory.java:79)
at
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabasesFactory.create(ShardingSphereDatabasesFactory.java:67)
at
org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory.create(MetaDataContextsFactory.java:90)
at
org.apache.shardingsphere.mode.manager.cluster.ClusterContextManagerBuilder.build(ClusterContextManagerBuilder.java:56)
at
org.apache.shardingsphere.proxy.initializer.BootstrapInitializer.createContextManager(BootstrapInitializer.java:73)
at org.apach
Here is the code for the OrderTableComplex class:
package com.mysql.sharding.proxy.complex;
import com.mysql.sharding.proxy.util.ComplexStringUtils;
import
org.apache.shardingsphere.sharding.api.sharding.complex.ComplexKeysShardingAlgorithm;
import
org.apache.shardingsphere.sharding.api.sharding.complex.ComplexKeysShardingValue;
//import org.apache.shardingsphere.infra.;
import java.util.;
public class OrderTableComplex implements ComplexKeysShardingAlgorithm {
private Properties props = new Properties();
@Override
public Collection<String> doSharding(Collection<String> collection,
ComplexKeysShardingValue<Long> complexKeysShardingValue) {
List<String> shardingList = new ArrayList();
String logicTableName = complexKeysShardingValue.getLogicTableName();
Map<String, Collection<Long>> columnNameAndShardingValuesMap =
complexKeysShardingValue.getColumnNameAndShardingValuesMap();
List IdList = (List) columnNameAndShardingValuesMap.get("id");
List kList = (List) columnNameAndShardingValuesMap.get("k");
List cList=(List)columnNameAndShardingValuesMap.get("c");
List padList=(List)columnNameAndShardingValuesMap.get("pad");
Long id = IdList != null ? ComplexStringUtils.getObjLong(IdList.get(0))
: 0L;
Long k = kList != null ? ComplexStringUtils.getObjLong(kList.get(0)) :
0L;
String c=cList != null ? ComplexStringUtils.getObjStr(cList.get(0)) :
null;
String pad=padList != null ?
ComplexStringUtils.getObjStr(padList.get(0)) : null;
Long modVal = 0L;
Long
MAX=(id+k+Integer.valueOf(String.valueOf(cList))+Integer.valueOf(String.valueOf(padList)));
modVal=MAX%10;
for (Iterator<String> iter = collection.iterator(); iter.hasNext(); ) {
String str = iter.next();
if ((logicTableName + modVal).equals(str)) {
shardingList.add(str);
}
}
return shardingList;
}
@Override
public void init() {
}
@Override
public String getType() {
return "OrderTableComplex";
}
@Override
public Properties getProps() {
return this.props;
}
@Override
public void setProps(Properties properties) {
this.props = properties;
}
}
Here is the pom configuration file for Maven
4.0.0
<groupId>com.mysql.sharding</groupId>
<artifactId>shardingsphere1</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>16</source>
<target>16</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-jdbc-core</artifactId>
<version>5.0.0-alpha</version>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>18</maven.compiler.source>
<maven.compiler.target>18</maven.compiler.target>
</properties>
#
config-sharding.yaml
databaseName: sharding_db
dataSources:
ds_0:
url: jdbc:mysql://172.30.1.17:3306/ds_0?serverTimezone=UTC&useSSL=false
username: root
password: root123
connectionTimeoutMilliseconds: 30000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 50
minPoolSize: 1
ds_1:
url: jdbc:mysql://172.30.1.18:3306/ds_1?serverTimezone=UTC&useSSL=false
username: root
password: root123
connectionTimeoutMilliseconds: 30000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 50
minPoolSize: 1
rules:
!SHARDING
tables:
sbtest1:
actualDataNodes: ds_${0..1}.sbtest1${0..9}
databaseStrategy:
complex:
shardingColumns: id,k,c,pad
shardingAlgorithmName: order-db-complex
tableStrategy:
complex:
shardingColumns: id,k,c,pad
shardingAlgorithmName: order-table-complex
keyGenerateStrategy:
column: id
keyGeneratorName: snowflake
shardingAlgorithms:
order-table-complex:
type: OrderTableComplex
order-db-complex:
type: OrderDbComplex
alg_mod:
type: MOD
props:
sharding-count: 2
alg_hash_mod:
type: HASH_MOD
props:
sharding-count: 10
keyGenerators:
snowflake:
type: SNOWFLAKE
Can you provide information on the use of the composite sharding algorithm
in version 5.3.1
--
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:
[email protected]
For queries about this service, please contact Infrastructure at:
[email protected]