diff --git a/hadoop-yarn-project/CHANGES.txt b/hadoop-yarn-project/CHANGES.txt index 2009b47ad54..803d725bb66 100644 --- a/hadoop-yarn-project/CHANGES.txt +++ b/hadoop-yarn-project/CHANGES.txt @@ -589,6 +589,9 @@ Release 2.8.0 - UNRELEASED YARN-3875. FSSchedulerNode#reserveResource() doesn't print Application Id properly in log. (Bibin A Chundatt via devaraj) + YARN-3882. AggregatedLogFormat should close aclScanner and ownerScanner + after create them. (zhihai xu via xgong) + Release 2.7.2 - UNRELEASED INCOMPATIBLE CHANGES diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/logaggregation/AggregatedLogFormat.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/logaggregation/AggregatedLogFormat.java index debe77038a5..c9453b31473 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/logaggregation/AggregatedLogFormat.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/logaggregation/AggregatedLogFormat.java @@ -489,18 +489,23 @@ public class AggregatedLogFormat { * @throws IOException */ public String getApplicationOwner() throws IOException { - TFile.Reader.Scanner ownerScanner = reader.createScanner(); - LogKey key = new LogKey(); - while (!ownerScanner.atEnd()) { - TFile.Reader.Scanner.Entry entry = ownerScanner.entry(); - key.readFields(entry.getKeyStream()); - if (key.toString().equals(APPLICATION_OWNER_KEY.toString())) { - DataInputStream valueStream = entry.getValueStream(); - return valueStream.readUTF(); + TFile.Reader.Scanner ownerScanner = null; + try { + ownerScanner = reader.createScanner(); + LogKey key = new LogKey(); + while (!ownerScanner.atEnd()) { + TFile.Reader.Scanner.Entry entry = ownerScanner.entry(); + key.readFields(entry.getKeyStream()); + if (key.toString().equals(APPLICATION_OWNER_KEY.toString())) { + DataInputStream valueStream = entry.getValueStream(); + return valueStream.readUTF(); + } + ownerScanner.advance(); } - ownerScanner.advance(); + return null; + } finally { + IOUtils.cleanup(LOG, ownerScanner); } - return null; } /** @@ -513,38 +518,42 @@ public class AggregatedLogFormat { public Map getApplicationAcls() throws IOException { // TODO Seek directly to the key once a comparator is specified. - TFile.Reader.Scanner aclScanner = reader.createScanner(); - LogKey key = new LogKey(); - Map acls = - new HashMap(); - while (!aclScanner.atEnd()) { - TFile.Reader.Scanner.Entry entry = aclScanner.entry(); - key.readFields(entry.getKeyStream()); - if (key.toString().equals(APPLICATION_ACL_KEY.toString())) { - DataInputStream valueStream = entry.getValueStream(); - while (true) { - String appAccessOp = null; - String aclString = null; - try { - appAccessOp = valueStream.readUTF(); - } catch (EOFException e) { - // Valid end of stream. - break; + TFile.Reader.Scanner aclScanner = null; + try { + aclScanner = reader.createScanner(); + LogKey key = new LogKey(); + Map acls = + new HashMap(); + while (!aclScanner.atEnd()) { + TFile.Reader.Scanner.Entry entry = aclScanner.entry(); + key.readFields(entry.getKeyStream()); + if (key.toString().equals(APPLICATION_ACL_KEY.toString())) { + DataInputStream valueStream = entry.getValueStream(); + while (true) { + String appAccessOp = null; + String aclString = null; + try { + appAccessOp = valueStream.readUTF(); + } catch (EOFException e) { + // Valid end of stream. + break; + } + try { + aclString = valueStream.readUTF(); + } catch (EOFException e) { + throw new YarnRuntimeException("Error reading ACLs", e); + } + acls.put(ApplicationAccessType.valueOf(appAccessOp), aclString); } - try { - aclString = valueStream.readUTF(); - } catch (EOFException e) { - throw new YarnRuntimeException("Error reading ACLs", e); - } - acls.put(ApplicationAccessType.valueOf(appAccessOp), aclString); } - + aclScanner.advance(); } - aclScanner.advance(); + return acls; + } finally { + IOUtils.cleanup(LOG, aclScanner); } - return acls; } - + /** * Read the next key and return the value-stream. *