分布式事务


Seata

在数据库中存储数据 创建seata数据库

drop table if exists global_table;
create table 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_gmt_modified_status (gmt_modified, status),
    key idx_transaction_id (transaction_id)
);
drop table if exists branch_table;
create table branch_table (
    branch_id bigint not null,
    xid varchar(128) not null,
    transaction_id bigint ,
    resource_group_id varchar(32),
    resource_id varchar(256) ,
    lock_key varchar(128) ,
    branch_type varchar(8) ,
    status tinyint,
    client_id varchar(64),
    application_data varchar(2000),
    gmt_create datetime,
    gmt_modified datetime,
    primary key (branch_id),
    key idx_xid (xid)
);

drop table if exists lock_table;
create table lock_table (
    row_key varchar(128) not null,
    xid varchar(96),
    transaction_id long ,
    branch_id long,
    resource_id varchar(256) ,
    table_name varchar(32) ,
    pk varchar(36) ,
    gmt_create datetime ,
    gmt_modified datetime,
    primary key(row_key)
);

image-20230803151743057

Seata数据库准备

CREATE DATABASE seata_order;
CREATE DATABASE seata_storage;
CREATE DATABASE seata_account;

在seata_order库下创建t_order表

create table t_order(
    'id' BIGINT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
    'user_id' BIGINT(11) DEFAULT NULL COMMENT '用户id',
    'product_id' BIGINT(11) DEFAULT NULL COMMENT '产品id',
    'count' INT(11) DEFAULT NULL COMMENT '数量',
    'money' DECIMAL(11,0) DEFAULT NULL COMMENT '金额',
    'status' INT(1) DEFAULT NULL COMMENT '订单状态:0:创建中;1:已完结'
) ENGINE=INNODB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8;

SELECT * FROM t


文章作者: 毛豆不逗比
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 毛豆不逗比 !
  目录
{% include '_third-party/exturl.swig' %} {% include '_third-party/bookmark.swig' %} {% include '_third-party/copy-code.swig' %} + {% include '_custom/custom.swig' %}