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

[improve][transactions] Add command to list transaction coordinators #17522

Merged
merged 6 commits into from Nov 11, 2022

Conversation

nicoloboschi
Copy link
Contributor

Fixes #17513

Motivation

At the moment there's no way to list all the transaction coordinators and to understand to which broker own.

Modifications

  • New endpoint `transactions/coordinators´ to get all the coordinators
    • Under the hood it does a lookup to the TC partitioned topic
  • New data object ´TransactionCoordinatorInfo´ -> only contains the brokerServiceUrl field
  • Added the equivalent client call in the pulsar-client admin
  • Added the equivalent client call in the pulsar-admin CLI coordinators-list
  • doc-not-needed

@github-actions github-actions bot added the doc-not-needed Your PR changes do not impact docs label Sep 7, 2022
.thenAccept(map -> {
if (map.isEmpty()) {
asyncResponse.resume(new RestException(Response.Status.NOT_FOUND,
"Transaction coordinator not found"));
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not actually a "problem" to be reported as 404.
we can simply return an empty result.

how can we get to this situation ? when the partitions are not loaded by any broker ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

true, removed

public void testListTransactionCoordinators() throws Exception {
initTransaction(4);
final Map<Integer, TransactionCoordinatorInfo> result = admin
.transactions().listTransactionCoordinatorsAsync().get();
Copy link
Contributor

Choose a reason for hiding this comment

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

should we use Awaitility here ?
are we guaranteed that when we reach this point all the partitions are loaded ?

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 the initTransaction method we wait for all the topic partitions to be loaded

Awaitility.await().until(() ->
                pulsar.getTransactionMetadataStoreService().getStores().size() == coordinatorSize);

return;
}
Map<Integer, TransactionCoordinatorInfo> result = new HashMap<>();
map.forEach((topicPartition, brokerServiceUrl) -> {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that we should return something also for the partitions that are not currently "loaded"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

*
* @return the transaction coordinators list.
*/
Map<Integer, TransactionCoordinatorInfo> listTransactionCoordinators() throws PulsarAdminException;
Copy link
Contributor

Choose a reason for hiding this comment

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

question (not a request for a change):
why returning a Map and not a List ?
I don't think that returning a Map has a particular advantage over returning a List

Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved to List

@NoArgsConstructor
@AllArgsConstructor
public class TransactionCoordinatorInfo {
private String brokerServiceUrl;
Copy link
Contributor

Choose a reason for hiding this comment

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

I would add the id as well, it would make it easier further processing downstream

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agreed

@congbobo184
Copy link
Contributor

@nicoloboschi hi, why not add the broker address into org.apache.pulsar.common.policies.data.TransactionCoordinatorStats, in this way, we don't need to add the new interface.

@congbobo184 congbobo184 added area/transaction doc-required Your PR changes impact docs and you will update later. area/admin and removed doc-not-needed Your PR changes do not impact docs labels Sep 13, 2022
@congbobo184 congbobo184 added this to the 2.12.0 milestone Sep 13, 2022
@github-actions github-actions bot added the doc-not-needed Your PR changes do not impact docs label Sep 13, 2022
@github-actions
Copy link

The pr had no activity for 30 days, mark with Stale label.

@nicoloboschi
Copy link
Contributor Author

@nicoloboschi hi, why not add the broker address into org.apache.pulsar.common.policies.data.TransactionCoordinatorStats, in this way, we don't need to add the new interface.

The stats output is not needed here and they're hard to read considering you have multiple coordinators. Adding the related broker to the stat object requires a lookup request. I'd prefer to not add it

@eolivelli PTAL 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

@nicoloboschi nicoloboschi added ready-to-test and removed doc-required Your PR changes impact docs and you will update later. labels Oct 24, 2022
@nicoloboschi
Copy link
Contributor Author

/pulsarbot rerun-failure-checks

@codecov-commenter
Copy link

codecov-commenter commented Oct 24, 2022

Codecov Report

Merging #17522 (d4f415d) into master (b31c5a6) will increase coverage by 0.08%.
The diff coverage is 70.83%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #17522      +/-   ##
============================================
+ Coverage     46.98%   47.07%   +0.08%     
- Complexity    10343    10382      +39     
============================================
  Files           692      692              
  Lines         67766    67790      +24     
  Branches       7259     7258       -1     
============================================
+ Hits          31842    31913      +71     
+ Misses        32344    32315      -29     
+ Partials       3580     3562      -18     
Flag Coverage Δ
unittests 47.07% <70.83%> (+0.08%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...che/pulsar/broker/admin/impl/TransactionsBase.java 71.97% <66.66%> (-0.42%) ⬇️
...rg/apache/pulsar/broker/admin/v3/Transactions.java 77.23% <100.00%> (+0.56%) ⬆️
...lsar/broker/service/StickyKeyConsumerSelector.java 50.00% <0.00%> (-50.00%) ⬇️
...e/HashRangeExclusiveStickyKeyConsumerSelector.java 0.00% <0.00%> (-36.93%) ⬇️
...oker/loadbalance/LoadResourceQuotaUpdaterTask.java 44.44% <0.00%> (-33.34%) ⬇️
...lsar/broker/loadbalance/impl/ThresholdShedder.java 3.26% <0.00%> (-30.07%) ⬇️
...rg/apache/pulsar/broker/lookup/v1/TopicLookup.java 60.00% <0.00%> (-13.34%) ⬇️
...e/pulsar/broker/service/EntryBatchIndexesAcks.java 82.14% <0.00%> (-10.72%) ⬇️
...org/apache/pulsar/broker/loadbalance/LoadData.java 58.33% <0.00%> (-8.34%) ⬇️
...he/pulsar/client/impl/PartitionedProducerImpl.java 30.34% <0.00%> (-5.13%) ⬇️
... and 46 more

initTransaction(4);
final List<TransactionCoordinatorInfo> result = admin
.transactions().listTransactionCoordinatorsAsync().get();
System.out.println("result" + result);
Copy link
Contributor

Choose a reason for hiding this comment

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

delete

return getPulsarResources()
.getTopicResources()
.getExistingPartitions(SystemTopicNames.TRANSACTION_COORDINATOR_ASSIGN);
})
.thenAccept(allPartitions -> {
allPartitions
.stream()
.filter(partition -> SystemTopicNames
.isTransactionCoordinatorAssign(TopicName.get(partition)))
.forEach(partition -> {
final int coordinatorId = TopicName.getPartitionIndex(partition);
if (!result.containsKey(coordinatorId)) {
result.put(coordinatorId,
new TransactionCoordinatorInfo(coordinatorId, null));
}
});
asyncResponse.resume(result.values());
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 to check again?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because there may be partitions not currently loaded by any broker but it's valuable for the user to know that exists

Copy link
Contributor

Choose a reason for hiding this comment

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

sorry for late response, lookupPartitionedTopicAsync has already return all the partition, it will not missing. are you test it will miss?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you're right. I left only the lookup PTAL

@nicoloboschi
Copy link
Contributor Author

@congbobo184 I fixed the debug line and answered to your question

@nicoloboschi nicoloboschi merged commit 1db89d7 into apache:master Nov 11, 2022
nicoloboschi added a commit to datastax/pulsar that referenced this pull request Nov 11, 2022
…pache#17522)

* [improve][transactions] Add command to list transaction coordinators url

* Address pr's comment and rebase

* checkstyle

* remove debug

* Remove useless call and fix style

* style

(cherry picked from commit 1db89d7)
@nicoloboschi nicoloboschi deleted the cli-transaction-coordinators branch December 1, 2022 16:42
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.

[Transactions] Add pulsar-admin commands to lookup Coordinators
4 participants