diff --git a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ChunkKeyHandler.java b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ChunkKeyHandler.java index 38845eb81ea3..21bd114551aa 100644 --- a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ChunkKeyHandler.java +++ b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ChunkKeyHandler.java @@ -31,6 +31,7 @@ import com.google.gson.JsonArray; import com.google.gson.JsonElement; import org.apache.hadoop.hdds.cli.SubcommandWithParent; +import org.apache.hadoop.hdds.client.ECReplicationConfig; import org.apache.hadoop.hdds.client.StandaloneReplicationConfig; import org.apache.hadoop.hdds.protocol.DatanodeDetails; import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos; @@ -67,7 +68,7 @@ public class ChunkKeyHandler extends KeyHandler implements SubcommandWithParent { - private XceiverClientManager xceiverClientManager; + private XceiverClientManager xceiverClientManager; private XceiverClientSpi xceiverClient; private OzoneManagerProtocol ozoneManagerClient; @@ -115,11 +116,17 @@ protected void execute(OzoneClient client, OzoneAddress address) ContainerChunkInfo containerChunkInfo = new ContainerChunkInfo(); long containerId = keyLocation.getContainerID(); chunkPaths.clear(); - Pipeline pipeline = keyLocation.getPipeline(); - if (pipeline.getType() != HddsProtos.ReplicationType.STAND_ALONE) { - pipeline = Pipeline.newBuilder(pipeline) + Pipeline keyPipeline = keyLocation.getPipeline(); + boolean isECKey = + keyPipeline.getReplicationConfig().getReplicationType() == + HddsProtos.ReplicationType.EC; + Pipeline pipeline; + if (keyPipeline.getType() != HddsProtos.ReplicationType.STAND_ALONE) { + pipeline = Pipeline.newBuilder(keyPipeline) .setReplicationConfig(StandaloneReplicationConfig .getInstance(ONE)).build(); + } else { + pipeline = keyPipeline; } xceiverClient = xceiverClientManager.acquireClientForReadData(pipeline); // Datanode is queried to get chunk information.Thus querying the @@ -161,11 +168,17 @@ protected void execute(OzoneClient client, OzoneAddress address) } containerChunkInfoVerbose.setContainerPath(containerData .getContainerPath()); - containerChunkInfoVerbose.setPipeline(keyLocation.getPipeline()); + containerChunkInfoVerbose.setPipeline(keyPipeline); containerChunkInfoVerbose.setChunkInfos(chunkDetailsList); containerChunkInfo.setFiles(chunkPaths); - containerChunkInfo.setPipelineID( - keyLocation.getPipeline().getId().getId()); + containerChunkInfo.setPipelineID(keyPipeline.getId().getId()); + if (isECKey) { + ChunkType blockChunksType = + isECParityBlock(keyPipeline, entry.getKey()) ? + ChunkType.PARITY : ChunkType.DATA; + containerChunkInfoVerbose.setChunkType(blockChunksType); + containerChunkInfo.setChunkType(blockChunksType); + } Gson gson = new GsonBuilder().create(); if (isVerbose()) { element = gson.toJsonTree(containerChunkInfoVerbose); @@ -192,6 +205,13 @@ protected void execute(OzoneClient client, OzoneAddress address) } } + private boolean isECParityBlock(Pipeline pipeline, DatanodeDetails dn) { + //index is 1-based, + //e.g. for RS-3-2 we will have data indexes 1,2,3 and parity indexes 4,5 + return pipeline.getReplicaIndex(dn) > + ((ECReplicationConfig) pipeline.getReplicationConfig()).getData(); + } + @Override public Class getParentType() { return OzoneDebug.class; diff --git a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ChunkType.java b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ChunkType.java new file mode 100644 index 000000000000..610eab54d6ff --- /dev/null +++ b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ChunkType.java @@ -0,0 +1,24 @@ +/** + * 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.ozone.debug; + +/** + * The type of chunks of an Erasure Coded key. + */ +public enum ChunkType { + DATA, PARITY +} diff --git a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ContainerChunkInfo.java b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ContainerChunkInfo.java index cf57d95397bb..f88e08413d4b 100644 --- a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ContainerChunkInfo.java +++ b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ContainerChunkInfo.java @@ -35,6 +35,7 @@ public class ContainerChunkInfo { private HashSet files; private UUID pipelineID; private Pipeline pipeline; + private ChunkType chunkType; public void setFiles(HashSet files) { this.files = files; @@ -60,6 +61,9 @@ public void setChunkInfos(List chunkInfos) { this.chunkInfos = chunkInfos; } + public void setChunkType(ChunkType chunkType) { + this.chunkType = chunkType; + } @Override public String toString() { @@ -75,6 +79,8 @@ public String toString() { + "files=" + files + "PipelineID=" - + pipelineID; + + pipelineID + + "ChunkType=" + + chunkType; } }