You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "ICALLYOU (via GitHub)" <gi...@apache.org> on 2023/02/28 06:49:28 UTC

[GitHub] [shardingsphere] ICALLYOU opened a new issue, #24373: A Question about shardingsphere-proxy

ICALLYOU opened a new issue, #24373:
URL: https://github.com/apache/shardingsphere/issues/24373

   (shardingsphere-proxy)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.*;
   
   /**
    * @author linzf
    * @since 2023-2-27
    * 类描述: 复合分片算法
    */
   public class OrderTableComplex implements ComplexKeysShardingAlgorithm<Long> {
   
   
       private Properties props = new Properties();
   
       /**
        * 功能描述: 实现分片的具体实现,数据库根据用户ID和订单ID来实现分片,
        * 意味着只要某张表中应用了这个复合分片算法,然后字段里面有包含用户ID
        * 和订单ID的SQL那就会实现数据库的分片。
        *
        * @param collection
        * @param complexKeysShardingValue
        * @return
        */
       @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;
           /**
            * 分片规则:id、k为数字,c、pad为字符串,需要进行混合分片,分片规则如下:
            * 1、求和值为MAX=(id+k+c的ASCII值+pad的ASCII值)
            * 2、对和取余进行分表
            */
   
           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() {
   
       }
   
       /**
        * 功能描述: 对应sharding-algorithms配置里面的type属性里面配置的值
        *
        * @return
        */
       @Override
       public String getType() {
           return "OrderTableComplex";
       }
   
       @Override
       public Properties getProps() {
           return this.props;
       }
   
       /**
        * 功能描述: 获取application.yml中的当前分片算法的配置信息
        *
        * @param properties application.yml中的当前分片算法的配置信息
        */
       @Override
       public void setProps(Properties properties) {
           this.props = properties;
       }
   
   }
   
   Here is the pom configuration file for Maven
   
   <?xml version="1.0" encoding="UTF-8"?>
   <project xmlns="http://maven.apache.org/POM/4.0.0"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
       <modelVersion>4.0.0</modelVersion>
   
       <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>
   
   </project>
   
   
   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: notifications-unsubscribe@shardingsphere.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] RaigorJiang commented on issue #24373: An ERRROR about ComplexKeysShardingAlgorithm(shardingsphere-proxy5.3.1)

Posted by "RaigorJiang (via GitHub)" <gi...@apache.org>.
RaigorJiang commented on issue #24373:
URL: https://github.com/apache/shardingsphere/issues/24373#issuecomment-1449394100

   @ICALLYOU 
   It looks like your SPI does not implement the 5.3.1 version of the interface, for example the `init` method definition is different.
   
   <img width="395" alt="image" src="https://user-images.githubusercontent.com/5668787/222057214-5370e400-8e30-4208-956a-36fabb26244e.png">
   
   
   Please implement a custom algorithm when relying on 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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] ICALLYOU commented on issue #24373: An ERRROR about ComplexKeysShardingAlgorithm(shardingsphere-proxy5.3.1)

Posted by "ICALLYOU (via GitHub)" <gi...@apache.org>.
ICALLYOU commented on issue #24373:
URL: https://github.com/apache/shardingsphere/issues/24373#issuecomment-1449538632

   @RaigorJiang 


-- 
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] ICALLYOU commented on issue #24373: An ERRROR about ComplexKeysShardingAlgorithm(shardingsphere-proxy5.3.1)

Posted by "ICALLYOU (via GitHub)" <gi...@apache.org>.
ICALLYOU commented on issue #24373:
URL: https://github.com/apache/shardingsphere/issues/24373#issuecomment-1449451209

   ![图片](https://user-images.githubusercontent.com/48971995/222066725-6a74dca8-2126-4afb-a55a-57167696a0ed.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] ICALLYOU closed issue #24373: An ERRROR about ComplexKeysShardingAlgorithm(shardingsphere-proxy5.3.1)

Posted by "ICALLYOU (via GitHub)" <gi...@apache.org>.
ICALLYOU closed issue #24373: An ERRROR about ComplexKeysShardingAlgorithm(shardingsphere-proxy5.3.1)
URL: https://github.com/apache/shardingsphere/issues/24373


-- 
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] RaigorJiang commented on issue #24373: An ERRROR about ComplexKeysShardingAlgorithm(shardingsphere-proxy5.3.1)

Posted by "RaigorJiang (via GitHub)" <gi...@apache.org>.
RaigorJiang commented on issue #24373:
URL: https://github.com/apache/shardingsphere/issues/24373#issuecomment-1449899731

   ```xml
   <dependency>
       <groupId>org.apache.shardingsphere</groupId>
       <artifactId>shardingsphere-jdbc-core</artifactId>
       <version>5.3.1</version>
   </dependency>
   ```


-- 
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] ICALLYOU commented on issue #24373: An ERRROR about ComplexKeysShardingAlgorithm(shardingsphere-proxy5.3.1)

Posted by "ICALLYOU (via GitHub)" <gi...@apache.org>.
ICALLYOU commented on issue #24373:
URL: https://github.com/apache/shardingsphere/issues/24373#issuecomment-1449410175

   @RaigorJiang 


-- 
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] RaigorJiang commented on issue #24373: An ERRROR about ComplexKeysShardingAlgorithm(shardingsphere-proxy5.3.1)

Posted by "RaigorJiang (via GitHub)" <gi...@apache.org>.
RaigorJiang commented on issue #24373:
URL: https://github.com/apache/shardingsphere/issues/24373#issuecomment-1449447627

   Please change your pom to 5.3.1
   
   ```xml
   <dependencies>
       <dependency>
           <groupId>org.apache.shardingsphere</groupId>
           <artifactId>shardingsphere-jdbc-core</artifactId>
           <version>5.0.0-alpha</version>
       </dependency>
   </dependencies>
   ```


-- 
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] ICALLYOU commented on issue #24373: An ERRROR about ComplexKeysShardingAlgorithm(shardingsphere-proxy5.3.1)

Posted by "ICALLYOU (via GitHub)" <gi...@apache.org>.
ICALLYOU commented on issue #24373:
URL: https://github.com/apache/shardingsphere/issues/24373#issuecomment-1449408475

   I don't know how to write a custom algorithm for 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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] ICALLYOU commented on issue #24373: An ERRROR about ComplexKeysShardingAlgorithm(shardingsphere-proxy5.3.1)

Posted by "ICALLYOU (via GitHub)" <gi...@apache.org>.
ICALLYOU commented on issue #24373:
URL: https://github.com/apache/shardingsphere/issues/24373#issuecomment-1449407025

   Is there an API for 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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] zhaojinchao95 commented on issue #24373: An ERRROR about ComplexKeysShardingAlgorithm(shardingsphere-proxy5.3.1)

Posted by "zhaojinchao95 (via GitHub)" <gi...@apache.org>.
zhaojinchao95 commented on issue #24373:
URL: https://github.com/apache/shardingsphere/issues/24373#issuecomment-1448352632

   @ICALLYOU Please translate your issue Chinese to English.


-- 
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] ICALLYOU commented on issue #24373: An ERRROR about ComplexKeysShardingAlgorithm(shardingsphere-proxy5.3.1)

Posted by "ICALLYOU (via GitHub)" <gi...@apache.org>.
ICALLYOU commented on issue #24373:
URL: https://github.com/apache/shardingsphere/issues/24373#issuecomment-1449442986

   
   ![图片](https://user-images.githubusercontent.com/48971995/222065319-6c7f53be-f901-48e4-b032-06eb860277b2.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