sharding-jdbc4,How to configure only tables that need to be fragmented through default config and customized code
Does sharding JDBC support the following? Only the default fragmentation fields and strategy are configured for the databases and tables. The actual data nodes of tables are not configured. The assign tables are obtained through my customized mapping(myself java code). I have many modules in my project. Each module only configures tables participating in sharding, and all projects share a common customized sharding rule. For example: //my customized mapping(sharding rule) Map<String,String> shardingMap = new HashMap<>(); shardingMap.put("tenantId1","db_0:table_01"); shardingMap.put("tenantId2","db_0:table_02"); shardingMap.put("tenantId3","db_1:table_03"); shardingMap.put("tenantId4","db_1:table_04");
//Each module defines its own partition table: {sku_info,sku_stock……}
How to implement the code? thanks
You wanna "sku_info" literally instead of "table" of "db_0:table_01" in runtime?
Hi, @fantacy2001 ,
ShardingSphere need you configured actual data nodes if you want to shard both datasources and tables. If there are no actualDataNodes configured, ShardingSphere can't know what's the Possible shardingNodes which should be input into your sharding algorithms.
For your situation, I think you can have a try like follow:
dataSources:
ds_0: !!com.zaxxer.hikari.HikariDataSource
driverClassName: com.mysql.jdbc.Driver
jdbcUrl: jdbc:mysql://localhost:3306/demo_ds_0?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
username: root
password:
ds_1: !!com.zaxxer.hikari.HikariDataSource
driverClassName: com.mysql.jdbc.Driver
jdbcUrl: jdbc:mysql://localhost:3306/demo_ds_1?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
username: root
password:
shardingRule:
tables:
tableA:
actualDataNodes: ds_0.tenantId&->{1..2},ds_1.tenantId{3..4}
tableB:
actualDataNodes: ds_0.tenantId&->{1..2},ds_1.tenantId{3..4}
defaultDatabaseStrategy:
stardard:
shardingColumn: xxx
preciseShardingAlgorithm: ${your.algorithm}
defaultTableStrategy:
stardard:
shardingColumn: yyy
preciseShardingAlgorithm: ${your.algorithm}
and map the actual tableName in your algorithms.
You wanna "sku_info" literally instead of "table" of "db_0:table_01" in runtime? yes,I want to use my own mapping to find the real table name into the sharding algorithms.
Hi, @fantacy2001 ,
ShardingSphere need you configured actual data nodes if you want to shard both datasources and tables. If there are no
actualDataNodesconfigured, ShardingSphere can't know what's the Possible shardingNodes which should be input into your sharding algorithms.For your situation, I think you can have a try like follow:
dataSources: ds_0: !!com.zaxxer.hikari.HikariDataSource driverClassName: com.mysql.jdbc.Driver jdbcUrl: jdbc:mysql://localhost:3306/demo_ds_0?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8 username: root password: ds_1: !!com.zaxxer.hikari.HikariDataSource driverClassName: com.mysql.jdbc.Driver jdbcUrl: jdbc:mysql://localhost:3306/demo_ds_1?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8 username: root password: shardingRule: tables: tableA: actualDataNodes: ds_0.tenantId&->{1..2},ds_1.tenantId{3..4} tableB: actualDataNodes: ds_0.tenantId&->{1..2},ds_1.tenantId{3..4} defaultDatabaseStrategy: stardard: shardingColumn: xxx preciseShardingAlgorithm: ${your.algorithm} defaultTableStrategy: stardard: shardingColumn: yyy preciseShardingAlgorithm: ${your.algorithm}and map the actual tableName in your algorithms.
tenantId on my example is shardingColumn,my general mapping only defines the suffix of the table name and database name, it is used by all modules. Whether each module can only configure tables participating in sharding. Then take the general mapping and assemble the real table according to the configured partition table name into the sharding algorithms ? if i have configured 'actualDataNodes', all modules need to be configured it。 the other question: sharding tablename: table(no suffix)、table_001、table_002.... table_00n,like this def, How to implement in the configuration file? Please help me out of your busy schedule. Thank you very much!!!
I don't understand your question clearly. Do you mean that you want only configure defaultDatabaseStrategy and defaultTableStrategy without tables?
I don't understand your question clearly. Do you mean that you want only configure
defaultDatabaseStrategyanddefaultTableStrategywithouttables?
besides defaultDatabaseStrategy and defaultTableStrategy, Can only define the tables who need sharding?
I don't understand your question clearly. Do you mean that you want only configure
defaultDatabaseStrategyanddefaultTableStrategywithouttables?besides
defaultDatabaseStrategyanddefaultTableStrategy, Can only define the tables who need sharding?
Do you mean you want just configure which tables you want to shard without actualDataNodes?
I don't understand your question clearly. Do you mean that you want only configure
defaultDatabaseStrategyanddefaultTableStrategywithouttables?besides
defaultDatabaseStrategyanddefaultTableStrategy, Can only define the tables who need sharding?Do you mean you want just configure which tables you want to shard without actualDataNodes?
yes, i mean this
Possibly not, no actualDataNodes means that you want shard datasource only. And if you want to shard both datasources and tables, you should configure actualDataNodes ensure the input of your sharding algorithm is correct.
Possibly not, no actualDataNodes means that you want shard datasource only. And if you want to shard both datasources and tables, you should configure actualDataNodes ensure the input of your sharding algorithm is correct.
o, understand, thanks very much!! another question: one existing project, now I want to introduce sharding-jdbc to sharding db and table, my existing table : table(no suffix)、table_001、table_002.... table_00n,like this define, How to configure actualDataNodes ? Please help me ,thank you!
another question: one existing project, now I want to introduce sharding-jdbc to sharding db and table, my existing table : table(no suffix)、table_001、table_002.... table_00n,like this define, How to configure actualDataNodes ? Please help me ,thank you!
configure actualDataNodes like follow:
actualDataNodes: ds.table,ds0.table00$->{1..9},ds0.table01$->{1..9} ...
another question: one existing project, now I want to introduce sharding-jdbc to sharding db and table, my existing table : table(no suffix)、table_001、table_002.... table_00n,like this define, How to configure actualDataNodes ? Please help me ,thank you!
configure actualDataNodes like follow:
actualDataNodes: ds.table,ds0.table00$->{1..9},ds0.table01$->{1..9} ...
thank you very much!!!