Scenario 1 local prepared ,remote commited
local:select local_tran_id,state from dba_2pc_pending;
LOCAL_TRAN_ID STATE
6.22.290635 prepared
remote DB:
select local_tran_id,state from dba_2pc_pending;
LOCAL_TRAN_ID STATE
1.92.66874 commited
即表示远程数据库可能已经commit,但是本地数据库未知远程数据库的状态,还是处于prepared状态。我们需要如下处理:
local:commit force '6.22.290635';
exec DBMS_TRANSACTION.PURGE_LOST_DB_ENTRY('6.22.290635');
remote DB:
exec DBMS_TRANSACTION.PURGE_LOST_DB_ENTRY('1.92.66874');
Scenario2 local commited,remote commited
local:select local_tran_id,state from dba_2pc_pending;
LOCAL_TRAN_ID STATE
6.22.290635 commited
remote DB:
select local_tran_id,state from dba_2pc_pending;
LOCAL_TRAN_ID STATE
1.92.66874 commited
即表示本地和远程数据库均完成commit,但未清除分布式事务信息,我们需要如下处理:
local:exec DBMS_TRANSACTION.PURGE_LOST_DB_ENTRY('6.22.290635');
remote DB:
exec DBMS_TRANSACTION.PURGE_LOST_DB_ENTRY('1.92.66874');
3.FORGET PHASE:
3.1 参与的点通知commit point site他们已经完成commit,commit point site就能忘记(forget)这个事务。
3.2 commit point site在远程数据库上清除分布式事务信息。
3.3 commit point site通知Global Coordinator可以清除本地的分布式事务信息。
3.4 Global Coordinator清除分布式事务信息。
local:
select local_tran_id,state from dba_2pc_pending;LOCAL_TRAN_ID STATE
6.22.290635 commited
remote DB
select local_tran_id,state from dba_2pc_pending;no rows selected.
即表示远端已完成commit,通知Global Coordinator清除分布式事务信息,但是本地没有收到该信息,我们改如下处理:
localexec DBMS_TRANSACTION.PURGE_LOST_DB_ENTRY('6.22.290635');
总结分佈式事务的状态依次如下:
phase local_state remote_state actionprepare collecting
prepared /
/ 本地DBMS_TRANSACTION.PURGE_LOST_DB_ENTRY
本地rollback force后PURGE_LOST_DB_ENTRY
commit prepared
commited commited
commited 本地commit force后本地和远程均PURGE
本地和远程均PURGE_LOST_DB_ENTRY
forget commited / 本地PURGE_LOST_DB_ENTRY