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

Add getTxnID method in Transaction.java #11438

Merged
merged 5 commits into from
Jul 27, 2021
Merged

Add getTxnID method in Transaction.java #11438

merged 5 commits into from
Jul 27, 2021

Conversation

liangyepianzhou
Copy link
Contributor

@liangyepianzhou liangyepianzhou commented Jul 23, 2021

Motivation

In order to facilitate the use of transaction, it is more convenient to obtain TxnId

implement

Add getTxnID() method in Transaction.java and implement in TransactionImp.

Test

Write a test in transactionTest .


@Test
public void testGetTxnID() throws Exception {
Awaitility.await().atMost(4, TimeUnit.SECONDS).until(()->{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need Awaitility here? I think the transaction can be created directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TransactionCoodinator may not be ready

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I see. Could you please help add a comment? This will help others to understand.
Related to this fix: #11357

}
return true;
});
Transaction transaction = pulsarClient.newTransaction()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why need to create the transaction again?

Comment on lines +159 to +160
Assert.assertEquals(txnID.getLeastSigBits(), 1);
Assert.assertEquals(txnID.getMostSigBits(), 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will always get transaction ID (1,0) here? I mean we can just check the txnID is not null.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact it should always be this

Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very good.

I have a comment about the test.
can you please take a look ?

public void testGetTxnID() throws Exception {
Awaitility.await().atMost(4, TimeUnit.SECONDS).until(()->{
try {
Transaction transaction = pulsarClient.newTransaction()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@congbobo184 @codelipenghui
I believe that this is not a good expected behaviour for a client.

it should be the newTransaction() method that waits for one Coordinator to be available up to a given (configurable) timeout.
otherwise the API is difficult to understand and to use.

can we add an utility method in TransactionTestBase like "waitForCoordinatorToBeAvailable" ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good suggestion.
but this PR is mainly for getTxnID, and waitForCoordinatorToBeAvailable will be optimized later

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand your concern @liangyuanpeng
But if we leave here this Awaiatilty loop we won't remove it in the future probably.

It is better to fix it now

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you prefer we can create a separate patch to be committed before this patch.
But adding that method should be easy

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Different tests may require different numbers of broker and tc.
Is it more appropriate to mention a pr to fix this problem ?
If you don't mind, I will do this later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have optimized waitForCoordinatorToBeAvailable method for TransactionTest.

Copy link
Contributor

@congbobo184 congbobo184 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! @eolivelli waitForCoordinatorToBeAvailable can be implemented in another pr. what do you think? @liangyuanpeng Are you interested in implementing it in the next PR??

@codelipenghui
Copy link
Contributor

I think we can implement the waitForCoordinatorToBeAvailable first and then merge this PR.

Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very better !

I left some final comments.
We are on our way !
thank you

@@ -53,23 +61,26 @@

private static final String TENANT = "tnx";
private static final String NAMESPACE1 = TENANT + "/ns1";
private static final int NUM_BROKER = 1;
private static final int NUM_TC_PER_ = 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a typo here ? why this variable ends with a '_' ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

terribly sorry.
I overlooked this detail.
Thanks for pointing out.

this.internalSetup();

String[] brokerServiceUrlArr = getPulsarServiceList().get(0).getBrokerServiceUrl().split(":");
String[] brokerServiceUrlArr = getPulsarServiceList().get(NUM_BROKER - 1).getBrokerServiceUrl().split(":");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why we are picking the last and not the first ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excuse me.
I can't think of the difference between them, I just use NUM_BROKER-1 uniformly.
But maybe, if there is no difference, it is a great philosophy to modify as little as possible.

Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very good
I left my final feedback.

then the patch is good to go from my point of you

thanks for your patience

@@ -53,23 +61,26 @@

private static final String TENANT = "tnx";
private static final String NAMESPACE1 = TENANT + "/ns1";
private static final int NUM_BROKER = 1;
private static final int NUM_TC_PER = 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about NUM_PARTITIONS ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your help and guidance,
your meticulous spirit and outstanding design concept have benefited me a lot

@@ -53,23 +61,26 @@

private static final String TENANT = "tnx";
private static final String NAMESPACE1 = TENANT + "/ns1";
private static final int NUM_BROKER = 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about NUM_BROKERS ?

@codelipenghui
Copy link
Contributor

@eolivelli Thanks for the review. Could you please help take a look again?

Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

thank you

@eolivelli eolivelli merged commit 1977a84 into apache:master Jul 27, 2021
codelipenghui pushed a commit that referenced this pull request Jul 30, 2021
@codelipenghui codelipenghui added the cherry-picked/branch-2.8 Archived: 2.8 is end of life label Jul 30, 2021
bharanic-dev pushed a commit to bharanic-dev/pulsar that referenced this pull request Mar 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants