From c579d06b33c3a6d0a9a024c38a42da3dcb683f2b Mon Sep 17 00:00:00 2001 From: "Doroszlai, Attila" <6454655+adoroszlai@users.noreply.github.com> Date: Mon, 14 Oct 2024 03:57:38 +0200 Subject: [PATCH] HDDS-11574. Ozone client leak in TestS3SDKV1 (#7308) --- .../org/apache/hadoop/hdds/HddsUtils.java | 2 +- .../s3/awssdk/v1/AbstractS3SDKV1Tests.java | 19 ++++++++++--------- .../src/test/resources/log4j.properties | 1 + 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/HddsUtils.java b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/HddsUtils.java index 88489652e0e..e3b90da794b 100644 --- a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/HddsUtils.java +++ b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/HddsUtils.java @@ -884,7 +884,7 @@ public static HddsProtos.UUID toProtobuf(UUID uuid) { */ public static void reportLeak(Class clazz, String stackTrace, Logger log) { String warning = String.format("%s is not closed properly", clazz.getSimpleName()); - if (stackTrace != null && LOG.isDebugEnabled()) { + if (stackTrace != null && log.isDebugEnabled()) { String debugMessage = String.format("%nStackTrace for unclosed instance: %s", stackTrace); warning = warning.concat(debugMessage); diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/s3/awssdk/v1/AbstractS3SDKV1Tests.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/s3/awssdk/v1/AbstractS3SDKV1Tests.java index 069ac4bd9dc..15f1e10a630 100644 --- a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/s3/awssdk/v1/AbstractS3SDKV1Tests.java +++ b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/s3/awssdk/v1/AbstractS3SDKV1Tests.java @@ -430,17 +430,18 @@ public void testGetObjectWithoutETag() throws Exception { byte[] valueBytes = value.getBytes(StandardCharsets.UTF_8); OzoneConfiguration conf = cluster.getConf(); - OzoneClient ozoneClient = OzoneClientFactory.getRpcClient(conf); - ObjectStore store = ozoneClient.getObjectStore(); + try (OzoneClient ozoneClient = OzoneClientFactory.getRpcClient(conf)) { + ObjectStore store = ozoneClient.getObjectStore(); - OzoneVolume volume = store.getS3Volume(); - OzoneBucket bucket = volume.getBucket(bucketName); + OzoneVolume volume = store.getS3Volume(); + OzoneBucket bucket = volume.getBucket(bucketName); - try (OzoneOutputStream out = bucket.createKey(keyName, - valueBytes.length, - ReplicationConfig.fromTypeAndFactor(ReplicationType.RATIS, ReplicationFactor.ONE), - Collections.emptyMap())) { - out.write(valueBytes); + try (OzoneOutputStream out = bucket.createKey(keyName, + valueBytes.length, + ReplicationConfig.fromTypeAndFactor(ReplicationType.RATIS, ReplicationFactor.ONE), + Collections.emptyMap())) { + out.write(valueBytes); + } } S3Object s3Object = s3Client.getObject(bucketName, keyName); diff --git a/hadoop-ozone/integration-test/src/test/resources/log4j.properties b/hadoop-ozone/integration-test/src/test/resources/log4j.properties index 564b729d5fc..c732a15c48a 100644 --- a/hadoop-ozone/integration-test/src/test/resources/log4j.properties +++ b/hadoop-ozone/integration-test/src/test/resources/log4j.properties @@ -21,3 +21,4 @@ log4j.logger.org.apache.hadoop.security.ShellBasedUnixGroupsMapping=ERROR log4j.logger.org.apache.hadoop.util.NativeCodeLoader=ERROR log4j.logger.org.apache.hadoop.hdds.utils.db.managed=TRACE log4j.logger.org.apache.hadoop.hdds.utils.db.CodecBuffer=DEBUG +log4j.logger.org.apache.hadoop.ozone.client.OzoneClientFactory=DEBUG