From 7b2540770ecdbe516660b3edbe60a9633ff99fab Mon Sep 17 00:00:00 2001 From: Wangda Tan Date: Thu, 16 Jul 2015 16:06:20 -0700 Subject: [PATCH] YARN-3930. FileSystemNodeLabelsStore should make sure edit log file closed when exception is thrown. (Dian Fu via wangda) (cherry picked from commit fa2b63ed162410ba05eadf211a1da068351b293a) --- hadoop-yarn-project/CHANGES.txt | 3 ++ .../nodelabels/FileSystemNodeLabelsStore.java | 39 ++++++++++++------- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/hadoop-yarn-project/CHANGES.txt b/hadoop-yarn-project/CHANGES.txt index a870ca53b8c..800f5964091 100644 --- a/hadoop-yarn-project/CHANGES.txt +++ b/hadoop-yarn-project/CHANGES.txt @@ -589,6 +589,9 @@ Release 2.8.0 - UNRELEASED YARN-3805. Update the documentation of Disk Checker based on YARN-90. (Masatake Iwasaki via ozawa) + YARN-3930. FileSystemNodeLabelsStore should make sure edit log file closed when + exception is thrown. (Dian Fu via wangda) + 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/nodelabels/FileSystemNodeLabelsStore.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/nodelabels/FileSystemNodeLabelsStore.java index f26e2048a02..abf07e805a2 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/nodelabels/FileSystemNodeLabelsStore.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/nodelabels/FileSystemNodeLabelsStore.java @@ -127,31 +127,40 @@ public class FileSystemNodeLabelsStore extends NodeLabelsStore { @Override public void updateNodeToLabelsMappings( Map> nodeToLabels) throws IOException { - ensureAppendEditlogFile(); - editlogOs.writeInt(SerializedLogType.NODE_TO_LABELS.ordinal()); - ((ReplaceLabelsOnNodeRequestPBImpl) ReplaceLabelsOnNodeRequest - .newInstance(nodeToLabels)).getProto().writeDelimitedTo(editlogOs); - ensureCloseEditlogFile(); + try { + ensureAppendEditlogFile(); + editlogOs.writeInt(SerializedLogType.NODE_TO_LABELS.ordinal()); + ((ReplaceLabelsOnNodeRequestPBImpl) ReplaceLabelsOnNodeRequest + .newInstance(nodeToLabels)).getProto().writeDelimitedTo(editlogOs); + } finally { + ensureCloseEditlogFile(); + } } @Override public void storeNewClusterNodeLabels(List labels) throws IOException { - ensureAppendEditlogFile(); - editlogOs.writeInt(SerializedLogType.ADD_LABELS.ordinal()); - ((AddToClusterNodeLabelsRequestPBImpl) AddToClusterNodeLabelsRequest - .newInstance(labels)).getProto().writeDelimitedTo(editlogOs); - ensureCloseEditlogFile(); + try { + ensureAppendEditlogFile(); + editlogOs.writeInt(SerializedLogType.ADD_LABELS.ordinal()); + ((AddToClusterNodeLabelsRequestPBImpl) AddToClusterNodeLabelsRequest + .newInstance(labels)).getProto().writeDelimitedTo(editlogOs); + } finally { + ensureCloseEditlogFile(); + } } @Override public void removeClusterNodeLabels(Collection labels) throws IOException { - ensureAppendEditlogFile(); - editlogOs.writeInt(SerializedLogType.REMOVE_LABELS.ordinal()); - ((RemoveFromClusterNodeLabelsRequestPBImpl) RemoveFromClusterNodeLabelsRequest.newInstance(Sets - .newHashSet(labels.iterator()))).getProto().writeDelimitedTo(editlogOs); - ensureCloseEditlogFile(); + try { + ensureAppendEditlogFile(); + editlogOs.writeInt(SerializedLogType.REMOVE_LABELS.ordinal()); + ((RemoveFromClusterNodeLabelsRequestPBImpl) RemoveFromClusterNodeLabelsRequest.newInstance(Sets + .newHashSet(labels.iterator()))).getProto().writeDelimitedTo(editlogOs); + } finally { + ensureCloseEditlogFile(); + } } /* (non-Javadoc)