You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "qichanglong (via GitHub)" <gi...@apache.org> on 2023/12/14 03:32:36 UTC
[I] How to read the master data rather than slave in one Transaction? [shardingsphere]
qichanglong opened a new issue, #29400:
URL: https://github.com/apache/shardingsphere/issues/29400
## Bug Report
**For English only**, other languages will not accept.
Before report a bug, make sure you have:
- Searched open and closed [GitHub issues](https://github.com/apache/shardingsphere/issues).
- Read documentation: [ShardingSphere Doc](https://shardingsphere.apache.org/document/current/en/overview).
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**.
Please answer these questions before submitting your issue. Thanks!
### Which version of ShardingSphere did you use?
5.4.0
### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
shardingSphere-jdbc
### Expected behavior
In one Transaction, before the insert data is commit in master db, the following read is also from **master**
### Actual behavior
In one Transaction, before the insert data is commit in master db, the following read is from **salve**, which lead to an empty result.
### Reason analyze (If you can)
the @Transactional annotation works, becase when an Exception occurs, the uncommit insert data is rollback。
but it turns out that the shardingSphere still read from the slave in one transaction.
### Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.
### Example codes for reproduce this issue (such as a github link).
The code is as following:
1. introduce the shardingSphere-jdbc 5.4.0
```
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-jdbc-core</artifactId>
<version>${shardingsphere.version}</version>
</dependency>
```
2. produce **shardingJdbcDatasource** bean in the way of java api
```
@Bean
public DataSource shardingSphereDataSource() throws SQLException {
ReadwriteSplittingDataSourceRuleConfiguration dataSourceConfig =
new ReadwriteSplittingDataSourceRuleConfiguration(
SHARDING_DS_NAME, SHARDING_JDBC_MASTER, Arrays.asList(SHARDING_JDBC_SLAVE),
SHARDING_LOAD_BALANCE_NAME);
Properties algorithmProps = new Properties();
algorithmProps.setProperty(SHARDING_JDBC_SLAVE, "1");
Map<String, AlgorithmConfiguration> algorithmConfigMap = new HashMap<>(1);
algorithmConfigMap.put(SHARDING_LOAD_BALANCE_NAME, new AlgorithmConfiguration(SHARDING_LOAD_BALANCE_TYPE,
algorithmProps));
ReadwriteSplittingRuleConfiguration ruleConfig =
new ReadwriteSplittingRuleConfiguration(Collections.singleton(dataSourceConfig), algorithmConfigMap);
Properties props = new Properties();
props.setProperty("sql-show", showSql);
return ShardingSphereDataSourceFactory.createDataSource(createDataSourceMap(),
Collections.singleton(ruleConfig), props);
}
```
3. config sqlSessionFactory and transactionManager in spring-context.xml
```
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="shardingSphereDataSource" />
</bean>
```
```
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="shardingSphereDataSource" />
<property name="typeAliasesPackage" value="com.thinkgem.jeesite,com.saj.commons,com.saj.appapi" />
<property name="typeAliasesSuperType"
value="com.thinkgem.jeesite.common.persistence.BaseEntity" />
<property name="mapperLocations" value="classpath:/mappings/**/*.xml" />
<property name="configLocation" value="classpath:/mybatis-config.xml"></property>
</bean>
```
--
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] How to read the master data rather than slave in one Transaction? [shardingsphere]
Posted by "niaucz (via GitHub)" <gi...@apache.org>.
niaucz commented on issue #29400:
URL: https://github.com/apache/shardingsphere/issues/29400#issuecomment-1867186285
[transactionalReadQueryStrategy ](https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/yaml-config/rules/readwrite-splitting/)
--
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] How to read the master data rather than slave in one Transaction? [shardingsphere]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on issue #29400:
URL: https://github.com/apache/shardingsphere/issues/29400#issuecomment-1908833765
There hasn't been any activity on this issue recently, and in order to prioritize active issues, it will be marked as stale.
--
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] How to read the master data rather than slave in one Transaction? [shardingsphere]
Posted by "terrymanu (via GitHub)" <gi...@apache.org>.
terrymanu closed issue #29400: How to read the master data rather than slave in one Transaction?
URL: https://github.com/apache/shardingsphere/issues/29400
--
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] How to read the master data rather than slave in one Transaction? [shardingsphere]
Posted by "qichanglong (via GitHub)" <gi...@apache.org>.
qichanglong commented on issue #29400:
URL: https://github.com/apache/shardingsphere/issues/29400#issuecomment-1868933469
> [transactionalReadQueryStrategy ](https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/yaml-config/rules/readwrite-splitting/)
thank you, problem solved!
--
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