YARN-6310. OutputStreams in AggregatedLogFormat.LogWriter can be left open upon exceptions. Contributed by Haibo Chen

This commit is contained in:
Jason Lowe 2017-03-10 11:07:19 -06:00
parent e06ff18ab6
commit deb9f56946

View File

@ -486,34 +486,34 @@ public TFile.Writer getWriter() {
}
private void writeVersion() throws IOException {
DataOutputStream out = this.writer.prepareAppendKey(-1);
try (DataOutputStream out = this.writer.prepareAppendKey(-1)) {
VERSION_KEY.write(out);
out.close();
out = this.writer.prepareAppendValue(-1);
}
try (DataOutputStream out = this.writer.prepareAppendValue(-1)) {
out.writeInt(VERSION);
out.close();
}
}
public void writeApplicationOwner(String user) throws IOException {
DataOutputStream out = this.writer.prepareAppendKey(-1);
try (DataOutputStream out = this.writer.prepareAppendKey(-1)) {
APPLICATION_OWNER_KEY.write(out);
out.close();
out = this.writer.prepareAppendValue(-1);
}
try (DataOutputStream out = this.writer.prepareAppendValue(-1)) {
out.writeUTF(user);
out.close();
}
}
public void writeApplicationACLs(Map<ApplicationAccessType, String> appAcls)
throws IOException {
DataOutputStream out = this.writer.prepareAppendKey(-1);
try (DataOutputStream out = this.writer.prepareAppendKey(-1)) {
APPLICATION_ACL_KEY.write(out);
out.close();
out = this.writer.prepareAppendValue(-1);
}
try (DataOutputStream out = this.writer.prepareAppendValue(-1)) {
for (Entry<ApplicationAccessType, String> entry : appAcls.entrySet()) {
out.writeUTF(entry.getKey().toString());
out.writeUTF(entry.getValue());
}
out.close();
}
}
public void append(LogKey logKey, LogValue logValue) throws IOException {
@ -522,12 +522,12 @@ public void append(LogKey logKey, LogValue logValue) throws IOException {
if (pendingUploadFiles.size() == 0) {
return;
}
DataOutputStream out = this.writer.prepareAppendKey(-1);
try (DataOutputStream out = this.writer.prepareAppendKey(-1)) {
logKey.write(out);
out.close();
out = this.writer.prepareAppendValue(-1);
}
try (DataOutputStream out = this.writer.prepareAppendValue(-1)) {
logValue.write(out, pendingUploadFiles);
out.close();
}
}
public void close() {