Skip to content
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

Hint question shardingjdbc 5.4.1 #29780

Closed
yflytom opened this issue Jan 19, 2024 · 10 comments
Closed

Hint question shardingjdbc 5.4.1 #29780

yflytom opened this issue Jan 19, 2024 · 10 comments

Comments

@yflytom
Copy link

yflytom commented Jan 19, 2024

shardingjdbc 5.4.1

pom.xml

      <dependency>
            <groupId>org.apache.shardingsphere</groupId>
            <artifactId>shardingsphere-jdbc-core</artifactId>
            <version>5.4.1</version>
            <exclusions>
                <exclusion>
                    <artifactId>snakeyaml</artifactId>
                    <groupId>org.yaml</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.yaml</groupId>
            <artifactId>snakeyaml</artifactId>
            <version>1.33</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>2.3.2.RELEASE</version>
            <exclusions>
                <exclusion>
                    <groupId>com.fasterxml.jackson.core</groupId>
                    <artifactId>jackson-databind</artifactId>
                </exclusion>
                <exclusion>
                    <artifactId>snakeyaml</artifactId>
                    <groupId>org.yaml</groupId>
                </exclusion>
            </exclusions>
        </dependency>

The following two pictures HINT have different local configuration methods. When I use the method of picture 1 to configure, an error will be reported. (下面这两个图片 HINT 地方配置方式不一致,当我使用图片1的方式进行配置,会报错)
image
image

sharding.yaml

image

error msg: (报错信息)
image
And it will flush logs crazily, causing the CPU to increase and the fan to spin wildly.(并且会疯狂刷日志,导致CPU升高,风扇狂转)


When I use the other configuration in Picture 2, no error will be reported, but it will not enter my custom algorithm. If I specify two data sources, it will query two data sources, and if it is three, it will query three data sources.
(当我使用图片2的另一种方式配置,不会报错,但是不会进入我的自定义算法中,指定两个数据源,他就查询两个数据源,三个就查询三个数据源)
image
查询
image

Custom algorithm
image

question:

  1. How should I configure the forced routing using hint? I want to implement the SAS architecture and multi-tenant function. By specifying the hint algorithm, I can obtain the corresponding user's library during execution, and the hint forcefully specifies the data source function.
    (问题:
    1、我到底应该怎样配置使用hint 强制路由,我是为了实现sas架构,多租户功能,通过指定hint算法,执行时获取对应用户所属库,hint强制指定数据源功能)

非常感谢!

@yflytom
Copy link
Author

yflytom commented Jan 21, 2024

@RaigorJiang
Copy link
Contributor

Hi @yflytom
I didn’t see any calls to HintManager in the demo, please read the Procedure section in the documentation.
https://shardingsphere.apache.org/document/5.4.1/en/user-manual/shardingsphere-jdbc/special-api/sharding/hint/

@RaigorJiang RaigorJiang changed the title Hint Bug shardingjdbc 5.4.1 Hint question shardingjdbc 5.4.1 Jan 24, 2024
@yflytom
Copy link
Author

yflytom commented Jan 24, 2024

Hi @yflytom I didn’t see any calls to HintManager in the demo, please read the Procedure section in the documentation. https://shardingsphere.apache.org/document/5.4.1/en/user-manual/shardingsphere-jdbc/special-api/sharding/hint/

@RaigorJiang

Do you mean that I need to manually code and specify HintManager before querying sql and then enter my custom hint algorithm? If so, don’t every query need to be manually coded and specified? Instead, after entering the algorithm Specify the data source and table again? Or can you provide some cases?
您的意思是我在查询sql之前需要手动编码,指定HintManager 然后才会进入我的自定义hint算法中吗,如果是这样不是每个查询都要手动编码指定吗,而不是,进入到算法中后再指定数据源和表吗?或者可以提供一些案例吗?

image

@yflytom
Copy link
Author

yflytom commented Jan 24, 2024

Hi @yflytom I didn’t see any calls to HintManager in the demo, please read the Procedure section in the documentation. https://shardingsphere.apache.org/document/5.4.1/en/user-manual/shardingsphere-jdbc/special-api/sharding/hint/

@RaigorJiang

Hello, I don’t quite understand. I can clearly specify the data sources and tables that need to be queried through custom algorithms. Why do I need to code HintManager to specify the data source (I now use AOP to intercept all queries. , and then encode HintManager to specify the data source and table name), aren't these two conflicts, or are they unnecessary

您好,我不是太明白,明明可以通过自定义算法里面指定需要查询的数据源和表,为什么还要编码 HintManager来指定数据源 (我现在通过AOP的方式,对所有的查询拦截,然后编码 HintManager 指定数据源和表名称),这两个不是冲突的存在吗,或者多此一举?

@RaigorJiang
Copy link
Contributor

Do you mean that I need to manually code and specify HintManager before querying sql and then enter my custom hint algorithm? If so, don’t every query need to be manually coded and specified? Instead, after entering the algorithm Specify the data source and table again? Or can you provide some cases? 您的意思是我在查询sql之前需要手动编码,指定HintManager 然后才会进入我的自定义hint算法中吗,如果是这样不是每个查询都要手动编码指定吗,而不是,进入到算法中后再指定数据源和表吗?或者可以提供一些案例吗?

image

Please see the Code

@RaigorJiang
Copy link
Contributor

Hi @yflytom I didn’t see any calls to HintManager in the demo, please read the Procedure section in the documentation. https://shardingsphere.apache.org/document/5.4.1/en/user-manual/shardingsphere-jdbc/special-api/sharding/hint/

@RaigorJiang

Hello, I don’t quite understand. I can clearly specify the data sources and tables that need to be queried through custom algorithms. Why do I need to code HintManager to specify the data source (I now use AOP to intercept all queries. , and then encode HintManager to specify the data source and table name), aren't these two conflicts, or are they unnecessary

So how to know the sharding value in your custom sharding algorithm?

@yflytom
Copy link
Author

yflytom commented Jan 25, 2024

Hi @yflytom I didn’t see any calls to HintManager in the demo, please read the Procedure section in the documentation. https://shardingsphere.apache.org/document/5.4.1/en/user-manual/shardingsphere-jdbc/special-api/sharding/hint/

@RaigorJiang
Hello, I don’t quite understand. I can clearly specify the data sources and tables that need to be queried through custom algorithms. Why do I need to code HintManager to specify the data source (I now use AOP to intercept all queries. , and then encode HintManager to specify the data source and table name), aren't these two conflicts, or are they unnecessary

So how to know the sharding value in your custom sharding algorithm?

Hello, I use Alibaba's TransmittableThreadLocal to pass parameters. I saw that Shardingjdbc also has this. Is it possible to open two methods, one is to customize the parameters, and the other is to use HintManager.

您好,我是使用阿里的TransmittableThreadLocal 传递参数,我看了Shardingjdbc 也有这个,是否可以开放两种方式,一种自定义的传参,一种是使用HintManager

@RaigorJiang
Copy link
Contributor

So how to know the sharding value in your custom sharding algorithm?

Hello, I use Alibaba's TransmittableThreadLocal to pass parameters. I saw that Shardingjdbc also has this. Is it possible to open two methods, one is to customize the parameters, and the other is to use HintManager.

The current doSharding method needs to receive the param shardingValue. According to your description, it may be necessary to add a method that does not require shardingValue.

I suggest that you describe the design in detail and how it is used, and then submit a PR.

Copy link

There hasn't been any activity on this issue recently, and in order to prioritize active issues, it will be marked as stale.

@github-actions github-actions bot added the stale label Feb 24, 2024
@RaigorJiang
Copy link
Contributor

Closed due to no response.
If this problem persists, please reopen it or submit a new one.

@RaigorJiang RaigorJiang closed this as not planned Won't fix, can't repro, duplicate, stale Apr 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants