Skip to content

readwrite-splitting data sources is incorrect when tableless #34387

@JoshuaChen

Description

@JoshuaChen

Bug Report

When using the following configuration, the value passed to rule.findDataSourceGroupRule(logicDataSourceName) is write_ds or read_ds_0, which fails to locate the correct dataSourceGroups (e.g., joshua in the configuration). This causes the ReadwriteSplitting logic to be skipped. This PR fixes the issue by ensuring the logicDataSourceName parameter passed is set to joshua.

mode:
  type: Standalone
  repository:
    type: JDBC

dataSources:
  write_ds:
    dataSourceClassName: com.zaxxer.hikari.HikariDataSource
    url: jdbc:postgresql://127.0.0.1:5432/mydatabase
    username: myuser
    password: secret
  read_ds_0:
    dataSourceClassName: com.zaxxer.hikari.HikariDataSource
    url: jdbc:postgresql://127.0.0.1:5432/mydatabase
    username: myuser
    password: secret
    readOnly: true

rules:
  - !READWRITE_SPLITTING
    dataSourceGroups:
      "joshua":
        writeDataSourceName: write_ds
        readDataSourceNames:
          - read_ds_0
        transactionalReadQueryStrategy: PRIMARY
        loadBalancerName: baseAA
    loadBalancers:
      baseAA: # Load balance algorithm name
        type: ROUND_ROBIN
  - !SINGLE
    tables:
      - "*.*.*"

props:
  sql-show: true

Which version of ShardingSphere did you use?

5.5.0/5.5.1/5.5.2-SNAPSHOT triggers BUG
5.4.1 works normally

Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?

ShardingSphere-JDBC

Expected behavior

Tableless write operations have transactions
Tableless write operations point to write_ds

Actual behavior

Tableless write operations have transactions
Tableless write operations do not always point to write_ds, but sometimes point to read_ds_0

Reason analyze (If you can)

#34340

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