You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by "swamirishi (via GitHub)" <gi...@apache.org> on 2023/03/13 16:45:59 UTC
[GitHub] [ozone] swamirishi commented on a diff in pull request #4387: HDDS-8145. ReadReplicas should close client
swamirishi commented on code in PR #4387:
URL: https://github.com/apache/ozone/pull/4387#discussion_r1134252572
##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ReadReplicas.java:
##########
@@ -91,64 +93,72 @@ public Class<?> getParentType() {
protected void execute(OzoneClient client, OzoneAddress address)
throws IOException, OzoneClientException {
+ address.ensureKeyAddress();
+
boolean isChecksumVerifyEnabled
= getConf().getBoolean("ozone.client.verify.checksum", true);
OzoneConfiguration configuration = new OzoneConfiguration(getConf());
configuration.setBoolean("ozone.client.verify.checksum",
!isChecksumVerifyEnabled);
- if (isChecksumVerifyEnabled) {
- clientProtocol = client.getObjectStore().getClientProxy();
- clientProtocolWithoutChecksum = new RpcClient(configuration, null);
- } else {
- clientProtocol = new RpcClient(configuration, null);
- clientProtocolWithoutChecksum = client.getObjectStore().getClientProxy();
- }
+ RpcClient newClient = new RpcClient(configuration, null);
+ try {
+ ClientProtocol noChecksumClient;
+ ClientProtocol checksumClient;
+ if (isChecksumVerifyEnabled) {
+ checksumClient = client.getObjectStore().getClientProxy();
+ noChecksumClient = newClient;
+ } else {
+ checksumClient = newClient;
+ noChecksumClient = client.getObjectStore().getClientProxy();
+ }
- address.ensureKeyAddress();
- String volumeName = address.getVolumeName();
- String bucketName = address.getBucketName();
- String keyName = address.getKeyName();
+ String volumeName = address.getVolumeName();
+ String bucketName = address.getBucketName();
+ String keyName = address.getKeyName();
- String directoryName = createDirectory(volumeName, bucketName, keyName);
+ File dir = createDirectory(volumeName, bucketName, keyName);
- OzoneKeyDetails keyInfoDetails
- = clientProtocol.getKeyDetails(volumeName, bucketName, keyName);
+ OzoneKeyDetails keyInfoDetails
+ = checksumClient.getKeyDetails(volumeName, bucketName, keyName);
- Map<OmKeyLocationInfo, Map<DatanodeDetails, OzoneInputStream>> replicas
- = clientProtocol.getKeysEveryReplicas(volumeName, bucketName, keyName);
+ Map<OmKeyLocationInfo, Map<DatanodeDetails, OzoneInputStream>> replicas =
+ checksumClient.getKeysEveryReplicas(volumeName, bucketName, keyName);
- Map<OmKeyLocationInfo, Map<DatanodeDetails, OzoneInputStream>>
- replicasWithoutChecksum = clientProtocolWithoutChecksum
- .getKeysEveryReplicas(volumeName, bucketName, keyName);
+ Map<OmKeyLocationInfo, Map<DatanodeDetails, OzoneInputStream>>
+ replicasWithoutChecksum = noChecksumClient
+ .getKeysEveryReplicas(volumeName, bucketName, keyName);
- JsonObject result = new JsonObject();
- result.addProperty(JSON_PROPERTY_FILE_NAME,
- volumeName + "/" + bucketName + "/" + keyName);
- result.addProperty(JSON_PROPERTY_FILE_SIZE, keyInfoDetails.getDataSize());
+ JsonObject result = new JsonObject();
+ result.addProperty(JSON_PROPERTY_FILE_NAME,
+ volumeName + "/" + bucketName + "/" + keyName);
+ result.addProperty(JSON_PROPERTY_FILE_SIZE, keyInfoDetails.getDataSize());
- JsonArray blocks = new JsonArray();
- downloadReplicasAndCreateManifest(keyName, replicas,
- replicasWithoutChecksum, directoryName, blocks);
- result.add(JSON_PROPERTY_FILE_BLOCKS, blocks);
+ JsonArray blocks = new JsonArray();
+ downloadReplicasAndCreateManifest(keyName, replicas,
+ replicasWithoutChecksum, dir, blocks);
+ result.add(JSON_PROPERTY_FILE_BLOCKS, blocks);
- Gson gson = new GsonBuilder().setPrettyPrinting().create();
- String prettyJson = gson.toJson(result);
+ Gson gson = new GsonBuilder().setPrettyPrinting().create();
+ String prettyJson = gson.toJson(result);
- String manifestFileName = keyName + "_manifest";
- System.out.println("Writing manifest file : " + manifestFileName);
- File manifestFile
- = new File(outputDir + "/" + directoryName + "/" + manifestFileName);
- Files.write(manifestFile.toPath(),
- prettyJson.getBytes(StandardCharsets.UTF_8));
+ String manifestFileName = keyName + "_manifest";
+ System.out.println("Writing manifest file : " + manifestFileName);
Review Comment:
nit: can this be logged instead?
##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ReadReplicas.java:
##########
@@ -91,64 +93,72 @@ public Class<?> getParentType() {
protected void execute(OzoneClient client, OzoneAddress address)
throws IOException, OzoneClientException {
+ address.ensureKeyAddress();
+
boolean isChecksumVerifyEnabled
= getConf().getBoolean("ozone.client.verify.checksum", true);
OzoneConfiguration configuration = new OzoneConfiguration(getConf());
configuration.setBoolean("ozone.client.verify.checksum",
!isChecksumVerifyEnabled);
- if (isChecksumVerifyEnabled) {
- clientProtocol = client.getObjectStore().getClientProxy();
- clientProtocolWithoutChecksum = new RpcClient(configuration, null);
- } else {
- clientProtocol = new RpcClient(configuration, null);
- clientProtocolWithoutChecksum = client.getObjectStore().getClientProxy();
- }
+ RpcClient newClient = new RpcClient(configuration, null);
+ try {
+ ClientProtocol noChecksumClient;
+ ClientProtocol checksumClient;
+ if (isChecksumVerifyEnabled) {
+ checksumClient = client.getObjectStore().getClientProxy();
+ noChecksumClient = newClient;
+ } else {
+ checksumClient = newClient;
+ noChecksumClient = client.getObjectStore().getClientProxy();
+ }
- address.ensureKeyAddress();
- String volumeName = address.getVolumeName();
- String bucketName = address.getBucketName();
- String keyName = address.getKeyName();
+ String volumeName = address.getVolumeName();
+ String bucketName = address.getBucketName();
+ String keyName = address.getKeyName();
- String directoryName = createDirectory(volumeName, bucketName, keyName);
+ File dir = createDirectory(volumeName, bucketName, keyName);
- OzoneKeyDetails keyInfoDetails
- = clientProtocol.getKeyDetails(volumeName, bucketName, keyName);
+ OzoneKeyDetails keyInfoDetails
+ = checksumClient.getKeyDetails(volumeName, bucketName, keyName);
- Map<OmKeyLocationInfo, Map<DatanodeDetails, OzoneInputStream>> replicas
- = clientProtocol.getKeysEveryReplicas(volumeName, bucketName, keyName);
+ Map<OmKeyLocationInfo, Map<DatanodeDetails, OzoneInputStream>> replicas =
+ checksumClient.getKeysEveryReplicas(volumeName, bucketName, keyName);
- Map<OmKeyLocationInfo, Map<DatanodeDetails, OzoneInputStream>>
- replicasWithoutChecksum = clientProtocolWithoutChecksum
- .getKeysEveryReplicas(volumeName, bucketName, keyName);
+ Map<OmKeyLocationInfo, Map<DatanodeDetails, OzoneInputStream>>
+ replicasWithoutChecksum = noChecksumClient
+ .getKeysEveryReplicas(volumeName, bucketName, keyName);
- JsonObject result = new JsonObject();
- result.addProperty(JSON_PROPERTY_FILE_NAME,
- volumeName + "/" + bucketName + "/" + keyName);
- result.addProperty(JSON_PROPERTY_FILE_SIZE, keyInfoDetails.getDataSize());
+ JsonObject result = new JsonObject();
+ result.addProperty(JSON_PROPERTY_FILE_NAME,
+ volumeName + "/" + bucketName + "/" + keyName);
+ result.addProperty(JSON_PROPERTY_FILE_SIZE, keyInfoDetails.getDataSize());
- JsonArray blocks = new JsonArray();
- downloadReplicasAndCreateManifest(keyName, replicas,
- replicasWithoutChecksum, directoryName, blocks);
- result.add(JSON_PROPERTY_FILE_BLOCKS, blocks);
+ JsonArray blocks = new JsonArray();
+ downloadReplicasAndCreateManifest(keyName, replicas,
+ replicasWithoutChecksum, dir, blocks);
+ result.add(JSON_PROPERTY_FILE_BLOCKS, blocks);
- Gson gson = new GsonBuilder().setPrettyPrinting().create();
- String prettyJson = gson.toJson(result);
+ Gson gson = new GsonBuilder().setPrettyPrinting().create();
+ String prettyJson = gson.toJson(result);
- String manifestFileName = keyName + "_manifest";
- System.out.println("Writing manifest file : " + manifestFileName);
- File manifestFile
- = new File(outputDir + "/" + directoryName + "/" + manifestFileName);
- Files.write(manifestFile.toPath(),
- prettyJson.getBytes(StandardCharsets.UTF_8));
+ String manifestFileName = keyName + "_manifest";
+ System.out.println("Writing manifest file : " + manifestFileName);
+ File manifestFile
+ = new File(dir, manifestFileName);
+ Files.write(manifestFile.toPath(),
+ prettyJson.getBytes(StandardCharsets.UTF_8));
+ } finally {
+ newClient.close();
Review Comment:
Can this finally block be moved to try-with-resource. Since if future change updates this inside try block, it might lead to same problem.
--
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.
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org