Browse Source

doc: add sample undo_log table sql

add sample mysql
tags/1.0.2-RC1
FengZhang GitHub 2 years ago
parent
commit
902cd252a8
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 108 additions and 13 deletions
  1. +10
    -1
      pkg/datasource/sql/exec/at/default.go
  2. +13
    -9
      pkg/datasource/sql/exec/executor.go
  3. +1
    -1
      pkg/datasource/sql/undo/builder/mysql_update_undo_log_builder.go
  4. +1
    -1
      sample/at/basic/service.go
  5. +13
    -1
      sample/dockercompose/docker-compose.yml
  6. +37
    -0
      sample/dockercompose/mysql/mysqld.cnf
  7. +33
    -0
      sample/dockercompose/mysql/order.sql

+ 10
- 1
pkg/datasource/sql/exec/at/default.go View File

@@ -23,7 +23,16 @@ import (
)

func init() {
exec.RegisterXAExecutor(types.DBTypeMySQL, func() exec.SQLExecutor {
exec.RegisterATExecutor(types.DBTypeMySQL, types.UpdateExecutor, func() exec.SQLExecutor {
return &ATExecutor{}
})
exec.RegisterATExecutor(types.DBTypeMySQL, types.SelectExecutor, func() exec.SQLExecutor {
return &ATExecutor{}
})
exec.RegisterATExecutor(types.DBTypeMySQL, types.InsertExecutor, func() exec.SQLExecutor {
return &ATExecutor{}
})
exec.RegisterATExecutor(types.DBTypeMySQL, types.DeleteExecutor, func() exec.SQLExecutor {
return &ATExecutor{}
})
}

+ 13
- 9
pkg/datasource/sql/exec/executor.go View File

@@ -78,15 +78,6 @@ type (

// BuildExecutor
func BuildExecutor(dbType types.DBType, txType types.TransactionType, query string) (SQLExecutor, error) {
if txType == types.XAMode {
hooks := make([]SQLHook, 0, 4)
hooks = append(hooks, commonHook...)

e := executorSoltsXA[dbType]()
e.Interceptors(hooks)
return e, nil
}

parseCtx, err := parser.DoParser(query)
if err != nil {
return nil, err
@@ -95,6 +86,19 @@ func BuildExecutor(dbType types.DBType, txType types.TransactionType, query stri
hooks := make([]SQLHook, 0, 4)
hooks = append(hooks, commonHook...)
hooks = append(hooks, hookSolts[parseCtx.SQLType]...)
hooks = append(hooks, commonHook...)

if txType == types.XAMode {
e := executorSoltsXA[dbType]()
e.Interceptors(hooks)
return e, nil
}

if txType == types.ATMode {
e := executorSoltsAT[dbType][parseCtx.ExecutorType]()
e.Interceptors(hooks)
return e, nil
}

factories, ok := executorSoltsAT[dbType]



+ 1
- 1
pkg/datasource/sql/undo/builder/mysql_update_undo_log_builder.go View File

@@ -54,7 +54,7 @@ func GetMySQLUpdateUndoLogBuilder() undo.UndoLogBuilder {
}

func (u *MySQLUpdateUndoLogBuilder) BeforeImage(ctx context.Context, execCtx *types.ExecContext) ([]*types.RecordImage, error) {
if execCtx.ParseContext.UpdateStmt == nil {
if execCtx == nil || execCtx.ParseContext == nil || execCtx.ParseContext.UpdateStmt == nil {
return nil, nil
}



+ 1
- 1
sample/at/basic/service.go View File

@@ -29,7 +29,7 @@ var (

func initService() {
var err error
db, err = sql.Open(sql2.SeataATMySQLDriver, "root:12345678@tcp(127.0.0.1:3306)/seata_client?multiStatements=true&interpolateParams=true")
db, err = sql.Open(sql2.SeataATMySQLDriver, "root:123456@tcp(127.0.0.1:3306)/seata_client?multiStatements=true&interpolateParams=true")
if err != nil {
panic("init service error")
}


+ 13
- 1
sample/dockercompose/docker-compose.yml View File

@@ -30,4 +30,16 @@ services:
image: zookeeper
ports:
- "2181:2181"
restart: on-failure
restart: on-failure

mysql:
image: mysql:5.7
container_name: mysql
environment:
- MYSQL_ROOT_PASSWORD=123456
command: --default-authentication-plugin=mysql_native_password --default-time-zone='+08:00'
volumes:
- ./mysql:/docker-entrypoint-initdb.d
- ./mysql/mysqld.cnf:/etc/mysql/mysql.conf.d/mysqld.cnf
ports:
- "3306:3306"

+ 37
- 0
sample/dockercompose/mysql/mysqld.cnf View File

@@ -0,0 +1,37 @@
# Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2.0,
# as published by the Free Software Foundation.
#
# This program is also distributed with certain software (including
# but not limited to OpenSSL) that is licensed under separate terms,
# as designated in a particular file or component or in included license
# documentation. The authors of MySQL hereby grant you an additional
# permission to link the program and your derivative works with the
# separately licensed software that they have included with MySQL.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License, version 2.0, for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

#
# The MySQL Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

[mysqld]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
#log-error = /var/log/mysql/error.log
# By default we only accept connections from localhost
bind-address = 0.0.0.0
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

+ 33
- 0
sample/dockercompose/mysql/order.sql View File

@@ -0,0 +1,33 @@
CREATE database if NOT EXISTS `seata_client` default character set utf8mb4 collate utf8mb4_unicode_ci;
USE `seata_client`;

SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

CREATE TABLE IF NOT EXISTS `order_tbl` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` varchar(255) DEFAULT NULL,
`commodity_code` varchar(255) DEFAULT NULL,
`count` int(11) DEFAULT '0',
`money` int(11) DEFAULT '0',
`descs` varchar(255) DEFAULT '',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO `seata_client`.`order_tbl` (`id`, `user_id`, `commodity_code`, `count`, `money`, `descs`) VALUES (1, 'NO-100001', 'C100000', 100, 10, 'init desc');

DROP TABLE IF EXISTS `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`),
KEY `idx_unionkey` (`xid`,`branch_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

Loading…
Cancel
Save