Skip to content

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

Merged
szetszwo merged 16 commits into
apache:masterfrom
adoroszlai:HDDS-10422
May 22, 2024
Merged

HDDS-10422. Fix some warnings about exposing internal representation in hdds-common#6351
szetszwo merged 16 commits into
apache:masterfrom
adoroszlai:HDDS-10422

Conversation

@adoroszlai

@adoroszlaiadoroszlai commented Mar 8, 2024

Copy link
Copy Markdown
Contributor

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

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

@szetszwoszetszwo left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
ContributorAuthor

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

Copy link
Copy Markdown
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
//NodeDecommissionManagerprivatebooleanvalidateDNPortMatch(intport, DatanodeDetailsdn) {
returndn.containPort(port);
}
//DatanodeDetailspublicsynchronizedbooleancontainPort(intport) {
for (Portp : ports) {
if (p.getValue() == port) {
returntrue;
}
}
returnfalse;
}
  • DatanodeIdYaml
@@ -238,8 +239,9@@privatestaticDatanodeDetailsYamlgetDatanodeDetailsYaml(
= newDatanodeLayoutStorage(conf, datanodeDetails.getUuidString());
Map<String, Integer> portDetails = newLinkedHashMap<>();
- if (!CollectionUtils.isEmpty(datanodeDetails.getPorts())) {
- for (DatanodeDetails.Portport : datanodeDetails.getPorts()) {
+ finalList<DatanodeDetails.Port> datanodePorts = datanodeDetails.getPorts();
+ if (!CollectionUtils.isEmpty(datanodePorts)) {
+ for (DatanodeDetails.Portport : datanodePorts) {
Fieldf = null;
try {
f = DatanodeDetails.Port.Name.class

Copy link
Copy Markdown
ContributorAuthor

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

Copy link
Copy Markdown
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.

privateScmInfo(StringclusterId, StringscmId, 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<>();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Use builder:

finalImmutableMap.Builder<DatanodeDetails, Integer> b = ImmutableMap.builder();
for (DatanodeDetailsdn : nodeStatus.keySet()) {
intindex = 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);

Copy link
Copy Markdown
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.

this.type = checksumType;
this.bytesPerChecksum = bytesPerChecksum;
this.checksums = checksums;
this.checksums = checksums == null ? ImmutableList.of() : ImmutableList.copyOf(checksums);

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

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

@szetszwoszetszwoMay 18, 2024

Copy link
Copy Markdown
Contributor

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
Copy Markdown
ContributorAuthor

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
Copy Markdown
ContributorAuthor

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

@szetszwoszetszwo left a comment

Copy link
Copy Markdown
Contributor

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:masterMay 22, 2024
@adoroszlai

Copy link
Copy Markdown
ContributorAuthor

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 freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code-cleanupChanges that aim to make code better, without changing functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@adoroszlai@szetszwo