-
Notifications
You must be signed in to change notification settings - Fork 588
HDDS-10422. Fix some warnings about exposing internal representation in hdds-common #6351
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
Conversation
szetszwo
left a comment
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.
@adoroszlai , Thanks for working on this! Please see the comments inlined and also https://issues.apache.org/jira/secure/attachment/13068960/6351_review.patch
BTW, this change is quite big. How about separating it into at least two JIRAs?
| if (info.hasStripeChecksum()) { | ||
| chunkInfo.setStripeChecksum(info.getStripeChecksum()); | ||
| } |
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 the case that info.hasStripeChecksum() is always false? If yes, how about adding a precondition?
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.
No, ChunkInfo proto may have stripe checksum. However, getStripeChecksum of the non-proto ChunkInfo is never called. I'll remove this part of the change.
| */ | ||
| public synchronized List<Port> getPorts() { | ||
| return ports; | ||
| return new ArrayList<>(ports); |
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 should also change the callers in order to reduce copying:
- NodeDecommissionManager
//NodeDecommissionManager
private boolean validateDNPortMatch(int port, DatanodeDetails dn) {
return dn.containPort(port);
}//DatanodeDetails
public synchronized boolean containPort(int port) {
for (Port p : ports) {
if (p.getValue() == port) {
return true;
}
}
return false;
}- DatanodeIdYaml
@@ -238,8 +239,9 @@ private static DatanodeDetailsYaml getDatanodeDetailsYaml(
= new DatanodeLayoutStorage(conf, datanodeDetails.getUuidString());
Map<String, Integer> portDetails = new LinkedHashMap<>();
- if (!CollectionUtils.isEmpty(datanodeDetails.getPorts())) {
- for (DatanodeDetails.Port port : datanodeDetails.getPorts()) {
+ final List<DatanodeDetails.Port> datanodePorts = datanodeDetails.getPorts();
+ if (!CollectionUtils.isEmpty(datanodePorts)) {
+ for (DatanodeDetails.Port port : datanodePorts) {
Field f = null;
try {
f = DatanodeDetails.Port.Name.classThere 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.
Thanks for the suggestion, updated.
| */ | ||
| public List<String> getRatisPeerRoles() { | ||
| return peerRoles; | ||
| return Collections.unmodifiableList(peerRoles); |
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.
Do it in constructor.
private ScmInfo(String clusterId, String scmId, List<String> peerRoles) {
this.clusterId = clusterId;
this.scmId = scmId;
this.peerRoles = Collections.unmodifiableList(peerRoles);
}| this.suggestedLeaderId = pipeline.getSuggestedLeaderId(); | ||
| if (nodeStatus != null) { | ||
| replicaIndexes = new HashMap<>(); | ||
| Map<DatanodeDetails, Integer> indexes = new HashMap<>(); |
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.
Use builder:
final ImmutableMap.Builder<DatanodeDetails, Integer> b = ImmutableMap.builder();
for (DatanodeDetails dn : nodeStatus.keySet()) {
int index = pipeline.getReplicaIndex(dn);
if (index > 0) {
b.put(dn, index);
}
}
replicaIndexes = b.build();| public Builder setNodeOrder(List<Integer> orders) { | ||
| // for build from ProtoBuf | ||
| this.nodeOrder = orders; | ||
| this.nodeOrder = orders == null ? ImmutableList.of() : ImmutableList.copyOf(orders); |
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.
Since the orders is from a proto, let's use this.nodeOrder = Collections.unmodifiableList(orders); to avoid copying.
| this.type = checksumType; | ||
| this.bytesPerChecksum = bytesPerChecksum; | ||
| this.checksums = checksums; | ||
| this.checksums = checksums == null ? ImmutableList.of() : ImmutableList.copyOf(checksums); |
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.
Copy is not needed here since it is from proto or a new list.
this.checksums = Collections.unmodifiableList(checksums);| public LeaseCallbackExecutor(T resource, List<Callable<Void>> callbacks) { | ||
| this.resource = resource; | ||
| this.callbacks = callbacks; | ||
| this.callbacks = callbacks == null ? ImmutableList.of() : ImmutableList.copyOf(callbacks); |
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.
callbacks always has zero or one element. Let's remove the List<>?
| quotaList.addQuotaList(OZONE_QUOTA_KB, Units.KB, KB); | ||
| quotaList.addQuotaList(OZONE_QUOTA_B, Units.B, 1L); | ||
| } | ||
| private static final QuotaList QUOTA_LIST = new QuotaList(); |
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.
OzoneQuota used to initalize contents of QuotaList, moved to the latter
The QuotaList class is inefficient. Let's remove it.
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.
Deferred to HDDS-10897.
|
Thanks @szetszwo for the review. Deferred some changes that can be logically grouped to separate tasks: HDDS-10896, HDDS-10897 and HDDS-10899. |
szetszwo
left a comment
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.
+1 the change looks good.
|
Thanks @szetszwo for reviewing and merging this. |
…concile-cli * HDDS-10239-container-reconciliation: (296 commits) HDDS-10897. Refactor OzoneQuota (apache#6714) HDDS-10422. Fix some warnings about exposing internal representation in hdds-common (apache#6351) HDDS-10899. Refactor Lease callbacks (apache#6715) HDDS-10890. Increase default value for hdds.container.ratis.log.appender.queue.num-elements (apache#6711) HDDS-10832. Client should switch to streaming based on OpenKeySession replication (apache#6683) HDDS-10435. Support S3 object tags for existing requests (apache#6607) HDDS-10883. Improve logging in Recon for finalising DN logic. (apache#6704) HDDS-8752. Enable TestOzoneRpcClientAbstract#testOverWriteKeyWithAndWithOutVersioning (apache#6702) HDDS-10875. XceiverRatisServer#getRaftPeersInPipeline should be called before XceiverRatisServer#removeGroup (apache#6696) HDDS-10514. Recon - Provide DN decommissioning detailed status and info inline with current CLI command output. (apache#6376) HDDS-10878. Bump zstd-jni to 1.5.6-3 (apache#6701) HDDS-10877. Bump Dropwizard metrics to 3.2.6 (apache#6699) HDDS-10876. Bump jackson to 2.16.2 (apache#6697) HDDS-6116. Remove flaky tag from TestSCMInstallSnapshot (apache#6695) HDDS-2643. TestOzoneDelegationTokenSecretManager#testRenewTokenFailureRenewalTime fails intermittently. HDDS-10699. Refactor ContainerBalancerTask and TestContainerBalancerTask (apache#6537) HDDS-10861. Ozone cli supports default ozone.om.service.id (apache#6680) HDDS-10859. Improve error messages when decommission and maintenance fail-early (apache#6678) HDDS-9031. Upgrade acceptance tests to Docker Compose v2 (apache#6667) HDDS-10559. Add a warning or a check to run repair tool as System user (apache#6574) ... Conflicts: hadoop-ozone/dist/src/main/smoketest/admincli/container.robot
What changes were proposed in this pull request?
Fix some Spotbugs (4.x) warnings that code
may expose internal representation. Notable changes:(deferred to HDDS-10896)OzoneQuotaused to initalize contents ofQuotaList, moved to the lattermove creation of mutable metrics objects to(deferred to HDDS-10897)PerformanceMetricsAlso remove unused
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/BatchOperation.java(seems to be outdated duplicate ofhadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/BatchOperation.java).https://issues.apache.org/jira/browse/HDDS-10422
How was this patch tested?
CI:
https://github.com/adoroszlai/ozone/actions/runs/8200024023