Skip to content

[READWRITE_SPLITTING] Can not find data source in sharding rule, invalid actual data node. #35147

@Iceberry-qdd

Description

@Iceberry-qdd

Question

For English only, other languages will not accept.

Before asking a question, make sure you have:

Please pay attention on issues you submitted, because we maybe need more details.
If no response anymore and we cannot reproduce it on current information, we will close it.


Version

<dependency>
    <groupId>org.apache.shardingsphere</groupId>
    <artifactId>shardingsphere-jdbc</artifactId>
    <version>5.5.2</version>
</dependency>

My needs

  1. ds_0 is write node, ds_1 and ds_2 are read nodes;
  2. On every ds, using autoTables rule, each tb_product table stores 1 month of data, based on the rule below, it'll create tb_product_0 ~ tb_product_12 automatically;
  3. SELECT sqls go to ds_1 or ds_2 node; update, delete, insert sqls goto ds_0 node.

My config

# Shardingsphere.yml
mode:
  type: Standalone
  repository:
    type: JDBC
dataSources:
  ds_0:
    dataSourceClassName: com.zaxxer.hikari.HikariDataSource
    driverClassName: com.mysql.cj.jdbc.Driver
    jdbcUrl: jdbc:mysql://localhost:3306/iceberry?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8
    username: iceberry
    password: iceberry
  ds_1:
    dataSourceClassName: com.zaxxer.hikari.HikariDataSource
    driverClassName: com.mysql.cj.jdbc.Driver
    jdbcUrl: jdbc:mysql://localhost:3307/iceberry?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8
    username: iceberry
    password: iceberry
  ds_2:
    dataSourceClassName: com.zaxxer.hikari.HikariDataSource
    driverClassName: com.mysql.cj.jdbc.Driver
    jdbcUrl: jdbc:mysql://localhost:3308/iceberry?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8
    username: iceberry
    password: iceberry
rules:
- !READWRITE_SPLITTING
  dataSourceGroups:
    rw_ds:
      writeDataSourceName: ds_0
      readDataSourceNames:
        - ds_1
        - ds_2
      transactionalReadQueryStrategy: PRIMARY
      loadBalancerName: random
  loadBalancers:
    random:
      type: RANDOM
- !SHARDING
  autoTables:
    tb_product:
      actualDataSources: rw_ds
      shardingStrategy:
        standard:
          shardingColumn: created_time
          shardingAlgorithmName: auto_table_interval
      keyGenerateStrategy:
        column: id
        keyGeneratorName: snowflake
      auditStrategy:
        auditorNames:
          - sharding_key_required_auditor
        allowHintDisable: true
  shardingAlgorithms:
    auto_table_interval:
      type: AUTO_INTERVAL
      props:
        datetime-lower: "2025-04-08 00:00:00"
        datetime-upper: "2026-04-08 00:00:00"
        sharding-seconds: 2678400
  auditors:
    sharding_key_required_auditor:
      type: DML_SHARDING_CONDITIONS
  keyGenerators:
    snowflake:
      type: SNOWFLAKE
props:
  sql-show: true

My Code

@MybatisTest
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
public class ProductMapperTests {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Test
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    void test_create_product_table() {
        String sql = """
                CREATE TABLE tb_product
                (
                    id           BIGINT                 NOT NULL PRIMARY KEY,
                    created_time DATETIME               NOT NULL,
                    is_ordered   TINYINT(1) DEFAULT 0   NOT NULL,
                    name         VARCHAR(64)            NULL
                );
                """;
        jdbcTemplate.execute(sql);
    }
}

My Error

The error is following (Click to expand):
Java HotSpot(TM) 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
2025-04-09T16:01:45.513+08:00  INFO 36324 --- [ShardingSphereDemo] [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2025-04-09T16:01:46.070+08:00  INFO 36324 --- [ShardingSphereDemo] [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-2 - Starting...
2025-04-09T16:01:46.333+08:00  INFO 36324 --- [ShardingSphereDemo] [           main] com.zaxxer.hikari.pool.HikariPool        : HikariPool-2 - Added connection conn0: url=jdbc:h2:mem:config user=SA
2025-04-09T16:01:46.336+08:00  INFO 36324 --- [ShardingSphereDemo] [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-2 - Start completed.
2025-04-09T16:01:46.408+08:00  INFO 36324 --- [ShardingSphereDemo] [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-3 - Starting...
2025-04-09T16:01:46.620+08:00  INFO 36324 --- [ShardingSphereDemo] [           main] com.zaxxer.hikari.pool.HikariPool        : HikariPool-3 - Added connection com.mysql.cj.jdbc.ConnectionImpl@cfb94fd
2025-04-09T16:01:46.620+08:00  INFO 36324 --- [ShardingSphereDemo] [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-3 - Start completed.

com.zaxxer.hikari.pool.HikariPool$PoolInitializationException: Failed to initialize pool: Can not find data source in sharding rule, invalid actual data node 'rw_ds.tb_product_0'.

	at com.zaxxer.hikari.pool.HikariPool.throwPoolInitializationException(HikariPool.java:584)
	at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:571)
	at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:98)
	at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:111)
	at org.springframework.jdbc.datasource.DataSourceUtils.fetchConnection(DataSourceUtils.java:160)
	at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:118)
	at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:81)
	at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:388)
	at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:421)
	at com.iceberry.ShardingSphereDemo.ProductMapperTests.test_create_product_table(ProductMapperTests.java:40)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
Caused by: org.apache.shardingsphere.sharding.exception.metadata.DataNodeGenerateException: Can not find data source in sharding rule, invalid actual data node 'rw_ds.tb_product_0'.
	at org.apache.shardingsphere.sharding.rule.ShardingTable.generateDataNodes(ShardingTable.java:193)
	at org.apache.shardingsphere.sharding.rule.ShardingTable.<init>(ShardingTable.java:128)
	at org.apache.shardingsphere.sharding.rule.ShardingRule.createShardingAutoTable(ShardingRule.java:211)
	at org.apache.shardingsphere.sharding.rule.ShardingRule.lambda$createShardingAutoTables$16(ShardingRule.java:204)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
	at java.base/java.util.LinkedList$LLSpliterator.forEachRemaining(LinkedList.java:1242)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
	at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
	at org.apache.shardingsphere.sharding.rule.ShardingRule.createShardingAutoTables(ShardingRule.java:205)
	at org.apache.shardingsphere.sharding.rule.ShardingRule.<init>(ShardingRule.java:127)
	at org.apache.shardingsphere.sharding.rule.builder.ShardingRuleBuilder.build(ShardingRuleBuilder.java:42)
	at org.apache.shardingsphere.sharding.rule.builder.ShardingRuleBuilder.build(ShardingRuleBuilder.java:36)
	at org.apache.shardingsphere.infra.rule.builder.database.DatabaseRulesBuilder.build(DatabaseRulesBuilder.java:69)
	at org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase.create(ShardingSphereDatabase.java:104)
	at org.apache.shardingsphere.mode.metadata.factory.ExternalMetaDataFactory.createGenericDatabases(ExternalMetaDataFactory.java:83)
	at org.apache.shardingsphere.mode.metadata.factory.ExternalMetaDataFactory.create(ExternalMetaDataFactory.java:71)
	at org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory.createByLocal(MetaDataContextsFactory.java:83)
	at org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory.create(MetaDataContextsFactory.java:72)
	at org.apache.shardingsphere.mode.manager.standalone.StandaloneContextManagerBuilder.build(StandaloneContextManagerBuilder.java:51)
	at org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource.createContextManager(ShardingSphereDataSource.java:74)
	at org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource.<init>(ShardingSphereDataSource.java:63)
	at org.apache.shardingsphere.driver.api.ShardingSphereDataSourceFactory.createDataSource(ShardingSphereDataSourceFactory.java:95)
	at org.apache.shardingsphere.driver.api.yaml.YamlShardingSphereDataSourceFactory.createDataSource(YamlShardingSphereDataSourceFactory.java:136)
	at org.apache.shardingsphere.driver.api.yaml.YamlShardingSphereDataSourceFactory.createDataSource(YamlShardingSphereDataSourceFactory.java:71)
	at org.apache.shardingsphere.driver.jdbc.core.driver.DriverDataSourceCache.createDataSource(DriverDataSourceCache.java:57)
	at org.apache.shardingsphere.driver.jdbc.core.driver.DriverDataSourceCache.lambda$get$0(DriverDataSourceCache.java:50)
	at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1708)
	at org.apache.shardingsphere.driver.jdbc.core.driver.DriverDataSourceCache.get(DriverDataSourceCache.java:50)
	at org.apache.shardingsphere.driver.ShardingSphereDriver.connect(ShardingSphereDriver.java:57)
	at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:120)
	at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:360)
	at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:202)
	at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:461)
	at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:550)
	... 11 more

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions