Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the pit of ShardingSphere?

2025-03-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

It is believed that many inexperienced people are at a loss about what the ShardingSphere pit is like. Therefore, this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

Phenomenon

In the 4.0.0-RC1 version, I set up the data to automatically generate the distributed primary key ID, and then when I inserted the data, I found that the automatically generated primary key ID assignment was wrong when one of the fields' value value was null.

Find a problem

What are we going to do? We can only start with his principle and source code. Set up the automatic generation of distributed primary keys, so how does it operate?

After some query and testing, ShardingSphere does this. After he got the sql processed by the business layer, he modified it on the sql. For example, I'm going to insert a piece of data into the user table with the following sql:

INSERT INTO user (name, remark, age) VALUES ('test', null, 18)

Then ShardingSphere will deal with it, he will add ID to my original sql, and then the normal sql should be:

INSERT INTO user (name, remark, age, id) VALUES ('test', null, 18,' primary key id')

But the truth is this:

INSERT INTO user (name, remark, age, id) VALUES ('test', 18,' primary key id', null)

How did this happen? It looks like there is something wrong with null's judgment at the time of the final assignment, so let's move on to the source code.

After another debug + search.

It is found that there is such an abstract class InsertOptimizeResultUnit, one of which is getCurrentIndex, as shown in the following figure:

What is this step of screenshot doing? He is mainly looking for the subscript of the last bit of the value array, because he makes a non-empty judgment on value every time, that is, as long as a value is empty, the subscript will be calculated by 1. So the final result is that it is obvious that he should add id after age, but the value of id overrides the value of age due to the error of subscript calculation.

Solution

First of all, I submitted the issue on github. The address is https://github.com/apache/incubator-shardingsphere/issues/2897.

Let's see if the developers of ShardingSphere have solved this problem, and if they want to solve it in a subsequent version, there are only two solutions:

1. I can only temporarily add a default value to the field, so that the value is not empty (not very good) 2. Pull down the code on github, then modify the source code yourself and then pack a package to finish reading the above. Have you mastered the method of ShardingSphere's pit? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report