springboot +sharding-jdbc5.3.2 + seata + dubblo + nacos 分表分库插入语句失败

方便更快捷的说明问题,可以按需填写(可删除)

使用环境:

springboot 2.1.3-release
nacos 2.1.2
seata 1.7
sharding-jdbc 5.3.2
dubbo 3.0.5
mysql 8

场景、问题:

实现在一个微服务A中的接口中 通过dubbo调用 另一个微服务B的保存接口,微服务B的保存表是通过shardingjdbc实现分表的,在微服务A的接口上加了@Transactional事务接口,现在调用保存微服务B,会报错:
ERROR i.s.r.d.s.s.c.AbstractTableMetaCache - get table meta of the table “逻辑表表名” error: Failed to fetch schema of “逻辑表表名”
java.sql.SQLException: Failed to fetch schema of “逻辑表表名”

下面给出微服务B的sharding.yaml的配置
dataSources:
db1:
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
driverClassName: com.mysql.cj.jdbc.Driver
jdbcUrl: jdbc:mysql://127.0.0.1:3306/db?characterEncoding=UTF-8&useUnicode=true&useSSL=false&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai&useInformationSchema=true&allowMultiQueries=true
username: root
password: root
connectionTimeoutMilliseconds: 30000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 50
minPoolSize: 1

#行表达式配置 – 固定配置分片表,固定分片键
rules:

  • !SHARDING
    tables:
    mp_plan_base:
    actualDataNodes: db1.mp_plan_base_$->{1…3}
    tableStrategy:
    standard:
    shardingColumn: plan_type
    shardingAlgorithmName: plan_type_inline
    shardingAlgorithms:
    plan_type_inline:
    type: INLINE
    props:
    algorithm-expression: mp_plan_base_$->{plan_type}

下面给出微服务B的application.yml的seata配置:

seata:
spring-cloud-alibaba-seata:
enabled: true
enabled: true
enable-auto-data-source-proxy: true #开启数据库代理
tx-service-group: my_test_tx_group #此处配置自定义的seata事务分组名称
service:
vgroupMapping:
my_test_tx_group: default
group-default:
default:
defaultGlobalTransactionTimeout: 60000
config:
type: nacos
nacos:
server-addr: ${NACOS_ADDRESS:127.0.0.1:8848}
group: SEATA_GROUP
namespace: 68159e00-9aa2-468a-bbed-e716245cb960
username: nacos
password: nacos
data-id: seataServer.properties
registry:
type: nacos
nacos:
application: seata-server
server-addr: ${NACOS_ADDRESS:127.0.0.1:8848}
group: SEATA_GROUP
namespace: 68159e00-9aa2-468a-bbed-e716245cb960
username: nacos
password: nacos

微服务A sharding.yaml配置

dataSources:
db1:
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
driverClassName: com.mysql.cj.jdbc.Driver
jdbcUrl: jdbc:mysql://127.0.0.1:3306/db2?characterEncoding=UTF-8&useUnicode=true&useSSL=false&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai&useInformationSchema=false&allowMultiQueries=true
username: root
password: root
connectionTimeoutMilliseconds: 30000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 50
minPoolSize: 1

rules:

  • !TRANSACTION
    defaultType: BASE
    providerType: Seata

已进行操作:

调用的方法
//@GlobalTransactional
@Transactional
public void insertOne(MpPlanMpsDTO mpPlanMpsDTO) {

    //TransactionTypeHolder.set(TransactionType.BASE);
    String xid = RootContext.getXID();
    logger.info("mp_plan_mps 全局事务 xid:{}", xid);





    MpPlanBaseDTO mpPlanBaseDTO = new MpPlanBaseDTO();
    MmsBeanCopierUtil.copy(mpPlanMpsDTO.getBaseData(), mpPlanBaseDTO);
    mpPlanBaseDTO.setCreatedBy("1");
    mpPlanBaseDTO.setCreatedDept("1");
    mpPlanBaseDTO.setCreationDate(new Date());
    mpPlanBaseDTO.setLastUpdatedBy("1");
    mpPlanBaseDTO.setLastUpdateDate(new Date());
    mpPlanBaseDTO.setLastUpdateIp("10.216.91.64");
    mpPlanBaseDTO.setOrgIdentity("1");
    mpPlanBaseDTO.setSecretLevel("1");
    mpPlanBaseDTO.setVersion(1L);
    mpPlanBaseDTO.setTenantId("1");
   //dubbo保存接口
    mpPlanBaseDubboService.insertOne(mpPlanBaseDTO);
    logger.info("mp_plan_base INSERT SUCCESS");

    if (true) {
        int i= 1/0;
    }

    logger.info("mp_plan_mps end");

}

现状:

现在调用保存微服务B,会报错:
ERROR i.s.r.d.s.s.c.AbstractTableMetaCache - get table meta of the table “逻辑表表名” error: Failed to fetch schema of “逻辑表表名”
java.sql.SQLException: Failed to fetch schema of “逻辑表表名”
谁遇到过类似的问题

京ICP备2021015875号