-
Notifications
You must be signed in to change notification settings - Fork 390
Open
Description
Expected Behavior
When the connection is bad, KazooClient should try to commit the transaction again. The state of committed before the retry attempt should be False, because zookeeper did not actually commit this transaction. Or KazooRetry should be able to reset committed when encounter retry-able connection-related errors.
Actual Behavior
Transaction is set as committed. Subsequent attempts by KazooRetry cause Transaction to raise ValueError due to _check_tx_state. This is due to commit_async setting committed to true before making the connection.
def commit_async(self):
"""Commit the transaction asynchronously.
:rtype: :class:`~kazoo.interfaces.IAsyncResult`
"""
self._check_tx_state()
self.committed = True
async_object = self.client.handler.async_result()
self.client._call(Transaction(self.operations), async_object)
return async_object
The problem is a result from the current intention for committed:
The ``committed`` attribute only indicates whether this
transaction has been sent to Zookeeper and is used to prevent
duplicate commits of the same transaction. The result should be
checked to determine if the transaction executed as desired.
This requires manually retrying to commit TransactionRequest.
Snippet to Reproduce the Problem
retry_policy = KazooRetry(max_tries=-1, delay=0.1, backoff=2, max_delay=60,sleep_func=gevent.sleep)
zk = KazooClient(connection_retry=retry_policy)
transaction = zk.transaction()
transaction.create('/example',data_to_bytes(value))
zk.retry(transaction.commit)
Logs with logging in DEBUG mode
Error raised: ValueError("Transaction already committed")
Specifications
- Kazoo version: 2.10.0
- Zookeeper configuration: tick time set to 2000
- Python version: 3.10.14
- OS: ubuntu
Metadata
Metadata
Assignees
Labels
No labels