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

边栏推荐
- Part 31 supplement (31) ECMAScript conversion to string and number
- Kubernetes basic self-study series | introduction to ingress API
- WOx WPM installing the Youdao plug-in
- [the way of programmer training] - 3 Character count statistics
- All you want to know about large screen visualization is here
- Part 32 supplement (32) string of ECMAScript
- leetcode 19. Delete the penultimate node of the linked list
- leetcode 92. Reverse linked list II
- Ten common methods of arrays tools
- Overview of Inspur Yunxi database executor
猜你喜欢

leetcode 69. Square root of X

Part 31 supplement (31) ECMAScript conversion to string and number

09 route guard authenticates URL

Advanced learning of MySQL -- Application -- Optimization of other SQL statements

The power of code refactoring: how to measure the success of refactoring

How to improve it electronic equipment performance management
A large number of missing anchor text

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)

Leetcode 5. Longest Palindromic Substring

d3dx9_ Where is 35.dll? d3dx9_ Where can I download 35.dll
随机推荐
Related configuration commands of Huawei LACP
d3dx9_ Where is 35.dll? d3dx9_ Where can I download 35.dll
Unity shadow shadow pancaking
Introduction to photoswape
d3dx9_ 39.dll how to repair -d3dx9_ 39.dll missing file download
d3dx9_ How to repair 40.dll? Win10 system d3dx9_ What if 40.dll is lost?
Software testing Basics - software testing history, process, classification, benefits, limitations
Deeply digitise, lead cloud nativity and serve more developers
[multithreading] thread communication scheduling, waiting set wait(), notify()
Etcd visualization tool: kstone deployment (I), rapid deployment based on Helm
Uploading multiple attachments from canvas apps to SharePoint
Cesium realizes satellite orbit detour
Awk determines whether the first column is greater than 1. If it is greater than 1, the row will be printed
Raspberry pie preliminary use
Ping An technology's practice of migrating from Oracle to ubisql
Ti Click: quickly set up tidb online laboratory through browser | ti- team interview can be conducted immediately
Part 32 supplement (32) string of ECMAScript
Byte + Google super full kotlin learning King fried notes! Kotlin introductory tutorial + Advanced kotlin enhanced actual combat (with demo)
LeetCode 124. Binary tree maximum path sum - binary tree series question 8
leetcode 69. Square root of X