pulsar icon indicating copy to clipboard operation
pulsar copied to clipboard

[improve][txn] Add getState in transaction for client API

Open congbobo184 opened this issue 3 years ago • 4 comments

Motivation

now org.apache.pulsar.client.api.transaction.Transaction dont have a interface for user to get the transaction state.

user can get the transaction state to do user's own op.

Modifications

  1. add the interface in org.apache.pulsar.client.api.transaction.Transaction getState
  2. TransactionImpl implement the interface
     * Get transaction state.
     *
     * @return {@link State} the state of the transaction.
     */
    State getState();

Verifying this change

add the test

Does this pull request potentially affect one of the following parts:

If yes was chosen, please highlight the changes

  • Dependencies (does it add or upgrade a dependency): (no)
  • The public API: (no)
  • The schema: (no)
  • The default values of configurations: (no)
  • The wire protocol: (no)
  • The rest endpoints: (no)
  • The admin cli options: (no)
  • Anything that affects deployment: (no)

Documentation

  • Does this pull request introduce a new feature? (yes)

  • If yes, how is the feature documented? (not applicable / docs / JavaDocs / not documented)

  • If a feature is not applicable for documentation, explain why?

  • If a feature is not documented yet in this PR, please create a followup issue for adding the documentation

  • [x] doc-not-needed

congbobo184 avatar Sep 02 '22 06:09 congbobo184

I hope it can be cherry-picked to release branches from branch-2.9. So that users can use the new method to check the transaction state. And the change will not introduce risk to release branches.

codelipenghui avatar Sep 02 '22 06:09 codelipenghui

@Anonymitaet Please help review the Java Doc

codelipenghui avatar Sep 05 '22 05:09 codelipenghui

@Anonymitaet @codelipenghui I have fixed the comments, please review again. Thanks! :)

congbobo184 avatar Sep 05 '22 13:09 congbobo184

@nicoloboschi I see a transaction production user. They are using TransactionImpl.checkIfOpen() to do some checks when they using transactions. Otherwise, they can only do it by catching exceptions, but it's a bad experience. The ideal case is users don't need to care about the transaction state, just commit it or abort it. Always under some complex use cases, users depend on the state check (same as client.isConnected(); consumer.isConnected();)

codelipenghui avatar Sep 08 '22 13:09 codelipenghui

Cherry-picked by #19834

Technoboy- avatar Mar 16 '23 11:03 Technoboy-