The main entrance for Sharding rules includes the configurations of data source, tables, binding tables and read-write split.
Real data sources list.
Configurations of logic table names, data node and table sharding rules.
It is used in the configurations of the mapping relationship between logic tables and actual tables and can be divided into two kinds: uniform distribution and user-defined distribution.
It means that data tables are evenly distributed in each data source, for example:
db0
├── t_order0
└── t_order1
db1
├── t_order0
└── t_order1
So the data node configurations will be as follow:
db0.t_order0, db0.t_order1, db1.t_order0, db1.t_order1
It means that data tables are distributed with certain rules, for example:
db0
├── t_order0
└── t_order1
db1
├── t_order2
├── t_order3
└── t_order4
So the data node configurations will be as follow:
db0.t_order0, db0.t_order1, db1.t_order2, db1.t_order3, db1.t_order4
There are two dimensions of sharding strategies, database sharding and table sharding.
DatabaseShardingStrategy
is used to configure data in the targeted database.
TableShardingStrategy
is used to configure data in the targeted table that exists in the database.
So the table sharding strategy relies on the result of the database sharding strategy.
API of those two kinds of strategies are totally same.
Replacing the original database auto-increment key with that generated in the server can make distributed key not repeat.