当前位置:网站首页>Analysis of shardingsphere core source code
Analysis of shardingsphere core source code
2022-06-27 17:47:00 【Comrade Xiaoqiang】
Download the source code ( Choose your favorite version )
https://github.com/apache/incubator-shardingsphere/archive/4.0.0-RC2.zip
2、 Import project to IDEA

3、sharding-core-parse compile
Note that this project is compiled first because : Some classes in the project need to rely on antlr4 SQL Parsing engine generation , Otherwise straight Connect and compile sharding The project reports the error that some classes cannot be found .
When compiling this project, you should pay attention to :lifecycle Under the install

4、 Compile the whole project
Pay attention to the use of maven-plugin compile , And remember to skip the test part when compiling
Translation time :sharding-sql-test The project will report an error , Just ignore it .
Compile the complete : function demo If it can be executed normally, the compilation is successful
Apache Incubation version - Module partition

Kernel analysis
Data fragmentation - Execution process

Parsing engine
The parsing process is divided into lexical parsing and grammatical parsing . A lexical parser is used to SQL Disassembled into atomic symbols that cannot be further divided Number , be called Token. And according to the dictionaries provided by different database dialects , Categorize it as a keyword , expression , Literally Quantities and operators . Using the syntax parser again will SQL Convert to an abstract syntax tree .
SELECT id, name FROM t_user WHERE status = 'ACTIVE' AND age > 18

sql Analyze the overall structure :

Routing engine
The built-in fragmentation strategy can be roughly divided into mantissa modulus 、 Hash 、 Range 、 label 、 Time and so on . Configured by the user The fragmentation strategy is more flexible , You can customize the composite partition strategy according to the user's needs .

SQL rewrite
Is the truth obtained after routing

Execution engine

The results merge
Multiple data result sets to be obtained from each data node , Combine into a result set and return to the requesting customer correctly End , It's called result merging .

Distributed primary key
Built in generator support :UUID、SNOWFLAKE, And extract the distributed primary key generator The interface of , It is convenient for users to realize the user-defined self increasing primary key generator .
SNOWFLAKE Snowflake algorithm
It can ensure that the primary keys of different processes are not repeated , Ordering of primary keys of the same process . Binary form package contain 4 part , The sub table from high to low is :1bit Sign bit 、41bit Time stamp bit 、10bit Working process bit and 12bit Serial number position .
- Sign bit (1bit)
Reserved symbol bits , Constant to zero .
- Time stamp bit (41bit)
41 The number of milliseconds a bit's timestamp can hold is 2 Of 41 The next power , The number of milliseconds used in a year is :365 * 24 * 60 * 6 0 * 1000 Math.pow(2, 41) / (365 * 24 * 60 * 60 * 1000L) = 69.73 Years don't repeat ;
- Work progress bit (10bit)
The logo is on the Java It's the only thing in the process , If it is a distributed application deployment, it should ensure that each working process id It's different Of . This value defaults to 0, It can be set by properties .
- Serial number position (12bit)
This sequence is used to generate different... In the same millisecond ID. If the number generated in this millisecond exceeds 4096(2 Of 12 The next power ), Then the generator will wait until the next millisecond to continue to generate .

Mybatis-SQL Execution process

The source code structure of sub database and sub table is as follows

边栏推荐
- How to modify / display GPIO status through ADB shell
- Alibaba cloud liupeizi: Inspiration from cloud games - innovation on the end
- Use pyinstaller to package py files into exe. Precautions and error typeerror:_ get_ sysconfigdata_ name() missing 1...‘ check_ Solutions to exists'
- Synchronization mechanism of dual namenodes
- 软件测试基础-软件测试历史流程,分类,好处,限制
- C language teacher workload management system
- Detailed explanation of various GPIO input and output modes (push-pull, open drain, quasi bidirectional port)
- 阿里云刘珅孜:云游戏带来的启发——端上创新
- [the way of programmer training] - 3 Character count statistics
- 黑马程序员-软件测试基础班-02-30-45工具代开浏览器运行代码,音、视频、测试点,音视频标签,布局标签。超链接语法进阶,绝对路径,相对路径
猜你喜欢

Use pyinstaller to package py files into exe. Precautions and error typeerror:_ get_ sysconfigdata_ name() missing 1...‘ check_ Solutions to exists'

CDH cluster installation

Community sharing jumpserver in the eyes of senior open source users: a fortress machine for "Crazy" iteration

2022年中国音频市场年度综合分析

leetcode 200. Number of islands

d3dx9_ How to repair 38.dll? d3dx9_ 38. How to download a missing DLL?

Mihayou sued Minmetals trust, which was exposed to product thunderstorms

Leetcode daily practice (sum of two numbers)
![[JS reverse hundreds of examples] I love to solve 2022 Spring Festival problems and receive red envelopes](/img/cb/0be2b2cf3b2cfa903190b7795d3cd7.jpg)
[JS reverse hundreds of examples] I love to solve 2022 Spring Festival problems and receive red envelopes

Part 32 supplement (32) string of ECMAScript
随机推荐
09 route guard authenticates URL
Study on heritability and field experiment design
Unity shadow shadow pancaking
Leetcode 704. Binary search
How to modify / display GPIO status through ADB shell
Mihayou sued Minmetals trust, which was exposed to product thunderstorms
The European unified charging specification act was passed before the end of the year, and it is planned to expand to products such as laptop and keyboard
Dark horse programmer - software testing foundation class -02-30-45 tools open browser running code, audio, video, test points, audio and video labels, layout labels. Advanced hyperlink syntax, absolu
[Niuke's questions] nowcoder claims to have remembered all Fibonacci numbers between 1 and 100000. To test him, we gave him a random number N and asked him to say the nth Fibonacci number. If the nth
wheel ui
[fxcg] today's market analysis
Oracle概念二
C语言教师工作量管理系统
C language set operation
d3dx9_ How to repair 33.dll? d3dx9_ What if 33.dll is lost?
Oracle concept II
2022年中国音频市场年度综合分析
Qt5 signal and slot mechanism (basic introduction to signal and slot)
d3dx9_ How to repair 40.dll? Win10 system d3dx9_ What if 40.dll is lost?
Introduction to photoswape