Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Table t_email does not exist. #34724

Open
harmonyzhang opened this issue Feb 19, 2025 · 0 comments
Open

Table t_email does not exist. #34724

harmonyzhang opened this issue Feb 19, 2025 · 0 comments

Comments

@harmonyzhang
Copy link

harmonyzhang commented Feb 19, 2025

@bean(name = DEFAULT_DATASOURCE)
public DataSource defaultDataSource() throws SQLException {
ReadwriteSplittingDataSourceGroupRuleConfiguration dataSourceConfig = new ReadwriteSplittingDataSourceGroupRuleConfiguration("ds_0", "ds_0_0", Arrays.asList("ds_0_1", "ds_0_2"), "round_lb");
ReadwriteSplittingDataSourceGroupRuleConfiguration dataSourceConfig1 = new ReadwriteSplittingDataSourceGroupRuleConfiguration("ds_1", "ds_1_0", Arrays.asList("ds_1_1", "ds_1_2"), "round_lb");
// 使用轮询负载均衡算法
Map<String, AlgorithmConfiguration> algorithmConfigMap = new HashMap<>(1);
algorithmConfigMap.put("round_lb", new AlgorithmConfiguration("ROUND_ROBIN", new Properties()));
ReadwriteSplittingRuleConfiguration ruleConfig = new ReadwriteSplittingRuleConfiguration(Arrays.asList(dataSourceConfig, dataSourceConfig1), algorithmConfigMap);
Properties props = new Properties();
props.setProperty("sql-show", Boolean.TRUE.toString());
Map<String, DataSource> dataSourceMap = createDataSourceMap();
return ShardingSphereDataSourceFactory.createDataSource(dataSourceMap, Arrays.asList(ruleConfig, createShardingRuleConfiguration()), props);
}

// 分片配置
private ShardingRuleConfiguration createShardingRuleConfiguration() throws SQLException {
ShardingRuleConfiguration result = new ShardingRuleConfiguration();
result.getTables().add(getTableRuleConfiguration("t_order"));
result.setDefaultDatabaseShardingStrategy(new StandardShardingStrategyConfiguration("company_id", "geo-hash-algorithm"));
result.setDefaultTableShardingStrategy(new StandardShardingStrategyConfiguration("company_id", "table-customize-algorithm"));
Properties props = new Properties();
props.setProperty("strategy", "standard");
// 标准算法
props.setProperty("algorithmClassName", GeoHashShardingAlgorithm.class.getName());
result.getShardingAlgorithms().put("geo-hash-algorithm", new AlgorithmConfiguration("CLASS_BASED", props));
Properties props1 = new Properties();
props1.setProperty("strategy", "standard");
// 标准算法
props1.setProperty("algorithmClassName", TableCustomizeShardingAlgorithm.class.getName());
result.getShardingAlgorithms().put("table-customize-algorithm", new AlgorithmConfiguration("CLASS_BASED", props1));
return result;
}

private ShardingTableRuleConfiguration getTableRuleConfiguration(String tableName) {
ShardingTableRuleConfiguration result = new ShardingTableRuleConfiguration(tableName, "ds_${0..1}." + tableName);
return result;
}

private Map<String, DataSource> createDataSourceMap() {
Map<String, DataSource> result = new HashMap<>(6, 1);
result.put("ds_0_0", createDataSource(readwriteProperties()));
result.put("ds_0_1", createDataSource(read1Properties()));
result.put("ds_0_2", createDataSource(read2Properties()));
result.put("ds_1_0", createDataSource(readwriteProperties()));
result.put("ds_1_1", createDataSource(read1Properties()));
result.put("ds_1_2", createDataSource(read2Properties()));
return result;
}

version: 5.5.1

Using the above configuration, the business error indicates that the table does not exist. It is found that tables without configured rules are all unavailable, and neither the custom database sharding algorithm nor the table sharding algorithm has been executed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant