-
Notifications
You must be signed in to change notification settings - Fork 640
HDDS-16388. Datanode putBlock Support StorageType #11223
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
base: HDDS-11233
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ | |
|
|
||
| import com.fasterxml.jackson.annotation.JsonIgnore; | ||
| import java.util.Objects; | ||
| import org.apache.hadoop.fs.StorageType; | ||
| import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos; | ||
| import org.apache.hadoop.hdds.protocol.proto.HddsProtos; | ||
|
|
||
|
|
@@ -34,29 +35,42 @@ public class BlockID { | |
| // BlockID object. | ||
| private final Integer replicaIndex; | ||
|
|
||
| // Represents storage type of Block on a particular Datanode. | ||
| // Note this variable in the OM side will be null, | ||
| // because the OmKeyLocationInfo#getProtobuf Use BlockID#getProtobuf to get Protobuf object, | ||
| // BlockID#getProtobuf does not set storageType value in Protobuf. | ||
|
|
||
| // Currently for java class BlockID, OM and Datanode share the same java class object, | ||
| // but the protobuf objects HddsProtos.BlockID and ContainerProtos.DatanodeBlockID are | ||
| // used for OM and Datanode respectively. | ||
| private StorageType storageType; | ||
|
|
||
| public BlockID(long containerID, long localID) { | ||
| this(containerID, localID, 0, null); | ||
| this(containerID, localID, 0, null, null); | ||
| } | ||
|
|
||
| private BlockID(long containerID, long localID, long bcsID, Integer repIndex) { | ||
| private BlockID(long containerID, long localID, long bcsID, Integer repIndex, | ||
| StorageType storageType) { | ||
| containerBlockID = new ContainerBlockID(containerID, localID); | ||
| blockCommitSequenceId = bcsID; | ||
| this.replicaIndex = repIndex; | ||
| this.storageType = storageType; | ||
| } | ||
|
|
||
| public BlockID(BlockID blockID) { | ||
| this(blockID.getContainerID(), blockID.getLocalID(), blockID.getBlockCommitSequenceId(), | ||
| blockID.getReplicaIndex()); | ||
| blockID.getReplicaIndex(), blockID.getStorageType()); | ||
| } | ||
|
|
||
| public BlockID(ContainerBlockID containerBlockID) { | ||
| this(containerBlockID, 0, null); | ||
| this(containerBlockID, 0, null, null); | ||
| } | ||
|
|
||
| private BlockID(ContainerBlockID containerBlockID, long bcsId, Integer repIndex) { | ||
| private BlockID(ContainerBlockID containerBlockID, long bcsId, Integer repIndex, StorageType storageType) { | ||
| this.containerBlockID = containerBlockID; | ||
| blockCommitSequenceId = bcsId; | ||
| this.replicaIndex = repIndex; | ||
| this.storageType = storageType; | ||
| } | ||
|
|
||
| public long getContainerID() { | ||
|
|
@@ -84,6 +98,10 @@ public ContainerBlockID getContainerBlockID() { | |
| return containerBlockID; | ||
| } | ||
|
|
||
| public StorageType getStorageType() { | ||
| return storageType; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| StringBuilder sb = new StringBuilder(64); | ||
|
|
@@ -94,7 +112,8 @@ public String toString() { | |
| public void appendTo(StringBuilder sb) { | ||
| containerBlockID.appendTo(sb); | ||
| sb.append(" bcsId: ").append(blockCommitSequenceId) | ||
| .append(" replicaIndex: ").append(replicaIndex); | ||
| .append(" replicaIndex: ").append(replicaIndex) | ||
| .append(" storageType: ").append(storageType); | ||
| } | ||
|
|
||
| @JsonIgnore | ||
|
|
@@ -103,6 +122,9 @@ public ContainerProtos.DatanodeBlockID getDatanodeBlockIDProtobuf() { | |
| if (replicaIndex != null) { | ||
| blockID.setReplicaIndex(replicaIndex); | ||
| } | ||
| if (storageType != null) { | ||
| blockID.setStorageTypeID(StorageTypeUtils.getID(storageType)); | ||
| } | ||
| return blockID.build(); | ||
| } | ||
|
|
||
|
|
@@ -116,10 +138,15 @@ public ContainerProtos.DatanodeBlockID.Builder getDatanodeBlockIDProtobufBuilder | |
|
|
||
| @JsonIgnore | ||
| public static BlockID getFromProtobuf(ContainerProtos.DatanodeBlockID blockID) { | ||
| StorageType storageType = null; | ||
| if (blockID.hasStorageTypeID() && blockID.getStorageTypeID() > 0) { | ||
| storageType = StorageTypeUtils.getStorageTypeFromID(blockID.getStorageTypeID()); | ||
| } | ||
| return new BlockID(blockID.getContainerID(), | ||
| blockID.getLocalID(), | ||
| blockID.getBlockCommitSequenceId(), | ||
| blockID.hasReplicaIndex() ? blockID.getReplicaIndex() : null); | ||
| blockID.hasReplicaIndex() ? blockID.getReplicaIndex() : null, | ||
| storageType); | ||
| } | ||
|
|
||
| @JsonIgnore | ||
|
|
@@ -133,7 +160,7 @@ public HddsProtos.BlockID getProtobuf() { | |
| public static BlockID getFromProtobuf(HddsProtos.BlockID blockID) { | ||
| return new BlockID( | ||
| ContainerBlockID.getFromProtobuf(blockID.getContainerBlockID()), | ||
| blockID.getBlockCommitSequenceId(), null); | ||
| blockID.getBlockCommitSequenceId(), null, null); | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -147,12 +174,13 @@ public boolean equals(Object o) { | |
| BlockID blockID = (BlockID) o; | ||
| return this.getContainerBlockID().equals(blockID.getContainerBlockID()) | ||
| && this.getBlockCommitSequenceId() == blockID.getBlockCommitSequenceId() | ||
| && Objects.equals(this.getReplicaIndex(), blockID.getReplicaIndex()); | ||
| && Objects.equals(this.getReplicaIndex(), blockID.getReplicaIndex()) | ||
| && Objects.equals(this.getStorageType(), blockID.getStorageType()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(containerBlockID.getContainerID(), containerBlockID.getLocalID(), | ||
| blockCommitSequenceId, replicaIndex); | ||
| blockCommitSequenceId, replicaIndex, storageType); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. |
||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
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.
Could this stay unset?
HDDS-15882will set the real type at thewriteChunkAsynccall below, which wouldn't touch this builder, so this line would be easy to leave behind claimingDISK.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.
Both
writeChunkAsyncmethod andthis.containerBlockDatarequire aStorageTypefield, which is used for different operations.You can refer to
replicationIndex, bothwriteChunkAsyncmethod andthis.containerBlockDataset this value.