mysql / mysql-js

NoSQL node.js connector for MySQL Cluster
170 stars 48 forks source link

XA #9

Open jdduncan opened 11 years ago

jdduncan commented 11 years ago

Here's a sketch for how distributed transactions would be supported.

Session.beginDistributedTransaction(xid) is a new immediate method returning a DistributedTransaction with XA transaction identifier "xid," where xid is a value assigned by some distributed transaction manager. The session's current transaction must be Idle. The effect is like getCurrentTransaction(), plus an operation to transform the current transaction into a distributed transaction with id xid, plus begin(). The transaction that is returned is Active and is not auto-commit.

The mysql adapter implements this using the SQL statement "XA BEGIN xid". The ndb adapter implements it as a simple begin.

Transaction.prepare() is a new async method available only on distributed transactions. The mysql adapter implements prepare() as as the SQL statements "XA END xid", signaling the end of SQL DML, followed by "XA PREPARE xid". The ndb adapter implements prepare() by (1) issuing an executeNoCommit() on the current transaction and (2) storing the transaction in the Local Prepared List.

Transaction.commit() is executed by mysql using "XA COMMIT xid". By ndb as: executeCommit(), and, on success, remove the transaction from the Local Prepared List.

Transaction.rollback() is executed by mysql using of "XA ROLLBACK xid". By ndb as: rollback() and, on success, removal of transaction from the Local Prepared List.

Also has part of this support, SessionFactory must provide a DistributedRecoveryManager, which supports three methods listPreparedTransactions(), commit(xid), and rollback(xid). These are used for a recovery scenario that assumes NDB and mysql-js have kept running while the Transaction Manager restarted. They rely on a list of transactions that have been prepared, but not committed or rolled back. In the mysql case, this list is on the mysql server at the other end of the connection, but for the NDB case it is stored locally in mysql-js.

SessionFactory.getDistributedRecoveryManager() returns the recovery manager. (Or, aternately, the methods are available on SessionFactory itself).

ListPreparedTransactions() returns the list of prepared transactions. For mysql it is implemented as an "XA RECOVER" statement. For Ndb it is implemented by returning the xids of the transactions on the Local Prepared List. commit(xid) is calls commit() on the transaction matching xid.
rollback(xid) calls rollback() on the transaction matching xid.

Reference material for MySQL: http://dev.mysql.com/doc/refman/5.6/en/xa-statements.html and http://dev.mysql.com/doc/refman/5.6/en/xa-states.html

davidkhala commented 3 years ago

@jdduncan Dear John, long time no see, is this respository under actively maintained?

jdduncan commented 3 years ago

Hi! Feature development stopped a few years ago, but we will fix bugs. And jones-ndb is still shipped with MySQL Cluster 8.0, but not with 7.x versions.