-
Notifications
You must be signed in to change notification settings - Fork 13.7k
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
Conversation
BTW,I don't think you pulled the latest code. |
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()); |
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 don't think we need to refactor this function,the original code is straightforward enough
LGTM,please take a look,thanks @chia7712 |
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.
@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))); |
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 it expected that rack
will be empty
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 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.
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.
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."))));
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.
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); |
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.
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)) { |
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.
ditto
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.
@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.")))); |
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.
Could you please add UT for it? AdminRackAwareTest
is a good class to have the new test.
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.
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.
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
Minor modification, eliminate warnings for AdminUtils.