The following table describes the errors that indicate the rollback of a transaction.
| External error code | Internal error code | Error message |
|---|---|---|
| 6002 | -6224 | transaction need rollback |
| 6002 | -6223 | Transaction exiting |
| 6002 | -6211 | Transaction is killed |
| 6002 | -6213 | Transaction context does not exist |
A transaction rollback is not necessarily an error. Several situations can lead to transaction rollback, such as transaction timeout and participant leader switchover.
The following situations can trigger a leader switchover:
- O&M scenarios: switch replica leader, change primary zone, remove server, stop server
- Internal scheduling scenarios: migrate unit, bring replica offline, add replica in primary zone
- Internal exception scenarios: abnormal leader switchover
When RootService triggers a leader switchover, the system reserves a certain period for existing active transactions to complete and does not allow new transactions to start. After the period expires, all still-active transactions are migrated to the new leader. Then the leader switchover occurs, and the new leader continues to provide services.
In the following scenarios, transactions are killed during a leader switchover:
- The leader switchover is not triggered by RootService, for example, abnormal leader switchover
- Large transaction scenarios
- During migration of transactions to the new leader, the statement has not finished executing
When a transaction rollback error occurs, you can query the DBA_OB_SERVER_EVENT_HISTORY view to confirm whether a leader switchover has occurred. The following example shows a leader switchover process triggered by the switch replica leader command:
Query the log stream leader distribution before the leader switchover.
obclient> select TENANT_ID,LS_ID,SVR_IP,SVR_PORT,ROLE,PAXOS_MEMBER_LIST from GV$OB_LOG_STAT where tenant_id=1 and ls_id=1; +-----------+-------+-------------+----------+----------+---------------------------------------------------------------------------+ | TENANT_ID | LS_ID | SVR_IP | SVR_PORT | ROLE | PAXOS_MEMBER_LIST | +-----------+-------+-------------+----------+----------+---------------------------------------------------------------------------+ | 1 | 1 | xx.xx.xx.158| 2882 | FOLLOWER | xx.xx.xx.43:2882:1686125578254268,xx.xx.xx.106:2882:1,xx.xx.xx.158:2882:1 | | 1 | 1 | xx.xx.xx.43 | 2882 | FOLLOWER | xx.xx.xx.43:2882:1686125578254268,xx.xx.xx.106:2882:1,xx.xx.xx.158:2882:1 | | 1 | 1 | xx.xx.xx.106| 2882 | LEADER | xx.xx.xx.43:2882:1686125578254268,xx.xx.xx.106:2882:1,xx.xx.xx.158:2882:1 | +-----------+-------+-------------+----------+----------+---------------------------------------------------------------------------+ 3 rows in set (0.01 sec)Execute the leader switchover.
obclient> alter system switch replica leader ls=1 server='xx.xx.xx.158:2882' tenant='sys'; Query OK, 0 rows affected (0.01 sec)Query the log stream leader election events.
obclient> SELECT VALUE4 HAPPENED_TIME,svr_ip,VALUE1 TENANT_ID,VALUE2 LS_ID,event,name3,value3 FROM DBA_OB_SERVER_EVENT_HISTORY WHERE module="ELECTION"; +----------------------------+-------------+-----------+-------+---------------------------+-------+------------------------------------------------------------------------------------------------------------------+ | HAPPENED_TIME | svr_ip | TENANT_ID | LS_ID | event | name3 | value3 | +----------------------------+-------------+-----------+-------+---------------------------+-------+------------------------------------------------------------------------------------------------------------------+ | 2023-06-12 23:27:23.291335 | xx.xx.xx.106| 1 | 1 | prepare change leader | INFO | leader prepare to change leader : "xx.xx.xx.106:2882" -> "xx.xx.xx.158:2882", reason : MANUAL LEADER | | 2023-06-12 23:27:23.294363 | xx.xx.xx.158| 1 | 1 | change leader to takeover | INFO | new leader takeover : "xx.xx.xx.106:2882" -> "xx.xx.xx.158:2882" | | 2023-06-12 23:27:23.318691 | xx.xx.xx.43 | 1 | 1 | witness change leader | INFO | witness change leader : "xx.xx.xx.106:2882" -> "xx.xx.xx.158:2882" | | 2023-06-12 23:27:23.292954 | xx.xx.xx.106| 1 | 1 | change leader to revoke | INFO | old leader revoke : "xx.xx.xx.106:2882" -> "xx.xx.xx.158:2882" | | 2023-06-12 23:27:23.541978 | xx.xx.xx.158| 1 | 1 | witness change leader | INFO | witness change leader : "xx.xx.xx.106:2882" -> "xx.xx.xx.158:2882" | | 2023-06-12 23:27:23.542136 | xx.xx.xx.106| 1 | 1 | witness change leader | INFO | witness change leader : "xx.xx.xx.106:2882" -> "xx.xx.xx.158:2882" | +----------------------------+-------------+-----------+-------+---------------------------+-------+------------------------------------------------------------------------------------------------------------------+ 6 rows in set (0.02 sec)