Commit 626e22d6 authored by Jeremy Hylton's avatar Jeremy Hylton

Change prepare() signature in IDataManager.

The manager should raise an exception in its prepare() method rather
than returning a boolean to indicate failure.  Rationale: The txn
manager can't raise a reasonable exception, because it doesn't know
what the data manager couldn't prepare.
parent 54a47bce
......@@ -57,7 +57,8 @@ class IDataManager(Interface):
def prepare(transaction):
"""Begin two-phase commit of a transaction.
DataManager should return True or False.
The data manager must raise an exception if it is not prepared
to commit the transaction after executing prepare().
"""
def abort(transaction):
......
......@@ -23,18 +23,14 @@ class AbstractTransactionManager(object):
# commit calls _finishCommit() or abort()
assert txn._status is Status.ACTIVE
txn._status = Status.PREPARING
prepare_ok = True
self.logger.debug("%s: prepare", txn)
try:
for r in txn._resources:
if prepare_ok and not r.prepare(txn):
raise AbortError(r)
r.prepare(txn)
except:
txn._status = Status.FAILED
raise
txn._status = Status.PREPARED
# XXX An error below is intolerable. What state to use?
# Need code to handle this case.
self._finishCommit(txn)
def _finishCommit(self, txn):
......
......@@ -33,7 +33,6 @@ class TestDataManager:
def prepare(self, txn):
if self._fail == "prepare":
raise RuntimeError
return self._vote
def abort(self, txn):
if self._fail == "abort":
......@@ -126,15 +125,6 @@ class BaseTxnTests(unittest.TestCase):
self.assertEqual(txn.status(), Status.FAILED)
txn.abort()
def testCommitPrepareFalse(self):
txn = self.manager.begin()
txn.join(TestDataManager())
txn.join(TestDataManager(vote=False))
self.assertRaises(AbortError, txn.commit)
self.assertEqual(txn.status(), Status.FAILED)
self.assertRaises(IllegalStateError, txn.commit)
txn.abort()
def testCommitFailure(self):
txn = self.manager.begin()
txn.join(TestDataManager())
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment