Skip to content

Commit

Permalink
HDDS-10502. Improve generic type of IOUtils.close (apache#6361)
Browse files Browse the repository at this point in the history
  • Loading branch information
adoroszlai authored Mar 12, 2024
1 parent d68ea97 commit 6c95fc9
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static void close(Logger logger, AutoCloseable... closeables) {
* Close each argument, catching exceptions and logging them as error.
*/
public static void close(Logger logger,
Collection<AutoCloseable> closeables) {
Collection<? extends AutoCloseable> closeables) {
if (closeables == null) {
return;
}
Expand All @@ -94,7 +94,7 @@ public static void closeQuietly(AutoCloseable... closeables) {
/**
* Close each argument, swallowing exceptions.
*/
public static void closeQuietly(Collection<AutoCloseable> closeables) {
public static void closeQuietly(Collection<? extends AutoCloseable> closeables) {
close(null, closeables);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ public HeapEntry next() {
}

public void close() throws IOException {
iterators.forEach(IOUtils::closeQuietly);
IOUtils.closeQuietly(iterators);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -391,13 +391,8 @@ public OmSnapshot load(@Nonnull UUID key) {
@AfterEach
public void tearDown() {
IOUtils.closeQuietly(snapshotDiffManager);
if (columnFamilyHandles != null) {
columnFamilyHandles.forEach(IOUtils::closeQuietly);
}

IOUtils.closeQuietly(db);
IOUtils.closeQuietly(dbOptions);
IOUtils.closeQuietly(columnFamilyOptions);
IOUtils.closeQuietly(columnFamilyHandles);
IOUtils.closeQuietly(db, dbOptions, columnFamilyOptions);
}

private OmSnapshot getMockedOmSnapshot(UUID snapshotId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,7 @@ private void downloadReplicasAndCreateManifest(
blockJson.add(JSON_PROPERTY_BLOCK_REPLICAS, replicasJson);
blocks.add(blockJson);

blockReplicasWithoutChecksum.values()
.forEach(each -> IOUtils.close(LOG, each));
IOUtils.close(LOG, blockReplicasWithoutChecksum.values());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package org.apache.hadoop.ozone.freon;


import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.RandomUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hdds.DatanodeVersion;
Expand All @@ -43,6 +42,7 @@
import org.apache.hadoop.hdds.upgrade.HDDSLayoutVersionManager;
import org.apache.hadoop.hdds.utils.HAUtils;
import org.apache.hadoop.hdds.utils.HddsServerUtil;
import org.apache.hadoop.hdds.utils.IOUtils;
import org.apache.hadoop.hdds.utils.LegacyHadoopConfigurationSource;
import org.apache.hadoop.io.retry.RetryPolicies;
import org.apache.hadoop.io.retry.RetryPolicy;
Expand Down Expand Up @@ -186,7 +186,7 @@ public Void call() throws Exception {
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
scmClients.values().forEach(IOUtils::closeQuietly);
IOUtils.closeQuietly(scmClients.values());
IOUtils.closeQuietly(reconClient);
LOGGER.info("Successfully closed all the used resources");
saveDatanodesToFile();
Expand Down

0 comments on commit 6c95fc9

Please sign in to comment.