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, but sometimes the result of an event such as a transaction timeout or a leader switchover of participants.
A leader switchover is performed in the following scenarios:
- You run an O&M command to, for example, switch the replica leader, change the primary zone, remove a server, or stop a server.
- An internal scheduling task is performed, such as migrating units, bringing replicas offline, and generating replicas in the primary zone.
- A certain internal exception occurs.
If RootService triggers a leader switchover, the system denies the start of new transactions and waits some time for the existing active transactions to be completed. After the wait period elapses, the system migrates uncompleted transactions to the new leader and executes the leader switchover. Then, the new leader starts to provide services.
In the following scenarios, transactions are killed:
- The leader switchover is not triggered by RootService but by certain exceptions.
- Large transactions are in progress.
- The execution of statements has not been completed when uncompleted transactions are being migrated to the new leader.
When a transaction rollback error occurs, you can check whether a leader switchover is performed by using the DBA_OB_SERVER_EVENT_HISTORY view. The following example describes a leader switchover process triggered by running the switch replica leader command.
Query the distribution of log stream leaders 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 events involved in the leader election of log streams.
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)