|
@@ -52,11 +52,6 @@ import org.apache.hadoop.yarn.server.api.protocolrecords.impl.pb.ReplaceLabelsOn
|
|
|
import com.google.common.collect.Sets;
|
|
|
|
|
|
public class FileSystemNodeLabelsStore extends NodeLabelsStore {
|
|
|
-
|
|
|
- public FileSystemNodeLabelsStore(CommonNodeLabelsManager mgr) {
|
|
|
- super(mgr);
|
|
|
- }
|
|
|
-
|
|
|
protected static final Log LOG = LogFactory.getLog(FileSystemNodeLabelsStore.class);
|
|
|
|
|
|
protected static final String DEFAULT_DIR_NAME = "node-labels";
|
|
@@ -69,8 +64,8 @@ public class FileSystemNodeLabelsStore extends NodeLabelsStore {
|
|
|
|
|
|
Path fsWorkingPath;
|
|
|
FileSystem fs;
|
|
|
- FSDataOutputStream editlogOs;
|
|
|
- Path editLogPath;
|
|
|
+ private FSDataOutputStream editlogOs;
|
|
|
+ private Path editLogPath;
|
|
|
|
|
|
private String getDefaultFSNodeLabelsRootDir() throws IOException {
|
|
|
// default is in local: /tmp/hadoop-yarn-${user}/node-labels/
|
|
@@ -160,12 +155,40 @@ public class FileSystemNodeLabelsStore extends NodeLabelsStore {
|
|
|
ensureCloseEditlogFile();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ protected void loadFromMirror(Path newMirrorPath, Path oldMirrorPath)
|
|
|
+ throws IOException {
|
|
|
+ // If mirror.new exists, read from mirror.new,
|
|
|
+ FSDataInputStream is = null;
|
|
|
+ if (fs.exists(newMirrorPath)) {
|
|
|
+ is = fs.open(newMirrorPath);
|
|
|
+ } else if (fs.exists(oldMirrorPath)) {
|
|
|
+ is = fs.open(oldMirrorPath);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (null != is) {
|
|
|
+ List<NodeLabel> labels = new AddToClusterNodeLabelsRequestPBImpl(
|
|
|
+ AddToClusterNodeLabelsRequestProto.parseDelimitedFrom(is))
|
|
|
+ .getNodeLabels();
|
|
|
+ mgr.addToCluserNodeLabels(labels);
|
|
|
+
|
|
|
+ if (mgr.isCentralizedConfiguration()) {
|
|
|
+ // Only load node to labels mapping while using centralized configuration
|
|
|
+ Map<NodeId, Set<String>> nodeToLabels =
|
|
|
+ new ReplaceLabelsOnNodeRequestPBImpl(
|
|
|
+ ReplaceLabelsOnNodeRequestProto.parseDelimitedFrom(is))
|
|
|
+ .getNodeToLabels();
|
|
|
+ mgr.replaceLabelsOnNode(nodeToLabels);
|
|
|
+ }
|
|
|
+ is.close();
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
/* (non-Javadoc)
|
|
|
* @see org.apache.hadoop.yarn.nodelabels.NodeLabelsStore#recover(boolean)
|
|
|
*/
|
|
|
@Override
|
|
|
- public void recover(boolean ignoreNodeToLabelsMappings) throws YarnException,
|
|
|
+ public void recover() throws YarnException,
|
|
|
IOException {
|
|
|
/*
|
|
|
* Steps of recover
|
|
@@ -181,31 +204,13 @@ public class FileSystemNodeLabelsStore extends NodeLabelsStore {
|
|
|
// Open mirror from serialized file
|
|
|
Path mirrorPath = new Path(fsWorkingPath, MIRROR_FILENAME);
|
|
|
Path oldMirrorPath = new Path(fsWorkingPath, MIRROR_FILENAME + ".old");
|
|
|
-
|
|
|
- FSDataInputStream is = null;
|
|
|
- if (fs.exists(mirrorPath)) {
|
|
|
- is = fs.open(mirrorPath);
|
|
|
- } else if (fs.exists(oldMirrorPath)) {
|
|
|
- is = fs.open(oldMirrorPath);
|
|
|
- }
|
|
|
-
|
|
|
- if (null != is) {
|
|
|
- List<NodeLabel> labels =
|
|
|
- new AddToClusterNodeLabelsRequestPBImpl(
|
|
|
- AddToClusterNodeLabelsRequestProto.parseDelimitedFrom(is)).getNodeLabels();
|
|
|
- Map<NodeId, Set<String>> nodeToLabels =
|
|
|
- new ReplaceLabelsOnNodeRequestPBImpl(
|
|
|
- ReplaceLabelsOnNodeRequestProto.parseDelimitedFrom(is))
|
|
|
- .getNodeToLabels();
|
|
|
- mgr.addToCluserNodeLabels(labels);
|
|
|
- mgr.replaceLabelsOnNode(nodeToLabels);
|
|
|
- is.close();
|
|
|
- }
|
|
|
+
|
|
|
+ loadFromMirror(mirrorPath, oldMirrorPath);
|
|
|
|
|
|
// Open and process editlog
|
|
|
editLogPath = new Path(fsWorkingPath, EDITLOG_FILENAME);
|
|
|
if (fs.exists(editLogPath)) {
|
|
|
- is = fs.open(editLogPath);
|
|
|
+ FSDataInputStream is = fs.open(editLogPath);
|
|
|
|
|
|
while (true) {
|
|
|
try {
|
|
@@ -233,7 +238,7 @@ public class FileSystemNodeLabelsStore extends NodeLabelsStore {
|
|
|
new ReplaceLabelsOnNodeRequestPBImpl(
|
|
|
ReplaceLabelsOnNodeRequestProto.parseDelimitedFrom(is))
|
|
|
.getNodeToLabels();
|
|
|
- if (!ignoreNodeToLabelsMappings) {
|
|
|
+ if (mgr.isCentralizedConfiguration()) {
|
|
|
/*
|
|
|
* In case of Distributed NodeLabels setup,
|
|
|
* ignoreNodeToLabelsMappings will be set to true and recover will
|