@Override public void storeNewClusterNodeLabels(List<NodeLabel> labels) throws IOException { writeNewMirror(); }
@Override public void recover() throws YarnException, IOException { Path newMirrorPath = new Path(fsWorkingPath, MIRROR_FILENAME + ".new"); Path oldMirrorPath = new Path(fsWorkingPath, MIRROR_FILENAME); loadFromMirror(newMirrorPath, oldMirrorPath); // if new mirror exists, remove old mirror and rename new mirror if (fs.exists(newMirrorPath)) { // remove old mirror try { fs.delete(oldMirrorPath, false); } catch (IOException e) { // do nothing if (LOG.isDebugEnabled()) { LOG.debug("Exception while removing old mirror", e); } } // rename new to old fs.rename(newMirrorPath, oldMirrorPath); } LOG.info("Node label store recover is completed"); }
private void writeNewMirror() throws IOException { ReentrantReadWriteLock.ReadLock readLock = manager.readLock; try { // Acquire readlock to make sure we get cluster node labels and // node-to-labels mapping atomically. readLock.lock(); // Write mirror to mirror.new.tmp file Path newTmpPath = new Path(fsWorkingPath, MIRROR_FILENAME + ".new.tmp"); try (FSDataOutputStream os = fs.create(newTmpPath, true)) { StoreOp op = FSStoreOpHandler.getMirrorOp(getStoreType()); op.write(os, manager); } // Rename mirror.new.tmp to mirror.new (will remove .new if it's existed) Path newPath = new Path(fsWorkingPath, MIRROR_FILENAME + ".new"); fs.delete(newPath, false); fs.rename(newTmpPath, newPath); // Remove existing mirror and rename mirror.new to mirror Path mirrorPath = new Path(fsWorkingPath, MIRROR_FILENAME); fs.delete(mirrorPath, false); fs.rename(newPath, mirrorPath); } finally { readLock.unlock(); } } }
@Override public void removeClusterNodeLabels(Collection<String> labels) throws IOException { writeNewMirror(); }
@Override public void updateNodeToLabelsMappings( Map<NodeId, Set<String>> nodeToLabels) throws IOException { writeNewMirror(); }