bshashikant commented on a change in pull request #684: HDDS-3134. Debug Tool that gives chunk location information given a key. URL: https://github.com/apache/hadoop-ozone/pull/684#discussion_r405425453
########## File path: hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ChunkKeyHandler.java ########## @@ -0,0 +1,164 @@ +/* + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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; +/* +Class that provides chunk information given a specific key + */ + +import com.google.common.base.Preconditions; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import org.apache.hadoop.hdds.client.BlockID; +import org.apache.hadoop.hdds.protocol.DatanodeDetails; +import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos; +import org.apache.hadoop.hdds.scm.XceiverClientManager; +import org.apache.hadoop.hdds.scm.XceiverClientSpi; +import org.apache.hadoop.hdds.scm.cli.ContainerOperationClient; +import org.apache.hadoop.hdds.scm.container.common.helpers.ContainerWithPipeline; +import org.apache.hadoop.hdds.scm.storage.ContainerProtocolCalls; +import org.apache.hadoop.ozone.OzoneConsts; +import org.apache.hadoop.ozone.client.*; +import org.apache.hadoop.ozone.web.ozShell.Handler; +import org.apache.hadoop.ozone.web.ozShell.OzoneAddress; +import org.apache.hadoop.ozone.web.ozShell.Shell; +import picocli.CommandLine.Command; +import picocli.CommandLine.Parameters; + +/** + * Gives chunk information given key as parameter. + */ +@Command(name = "chunkinfo", + description = "returns chunk location information" + + " about an existing key") +public class ChunkKeyHandler extends Handler { + + @Parameters(arity = "1..1", description = Shell.OZONE_KEY_URI_DESCRIPTION) + private String uri; + + private ContainerOperationClient containerOperationClient; + private XceiverClientManager xceiverClientManager; + private XceiverClientSpi xceiverClient; + + private String getChunkLocationPath(String containerLocation) { + return containerLocation + File.separator + OzoneConsts.STORAGE_DIR_CHUNKS; + } + + @Override + public Void call() throws Exception { + OzoneAddress address = new OzoneAddress(uri); + containerOperationClient = new ContainerOperationClient( + createOzoneConfiguration()); + xceiverClientManager = new XceiverClientManager( + createOzoneConfiguration()); + address.ensureKeyAddress(); + JsonObject jsonObj = new JsonObject(); + JsonElement element; + try (OzoneClient client = address.createClient( + createOzoneConfiguration())) { + String volumeName = address.getVolumeName(); + String bucketName = address.getBucketName(); + String keyName = address.getKeyName(); + List<ContainerProtos.ChunkInfo> tempchunks = null; + List<ChunkDetails> chunkDetailsList = new ArrayList<ChunkDetails>(); + List<String> chunkPaths = new ArrayList<String>(); + OzoneVolume vol = client.getObjectStore().getVolume(volumeName); + OzoneBucket bucket = vol.getBucket(bucketName); + OzoneKeyDetails key = bucket.getKey(keyName); + // querying the keyLocations.The OM is queried to get containerID and + // localID pertaining to a given key + List<OzoneKeyLocation> keyLocationList = key.getOzoneKeyLocations(); + for (OzoneKeyLocation keyLocation:keyLocationList) { + ContainerChunkInfo containerChunkInfoVerbose = new + ContainerChunkInfo(); + ContainerChunkInfo containerChunkInfo = new ContainerChunkInfo(); + chunkPaths.clear(); + chunkDetailsList.clear(); + long containerId = keyLocation.getContainerID(); + long blockId = keyLocation.getLocalID(); + // scmClient is used to get container specific information like + // ContainerPath amd so on + ContainerWithPipeline container = containerOperationClient + .getContainerWithPipeline(containerId); + xceiverClient = xceiverClientManager.acquireClient( Review comment: do we really need instance of xceiveClient here? Also, we need to explicitly release it at the end ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: ozone-issues-unsubscr...@hadoop.apache.org For additional commands, e-mail: ozone-issues-h...@hadoop.apache.org