You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "longkaimao (via GitHub)" <gi...@apache.org> on 2023/03/14 06:17:44 UTC
[GitHub] [shardingsphere] longkaimao opened a new issue, #24586: How to configure 'seata.enable-auto-data-source-proxy' when using shardingsphere?
longkaimao opened a new issue, #24586:
URL: https://github.com/apache/shardingsphere/issues/24586
version:5.2.0
I am using shardingsphere5.2.0 + Seata1.6.0 for my code,if I configure seata.enable-auto-data-source-proxy=false,then the branch trancaction report a NullPointException error, which from SeataTransactionHolder.get().
`java.lang.NullPointerException: null
at org.apache.shardingsphere.transaction.base.seata.at.SeataATShardingTransactionManager.commit(SeataATShardingTransactionManager.java:110) ~`
If configure seata.enable-auto-data-source-proxy=true,then everything looks fine.
But I see the following samples:
https://github.com/seata/seata-samples/module:springcloud-seata-sharding-jdbc-mybatis-plus-samples
This sample configure seata.enable-auto-data-source-proxy=false
So,how do Iconfigure it?
thanks!
--
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
[GitHub] [shardingsphere] longkaimao commented on issue #24586: How to configure 'seata.enable-auto-data-source-proxy' when using shardingsphere?
Posted by "longkaimao (via GitHub)" <gi...@apache.org>.
longkaimao commented on issue #24586:
URL: https://github.com/apache/shardingsphere/issues/24586#issuecomment-1468320341
The NullPointException problem is the same as this issues #22356,but it looks like that issues hasn't been solved yet.
--
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
[GitHub] [shardingsphere] longkaimao commented on issue #24586: How to configure 'seata.enable-auto-data-source-proxy' when using shardingsphere?
Posted by "longkaimao (via GitHub)" <gi...@apache.org>.
longkaimao commented on issue #24586:
URL: https://github.com/apache/shardingsphere/issues/24586#issuecomment-1468100339
The following is my main code
- GlobalTransaction code
` @Transactional(rollbackFor = Exception.class)
@ShardingTransactionType(value = TransactionType.BASE)
public boolean add(OrderAddReq req) {
log.info("Seata全局事务id=================>{}", RootContext.getXID());
OrderEntity order = new OrderEntity();
order.setProductId(req.getProductId());
order.setMoney(req.getMoney());
order.setUserId(req.getUserId());
order.setCount(req.getCount());
order.setStatus(0);
this.baseOrderService.save(order);
AccountOpReq accountOpReq = new AccountOpReq();
accountOpReq.setUserId(req.getUserId());
accountOpReq.setMoney(req.getMoney());
Result<?> result = accountApi.accountOp(accountOpReq);
if(!result.success()){
throw new BaseFlowException(result.getMsg());
}
if(req.getCount() == 10000){
int i = 1/0;
}
return true;
}
`
- branch transaction code
1. seata config in bootstrap.yml
`
sfs:
nacos:
server-addr: ${spring.cloud.nacos.discovery.server-addr}
namespace: seata-server-160
group: SEATA_GROUP
seata:
enabled: true
application-id : ${spring.application.name}
tx-service-group: default_tx_group
use-jdk-proxy: true
enable-auto-data-source-proxy: true
registry:
type: nacos
nacos:
application: seata-server
server-addr: ${sfs.nacos.server-addr}
namespace: ${sfs.nacos.namespace}
group: ${sfs.nacos.group}
config:
type: nacos
nacos:
server-addr: ${sfs.nacos.server-addr}
namespace: ${sfs.nacos.namespace}
group: ${sfs.nacos.group}
data-id: seataServer.properties
service:
vgroupMapping:
default_tx_group: default`
2. sharding config
`#账号微服务服务信息-分库又分表
server.port=9220
spring.application.name=account
#订单微服务注册中心
spring.cloud.nacos.discovery.server-addr=82.157.70.56:8848
spring.cloud.nacos.discovery.group=DEFAULT_GROUP
spring.cloud.nacos.discovery.namespace=public
spring.cloud.nacos.discovery.username=nacos
spring.cloud.nacos.discovery.password=lkmNacos
#sharding-jdbc数据源配置
spring.shardingsphere.datasource.names=ds-0,ds-1
spring.shardingsphere.mode.type=Standalone
#spring.shardingsphere.mode.repository.type=File
spring.shardingsphere.mode.overwrite=true
spring.shardingsphere.datasource.ds-0.type=com.zaxxer.hikari.HikariDataSource
spring.shardingsphere.datasource.ds-0.driver-class-name=com.mysql.cj.jdbc.Driver
spring.shardingsphere.datasource.ds-0.jdbc-url=jdbc:mysql://82.157.70.56:3306/seata-account-0?serverTimezone=UTC&characterEncoding=utf8
spring.shardingsphere.datasource.ds-0.username=root
spring.shardingsphere.datasource.ds-0.password=l
spring.shardingsphere.datasource.ds-1.type=com.zaxxer.hikari.HikariDataSource
spring.shardingsphere.datasource.ds-1.driver-class-name=com.mysql.cj.jdbc.Driver
spring.shardingsphere.datasource.ds-1.jdbc-url=jdbc:mysql://82.157.70.56:3306/seata-account-1?serverTimezone=UTC&characterEncoding=utf8
spring.shardingsphere.datasource.ds-1.username=root
spring.shardingsphere.datasource.ds-1.password=l
#sharding-jdbc分片配置
spring.shardingsphere.rules.sharding.default-database-strategy.standard.sharding-column=id
spring.shardingsphere.rules.sharding.default-database-strategy.standard.sharding-algorithm-name=database-inline
spring.shardingsphere.rules.sharding.binding-tables[0]=t_account
#spring.shardingsphere.rules.sharding.broadcast-tables=t_address
spring.shardingsphere.rules.sharding.tables.t_account.actual-data-nodes=ds-$->{0..1}.t_account_$->{0..2}
spring.shardingsphere.rules.sharding.tables.t_account.table-strategy.standard.sharding-column=id
spring.shardingsphere.rules.sharding.tables.t_account.table-strategy.standard.sharding-algorithm-name=t-account-inline
spring.shardingsphere.rules.sharding.tables.t_account.key-generate-strategy.column=id
spring.shardingsphere.rules.sharding.tables.t_account.key-generate-strategy.key-generator-name=snowflake
spring.shardingsphere.rules.sharding.sharding-algorithms.database-inline.type=INLINE
spring.shardingsphere.rules.sharding.sharding-algorithms.database-inline.props.algorithm-expression=ds-$->{id % 2}
spring.shardingsphere.rules.sharding.sharding-algorithms.t-account-inline.type=INLINE
spring.shardingsphere.rules.sharding.sharding-algorithms.t-account-inline.props.algorithm-expression=t_account_$->{id % 3}
spring.shardingsphere.rules.sharding.key-generators.snowflake.type=SNOWFLAKE
#sharding-jdbc显示最终SQL
spring.shardingsphere.props.sql.show=true
#mybatis-plus配置
mybatis-plus.configuration.map-underscore-to-camel-case=true
logging.level.io.seata=info
`
3. branch transaction code
`@Service
@Slf4j
public class AccountService {
@Resource
IBaseAccountService baseAccountService;
public List<AccountEntity> list(){
return baseAccountService.list();
}
/**
* 以下在enable-auto-data-source-proxy开启和关闭的情况下,是否使用注解Transactional和ShardingSphereTransactionType,对事务回滚的结果
* enable-auto-data-source-proxy @Transactional @ShardingSphereTransactionType 结果
* true 有 无 回滚成功
* false 无 有 回滚成功
* false 有 无 分支事务没有回滚
* false 有 有 空指针异常
* true 有 有 空指针异常
* true 无 有 空指针异常
*
* @param req
*/
@Transactional(rollbackFor = Exception.class)
// @ShardingSphereTransactionType(value = TransactionType.BASE)
public void op(AccountOpReq req) {
log.info("Seata全局事务id=================>{}", RootContext.getXID());
AccountEntity byUserId = new AccountEntity();
byUserId.setUserId(req.getUserId());
byUserId.setUsed(new BigDecimal(1000L));
byUserId.setResidue(req.getMoney());
this.baseAccountService.save(byUserId);
}
}`
--
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
[GitHub] [shardingsphere] sandynz commented on issue #24586: How to configure 'seata.enable-auto-data-source-proxy' when using shardingsphere?
Posted by "sandynz (via GitHub)" <gi...@apache.org>.
sandynz commented on issue #24586:
URL: https://github.com/apache/shardingsphere/issues/24586#issuecomment-1467957405
Hi @longkaimao , thanks for your feedback. Could you supply a demo project to reproduce it?
--
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 configure 'seata.enable-auto-data-source-proxy' when using shardingsphere? [shardingsphere]
Posted by "waxJava2615 (via GitHub)" <gi...@apache.org>.
waxJava2615 commented on issue #24586:
URL: https://github.com/apache/shardingsphere/issues/24586#issuecomment-1853225361
I have the same problem
--
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
[GitHub] [shardingsphere] freshchen commented on issue #24586: How to configure 'seata.enable-auto-data-source-proxy' when using shardingsphere?
Posted by "freshchen (via GitHub)" <gi...@apache.org>.
freshchen commented on issue #24586:
URL: https://github.com/apache/shardingsphere/issues/24586#issuecomment-1658702599
今天我遇到了类似问题,报错但是不影响回滚,主要是只有开启全局事务的服务(TM)能正常运行,其余的 RM 获取不到就报空指针
解决方式:自己重写下 SeataATShardingSphereTransactionManager 的 commit 和 rollback 方法在 SeataTransactionHolder get 的时候都需要判空后再执行对应的 commit 或者 rollback
--
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
[GitHub] [shardingsphere] github-actions[bot] commented on issue #24586: How to configure 'seata.enable-auto-data-source-proxy' when using shardingsphere?
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on issue #24586:
URL: https://github.com/apache/shardingsphere/issues/24586#issuecomment-1699769129
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
[GitHub] [shardingsphere] sandynz commented on issue #24586: How to configure 'seata.enable-auto-data-source-proxy' when using shardingsphere?
Posted by "sandynz (via GitHub)" <gi...@apache.org>.
sandynz commented on issue #24586:
URL: https://github.com/apache/shardingsphere/issues/24586#issuecomment-1467958584
Hi @FlyingZC , could you help to have a look at it?
--
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
[GitHub] [shardingsphere] longkaimao commented on issue #24586: How to configure 'seata.enable-auto-data-source-proxy' when using shardingsphere?
Posted by "longkaimao (via GitHub)" <gi...@apache.org>.
longkaimao commented on issue #24586:
URL: https://github.com/apache/shardingsphere/issues/24586#issuecomment-1468279761
@FlyingZC @sandynz please help me to have a look.Thanks a lot.
--
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 configure 'seata.enable-auto-data-source-proxy' when using shardingsphere? [shardingsphere]
Posted by "linghengqian (via GitHub)" <gi...@apache.org>.
linghengqian commented on issue #24586:
URL: https://github.com/apache/shardingsphere/issues/24586#issuecomment-1948757105
- I believe this is essentially a duplicate of https://github.com/apache/shardingsphere/issues/22356#issuecomment-1948463141 , and the use of annotations within `io.seata:seata-spring-boot-starter` should be avoided, including `io.seata.spring.annotation.GlobalTransactional`.
- I believe this issue involves adjustments to the Spring Boot Starter side of Seata.
--
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