[CONJ-803] failover re-execution using "redo transaction" Created: 2020-06-29 Updated: 2021-05-07 Resolved: 2021-04-22 |
|
| Status: | Closed |
| Project: | MariaDB Connector/J |
| Component/s: | Failover |
| Affects Version/s: | None |
| Fix Version/s: | 3.0.0 |
| Type: | New Feature | Priority: | Major |
| Reporter: | Diego Dupin | Assignee: | Diego Dupin |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Description |
|
The driver has failover implementation, but there is some limitation that can be solved using a redo transaction implementation. There are many benefits to using this approach. Current stateOn a failover occurring on a slave connection, reconnection is done to another slave if possible and the query is re-executed on that new slave or on the master connection if no slave connection is reestablished without interruption. Problem is when failover occurs on a master connection: the only case when that is handled transparently is when a query was not in a transaction and was a SELECT command. Proposed implementationJdbc default with autocommit enable. When a failover occurs on a primary connection with auto-commit enable, the driver can still not know more and will just reconnect connection and throw an exception like current implementation. (An exception can be done for PING command) Redo transaction approach is to save commands (COM_EXECUTE / COM_STMT_EXECUTE, COM_STMT_LONG_DATA) in transaction. When a failover occurs during a transaction and failing command is not a COMMIT/ROLLBACK command, the connector can automatically reconnect and replay transaction, making failover completely transparent. Auto-commit and transaction state already exist in protocol using SERVER_STATUS_IN_TRANS and SERVER_STATUS_AUTOCOMMIT flag in server status flag in all server version. The drawback of redo transaction implementation is saving transaction in buffer until completion, but this can be avoided setting a maximum buffer length (if transaction is too big, clearing saving buffer, then throwing a exception on failover). Most of the time, queries occurs in transaction (ORM for example doesn't permit using auto-commit), so redo transaction implementation will solve most of failover cases transparently for user point of view. Typology considerationThis solution is particulary adapted for
|
| Comments |
| Comment by Diego Dupin [ 2021-04-22 ] | |||||||||||||||||||||||
|
option `transactionReplay` permit to enable this functionnality, disabled by default. | |||||||||||||||||||||||
| Comment by Diego Dupin [ 2021-05-07 ] | |||||||||||||||||||||||
|
Some explaination of implementation : Enabling this parameter, all queries in transaction are cached until commit/rollback. There is a few limitations:
explaination of non-idempotent issues :
setting ids, no problem
other possibility:
But here is an example of non-replayable queries
problem here is that generated id has been retrieved from first command, and used to create new query. Replaying that transaction, generated id will surely be different, and other inserts foreign key will fails. |