AT模式

AT 模式是一种无侵入的分布式事务解决方案

业务sql

  1. create
  2. database IF NOT EXISTS seata_order ;
  3. USE
  4. seata_order;
  5. DROP TABLE IF EXISTS `t_order`;
  6. CREATE TABLE `t_order`
  7. (
  8. `id` bigint(11) NOT NULL AUTO_INCREMENT,
  9. `user_id` bigint(20) DEFAULT NULL COMMENT '用户id',
  10. `product_id` bigint(11) DEFAULT NULL COMMENT '产品id',
  11. `count` int(11) DEFAULT NULL COMMENT '数量',
  12. `money` decimal(11, 0) DEFAULT NULL COMMENT '金额',
  13. `status` int(1) DEFAULT NULL COMMENT '订单状态: 0:创建中 1:已完结',
  14. PRIMARY KEY (`int`) USING BTREE
  15. ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '订单表' ROW_FORMAT = Dynamic;
  16. DROP TABLE IF EXISTS `undo_log`;
  17. CREATE TABLE `undo_log`
  18. (
  19. `id` bigint(20) NOT NULL AUTO_INCREMENT,
  20. `branch_id` bigint(20) NOT NULL,
  21. `xid` varchar(100) NOT NULL,
  22. `context` varchar(128) NOT NULL,
  23. `rollback_info` longblob NOT NULL,
  24. `log_status` int(11) NOT NULL,
  25. `log_created` datetime NOT NULL,
  26. `log_modified` datetime NOT NULL,
  27. `ext` varchar(100) DEFAULT NULL,
  28. PRIMARY KEY (`id`),
  29. UNIQUE KEY `ux_undo_log` (`xid`,`branch_id`)
  30. ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
  31. create
  32. database IF NOT EXISTS seata_storage;
  33. USE
  34. seata_storage;
  35. DROP TABLE IF EXISTS `t_storage`;
  36. CREATE TABLE `t_storage`
  37. (
  38. `id` bigint(11) NOT NULL AUTO_INCREMENT,
  39. `product_id` bigint(11) DEFAULT NULL COMMENT '产品id',
  40. `total` int(11) DEFAULT NULL COMMENT '总库存',
  41. `used` int(11) DEFAULT NULL COMMENT '已用库存',
  42. `residue` int(11) DEFAULT NULL COMMENT '剩余库存',
  43. PRIMARY KEY (`int`) USING BTREE
  44. ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '库存' ROW_FORMAT = Dynamic;
  45. INSERT INTO `t_storage`
  46. VALUES (1, 1, 100, 0, 100);
  47. DROP TABLE IF EXISTS `undo_log`;
  48. CREATE TABLE `undo_log`
  49. (
  50. `id` bigint(20) NOT NULL AUTO_INCREMENT,
  51. `branch_id` bigint(20) NOT NULL,
  52. `xid` varchar(100) NOT NULL,
  53. `context` varchar(128) NOT NULL,
  54. `rollback_info` longblob NOT NULL,
  55. `log_status` int(11) NOT NULL,
  56. `log_created` datetime NOT NULL,
  57. `log_modified` datetime NOT NULL,
  58. `ext` varchar(100) DEFAULT NULL,
  59. PRIMARY KEY (`id`),
  60. UNIQUE KEY `ux_undo_log` (`xid`,`branch_id`)
  61. ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
  62. CREATE
  63. database IF NOT EXISTS seata_account;
  64. USE
  65. seata_account;
  66. DROP TABLE IF EXISTS `t_account`;
  67. CREATE TABLE `t_account`
  68. (
  69. `id` bigint(11) NOT NULL COMMENT 'id',
  70. `user_id` bigint(11) DEFAULT NULL COMMENT '用户id',
  71. `total` decimal(10, 0) DEFAULT NULL COMMENT '总额度',
  72. `used` decimal(10, 0) DEFAULT NULL COMMENT '已用余额',
  73. `residue` decimal(10, 0) DEFAULT NULL COMMENT '剩余可用额度',
  74. PRIMARY KEY (`id`) USING BTREE
  75. ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '账户表' ROW_FORMAT = Dynamic;
  76. INSERT INTO `t_account`
  77. VALUES (1, 1, 1000, 0, 1000);
  78. DROP TABLE IF EXISTS `undo_log`;
  79. CREATE TABLE `undo_log`
  80. (
  81. `id` bigint(20) NOT NULL AUTO_INCREMENT,
  82. `branch_id` bigint(20) NOT NULL,
  83. `xid` varchar(100) NOT NULL,
  84. `context` varchar(128) NOT NULL,
  85. `rollback_info` longblob NOT NULL,
  86. `log_status` int(11) NOT NULL,
  87. `log_created` datetime NOT NULL,
  88. `log_modified` datetime NOT NULL,
  89. `ext` varchar(100) DEFAULT NULL,
  90. PRIMARY KEY (`id`),
  91. UNIQUE KEY `ux_undo_log` (`xid`,`branch_id`)
  92. ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

代码demo

https://gitee.com/smalldust111/demo-seata

问题

no available service ‘null’ found, please make sure registry config correct

升版本到1.4

2022-04-15 22:44:05.244 ERROR 18852 —- [ restartedMain] i.s.c.r.netty.NettyClientChannelManager : 0101 can not connect to 10.233.96.208:8091 cause:can not register RM,err:can not connect to services-server.io.seata.common.exception.FrameworkException: can not register RM,err:can not connect to services-server.

注册中心使用内部ip,本地不能访问到k8s机器内部ip
修改为ipvs:https://www.jianshu.com/p/31b161b99dc6
修改内核版本原因:https://blog.csdn.net/cljdsc/article/details/115701562
如何修改:https://www.cnblogs.com/varden/p/15178853.html

参考

seata官网: https://seata.io/zh-cn/docs/user/quickstart.html
https://seata.io/zh-cn/docs/user/configuration/nacos.html

https://blog.csdn.net/qq_43437874/article/details/123249542