adoroszlai commented on code in PR #6655:
URL: https://github.com/apache/ozone/pull/6655#discussion_r1844935071
##########
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/protocol/DatanodeDetails.java:
##########
@@ -492,14 +497,19 @@ public HddsProtos.DatanodeDetailsProto.Builder
toProtoBuilder(
ClientVersion.fromProtoValue(clientVersion)
.compareTo(VERSION_HANDLES_UNKNOWN_DN_PORTS) >= 0;
for (Port port : ports) {
- if (handlesUnknownPorts || Name.V0_PORTS.contains(port.getName())) {
- builder.addPorts(port.toProto());
- } else {
- if (LOG.isDebugEnabled()) {
- LOG.debug("Skip adding {} port {} to proto message for client v{}",
- port.getName(), port.getValue(), clientVersion);
+ if (requiredPorts.isEmpty() || requiredPorts.contains(port.name)) {
+ if (handlesUnknownPorts || Name.V0_PORTS.contains(port.getName())) {
+ builder.addPorts(port.toProto());
+ } else {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Skip adding {} port {} to proto message for client v{}",
+ port.getName(), port.getValue(), clientVersion);
+ }
}
}
Review Comment:
My
[suggestion](https://github.com/apache/ozone/pull/6655#pullrequestreview-2045531935)
included that, plus two minor optimizations:
- check whether all ports are needed (`requiredPorts.isEmpty()`) once,
before the loop
- exit from loop if found all requested ports
It would be nice to adopt these.
```java
final int requestedPortCount = requiredPorts.size();
final boolean maySkip = requestedPortCount > 0;
for (Port port : ports) {
if (maySkip && !requiredPorts.contains(port.getName())) {
if (LOG.isDebugEnabled()) {
LOG.debug("Skip adding {} port {} to proto message",
port.getName(), port.getValue());
}
} else if (handlesUnknownPorts ||
Name.V0_PORTS.contains(port.getName())) {
builder.addPorts(port.toProto());
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("Skip adding {} port {} to proto message for client v{}",
port.getName(), port.getValue(), clientVersion);
}
}
if (maySkip && builder.getPortsCount() == requestedPortCount) {
break;
}
}
```
https://github.com/adoroszlai/ozone/blob/dce755c4f3a3e409dfc4b43bc16a48cf2a068842/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/protocol/DatanodeDetails.java#L458-L477
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]