You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "Nilesh18398 (via GitHub)" <gi...@apache.org> on 2026/06/29 13:13:45 UTC

[I] Read/Write splitting not working and sharding tables not found errors in Sharding setup [shardingsphere]

Nilesh18398 opened a new issue, #38955:
URL: https://github.com/apache/shardingsphere/issues/38955

   I’m facing two issues in my Sharding setup:
   
   1. Read/Write Splitting Issue
   
   All queries (both SELECT and INSERT) are being routed incorrectly. In some cases, all queries go to either the master or the read-only slave, instead of being properly split between them.
   
   This behavior is inconsistent and affects all non-shared tables.
   
   2. Sharding Tables Not Found
   
   I am also getting errors indicating that sharding tables cannot be found. This happens during query execution.
   
   Error
   `org.apache.shardingsphere.infra.exception.kernel.metadata.TableNotFoundException: Table or view 'order' does not exist.
   	at org.apache.shardingsphere.infra.binder.engine.segment.dml.from.type.SimpleTableSegmentBinder.lambda$checkTableExists$12(SimpleTableSegmentBinder.java:187)
   	at org.apache.shardingsphere.infra.exception.ShardingSpherePreconditions.checkState(ShardingSpherePreconditions.java:44)
   	at org.apache.shardingsphere.infra.binder.engine.segment.dml.from.type.SimpleTableSegmentBinder.checkTableExists(SimpleTableSegmentBinder.java:187)
   	at org.apache.shardingsphere.infra.binder.engine.segment.dml.from.type.SimpleTableSegmentBinder.bind(SimpleTableSegmentBinder.java:94)
   	at org.apache.shardingsphere.infra.binder.engine.segment.dml.from.TableSegmentBinder.bind(TableSegmentBinder.java:57)
   	at org.apache.shardingsphere.infra.binder.engine.statement.dml.SelectStatementBinder.lambda$bind$1(SelectStatementBinder.java:72)
   	at java.base/java.util.Optional.map(Optional.java:260)
   	at org.apache.shardingsphere.infra.binder.engine.statement.dml.SelectStatementBinder.bind(SelectStatementBinder.java:72)
   	at org.apache.shardingsphere.infra.binder.engine.type.DMLStatementBindEngine.bind(DMLStatementBindEngine.java:45)
   	at org.apache.shardingsphere.infra.binder.engine.SQLBindEngine.bindSQLStatement(SQLBindEngine.java:73)
   	at org.apache.shardingsphere.infra.binder.engine.SQLBindEngine.bind(SQLBindEngine.java:59)
   	at org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSpherePreparedStatement.<init>(ShardingSpherePreparedStatement.java:144)
   	at org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSpherePreparedStatement.<init>(ShardingSpherePreparedStatement.java:119)
   	at org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection.prepareStatement(ShardingSphereConnection.java:113)
   	at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$4.doPrepare(StatementPreparerImpl.java:151)
   	at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:180)
   	at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareQueryStatement(StatementPreparerImpl.java:153)
   	at org.hibernate.sql.exec.internal.StandardStatementCreator.createStatement(StandardStatementCreator.java:49)
   	at org.hibernate.sql.results.jdbc.internal.DeferredResultSetAccess.executeQuery(DeferredResultSetAccess.java:236)
   	at org.hibernate.sql.results.jdbc.internal.DeferredResultSetAccess.getResultSet(DeferredResultSetAccess.java:172)
   	at org.hibernate.sql.results.jdbc.internal.AbstractResultSetAccess.getMetaData(AbstractResultSetAccess.java:36)
   	at org.hibernate.sql.results.jdbc.internal.AbstractResultSetAccess.getColumnCount(AbstractResultSetAccess.java:52)
   	at org.hibernate.query.results.ResultSetMappingImpl.resolve(ResultSetMappingImpl.java:194)
   	at org.hibernate.sql.exec.internal.JdbcSelectExecutorStandardImpl.resolveJdbcValuesSource(JdbcSelectExecutorStandardImpl.java:340)
   	at org.hibernate.sql.exec.internal.JdbcSelectExecutorStandardImpl.doExecuteQuery(JdbcSelectExecutorStandardImpl.java:137)
   	at org.hibernate.sql.exec.internal.JdbcSelectExecutorStandardImpl.executeQuery(JdbcSelectExecutorStandardImpl.java:102)
   	at org.hibernate.sql.exec.spi.JdbcSelectExecutor.executeQuery(JdbcSelectExecutor.java:91)
   	at org.hibernate.sql.exec.spi.JdbcSelectExecutor.list(JdbcSelectExecutor.java:165)
   	at org.hibernate.sql.exec.spi.JdbcSelectExecutor.list(JdbcSelectExecutor.java:142)
   	at org.hibernate.sql.exec.spi.JdbcSelectExecutor.list(JdbcSelectExecutor.java:132)
   	at org.hibernate.query.sql.internal.NativeSelectQueryPlanImpl.performList(NativeSelectQueryPlanImpl.java:135)
   	at org.hibernate.query.sql.internal.NativeQueryImpl.doList(NativeQueryImpl.java:697)
   	at org.hibernate.query.spi.AbstractSelectionQuery.list(AbstractSelectionQuery.java:143)
   	at org.hibernate.query.spi.AbstractSelectionQuery.getSingleResult(AbstractSelectionQuery.java:275)
   	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
   	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
   	at org.springframework.orm.jpa.SharedEntityManagerCreator$DeferredQueryInvocationHandler.invoke(SharedEntityManagerCreator.java:419)
   	at jdk.proxy2/jdk.proxy2.$Proxy287.getSingleResult(Unknown Source)
   	at org.springframework.data.jpa.repository.query.JpaQueryExecution$SingleEntityExecution.doExecute(JpaQueryExecution.java:226)
   	at org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:95)
   	at org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:160)
   	at org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:148)
   	at org.springframework.data.repository.core.support.RepositoryMethodInvoker.doInvoke(RepositoryMethodInvoker.java:170)
   	at org.springframework.data.repository.core.support.RepositoryMethodInvoker.invoke(RepositoryMethodInvoker.java:158)
   	at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.doInvoke(QueryExecutorMethodInterceptor.java:170)
   	at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.invoke(QueryExecutorMethodInterceptor.java:149)
   	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
   	at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:69)
   	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
   	at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:380)
   	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:119)
   	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
   	at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:138)
   	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
   	at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:136)
   	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
   	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:223)
   	at jdk.proxy2/jdk.proxy2.$Proxy211.findCountByUnitIdAndThingIdAndCreatedAt(Unknown Source)
   `
   Configuration
   
   `
   
   	@Configuration
   public class ShardingSphereConfig {
   
   	@Value("${DB_HOST}")
   	private String dbHost;
   
   	@Value("${DB_HOST_SLAVE}")
   	private String dbHostSlave;
   
   	@Value("${DB_PORT}")
   	private String dbPort;
   
   	@Value("${DB_NAME}")
   	private String dbName;
   
   	@Value("${DB_USERNAME}")
   	private String dbUsername;
   
   	@Value("${DB_PASSWORD}")
   	private String dbPassword;
   
   	@Bean
   	@Primary
   	public DataSource dataSource() throws SQLException {
   
   		Map<String, DataSource> dataSources = new HashMap<>();
   
   		dataSources.put("ds_master", createDataSource(dbHost, "ds_master", false));
   		dataSources.put("ds_slave", createDataSource(dbHostSlave, "ds_slave", true));
   
   		// =====================================================
   		// READ WRITE SPLITTING RULE
   		// =====================================================
   		ReadwriteSplittingDataSourceGroupRuleConfiguration rwGroup = new ReadwriteSplittingDataSourceGroupRuleConfiguration(
   				"readwrite_ds", "ds_master", List.of("ds_slave"), TransactionalReadQueryStrategy.DYNAMIC,
   				"round_robin");
   
   		Map<String, AlgorithmConfiguration> loadBalancers = new HashMap<>();
   		loadBalancers.put("round_robin", new AlgorithmConfiguration("ROUND_ROBIN", new Properties()));
   
   		ReadwriteSplittingRuleConfiguration rwRule = new ReadwriteSplittingRuleConfiguration(List.of(rwGroup),
   				loadBalancers);
   
   		// --------------------------------------------------
   		// Sharding Rule
   		// --------------------------------------------------
   
   		ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
   
   		addTableRule(shardingRuleConfig, "order", "order_$->{1..24}", "order_inline");
   
   
   		// =================================================
   		// SHARDING ALGORITHMS
   		// =================================================
   
   		addInlineAlgorithm(shardingRuleConfig, "order_inline",
   				"order_${(thing_id.hashCode() & Integer.MAX_VALUE) % 24 + 1}");
   
   		// --------------------------------------------------
   		// Single Tables
   		// --------------------------------------------------
   
   		SingleRuleConfiguration single = new SingleRuleConfiguration();
   		single.getTables().add("*.*");
   
   		// --------------------------------------------------
   		// Properties
   		// --------------------------------------------------
   
   		Properties props = new Properties();
   		props.setProperty("sql-show", "true");
   		props.setProperty("sql-simple", "false");
   		props.setProperty("kernel-executor-size", "16");
   
   		DataSource ds = ShardingSphereDataSourceFactory.createDataSource(dataSources,
   				List.of(shardingRuleConfig, rwRule, single), props);
   
   		shardingRuleConfig.getShardingAlgorithms().forEach((k, v) -> System.out.println(k + " -> " + v.getType()));
   
   		return ds;
   	}
   
   	private HikariDataSource createDataSource(String host, String poolName, boolean readonly) {
   
   		HikariDataSource ds = new HikariDataSource();
   
   		ds.setDriverClassName("com.mysql.cj.jdbc.Driver");
   
   		ds.setJdbcUrl("jdbc:mysql://" + host + ":" + dbPort + "/" + dbName + "?useSSL=false"
   				+ "&allowPublicKeyRetrieval=true" + "&serverTimezone=UTC");
   
   		ds.setUsername(dbUsername);
   		ds.setPassword(dbPassword);
   		ds.setReadOnly(readonly);
   		ds.setPoolName(poolName);
   		ds.setMaximumPoolSize(20);
   		ds.setMinimumIdle(5);
   
   		return ds;
   	}
   
   	private void addTableRule(ShardingRuleConfiguration config, String logicTable, String actualTables,
   			String algorithmName) {
   
   		ShardingTableRuleConfiguration tableRule = new ShardingTableRuleConfiguration(logicTable,
   				"readwrite_ds." + actualTables);
   
   		tableRule.setTableShardingStrategy(new StandardShardingStrategyConfiguration("order_id", algorithmName));
   
   		config.getTables().add(tableRule);
   	}
   
   	// =====================================================
   	// ADD INLINE ALGORITHM
   	// =====================================================
   
   	private void addInlineAlgorithm(ShardingRuleConfiguration config, String algorithmName, String expression) {
   
   		Properties props = new Properties();
   
   		props.setProperty("algorithm-expression", expression);
   
   		props.setProperty("allow-range-query-with-inline-sharding", "true");
   
   		config.getShardingAlgorithms().put(algorithmName, new AlgorithmConfiguration("INLINE", props));
   	}`
   Dependencies
   `[INFO] +- org.springframework.boot:spring-boot-starter-actuator:jar:3.5.8:compile
   [INFO] |  +- org.springframework.boot:spring-boot-actuator-autoconfigure:jar:3.5.8:compile
   [INFO] |  |  \- org.springframework.boot:spring-boot-actuator:jar:3.5.8:compile
   [INFO] |  +- io.micrometer:micrometer-observation:jar:1.15.6:compile
   [INFO] |  |  \- io.micrometer:micrometer-commons:jar:1.15.6:compile
   [INFO] |  \- io.micrometer:micrometer-jakarta9:jar:1.15.6:compile
   [INFO] +- org.springframework.boot:spring-boot-starter-security:jar:3.5.8:compile
   [INFO] |  +- org.springframework:spring-aop:jar:6.2.14:compile
   [INFO] |  +- org.springframework.security:spring-security-config:jar:6.5.7:compile
   [INFO] |  |  \- org.springframework.security:spring-security-core:jar:6.5.7:compile
   [INFO] |  |     \- org.springframework.security:spring-security-crypto:jar:6.5.7:compile
   [INFO] |  \- org.springframework.security:spring-security-web:jar:6.5.7:compile
   [INFO] |     \- org.springframework:spring-expression:jar:6.2.14:compile
   [INFO] +- com.fasterxml.jackson.core:jackson-core:jar:2.19.4:compile
   [INFO] +- com.fasterxml.jackson.core:jackson-databind:jar:2.19.4:compile
   [INFO] +- com.fasterxml.jackson.core:jackson-annotations:jar:2.19.4:compile
   [INFO] +- org.springframework.cloud:spring-cloud-starter-bootstrap:jar:4.3.1:compile
   [INFO] |  \- org.springframework.cloud:spring-cloud-starter:jar:4.3.1:compile
   [INFO] |     +- org.springframework.cloud:spring-cloud-context:jar:4.3.1:compile
   [INFO] |     \- org.springframework.cloud:spring-cloud-commons:jar:4.3.1:compile
   [INFO] +- org.springframework.boot:spring-boot-starter:jar:3.5.8:compile
   [INFO] |  +- org.springframework.boot:spring-boot:jar:3.5.8:compile
   [INFO] |  +- org.springframework.boot:spring-boot-autoconfigure:jar:3.5.8:compile
   [INFO] |  +- jakarta.annotation:jakarta.annotation-api:jar:2.1.1:compile
   [INFO] |  +- org.springframework:spring-core:jar:6.2.14:compile
   [INFO] |  |  \- org.springframework:spring-jcl:jar:6.2.14:compile
   [INFO] |  \- org.yaml:snakeyaml:jar:2.4:compile
   [INFO] +- org.springframework.boot:spring-boot-starter-web:jar:3.5.8:compile
   [INFO] |  +- org.springframework.boot:spring-boot-starter-json:jar:3.5.8:compile
   [INFO] |  |  +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.19.4:compile
   [INFO] |  |  \- com.fasterxml.jackson.module:jackson-module-parameter-names:jar:2.19.4:compile
   [INFO] |  +- org.springframework.boot:spring-boot-starter-tomcat:jar:3.5.8:compile
   [INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-core:jar:10.1.49:compile
   [INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-el:jar:10.1.49:compile
   [INFO] |  |  \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:10.1.49:compile
   [INFO] |  +- org.springframework:spring-web:jar:6.2.14:compile
   [INFO] |  \- org.springframework:spring-webmvc:jar:6.2.14:compile
   [INFO] +- org.springframework.boot:spring-boot-starter-data-jpa:jar:3.5.8:compile
   [INFO] |  +- org.springframework.boot:spring-boot-starter-jdbc:jar:3.5.8:compile
   [INFO] |  |  \- com.zaxxer:HikariCP:jar:6.3.3:compile
   [INFO] |  +- org.hibernate.orm:hibernate-core:jar:6.6.36.Final:compile
   [INFO] |  |  +- jakarta.persistence:jakarta.persistence-api:jar:3.1.0:compile
   [INFO] |  |  +- jakarta.transaction:jakarta.transaction-api:jar:2.0.1:compile
   [INFO] |  |  +- org.jboss.logging:jboss-logging:jar:3.6.1.Final:compile
   [INFO] |  |  +- org.hibernate.common:hibernate-commons-annotations:jar:7.0.3.Final:runtime
   [INFO] |  |  +- io.smallrye:jandex:jar:3.2.0:runtime
   [INFO] |  |  +- com.fasterxml:classmate:jar:1.7.1:compile
   [INFO] |  |  +- net.bytebuddy:byte-buddy:jar:1.17.8:runtime
   [INFO] |  |  +- org.glassfish.jaxb:jaxb-runtime:jar:4.0.6:runtime
   [INFO] |  |  |  \- org.glassfish.jaxb:jaxb-core:jar:4.0.6:runtime
   [INFO] |  |  |     +- org.eclipse.angus:angus-activation:jar:2.0.3:runtime
   [INFO] |  |  |     +- org.glassfish.jaxb:txw2:jar:4.0.6:runtime
   [INFO] |  |  |     \- com.sun.istack:istack-commons-runtime:jar:4.1.2:runtime
   [INFO] |  |  +- jakarta.inject:jakarta.inject-api:jar:2.0.1:runtime
   [INFO] |  |  \- org.antlr:antlr4-runtime:jar:4.13.0:compile
   [INFO] |  +- org.springframework.data:spring-data-jpa:jar:3.5.6:compile
   [INFO] |  |  \- org.springframework:spring-orm:jar:6.2.14:compile
   [INFO] |  \- org.springframework:spring-aspects:jar:6.2.14:compile
   [INFO] |     \- org.aspectj:aspectjweaver:jar:1.9.25:compile
   [INFO] +- org.springframework.batch:spring-batch-core:jar:5.2.4:compile
   [INFO] |  +- org.springframework.batch:spring-batch-infrastructure:jar:5.2.4:compile
   [INFO] |  +- org.springframework:spring-beans:jar:6.2.14:compile
   [INFO] |  +- org.springframework:spring-context:jar:6.2.14:compile
   [INFO] |  +- org.springframework:spring-tx:jar:6.2.14:compile
   [INFO] |  +- org.springframework:spring-jdbc:jar:6.2.14:compile
   [INFO] |  +- io.micrometer:micrometer-core:jar:1.15.6:compile
   [INFO] |  |  +- org.hdrhistogram:HdrHistogram:jar:2.2.2:runtime
   [INFO] |  |  \- org.latencyutils:LatencyUtils:jar:2.0.3:runtime
   [INFO] |  \- org.springframework.data:spring-data-commons:jar:3.5.6:compile
   [INFO] +- org.springframework.boot:spring-boot-starter-batch:jar:3.5.8:compile
   [INFO] +- org.dom4j:dom4j:jar:2.2.0:compile
   [INFO] +- org.springframework.kafka:spring-kafka:jar:3.3.11:compile
   [INFO] |  +- org.springframework:spring-messaging:jar:6.2.14:compile
   [INFO] |  +- org.springframework.retry:spring-retry:jar:2.0.12:compile
   [INFO] |  \- org.apache.kafka:kafka-clients:jar:3.9.1:compile
   [INFO] |     +- com.github.luben:zstd-jni:jar:1.5.6-4:runtime
   [INFO] |     +- org.lz4:lz4-java:jar:1.8.0:runtime
   [INFO] |     \- org.xerial.snappy:snappy-java:jar:1.1.10.5:runtime
   [INFO] +- org.springframework.boot:spring-boot-configuration-processor:jar:3.5.8:compile (optional)
   [INFO] +- org.apache.commons:commons-lang3:jar:3.18.0:compile
   [INFO] +- org.projectlombok:lombok:jar:1.18.42:compile
   [INFO] +- org.apache.shardingsphere:shardingsphere-jdbc:jar:5.5.3:compile
   [INFO] |  +- org.apache.shardingsphere:shardingsphere-infra-url-core:jar:5.5.3:compile
   [INFO] |  |  \- org.apache.shardingsphere:shardingsphere-infra-url-spi:jar:5.5.3:compile
   [INFO] |  |     \- org.apache.shardingsphere:shardingsphere-cluster-mode-repository-api:jar:5.5.3:compile
   [INFO] |  +- org.apache.shardingsphere:shardingsphere-transaction-core:jar:5.5.3:compile
   [INFO] |  |  +- org.apache.shardingsphere:shardingsphere-transaction-api:jar:5.5.3:compile
   [INFO] |  |  \- org.apache.shardingsphere:shardingsphere-infra-executor:jar:5.5.3:compile
   [INFO] |  |     +- org.apache.shardingsphere:shardingsphere-infra-rewrite-core:jar:5.5.3:compile
   [INFO] |  |     |  \- org.apache.shardingsphere:shardingsphere-sql-translator-core:jar:5.5.3:compile
   [INFO] |  |     |     \- org.apache.shardingsphere:shardingsphere-sql-translator-api:jar:5.5.3:compile
   [INFO] |  |     \- com.alibaba:transmittable-thread-local:jar:2.14.2:compile
   [INFO] |  +- org.apache.shardingsphere:shardingsphere-transaction-xa-core:jar:5.5.3:compile
   [INFO] |  |  \- org.apache.shardingsphere:shardingsphere-transaction-xa-spi:jar:5.5.3:compile
   [INFO] |  +- org.apache.shardingsphere:shardingsphere-global-clock-core:jar:5.5.3:compile
   [INFO] |  |  \- org.apache.shardingsphere:shardingsphere-global-clock-api:jar:5.5.3:compile
   [INFO] |  +- org.apache.shardingsphere:shardingsphere-global-clock-tso-provider-local:jar:5.5.3:compile
   [INFO] |  |  \- org.apache.shardingsphere:shardingsphere-global-clock-tso-spi:jar:5.5.3:compile
   [INFO] |  +- org.apache.shardingsphere:shardingsphere-authority-core:jar:5.5.3:compile
   [INFO] |  |  \- org.apache.shardingsphere:shardingsphere-authority-api:jar:5.5.3:compile
   [INFO] |  +- org.apache.shardingsphere:shardingsphere-single-core:jar:5.5.3:compile
   [INFO] |  |  +- org.apache.shardingsphere:shardingsphere-sql-federation-api:jar:5.5.3:compile
   [INFO] |  |  +- org.apache.shardingsphere:shardingsphere-mode-spi:jar:5.5.3:compile
   [INFO] |  |  \- org.apache.shardingsphere:shardingsphere-infra-route-core:jar:5.5.3:compile
   [INFO] |  |     \- org.apache.shardingsphere:shardingsphere-infra-checker:jar:5.5.3:compile
   [INFO] |  +- org.apache.shardingsphere:shardingsphere-infra-context:jar:5.5.3:compile
   [INFO] |  |  \- org.apache.shardingsphere:shardingsphere-infra-session:jar:5.5.3:compile
   [INFO] |  +- org.apache.shardingsphere:shardingsphere-sql-federation-core:jar:5.5.3:compile
   [INFO] |  |  \- org.apache.shardingsphere:shardingsphere-sql-federation-executor:jar:5.5.3:compile
   [INFO] |  |     +- org.apache.shardingsphere:shardingsphere-sql-federation-compiler:jar:5.5.3:compile
   [INFO] |  |     |  +- org.apache.calcite:calcite-core:jar:1.40.0:compile
   [INFO] |  |     |  |  +- org.apache.calcite:calcite-linq4j:jar:1.40.0:compile
   [INFO] |  |     |  |  +- org.locationtech.jts:jts-core:jar:1.19.0:compile
   [INFO] |  |     |  |  +- org.locationtech.jts.io:jts-io-common:jar:1.19.0:compile
   [INFO] |  |     |  |  |  \- com.googlecode.json-simple:json-simple:jar:1.1.1:compile
   [INFO] |  |     |  |  +- org.locationtech.proj4j:proj4j:jar:1.2.2:compile
   [INFO] |  |     |  |  +- org.apache.calcite.avatica:avatica-core:jar:1.26.0:compile
   [INFO] |  |     |  |  +- com.google.uzaygezen:uzaygezen-core:jar:0.2:runtime
   [INFO] |  |     |  |  +- com.yahoo.datasketches:sketches-core:jar:0.9.0:runtime
   [INFO] |  |     |  |  |  \- com.yahoo.datasketches:memory:jar:0.9.0:runtime
   [INFO] |  |     |  |  +- commons-codec:commons-codec:jar:1.18.0:runtime
   [INFO] |  |     |  |  +- net.hydromatic:aggdesigner-algorithm:jar:6.0:runtime
   [INFO] |  |     |  |  |  \- commons-lang:commons-lang:jar:2.4:runtime
   [INFO] |  |     |  |  +- org.apache.commons:commons-math3:jar:3.6.1:runtime
   [INFO] |  |     |  |  +- org.apache.commons:commons-text:jar:1.11.0:runtime
   [INFO] |  |     |  |  +- org.codehaus.janino:commons-compiler:jar:3.1.12:runtime
   [INFO] |  |     |  |  \- org.codehaus.janino:janino:jar:3.1.12:runtime
   [INFO] |  |     |  \- com.jayway.jsonpath:json-path:jar:2.9.0:compile
   [INFO] |  |     |     \- net.minidev:json-smart:jar:2.5.2:runtime
   [INFO] |  |     |        \- net.minidev:accessors-smart:jar:2.5.2:runtime
   [INFO] |  |     |           \- org.ow2.asm:asm:jar:9.7.1:runtime
   [INFO] |  |     \- org.apache.shardingsphere:shardingsphere-infra-merge:jar:5.5.3:compile
   [INFO] |  +- org.apache.shardingsphere:shardingsphere-sql-parser-core:jar:5.5.3:compile
   [INFO] |  |  +- org.apache.shardingsphere:shardingsphere-sql-parser-api:jar:5.5.3:compile
   [INFO] |  |  \- org.apache.shardingsphere:shardingsphere-infra-parser:jar:5.5.3:compile
   [INFO] |  |     +- org.apache.shardingsphere:shardingsphere-parser-distsql-engine:jar:5.5.3:compile
   [INFO] |  |     |  \- org.apache.shardingsphere:shardingsphere-parser-distsql-statement:jar:5.5.3:compile
   [INFO] |  |     \- org.apache.shardingsphere:shardingsphere-database-exception-core:jar:5.5.3:compile
   [INFO] |  +- org.apache.shardingsphere:shardingsphere-database-connector-h2:jar:5.5.3:compile
   [INFO] |  |  \- org.apache.shardingsphere:shardingsphere-database-connector-core:jar:5.5.3:compile
   [INFO] |  |     +- org.apache.shardingsphere:shardingsphere-infra-spi:jar:5.5.3:compile
   [INFO] |  |     |  \- org.apache.shardingsphere:shardingsphere-infra-exception:jar:5.5.3:compile
   [INFO] |  |     |     \- org.apache.shardingsphere:shardingsphere-infra-annotation:jar:5.5.3:compile
   [INFO] |  |     \- org.apache.shardingsphere:shardingsphere-infra-util:jar:5.5.3:compile
   [INFO] |  +- com.google.guava:guava:jar:33.4.6-jre:compile
   [INFO] |  |  +- com.google.guava:failureaccess:jar:1.0.3:compile
   [INFO] |  |  \- org.jspecify:jspecify:jar:1.0.0:compile
   [INFO] |  +- com.cedarsoftware:java-util:jar:4.90.0:compile
   [INFO] |  \- org.slf4j:slf4j-api:jar:2.0.17:compile
   [INFO] +- org.apache.shardingsphere:shardingsphere-sharding-api:jar:5.5.3:compile
   [INFO] |  +- org.apache.shardingsphere:shardingsphere-infra-algorithm-core:jar:5.5.3:compile
   [INFO] |  \- org.apache.shardingsphere:shardingsphere-infra-binder-core:jar:5.5.3:compile
   [INFO] +- org.apache.shardingsphere:shardingsphere-readwrite-splitting-api:jar:5.5.3:compile
   [INFO] +- org.apache.shardingsphere:shardingsphere-infra-data-source-pool-hikari:jar:5.5.3:compile
   [INFO] |  \- org.apache.shardingsphere:shardingsphere-infra-data-source-pool-core:jar:5.5.3:compile
   [INFO] +- org.apache.shardingsphere:shardingsphere-mode-core:jar:5.5.3:compile
   [INFO] |  +- org.apache.shardingsphere:shardingsphere-mode-node:jar:5.5.3:compile
   [INFO] |  |  \- org.apache.shardingsphere:shardingsphere-infra-common:jar:5.5.3:compile
   [INFO] |  |     \- org.apache.shardingsphere:shardingsphere-database-connector-sql92:jar:5.5.3:compile
   [INFO] |  \- org.apache.shardingsphere:shardingsphere-single-api:jar:5.5.3:compile
   [INFO] +- org.apache.shardingsphere:shardingsphere-standalone-mode-repository-memory:jar:5.5.3:compile
   [INFO] |  +- org.apache.shardingsphere:shardingsphere-standalone-mode-repository-api:jar:5.5.3:compile
   [INFO] |  \- org.apache.shardingsphere:shardingsphere-standalone-mode-core:jar:5.5.3:compile
   [INFO] +- org.apache.shardingsphere:shardingsphere-authority-simple:jar:5.5.3:compile
   [INFO] +- org.apache.shardingsphere:shardingsphere-parser-sql-engine-mysql:jar:5.5.3:compile
   [INFO] |  +- org.apache.shardingsphere:shardingsphere-database-connector-mysql:jar:5.5.3:compile
   [INFO] |  +- org.apache.shardingsphere:shardingsphere-parser-sql-statement-mysql:jar:5.5.3:compile
   [INFO] |  |  \- org.apache.shardingsphere:shardingsphere-parser-sql-statement-core:jar:5.5.3:compile
   [INFO] |  |     \- org.apache.groovy:groovy:jar:4.0.29:compile
   [INFO] |  \- org.apache.shardingsphere:shardingsphere-parser-sql-engine-core:jar:5.5.3:compile
   [INFO] |     +- org.apache.shardingsphere:shardingsphere-parser-sql-spi:jar:5.5.3:compile
   [INFO] |     \- com.github.ben-manes.caffeine:caffeine:jar:3.2.3:compile
   [INFO] +- com.google.code.gson:gson:jar:2.13.2:compile
   [INFO] |  \- com.google.errorprone:error_prone_annotations:jar:2.41.0:compile
   [INFO] +- junit:junit:jar:4.13.2:test
   [INFO] |  \- org.hamcrest:hamcrest-core:jar:3.0:test
   [INFO] |     \- org.hamcrest:hamcrest:jar:3.0:test
   [INFO] +- com.jch.iot.vcc:common:jar:0.0.1-SNAPSHOT:compile
   [INFO] |  +- org.springframework.boot:spring-boot-starter-validation:jar:3.5.8:compile
   [INFO] |  |  \- org.hibernate.validator:hibernate-validator:jar:8.0.3.Final:compile
   [INFO] |  |     \- jakarta.validation:jakarta.validation-api:jar:3.0.2:compile
   [INFO] |  +- org.springframework.boot:spring-boot-starter-data-rest:jar:3.5.8:compile
   [INFO] |  |  \- org.springframework.data:spring-data-rest-webmvc:jar:4.5.6:compile
   [INFO] |  |     \- org.springframework.data:spring-data-rest-core:jar:4.5.6:compile
   [INFO] |  |        +- org.springframework.hateoas:spring-hateoas:jar:2.5.1:compile
   [INFO] |  |        +- org.springframework.plugin:spring-plugin-core:jar:3.0.0:compile
   [INFO] |  |        \- org.atteo:evo-inflector:jar:1.3:compile
   [INFO] |  +- com.mysql:mysql-connector-j:jar:9.5.0:compile
   [INFO] |  +- org.json:json:jar:20251224:compile
   [INFO] |  +- io.jsonwebtoken:jjwt-api:jar:0.13.0:compile
   [INFO] |  +- io.jsonwebtoken:jjwt-impl:jar:0.13.0:runtime
   [INFO] |  +- io.jsonwebtoken:jjwt-jackson:jar:0.13.0:runtime
   [INFO] |  +- org.modelmapper:modelmapper:jar:2.3.0:compile
   [INFO] |  +- com.squareup.okhttp3:okhttp:jar:4.12.0:compile
   [INFO] |  |  +- com.squareup.okio:okio:jar:3.6.0:compile
   [INFO] |  |  |  \- com.squareup.okio:okio-jvm:jar:3.6.0:compile
   [INFO] |  |  |     \- org.jetbrains.kotlin:kotlin-stdlib-common:jar:1.9.25:compile
   [INFO] |  |  \- org.jetbrains.kotlin:kotlin-stdlib-jdk8:jar:1.9.25:compile
   [INFO] |  |     +- org.jetbrains.kotlin:kotlin-stdlib:jar:1.9.25:compile
   [INFO] |  |     |  \- org.jetbrains:annotations:jar:13.0:compile
   [INFO] |  |     \- org.jetbrains.kotlin:kotlin-stdlib-jdk7:jar:1.9.25:compile
   [INFO] |  +- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.19.4:compile
   [INFO] |  +- org.apache.commons:commons-collections4:jar:4.4:compile
   [INFO] |  +- io.swagger.core.v3:swagger-annotations:jar:2.2.41:compile
   [INFO] |  \- org.springframework.boot:spring-boot-starter-parent:pom:4.0.7:compile
   [INFO] +- org.springframework.boot:spring-boot-starter-cache:jar:3.5.8:compile
   [INFO] |  \- org.springframework:spring-context-support:jar:6.2.14:compile
   [INFO] +- jakarta.activation:jakarta.activation-api:jar:2.1.4:compile
   [INFO] +- commons-validator:commons-validator:jar:1.10.1:compile
   [INFO] |  +- commons-beanutils:commons-beanutils:jar:1.11.0:compile
   [INFO] |  +- commons-digester:commons-digester:jar:2.1:compile
   [INFO] |  +- commons-logging:commons-logging:jar:1.3.5:compile
   [INFO] |  \- commons-collections:commons-collections:jar:3.2.2:compile
   [INFO] +- jakarta.servlet:jakarta.servlet-api:jar:6.0.0:provided
   [INFO] +- org.springframework.boot:spring-boot-starter-log4j2:jar:3.5.8:compile
   [INFO] |  +- org.apache.logging.log4j:log4j-slf4j2-impl:jar:2.26.0:compile
   [INFO] |  |  \- org.apache.logging.log4j:log4j-api:jar:2.26.0:compile
   [INFO] |  +- org.apache.logging.log4j:log4j-core:jar:2.26.0:compile
   [INFO] |  \- org.apache.logging.log4j:log4j-jul:jar:2.26.0:compile
   [INFO] +- jakarta.xml.bind:jakarta.xml.bind-api:jar:4.0.4:compile
   [INFO] \- org.bouncycastle:bcprov-jdk18on:jar:1.84:compile`
   Expected Behavior
   SELECT queries should go to read replicas (slaves)
   INSERT/UPDATE/DELETE should go to master
   Sharded tables should be correctly resolved and found
   
   Actual Behavior
   All queries are routed incorrectly (either all to master or all to slave)
   Sharded tables are reported as missing during execution
   
   Environment
   Framework: spring boot 3.5.8
   Sharding library: 5.5.3
   Database: mysql
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Read/Write splitting not working and sharding tables not found errors in Sharding setup [shardingsphere]

Posted by "Nilesh18398 (via GitHub)" <gi...@apache.org>.
Nilesh18398 closed issue #38955: Read/Write splitting not working and sharding tables not found errors in Sharding setup
URL: https://github.com/apache/shardingsphere/issues/38955


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Read/Write splitting not working and sharding tables not found errors in Sharding setup [shardingsphere]

Posted by "terrymanu (via GitHub)" <gi...@apache.org>.
terrymanu commented on issue #38955:
URL: https://github.com/apache/shardingsphere/issues/38955#issuecomment-4881250116

   Hi @Nilesh18398, thanks for the detailed config.
   
   This does not look like a confirmed ShardingSphere bug from the current evidence; it is currently a configuration/usage issue. Sharding, read/write splitting, and single tables can be used together, but the posted sharding rule is inconsistent: the table strategy is configured with `order_id`, while the `INLINE` expression uses `thing_id`. In ShardingSphere 5.5.3 the inline algorithm evaluates the expression with the configured sharding column name, so those values must match.
   
   For read/write splitting, writes should still route to the write data source by SQL type. The part that can look surprising is `TransactionalReadQueryStrategy.DYNAMIC`: transactional reads can be routed through the read load balancer, and the docs say `FIXED`/`DYNAMIC` require strong primary-replica synchronization. For a normal MySQL primary/replica setup, please use the default/`PRIMARY` transactional read strategy unless that guarantee exists.
   
   Please align the sharding column and inline expression, verify that physical tables `order_1` through `order_24` exist and are visible through the `readwrite_ds` group metadata, and then retest with `sql-show` output. I suggest labeling this as `type: question` and `status: invalid` for now. If the same behavior remains after the configuration is corrected, please provide the exact SQL, full `sql-show` route logs, table DDL, and the physical table list from the write and read data sources so we can classify a possible bug.
   
   Community members are also welcome to share a minimal Java API example for this sharding + read/write splitting shape.
   
   The reply above is based on the analysis below; the detailed reasoning is kept here for reference and follow-up contributors.
   
   ### Problem Understanding
   
   - **Issue:** `apache/shardingsphere#38955` reports JDBC read/write splitting routing surprises and `TableNotFoundException: Table or view 'order' does not exist` with `shardingsphere-jdbc:5.5.3`. Source: https://github.com/apache/shardingsphere/issues/38955 (`OBS-1`)
   - **Topology:** JDBC + Standalone; registry/config center: N/A; database: MySQL; framework path includes Spring Data JPA/Hibernate. Source: issue body and stack trace (`OBS-1`)
   - **Observed Evidence:** The config creates `readwrite_ds` from `ds_master` and `ds_slave`, uses `TransactionalReadQueryStrategy.DYNAMIC`, defines logic table `order` with actual nodes `readwrite_ds.order_$->{1..24}`, sets table sharding column `order_id`, and defines inline expression `order_${(thing_id.hashCode() & Integer.MAX_VALUE) % 24 + 1}`. Source: issue body (`OBS-2`)
   
   ### Root Cause
   
   - **Observation:** The ShardingSphere 5.5.3 Java API docs define `logicTable`, `actualDataNodes`, and `tableShardingStrategy`, and the standard sharding strategy has `shardingColumn` plus `shardingAlgorithmName`. Source: https://shardingsphere.apache.org/document/5.5.3/en/user-manual/shardingsphere-jdbc/java-api/rules/sharding/ (`OBS-3`)
   - **Observation:** In 5.5.3, `InlineShardingAlgorithm` checks that the inline expression contains the configured sharding column and evaluates the expression with only that column name as the variable. Source: `features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/inline/InlineShardingAlgorithm.java:66` to `:73` (`OBS-4`)
   - **Observation:** In 5.5.3, `SimpleTableSegmentBinder` throws `TableNotFoundException` when the ShardingSphere schema metadata does not contain the referenced table. Source: `infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/dml/from/type/SimpleTableSegmentBinder.java:93` to `:95`, `:187` (`OBS-5`)
   - **Inference:** Because the strategy column is `order_id` but the inline expression references `thing_id`, the table sharding rule is misconfigured. If the intended sharding key is `thing_id`, the strategy column should be `thing_id`; if the intended key is `order_id`, the inline expression should use `order_id`. (`INF-1`, from `OBS-2`, `OBS-3`, `OBS-4`)
   - **Confidence:** High for the inline sharding mismatch; Medium for the exact metadata-loading cause because the issue does not include physical table DDL or a complete table inventory.
   
   ### Problem Analysis
   
   - **Issue Type:** Misunderstanding / Invalid Usage
   - **Evidence:** Read/write splitting group names can be used as sharding actual data node prefixes in project tests. Source: `test/e2e/sql/src/test/resources/env/scenario/readwrite_splitting/jdbc/conf/mysql/rules.yaml:55` to `:83` (`OBS-6`)
   - **Evidence:** Readwrite-splitting maps a logical group name to all physical write/read data sources, and the physical data source aggregator replaces those physical names with the group where appropriate. Sources: `features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/attribute/ReadwriteSplittingDataSourceMapperRuleAttribute.java:39` to `:43`, `infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/PhysicalDataSourceAggregator.java:45` to `:66` (`OBS-7`)
   - **Evidence:** Non-`SELECT` statements are primary-route statements in read/write splitting, while transactional reads with `DYNAMIC` use the standard read route. Sources: `features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/route/qualified/type/QualifiedReadwriteSplittingPrimaryDataSourceRouter.java:39` to `:45`, `features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/route/qualified/type/QualifiedReadwriteSplittingTransactionalDataSourceRouter.java:45` to `:55`, `features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/route/standard/StandardReadwriteSplittingDataSourceRouter.java:41` to `:42` (`OBS-8`)
   - **Evidence:** The docs state that `DYNAMIC` and `FIXED` transactional read strategies require strong primary-replica synchronization, such as openGauss. Source: https://shardingsphere.apache.org/document/current/en/user-manual/shardingsphere-jdbc/java-api/rules/readwrite-splitting/ (`OBS-9`)
   - **Duplicate / Prior Fix Check:** Same-repository search found no exact duplicate or fixing PR. #33709 has a similar `TableNotFoundException` symptom but different configuration and was closed as `status: need more info`, so it should not be used as a duplicate. (`OBS-10`)
   - **Label Recommendation:** `type: question`, `status: invalid`
   
   ### Problem Conclusion
   
   - **Evidence Confidence:** Medium
   - **Impact Scope:** Single JDBC application configuration; sharding table `order`; read/write splitting group `readwrite_ds`; MySQL primary/replica behavior inside transactions
   - **Topology:** JDBC + Standalone; registry/config center: N/A
   - **Issue Type:** Misunderstanding / Invalid Usage
   - **Recommended Labels:** `type: question`, `status: invalid`
   - **Next Action:** Correct the sharding column/expression mismatch, use `PRIMARY` transactional read strategy unless strong replication consistency is guaranteed, verify that `order_1` through `order_24` exist and are visible through `readwrite_ds`, then provide exact SQL plus `sql-show` logs if the corrected setup still fails.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org