From 11ac10fe1d95d67dc099e787041e0f81a507fbf2 Mon Sep 17 00:00:00 2001 From: Jason Lowe Date: Thu, 28 Sep 2017 16:38:30 -0500 Subject: [PATCH] HADOOP-14902. LoadGenerator#genFile write close timing is incorrectly calculated. Contributed by Hanisha Koneru (cherry picked from commit 6f789fe05766a61b12ca10df3f26ee354eac84aa) --- .../apache/hadoop/fs/loadGenerator/LoadGenerator.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/loadGenerator/LoadGenerator.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/loadGenerator/LoadGenerator.java index 0bb1b46608d..b74e75d9ef7 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/loadGenerator/LoadGenerator.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/loadGenerator/LoadGenerator.java @@ -322,6 +322,7 @@ public class LoadGenerator extends Configured implements Tool { private void genFile(Path file, long fileSize) throws IOException { long startTimestamp = Time.monotonicNow(); FSDataOutputStream out = null; + boolean isOutClosed = false; try { out = fc.create(file, EnumSet.of(CreateFlag.CREATE, CreateFlag.OVERWRITE), @@ -337,11 +338,15 @@ public class LoadGenerator extends Configured implements Tool { i -= s; } - startTimestamp = Time.monotonicNow(); - executionTime[WRITE_CLOSE] += (Time.monotonicNow() - startTimestamp); + startTime = Time.monotonicNow(); + out.close(); + executionTime[WRITE_CLOSE] += (Time.monotonicNow() - startTime); numOfOps[WRITE_CLOSE]++; + isOutClosed = true; } finally { - IOUtils.cleanupWithLogger(LOG, out); + if (!isOutClosed && out != null) { + out.close(); + } } } }