Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transaction Commit retries cause _check_tx_state to raise ValueError #757

Open
Darejkal opened this issue Oct 18, 2024 · 2 comments
Open

Comments

@Darejkal
Copy link

Darejkal commented Oct 18, 2024

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
@Darejkal Darejkal changed the title Transaction retries cause _check_tx_state to raise ValueError Transaction Commit retries cause _check_tx_state to raise ValueError Oct 18, 2024
@ceache
Copy link
Contributor

ceache commented Oct 18, 2024 via email

@Darejkal
Copy link
Author

The current behaviour of TransactionRequest is to set committed before making the connection. This makes subsequent calls to TransactionRequest.commit throw ValueError. KazooRetry will then just give up after the first failed connection apparently.

You are not supposed to reuse the transaction after it fails (or succeeds).

I agree. One thing though. I think it conflicts with the role of using KazooRetry.retry:

Call a function with arguments until it completes without throwing a Kazoo exception

We could either fix this by setting committed to False in the retry loop or add a documentation that KazooRetry is not meant for TransactionRequest. Both of which scream of technical debt for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants