N
N
nord_ua2012-03-16 17:04:40
MySQL
nord_ua, 2012-03-16 17:04:40

Distributed transaction not working in PHP + MySQL?

Good afternoon.
I happened to use distributed transactions in a php script. As far as I understand from the docks , having several connections to the database in each, we must open an XA transaction with a unique identifier, then complete it, prepare and commit.
those. looks like that:

[localhost] XA START 'tx-4f633bd5cfd9c7.06037054'
[192.168.56.10] XA START 'tx-4f633bd5cfd9c7.06037054'
[localhost] INSERT INTO `some_table` (field, value) VALUES ('field 191', '845')
[192.168.56.10] INSERT INTO `some_table` (field, value) VALUES ('field 191', '558')
[localhost] XA END 'tx-4f633bd5cfd9c7.06037054'
[localhost] XA PREPARE 'tx-4f633bd5cfd9c7.06037054
[192.168.56.10] Xa End 'TX-4F633BD5CFD9C7.06037054'
[192.168.56.10] Xa Prepare 'TX-4F633BD5CFD9C7.06037054'
[Localhost] XA Commit 'TX-4F633BD5CFD9C7.06037054'
[192.168.56.10] XA Commit 'TX- 4f633bd5cfd9c7.06037054'

The code that does this can be found here
Everything works as it should when everything works as it should. But when I drop one server after doing END and PREPARE and just before doing COMMIT I get the following message:
LAST INT: 325
[localhost] XA START 'tx-4f633eb70ca183.03963688'
[192.168.56.10] XA START 'tx-4f633eb70ca183.03963688'
[localhost] INSERT INTO `some_table` (field, value) VALUES ('field 325', '818')
[192.168.56.10] INSERT INTO `some_table` (field, value) VALUES ('field 325', '677')
[localhost] XA END 'tx-4f633eb70ca183.03963688'
[localhost] XA PREPARE 'tx- Sleep .
_
_
Press enter…
Done. Committing.
[localhost] XA COMMIT 'tx-4f633eb70ca183.03963688'
[192.168.56.10] XA COMMIT 'tx-4f633eb70ca183.
[192.168.56.10] ERROR: MySQL server has gone away

According to the logs, everything is correct, only on the first server the line was inserted into the database, but not on the second server. Besides there is no transaction in RECOVERY.
LOCALHOST:
mysql> select * from some_table;
+----+-----------+-------+
| id | field | value |
+----+-----------+-------+
| 1 | field 325 | 818 |
+----+-----------+-------+
1 row in set (0.00 sec)
mysql> XA RECOVER;
Empty set (0.00 sec)

192.168.56.10
mysql> select * from some_table;
Empty set (0.00 sec)
mysql> xa recover;
Empty set (0.00 sec)

Those. there is no benefit from the transaction. With what it can be connected? Of course, you can follow the code so that there are no errors in the log, but then there is no point in transactions at all.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
vajadhava, 2012-03-16
@vajadhava

who knows…
try in this order:
[localhost] XA END 'tx-4f633bd5cfd9c7.06037054'
[192.168.56.10] XA END 'tx-4f633bd5cfd9c7.06037054'
[localhost] XA PREPARE 'tx-
4f633bd5cfd9c0.06 56.10] XA PREPARE 'tx-4f633bd5cfd9c7.06037054'

R
romik, 2012-03-16
@romik

A two-phase commit basically protects against the fact that one of the participants violates the constraint and refuses to commit. He also experiences some other failures, but not the intervention of a person who set himself the task of breaking him.
Well, it looks like bugs.mysql.com/bug.php?id=12161 is also relevant to your question.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question