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

HDDS-10422. Fix some warnings about exposing internal representation in hdds-common #6351

Merged
merged 16 commits into from
May 22, 2024

Conversation

adoroszlai
Copy link
Contributor

@adoroszlai adoroszlai commented Mar 8, 2024

What changes were proposed in this pull request?

Fix some Spotbugs (4.x) warnings that code may expose internal representation. Notable changes:

  • OzoneQuota used to initalize contents of QuotaList, moved to the latter (deferred to HDDS-10896)
  • move creation of mutable metrics objects to PerformanceMetrics (deferred to HDDS-10897)

Also remove unused hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/BatchOperation.java (seems to be outdated duplicate of hadoop-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

@adoroszlai adoroszlai added the code-cleanup Changes that aim to make code better, without changing functionality. label Mar 8, 2024
@adoroszlai adoroszlai self-assigned this Mar 8, 2024
@adoroszlai adoroszlai changed the title HDDS-10422. Fix some expose internal representation warnings in hdds-common HDDS-10422. Fix some warnings about exposing internal representation in hdds-common Mar 24, 2024
@adoroszlai adoroszlai requested a review from duongkame May 6, 2024 17:52
@adoroszlai adoroszlai requested a review from szetszwo May 18, 2024 13:07
Copy link
Contributor

@szetszwo szetszwo left a 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?

Comment on lines 100 to 102
if (info.hasStripeChecksum()) {
chunkInfo.setStripeChecksum(info.getStripeChecksum());
}
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 the case that info.hasStripeChecksum() is always false? If yes, how about adding a precondition?

Copy link
Contributor Author

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.

@@ -222,7 +222,7 @@ public synchronized void setPort(Name name, int port) {
* @return DataNode Ports
*/
public synchronized List<Port> getPorts() {
return ports;
return new ArrayList<>(ports);
Copy link
Contributor

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.class

Copy link
Contributor Author

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.

@@ -104,6 +105,6 @@ public String getScmId() {
* @return List of peer address
*/
public List<String> getRatisPeerRoles() {
return peerRoles;
return Collections.unmodifiableList(peerRoles);
Copy link
Contributor

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);
  }

@@ -555,13 +555,14 @@ public Builder(Pipeline pipeline) {
this.creationTimestamp = pipeline.getCreationTimestamp();
this.suggestedLeaderId = pipeline.getSuggestedLeaderId();
if (nodeStatus != null) {
replicaIndexes = new HashMap<>();
Map<DatanodeDetails, Integer> indexes = new HashMap<>();
Copy link
Contributor

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();

@@ -598,7 +599,7 @@ public Builder setNodes(List<DatanodeDetails> nodes) {

public Builder setNodeOrder(List<Integer> orders) {
// for build from ProtoBuf
this.nodeOrder = orders;
this.nodeOrder = orders == null ? ImmutableList.of() : ImmutableList.copyOf(orders);
Copy link
Contributor

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.

@@ -47,7 +49,7 @@ public ChecksumData(ChecksumType checksumType, int bytesPerChecksum,
List<ByteString> checksums) {
this.type = checksumType;
this.bytesPerChecksum = bytesPerChecksum;
this.checksums = checksums;
this.checksums = checksums == null ? ImmutableList.of() : ImmutableList.copyOf(checksums);
Copy link
Contributor

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);

@@ -45,7 +46,7 @@ public class LeaseCallbackExecutor<T> implements Runnable {
*/
public LeaseCallbackExecutor(T resource, List<Callable<Void>> callbacks) {
this.resource = resource;
this.callbacks = callbacks;
this.callbacks = callbacks == null ? ImmutableList.of() : ImmutableList.copyOf(callbacks);
Copy link
Contributor

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();
Copy link
Contributor

@szetszwo szetszwo May 18, 2024

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Deferred to HDDS-10897.

@adoroszlai
Copy link
Contributor Author

Thanks @szetszwo for the review. Deferred some changes that can be logically grouped to separate tasks: HDDS-10896, HDDS-10897 and HDDS-10899.

Copy link
Contributor

@szetszwo szetszwo left a 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.

@szetszwo szetszwo merged commit 0807a77 into apache:master May 22, 2024
39 checks passed
@adoroszlai
Copy link
Contributor Author

Thanks @szetszwo for reviewing and merging this.

@adoroszlai adoroszlai deleted the HDDS-10422 branch May 23, 2024 05:22
jojochuang pushed a commit to jojochuang/ozone that referenced this pull request May 23, 2024
errose28 added a commit to errose28/ozone that referenced this pull request May 28, 2024
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code-cleanup Changes that aim to make code better, without changing functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants