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

MINOR: Eliminate warnings for AdminUtils #16470

Merged
merged 12 commits into from
Jun 30, 2024
Merged

Conversation

LoganZhuZzz
Copy link
Contributor

Minor modification, eliminate warnings for AdminUtils.

@gongxuanzhang
Copy link
Contributor

BTW,I don't think you pulled the latest code.
before your commit,please run ./gradlew checkstyleMain checkstyleTest spotlessCheck to ensure code style

@LoganZhuZzz
Copy link
Contributor Author

BTW,I don't think you pulled the latest code. before your commit,please run ./gradlew checkstyleMain checkstyleTest spotlessCheck to ensure code style

Thanks for that, I will use the latest code and ensure code style

int currentPartitionId = Math.max(0, startPartitionId);
int nextReplicaShift = fixedStartIndex >= 0 ? fixedStartIndex : RAND.nextInt(brokerList.size());
int nextReplicaShift = determineIndex(fixedStartIndex, brokerList.size());
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need to refactor this function,the original code is straightforward enough

@gongxuanzhang
Copy link
Contributor

LGTM,please take a look,thanks @chia7712

Copy link
Contributor

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

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

@zeq96 thanks for patch

@@ -166,7 +166,7 @@ private static Map<Integer, List<Integer>> assignReplicasToBrokersRackAware(int
int fixedStartIndex,
int startPartitionId) {
Map<Integer, String> brokerRackMap = new HashMap<>();
brokerMetadatas.forEach(m -> brokerRackMap.put(m.id, m.rack.get()));
brokerMetadatas.forEach(m -> brokerRackMap.put(m.id, m.rack.orElse(null)));
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it expected that rack will be empty

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is it expected that rack will be empty

Before calling this function, the parameter brokerMetadatas has already been checked. If rack is empty, an AdminOperationException will be thrown. However, my IDE still issues a warning, so I made an equivalent replacement. Next time, I will ignore this situation.

Copy link
Contributor

Choose a reason for hiding this comment

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

Before calling this function, the parameter brokerMetadatas has already been checked. If rack is empty, an AdminOperationException will be thrown. However, my IDE still issues a warning, so I made an equivalent replacement. Next time, I will ignore this situation.

How about moving the check into assignReplicasToBrokersRackAware? for example:

brokerMetadatas.forEach(m -> brokerRackMap.put(m.id, m.rack.orElseThrow(() -> new AdminOperationException("Not all brokers have rack information for replica rack aware assignment."))));

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Before calling this function, the parameter brokerMetadatas has already been checked. If rack is empty, an AdminOperationException will be thrown. However, my IDE still issues a warning, so I made an equivalent replacement. Next time, I will ignore this situation.

How about moving the check into assignReplicasToBrokersRackAware? for example:

brokerMetadatas.forEach(m -> brokerRackMap.put(m.id, m.rack.orElseThrow(() -> new AdminOperationException("Not all brokers have rack information for replica rack aware assignment."))));

great suggestion, I will do it

@@ -128,12 +128,10 @@ public static Map<Integer, List<Integer>> assignReplicasToBrokers(Collection<Bro
throw new InvalidReplicationFactorException("Replication factor: " + replicationFactor + " larger than available brokers: " + brokerMetadatas.size() + ".");
if (brokerMetadatas.stream().noneMatch(b -> b.rack.isPresent()))
return assignReplicasToBrokersRackUnaware(nPartitions, replicationFactor, brokerMetadatas.stream().map(b -> b.id).collect(Collectors.toList()), fixedStartIndex,
startPartitionId);
startPartitionId);
Copy link
Contributor

Choose a reason for hiding this comment

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

please revert unrelated changes

@@ -196,7 +194,7 @@ private static Map<Integer, List<Integer>> assignReplicasToBrokersRackAware(int
// that do not have any replica, or
// 2. the broker has already assigned a replica AND there is one or more brokers that do not have replica assigned
if ((!racksWithReplicas.contains(rack) || racksWithReplicas.size() == numRacks)
&& (!brokersWithReplicas.contains(broker) || brokersWithReplicas.size() == numBrokers)) {
&& (!brokersWithReplicas.contains(broker) || brokersWithReplicas.size() == numBrokers)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

@gongxuanzhang
Copy link
Contributor

You can turn this setting off if you are troubled by IDEA's automatic modification of blank line

image

@LoganZhuZzz
Copy link
Contributor Author

You can turn this setting off if you are troubled by IDEA's automatic modification of blank line

image

Thanks for that

Copy link
Contributor

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

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

@LoganZhuZzz thanks for your patch. the change LGTM, but it would be nice to have a new test

@@ -166,7 +164,7 @@ private static Map<Integer, List<Integer>> assignReplicasToBrokersRackAware(int
int fixedStartIndex,
int startPartitionId) {
Map<Integer, String> brokerRackMap = new HashMap<>();
brokerMetadatas.forEach(m -> brokerRackMap.put(m.id, m.rack.get()));
brokerMetadatas.forEach(m -> brokerRackMap.put(m.id, m.rack.orElseThrow(() -> new AdminOperationException("Not all brokers have rack information for replica rack aware assignment."))));
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please add UT for it? AdminRackAwareTest is a good class to have the new test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could you please add UT for it? AdminRackAwareTest is a good class to have the new test.

I have added a new unit test for it. If there are any areas that could be improved, please provide me with some guidance and suggestions.

Copy link
Contributor

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

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

LGTM

@chia7712 chia7712 merged commit 33f5995 into apache:trunk Jun 30, 2024
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants