diff --git a/hadoop-ozone/cli-admin/src/main/java/org/apache/hadoop/ozone/admin/om/lease/LeaseRecoverer.java b/hadoop-ozone/cli-admin/src/main/java/org/apache/hadoop/ozone/admin/om/lease/LeaseRecoverer.java index 2a37ab658cf8..cbb987b49dff 100644 --- a/hadoop-ozone/cli-admin/src/main/java/org/apache/hadoop/ozone/admin/om/lease/LeaseRecoverer.java +++ b/hadoop-ozone/cli-admin/src/main/java/org/apache/hadoop/ozone/admin/om/lease/LeaseRecoverer.java @@ -57,15 +57,15 @@ public void setPath(String dbPath) { public Void call() throws Exception { OzoneConfiguration configuration = new OzoneConfiguration(); URI uri = URI.create(this.path); - FileSystem fs = FileSystem.get(uri, configuration); + try (FileSystem fs = FileSystem.get(uri, configuration)) { - if (fs instanceof LeaseRecoverable) { - ((LeaseRecoverable) fs).recoverLease(new Path(uri)); - } else { - throw new IllegalArgumentException("Unsupported file system: " - + fs.getScheme()); + if (fs instanceof LeaseRecoverable) { + ((LeaseRecoverable) fs).recoverLease(new Path(uri)); + } else { + throw new IllegalArgumentException("Unsupported file system: " + + fs.getScheme()); + } } - System.out.println("Lease recovery SUCCEEDED on " + uri); return null; diff --git a/hadoop-ozone/cli-shell/src/main/java/org/apache/hadoop/ozone/shell/volume/DeleteVolumeHandler.java b/hadoop-ozone/cli-shell/src/main/java/org/apache/hadoop/ozone/shell/volume/DeleteVolumeHandler.java index 2c2f3d2f21c9..3a5968a85156 100644 --- a/hadoop-ozone/cli-shell/src/main/java/org/apache/hadoop/ozone/shell/volume/DeleteVolumeHandler.java +++ b/hadoop-ozone/cli-shell/src/main/java/org/apache/hadoop/ozone/shell/volume/DeleteVolumeHandler.java @@ -172,9 +172,10 @@ private boolean cleanFSBucket(OzoneBucket bucket) { final Path path = new Path(ofsPrefix); OzoneConfiguration clientConf = new OzoneConfiguration(getConf()); clientConf.set(FS_DEFAULT_NAME_KEY, hostPrefix); - FileSystem fs = FileSystem.get(clientConf); - if (!fs.delete(path, true)) { - throw new IOException("Failed to delete bucket"); + try (FileSystem fs = FileSystem.get(clientConf)) { + if (!fs.delete(path, true)) { + throw new IOException("Failed to delete bucket"); + } } numberOfBucketsCleaned.getAndIncrement(); return true; diff --git a/hadoop-ozone/freon/src/main/java/org/apache/hadoop/ozone/freon/RandomKeyGenerator.java b/hadoop-ozone/freon/src/main/java/org/apache/hadoop/ozone/freon/RandomKeyGenerator.java index e73ddc77f2b4..ed636fba0cd3 100644 --- a/hadoop-ozone/freon/src/main/java/org/apache/hadoop/ozone/freon/RandomKeyGenerator.java +++ b/hadoop-ozone/freon/src/main/java/org/apache/hadoop/ozone/freon/RandomKeyGenerator.java @@ -1209,20 +1209,20 @@ public void run() { try { KeyValidate kv = validationQueue.poll(5, TimeUnit.SECONDS); if (kv != null) { - OzoneInputStream is = kv.bucket.readKey(kv.keyName); - dig.getMessageDigest().reset(); - byte[] curDigest = dig.digest(is); - totalWritesValidated.getAndIncrement(); - if (MessageDigest.isEqual(kv.digest, curDigest)) { - writeValidationSuccessCount.getAndIncrement(); - } else { - writeValidationFailureCount.getAndIncrement(); - LOG.warn("Data validation error for key {}/{}/{}", - kv.bucket.getVolumeName(), kv.bucket, kv.keyName); - LOG.warn("Expected checksum: {}, Actual checksum: {}", - kv.digest, curDigest); + try (OzoneInputStream is = kv.bucket.readKey(kv.keyName)) { + dig.getMessageDigest().reset(); + byte[] curDigest = dig.digest(is); + totalWritesValidated.getAndIncrement(); + if (MessageDigest.isEqual(kv.digest, curDigest)) { + writeValidationSuccessCount.getAndIncrement(); + } else { + writeValidationFailureCount.getAndIncrement(); + LOG.warn("Data validation error for key {}/{}/{}", + kv.bucket.getVolumeName(), kv.bucket, kv.keyName); + LOG.warn("Expected checksum: {}, Actual checksum: {}", + kv.digest, curDigest); + } } - is.close(); } } catch (IOException ex) { LOG.error("Exception while validating write.", ex);