Fix persistent transaction commit race condition.
authorMichael Adam <obnox@samba.org>
Tue, 21 Jul 2009 09:30:38 +0000 (11:30 +0200)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Wed, 29 Jul 2009 01:12:39 +0000 (11:12 +1000)
commitf88103516e5ad723062fb95fcb07a128f1069d69
tree51e4861bba61b40b48f5580310c5ff6c74c16fd7
parente9194a130327d6b05a8ab90bd976475b0e93b06d
Fix persistent transaction commit race condition.

In ctdb_client.c:ctdb_transaction_commit(), after a failed
TRANS2_COMMIT control call (for instance due to the 1-second
being exceeded waiting for a busy node's reply), there is a
1-second gap between the transaction_cancel() and
replay_transaction() calls in which there is no lock on the
persistent db. And due to the lack of global state
indicating that a transaction is in progress in ctdbd, other nodes
may succeed to start transactions on the db in this gap and
even worse work on top of the possibly already pushed changes.
So the data diverges on the several nodes.

This change fixes this by introducing global state for a transaction
commit being active in the ctdb_db_context struct and in a db_id field
in the client so that a client keeps track of _which_ tdb it as
transaction commit running on. These data are set by ctdb upon
entering the trans2_commit control and they are cleared in the
trans2_error or trans2_finished controls. This makes it impossible
to start a nother transaction or migrate a record to a different
node while a transaction is active on a persistent tdb, including
the retry loop.

This approach is dead lock free and still allows recovery process
to be started in the retry-gap between cancel and replay.
Also note, that this solution does not require any change in the
client side.

This was debugged and developed together with
Stefan Metzmacher <metze@samba.org> - thanks!

Michael
include/ctdb_private.h
server/ctdb_call.c
server/ctdb_daemon.c
server/ctdb_persistent.c