-
Notifications
You must be signed in to change notification settings - Fork 588
HDDS-13305. Create wrapper object for container checksums #8789
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
8f59ac0
HDDS-13305. Create wrapper object for container checksums
echonesis 3323de2
Merge branch 'master' into HDDS-13305
echonesis 902997d
merge fix
echonesis 1299510
PR review modification update
echonesis f0e922f
checkstyle update
echonesis 0253d2d
Replica modification update
echonesis ed449d4
merge fix
echonesis c9425f4
review update
echonesis 242f2e4
placeholder update
echonesis cffc5c2
checkstyle update
echonesis 620efb0
conflict fix
echonesis 42d61cf
reduce mod test
echonesis 5fd256e
ra test
echonesis f4ef042
fix: CR update
echonesis df89c7f
fix: CR update
echonesis d5cf9d9
Merge branch 'master' into HDDS-13305-dev
echonesis bb8bb9f
Use data-only factory method in ContainerReplicaHistory
adoroszlai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
87 changes: 87 additions & 0 deletions
87
...op-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/container/ContainerChecksums.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.hadoop.hdds.scm.container; | ||
|
|
||
| import java.util.Objects; | ||
| import net.jcip.annotations.Immutable; | ||
|
|
||
| /** | ||
| * Wrapper for container checksums (data, metadata, etc.). | ||
| * Provides equality, hash, and hex string rendering. | ||
| * A value of 0 indicates an unknown or unset checksum. | ||
| */ | ||
| @Immutable | ||
| public final class ContainerChecksums { | ||
| // Checksum of the data within the wrapper. | ||
| private final long dataChecksum; | ||
|
|
||
| // Checksum of the metadata within the wrapper. | ||
| private final long metadataChecksum; | ||
|
|
||
| private static final ContainerChecksums UNKNOWN = | ||
| new ContainerChecksums(0L, 0L); | ||
|
|
||
| private ContainerChecksums(long dataChecksum, long metadataChecksum) { | ||
| this.dataChecksum = dataChecksum; | ||
| this.metadataChecksum = metadataChecksum; | ||
| } | ||
|
|
||
| public static ContainerChecksums unknown() { | ||
| return UNKNOWN; | ||
| } | ||
|
|
||
| public static ContainerChecksums of(long dataChecksum) { | ||
| return new ContainerChecksums(dataChecksum, 0L); | ||
| } | ||
|
|
||
| public static ContainerChecksums of(long dataChecksum, long metadataChecksum) { | ||
| return new ContainerChecksums(dataChecksum, metadataChecksum); | ||
| } | ||
|
|
||
| public long getDataChecksum() { | ||
| return dataChecksum; | ||
| } | ||
|
|
||
| public long getMetadataChecksum() { | ||
| return metadataChecksum; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object obj) { | ||
| if (this == obj) { | ||
| return true; | ||
| } | ||
| if (!(obj instanceof ContainerChecksums)) { | ||
| return false; | ||
| } | ||
| ContainerChecksums that = (ContainerChecksums) obj; | ||
| return dataChecksum == that.dataChecksum && | ||
| metadataChecksum == that.metadataChecksum; | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(dataChecksum, metadataChecksum); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "data=" + Long.toHexString(getDataChecksum()) + | ||
| ", metadata=" + Long.toHexString(getMetadataChecksum()); | ||
| } | ||
| } |
55 changes: 55 additions & 0 deletions
55
...dds/common/src/test/java/org/apache/hadoop/hdds/scm/container/TestContainerChecksums.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.hadoop.hdds.scm.container; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertNotEquals; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| class TestContainerChecksums { | ||
| @Test | ||
| void testEqualsAndHashCode() { | ||
| ContainerChecksums c1 = ContainerChecksums.of(123L, 0L); | ||
| ContainerChecksums c2 = ContainerChecksums.of(123L, 0L); | ||
| ContainerChecksums c3 = ContainerChecksums.of(456L, 0L); | ||
| ContainerChecksums c4 = ContainerChecksums.of(123L, 789L); | ||
| ContainerChecksums c5 = ContainerChecksums.of(123L, 789L); | ||
| ContainerChecksums c6 = ContainerChecksums.of(123L, 790L); | ||
|
|
||
| assertEquals(c1, c2); | ||
| assertEquals(c1.hashCode(), c2.hashCode()); | ||
| assertNotEquals(c1, c3); | ||
| assertNotEquals(c1, c4); | ||
| assertEquals(c4, c5); | ||
| assertNotEquals(c4, c6); | ||
| } | ||
|
|
||
| @Test | ||
| void testToString() { | ||
| ContainerChecksums c1 = ContainerChecksums.of(0x1234ABCDL, 0L); | ||
| assertThat(c1.toString()).contains("data=1234abcd", "metadata=0"); | ||
|
|
||
| ContainerChecksums c2 = ContainerChecksums.of(0x1234ABCDL, 0xDEADBEEFL); | ||
| assertThat(c2.toString()).contains("data=1234abcd").contains("metadata=deadbeef"); | ||
|
|
||
| ContainerChecksums c3 = ContainerChecksums.unknown(); | ||
| assertThat(c3.toString()).contains("data=0").contains("metadata=0"); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 think we can just use
getChecksumsin place of getters for each individual checksum. Otherwise this class will need to be updated every timeContainerChecksumshas a value added to 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.
long getDataChecksumwas retained on my request to reduce change in existing tests. We don't need to adjust this class for future values.