什么是分布式事务
在处理事物时需要两个或更多分布的数据库,比如下图中的例子
如下语句就是SCOTT用户在在更新本地sales数据库,远程hq数据库和远程maint数据库
UPDATE scott.dept@hq.us.example.com
SET loc = 'REDWOOD SHORES'
WHERE deptno = 10;
UPDATE scott.emp
SET deptno = 11
WHERE deptno = 10;
UPDATE scott.bldg@maint.us.example.com
SET room = 1225
WHERE room = 1163;
COMMIT;
分布式数据库运行DML、DDL语句和DCL语句。
Session tree
Session tree是session和他们角色的关系结构模型。
一个分布式事务的所有节点都需要一个或多个下列角色
|
Role |
Description |
|
Client |
A node that references information in a database belonging to a different node. |
|
Database server |
A node that receives a request for information from another node. |
|
Global coordinator |
The node that originates the distributed transaction. |
|
Local coordinator |
A node that is forced to reference data on other nodes to complete its part of the transaction. |
|
Commit point site |
The node that commits or rolls back the transaction as instructed by the global coordinator. |
Client:每一个节点在另一个节点上都在扮演一个client
Database server:每一个数据库都是其他client的宿主,也可以叫做服务方。
Local coordinator:在分布式事务中,一个节点需要使用另一个节点的数据去完成事务时,都被称为Local coordinator。
Global coordinator:在分布式事务中,一个节点是发起事务的节点,那么被称为Global coordinator。
Commit point site:Commit point site是Global coordinator提交和撤回操作的节点。
分布式事务的提交
当未提交的非commit point site节点准备好的时候才会考虑提交,而这个时候commit point site的事务事实上已经提交了。因为redo日志记录了commit操作,即使一些节点还未准备好提交事务,事务也会被考虑提交。所以,当 commit point site已经提交的时候,一些分布式节点可能并未提交。每一个数据库服务都需要试用 commit point strength,当数据库服务是分布式的一部分式, commit point strength就决定了那个角色来完成提交工作。COMMIT_POINT_STRENGTH参数决定了数据库应该怎样提交。下图极好的解释了分布式事务的提交原理。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/31461640/viewspace-2140924/ ,如需转载,请注明出处,否则将追究法律责任。