当前位置:网站首页>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

边栏推荐
- Leetcode 33. Search rotation sort array
- Use pyinstaller to package py files into exe. Precautions and error typeerror:_ get_ sysconfigdata_ name() missing 1...‘ check_ Solutions to exists'
- 09 route guard authenticates URL
- Alibaba cloud liupeizi: Inspiration from cloud games - innovation on the end
- Alibaba cloud server is invaded
- Extract field year / quarter effect based on date
- Determine the maximum number of specific words in a string
- LACP details
- Advanced learning of MySQL -- Application -- view, stored procedure, trigger
- leetcode 19. Delete the penultimate node of the linked list
猜你喜欢

软件测试基础-软件测试历史流程,分类,好处,限制

Leetcode daily practice (sum of two numbers)

Kubernetes basic self-study series | introduction to ingress API

Oracle概念二

(5) SPI application design and simulation verification 1 - logic sorting

Autodesk Navisworks 2022软件安装包下载及安装教程

Alibaba cloud server is invaded

WOx WPM installing the Youdao plug-in

Defiato is an innovation that combines user-friendly features of a centralized platform with defi services
![[fxcg] today's market analysis](/img/97/fc6faa5ab693e383f085b407ce1d85.jpg)
[fxcg] today's market analysis
随机推荐
428 binary tree (501. mode in binary search tree, 701. insert operation in binary search tree, 450. delete node in binary search tree, 669. prune binary search tree)
CDH cluster installation
Handling of difficult and miscellaneous problems during the installation and configuration of qt5.5.1 desktop version (configuring arm compilation Kit)
Part 30 supplement (30) ECMAScript object
(5) SPI application design and simulation verification 2 - design code implementation
Hospital reservation and registration system - system structure
2/14 preliminary calculation geometry
Advanced learning of MySQL -- Application -- view, stored procedure, trigger
Oracle TRUNC function processing date format
The two trump brand products of Langjiu are resonating in Chengdu, continuously driving the consumption wave of bottled liquor
leetcode 82. Delete duplicate Element II in the sorting linked list
Halcon: discrete digital OCR recognition
【多线程】线程通信调度、等待集 wait() 、notify()
When the publish / subscribe mode encounters NET
Alibaba cloud liupeizi: Inspiration from cloud games - innovation on the end
Event listening mechanism
LACP details
Qt5 signal and slot mechanism (demonstrate the correlation between the control's own signal and slot function)
# Cesium实现卫星在轨绕行
2/15 topology sorting +dfs (the order of specified directions is very important) +bfs