in hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/replicas/chunk/ChunkKeyHandler.java [64:184]
protected void execute(OzoneClient client, OzoneAddress address)
throws IOException {
try (ContainerOperationClient containerOperationClient = new ContainerOperationClient(getOzoneConf());
XceiverClientManager xceiverClientManager = containerOperationClient.getXceiverClientManager()) {
OzoneManagerProtocol ozoneManagerClient = client.getObjectStore().getClientProxy().getOzoneManagerClient();
address.ensureKeyAddress();
ObjectNode result = JsonUtils.createObjectNode(null);
String volumeName = address.getVolumeName();
String bucketName = address.getBucketName();
String keyName = address.getKeyName();
List<ContainerProtos.ChunkInfo> tempchunks;
List<ChunkDetails> chunkDetailsList = new ArrayList<>();
HashSet<String> chunkPaths = new HashSet<>();
OmKeyArgs keyArgs = new OmKeyArgs.Builder().setVolumeName(volumeName)
.setBucketName(bucketName).setKeyName(keyName).build();
OmKeyInfo keyInfo = ozoneManagerClient.lookupKey(keyArgs);
// querying the keyLocations.The OM is queried to get containerID and
// localID pertaining to a given key
List<OmKeyLocationInfo> locationInfos =
keyInfo.getLatestVersionLocations().getBlocksLatestVersionOnly();
// for zero-sized key
if (locationInfos.isEmpty()) {
System.out.println("No Key Locations Found");
return;
}
ContainerLayoutVersion containerLayoutVersion = ContainerLayoutVersion
.getConfiguredVersion(getConf());
ArrayNode responseArrayList = JsonUtils.createArrayNode();
for (OmKeyLocationInfo keyLocation : locationInfos) {
ContainerChunkInfo containerChunkInfoVerbose = new ContainerChunkInfo();
ContainerChunkInfo containerChunkInfo = new ContainerChunkInfo();
long containerId = keyLocation.getContainerID();
chunkPaths.clear();
Pipeline keyPipeline = keyLocation.getPipeline();
boolean isECKey =
keyPipeline.getReplicationConfig().getReplicationType() ==
HddsProtos.ReplicationType.EC;
Pipeline pipeline;
if (!isECKey && keyPipeline.getType() != HddsProtos.ReplicationType.STAND_ALONE) {
pipeline = Pipeline.newBuilder(keyPipeline)
.setReplicationConfig(StandaloneReplicationConfig
.getInstance(ONE)).build();
} else {
pipeline = keyPipeline;
}
XceiverClientSpi xceiverClient = xceiverClientManager.acquireClientForReadData(pipeline);
try {
// Datanode is queried to get chunk information.Thus querying the
// OM,SCM and datanode helps us get chunk location information
ContainerProtos.DatanodeBlockID datanodeBlockID =
keyLocation.getBlockID().getDatanodeBlockIDProtobuf();
// doing a getBlock on all nodes
Map<DatanodeDetails, ContainerProtos.GetBlockResponseProto>
responses =
ContainerProtocolCalls.getBlockFromAllNodes(xceiverClient,
keyLocation.getBlockID().getDatanodeBlockIDProtobuf(),
keyLocation.getToken());
Map<DatanodeDetails, ContainerProtos.ReadContainerResponseProto> readContainerResponses =
containerOperationClient.readContainerFromAllNodes(
keyLocation.getContainerID(), pipeline);
ArrayNode responseFromAllNodes = JsonUtils.createArrayNode();
for (Map.Entry<DatanodeDetails, ContainerProtos.GetBlockResponseProto> entry : responses.entrySet()) {
chunkPaths.clear();
ObjectNode jsonObj = JsonUtils.createObjectNode(null);
if (entry.getValue() == null) {
LOG.error("Cant execute getBlock on this node");
continue;
}
tempchunks = entry.getValue().getBlockData().getChunksList();
ContainerProtos.ContainerDataProto containerData =
readContainerResponses.get(entry.getKey()).getContainerData();
for (ContainerProtos.ChunkInfo chunkInfo : tempchunks) {
String fileName = containerLayoutVersion.getChunkFile(new File(
getChunkLocationPath(containerData.getContainerPath())),
keyLocation.getBlockID(),
chunkInfo.getChunkName()).toString();
chunkPaths.add(fileName);
ChunkDetails chunkDetails = new ChunkDetails();
chunkDetails.setChunkName(fileName);
chunkDetails.setChunkOffset(chunkInfo.getOffset());
chunkDetailsList.add(chunkDetails);
}
containerChunkInfoVerbose.setContainerPath(containerData
.getContainerPath());
containerChunkInfoVerbose.setPipeline(keyPipeline);
containerChunkInfoVerbose.setChunkInfos(chunkDetailsList);
containerChunkInfo.setFiles(chunkPaths);
containerChunkInfo.setPipelineID(keyPipeline.getId().getId());
if (isECKey) {
ChunkType blockChunksType =
isECParityBlock(keyPipeline, entry.getKey()) ?
ChunkType.PARITY : ChunkType.DATA;
containerChunkInfoVerbose.setChunkType(blockChunksType);
containerChunkInfo.setChunkType(blockChunksType);
}
if (isVerbose()) {
jsonObj.set("Locations",
JsonUtils.createObjectNode(containerChunkInfoVerbose));
} else {
jsonObj.set("Locations",
JsonUtils.createObjectNode(containerChunkInfo));
}
jsonObj.put("Datanode-HostName", entry.getKey().getHostName());
jsonObj.put("Datanode-IP", entry.getKey().getIpAddress());
jsonObj.put("Container-ID", containerId);
jsonObj.put("Block-ID", keyLocation.getLocalID());
responseFromAllNodes.add(jsonObj);
}
responseArrayList.add(responseFromAllNodes);
} catch (InterruptedException e) {
throw new RuntimeException(e);
} finally {
xceiverClientManager.releaseClientForReadData(xceiverClient, false);
}
}
result.set("KeyLocations", responseArrayList);
String prettyJson = JsonUtils.toJsonStringWithDefaultPrettyPrinter(result);
System.out.println(prettyJson);
}
}