-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Conversation
|
||
@Test | ||
public void testGetTxnID() throws Exception { | ||
Awaitility.await().atMost(4, TimeUnit.SECONDS).until(()->{ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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?
Assert.assertEquals(txnID.getLeastSigBits(), 1); | ||
Assert.assertEquals(txnID.getMostSigBits(), 0); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this 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() |
There was a problem hiding this comment.
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" ?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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??
I think we can implement the |
There was a problem hiding this 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; |
There was a problem hiding this comment.
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 '_' ?
There was a problem hiding this comment.
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(":"); |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.
There was a problem hiding this 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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about NUM_PARTITIONS ?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about NUM_BROKERS ?
@eolivelli Thanks for the review. Could you please help take a look again? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
thank you
(cherry picked from commit 1977a84)
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 .