mysql distributed transaciton_Distributed Transaction Processing:mysql

Distributed Transaction Processing: The XA Specification

mysql XA Transactions

oracle 10g

mysql xa 例子

X/Open XA distributed transactions

SHOW ENGINES/G

查看是否支持innodb

use test;

CREATE TABLE aa(a INT, b CHAR (20), INDEX (a)) ENGINE=InnoDB;

xa begin 'abc','def',7;

insert into aa values(1, 'a');

xa end 'abc','def',7;

xa prepare 'abc','def',7;

xa commit 'abc','def',7;

xa rollback 'abc','def',7;

xa recover;

prepare 之后 recover 才能看到结果

xid在内部的定义

/** X/Open XA distributed transaction identifier */

struct xid_t {

long formatID; /*!< format identifier; -1

means that the XID is null */

long gtrid_length; /*!< value from 1 through 64 */

long bqual_length; /*!< value from 1 through 64 */

char data[XIDDATASIZE]; /*!< distributed transaction

identifier */

};

//在事务结构体中增加了一项

struct trx_struct{

XID xid; /*!< X/Open XA transaction

identification to identify a transaction branch */

}

enum xa_states {XA_NOTR=0, XA_ACTIVE, XA_IDLE, XA_PREPARED, XA_ROLLBACK_ONLY};

//begin 置为XA_ACTIVE, end置为 XA_IDLE

extern const char *xa_state_names[];

typedef struct st_xid_state {

/* For now, this is only used to catch duplicated external xids */

XID xid; // transaction identifier

enum xa_states xa_state; // used by external XA only

bool in_thd;

/* Error reported by the Resource Manager (RM) to the Transaction Manager. */

uint rm_error;

} XID_STATE;

struct st_transactions {

XID_STATE xid_state;

}

在 commit 或 rollback 时,根据xid找到相应的事务,进行相应的操作

不充许DTP的嵌套,一个连接只能执行完一个DTP事务后,才充许执行下一下

除了加了一个全局标记XID之处,从任何方面看,都只是本地局部事务加了一层壳,

现在的MYSQL,

在DTP中,mysql需要应用程序充当AP和TM角色,没看到数据库服务器提供了TM功能

在DTP中,只看到了TM对RM的调用,没看到RM主动调用TM,相当于实现了XA接口的一半;

对于autocommit的实现也没看到,估计就是前后包装一层已实现的XA接口。

你可能感兴趣的:(mysql,distributed,transaciton)