seata序列化问题

1:在seata1.5.X版本前,序列化方式不支持datatime

2:我在网上搜到的方法:

        无非就是:

        1:更改字段类型为timestamp(有个问题就是:①项目表很多,可能会影响线上数据②timestamp字段,时间区间只到2038年,从这一点就不能用这个)

        2:在seataServer配置中更改序列化方式为kryo(个人试了,没啥用,也有可能没弄好,反正我自己试了没用,自己可以试试)

        seata序列化问题_第1张图片

 引入依赖


            com.esotericsoftware.kryo
            kryo
            2.24.0
        
        
            com.esotericsoftware
            kryo
            4.0.2
        
        
            de.javakaffee
            kryo-serializers
            0.42
        

个人解决方案:

        在2022年5月17号官方地址,官方推出的1.5.1版本的解决了这个序列化问题:

        引入下面依赖:一定要版本对应这个很重要,seata服务版本更新一下,重启一下

       


            com.alibaba.cloud
            spring-cloud-starter-alibaba-seata
            2021.0.1.0
            
                
                    io.seata
                    seata-spring-boot-starter
                
                
                    io.seata
                    seata-all
                
            
        
        
            io.seata
            seata-spring-boot-starter
            1.5.1
        
        
            io.seata
            seata-all
            1.5.1
        

基本就解决了

下面是我的在rancher上用k8s镜像部署的一些详细的过程,仅供参考,自己取舍哈,不懂的,评论吧,原理啥的就别问我了哈O(∩_∩)O

k8s部署seata:

1:rancher上起seata服务

写上镜像名称,会自己拉镜像

seata序列化问题_第2张图片

seata序列化问题_第3张图片

 2:配置seata配置

data:
  registry.conf: |
#配置nacos的注册地址
    registry {
        type = "nacos"
        nacos {
          application = "seata-server"
          serverAddr = "xxxxx:18848"
          namespace = "walle-framework-dev-v2"
          group="SEATA_GROUP"
          username = "nacos"
          password = "nacos"
          cluster = "default"
        }
    }
#读取nacos上的配置
    config {
      type = "nacos"
      nacos {
        serverAddr = "xxxxxxx:18848"
        group = "SEATA_GROUP"
        username = "nacos"
        password = "nacos"
        file-extension = "yaml"
        dataId = "seataServer.yaml"
        namespace = "walle-framework-dev-v2"
        cluster = "default"
      }
    }

3:nacos上的seataServer配置

transport:
    type: TCP
    server: NIO
    heartbeat: true
    enableClientBatchSendRequest: true
    threadFactory:
        bossThreadPrefix: NettyBoss
        workerThreadPrefix: NettyServerNIOWorker
        serverExecutorThreadPrefix: NettyServerBizHandler
        shareBossWorker: false
        clientSelectorThreadPrefix: NettyClientSelector
        clientSelectorThreadSize: 1
        clientWorkerThreadPrefix: NettyClientWorkerThread
        bossThreadSize: 1
        workerThreadSize: default
    shutdown:
        wait: 3
service:
    vgroupMapping:
        walle-frame-seata-service-group: default
    default:
        grouplist: xxxxx:8091
    enableDegrade: false
    disableGlobalTransaction: false
service:
    vgroupMapping:
        walle-frame-seata-group: default
    enableDegrade: false
    disableGlobalTransaction: false
client:
    rm:
        asyncCommitBufferLimit: 10000
        lock:
            retryInterval: 10
            retryTimes: 30
            retryPolicyBranchRollbackOnConflict: true
        reportRetryCount: 5
        tableMetaCheckEnable: false
        tableMetaCheckerInterval: 60000
        sqlParserType: druid
        reportSuccessEnable: false
        sagaBranchRegisterEnable: false
        sagaJsonParser: fastjson
        tccActionInterceptorOrder: -2147482648
    tm:
        commitRetryCount: 5
        rollbackRetryCount: 5
        defaultGlobalTransactionTimeout: 60000
        degradeCheck: false
        degradeCheckAllowTimes: 10
        degradeCheckPeriod: 2000
        interceptorOrder: -2147482648
    undo:
        dataValidation: true
        logSerialization: kyro
        onlyCareUpdateColumns: true
        logTable: undo_log
        compress:
            enable: true
            type: zip
            threshold: 64k

## transaction log store, only used in seata-server
store:
  ## store mode: file、db、redis
  mode: db
  ## database store property
  db:
    ## the implement of javax.sql.DataSource, such as DruidDataSource(druid)/BasicDataSource(dbcp)/HikariDataSource(hikari) etc.
    datasource: druid
    ## mysql/oracle/postgresql/h2/oceanbase etc.
    dbType: mysql
    driverClassName: com.mysql.jdbc.Driver
    ## if using mysql to store the data, recommend add rewriteBatchedStatements=true in jdbc connection param
    url: jdbc:mysql://xxxxx:13306/seata?rewriteBatchedStatements=true
    user: walle
    password: Csii_walle
    minConn: 5
    maxConn: 100
    globalTable: global_table
    branchTable: branch_table
    lockTable: lock_table
    queryLimit: 100
    maxWait: 5000

4:在数据库创建对应的表

1:undo_log表格,主要用于数据回滚:每次有数据库操作的时候,比如增删改,会插入一条数据,接口调用完会自动删除,异常的时候会回滚,每个需要操作的数据库都需要创建这个表

CREATE TABLE `undo_log` (
  `id` bigint NOT NULL AUTO_INCREMENT,
  `branch_id` bigint NOT NULL,
  `xid` varchar(100) NOT NULL,
  `context` varchar(128) NOT NULL,
  `rollback_info` longblob NOT NULL,
  `log_status` int NOT NULL,
  `log_created` datetime NOT NULL,
  `log_modified` datetime NOT NULL,
  `ext` varchar(100) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `ux_undo_log` (`xid`,`branch_id`)
) ENGINE=InnoDB AUTO_INCREMENT=62 DEFAULT CHARSET=utf8mb3 COMMENT='用于AT 模式XID记录';

2:还有三个表

        

-- -------------------------------- The script used when storeMode is 'db' --------------------------------
-- the table to store GlobalSession data
CREATE TABLE IF NOT EXISTS `global_table`
(
    `xid`                       VARCHAR(128) NOT NULL,
    `transaction_id`            BIGINT,
    `status`                    TINYINT      NOT NULL,
    `application_id`            VARCHAR(32),
    `transaction_service_group` VARCHAR(32),
    `transaction_name`          VARCHAR(128),
    `timeout`                   INT,
    `begin_time`                BIGINT,
    `application_data`          VARCHAR(2000),
    `gmt_create`                DATETIME,
    `gmt_modified`              DATETIME,
    PRIMARY KEY (`xid`),
    KEY `idx_status_gmt_modified` (`status` , `gmt_modified`),
    KEY `idx_transaction_id` (`transaction_id`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4;

-- the table to store BranchSession data
CREATE TABLE IF NOT EXISTS `branch_table`
(
    `branch_id`         BIGINT       NOT NULL,
    `xid`               VARCHAR(128) NOT NULL,
    `transaction_id`    BIGINT,
    `resource_group_id` VARCHAR(32),
    `resource_id`       VARCHAR(256),
    `branch_type`       VARCHAR(8),
    `status`            TINYINT,
    `client_id`         VARCHAR(64),
    `application_data`  VARCHAR(2000),
    `gmt_create`        DATETIME(6),
    `gmt_modified`      DATETIME(6),
    PRIMARY KEY (`branch_id`),
    KEY `idx_xid` (`xid`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4;

-- the table to store lock data
CREATE TABLE IF NOT EXISTS `lock_table`
(
    `row_key`        VARCHAR(128) NOT NULL,
    `xid`            VARCHAR(128),
    `transaction_id` BIGINT,
    `branch_id`      BIGINT       NOT NULL,
    `resource_id`    VARCHAR(256),
    `table_name`     VARCHAR(32),
    `pk`             VARCHAR(36),
    `status`         TINYINT      NOT NULL DEFAULT '0' COMMENT '0:locked ,1:rollbacking',
    `gmt_create`     DATETIME,
    `gmt_modified`   DATETIME,
    PRIMARY KEY (`row_key`),
    KEY `idx_status` (`status`),
    KEY `idx_branch_id` (`branch_id`),
    KEY `idx_xid_and_branch_id` (`xid` , `branch_id`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4;

CREATE TABLE IF NOT EXISTS `distributed_lock`
(
    `lock_key`       CHAR(20) NOT NULL,
    `lock_value`     VARCHAR(20) NOT NULL,
    `expire`         BIGINT,
    primary key (`lock_key`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4;

INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('AsyncCommitting', ' ', 0);
INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('RetryCommitting', ' ', 0);
INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('RetryRollbacking', ' ', 0);
INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('TxTimeoutCheck', ' ', 0);

5:项目引入依赖


            com.alibaba.cloud
            spring-cloud-starter-alibaba-seata
            2021.0.1.0
            
                
                    io.seata
                    seata-spring-boot-starter
                
                
                    io.seata
                    seata-all
                
            
        
        
            io.seata
            seata-spring-boot-starter
            1.5.1
        
        
            io.seata
            seata-all
            1.5.1
        

6:配置yml

seata:
  data-source-proxy-mode: AT
  service:
    grouplist:
      default: xxxxx:8091
    vgroup-mapping:
      walle-frame-seata-service-group: default
  tx-service-group: walle-frame-seata-service-group

7:启动seata,编写测试代码测试,远程调用测试

你可能感兴趣的:(seata,java,spring,mysql,分布式,后端)