-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-17321][YARN] Avoid writing shuffle metadata to disk if NM recovery is disabled #19032
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,12 +29,14 @@ | |
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import com.google.common.annotations.VisibleForTesting; | ||
| import com.google.common.base.Objects; | ||
| import com.google.common.base.Preconditions; | ||
| import com.google.common.collect.Lists; | ||
| import org.apache.hadoop.conf.Configuration; | ||
| import org.apache.hadoop.fs.FileSystem; | ||
| import org.apache.hadoop.fs.Path; | ||
| import org.apache.hadoop.fs.permission.FsPermission; | ||
| import org.apache.hadoop.yarn.api.records.ContainerId; | ||
| import org.apache.hadoop.yarn.conf.YarnConfiguration; | ||
| import org.apache.hadoop.yarn.server.api.*; | ||
| import org.apache.spark.network.util.LevelDBProvider; | ||
| import org.iq80.leveldb.DB; | ||
|
|
@@ -73,6 +75,8 @@ | |
| public class YarnShuffleService extends AuxiliaryService { | ||
| private static final Logger logger = LoggerFactory.getLogger(YarnShuffleService.class); | ||
|
|
||
| private static final boolean DEFAULT_NM_RECOVERY_ENABLED = false; | ||
|
|
||
| // Port on which the shuffle server listens for fetch requests | ||
| private static final String SPARK_SHUFFLE_SERVICE_PORT_KEY = "spark.shuffle.service.port"; | ||
| private static final int DEFAULT_SPARK_SHUFFLE_SERVICE_PORT = 7337; | ||
|
|
@@ -153,14 +157,18 @@ protected void serviceInit(Configuration conf) throws Exception { | |
| _conf = conf; | ||
|
|
||
| boolean stopOnFailure = conf.getBoolean(STOP_ON_FAILURE_KEY, DEFAULT_STOP_ON_FAILURE); | ||
| boolean recoveryEnabled = conf.getBoolean(YarnConfiguration.NM_RECOVERY_ENABLED, | ||
| DEFAULT_NM_RECOVERY_ENABLED); | ||
|
|
||
| try { | ||
| // In case this NM was killed while there were running spark applications, we need to restore | ||
| // lost state for the existing executors. We look for an existing file in the NM's local dirs. | ||
| // If we don't find one, then we choose a file to use to save the state next time. Even if | ||
| // an application was stopped while the NM was down, we expect yarn to call stopApplication() | ||
| // when it comes back | ||
| registeredExecutorFile = initRecoveryDb(RECOVERY_FILE_NAME); | ||
| if (recoveryEnabled) { | ||
| registeredExecutorFile = initRecoveryDb(RECOVERY_FILE_NAME); | ||
| } | ||
|
|
||
| TransportConf transportConf = new TransportConf("shuffle", new HadoopConfigProvider(conf)); | ||
| blockHandler = new ExternalShuffleBlockHandler(transportConf, registeredExecutorFile); | ||
|
|
@@ -170,7 +178,7 @@ protected void serviceInit(Configuration conf) throws Exception { | |
| List<TransportServerBootstrap> bootstraps = Lists.newArrayList(); | ||
| boolean authEnabled = conf.getBoolean(SPARK_AUTHENTICATE_KEY, DEFAULT_SPARK_AUTHENTICATE); | ||
| if (authEnabled) { | ||
| createSecretManager(); | ||
| createSecretManager(recoveryEnabled); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think at this point it would be cleaner to do: |
||
| bootstraps.add(new AuthServerBootstrap(transportConf, secretManager)); | ||
| } | ||
|
|
||
|
|
@@ -194,30 +202,33 @@ protected void serviceInit(Configuration conf) throws Exception { | |
| } | ||
| } | ||
|
|
||
| private void createSecretManager() throws IOException { | ||
| private void createSecretManager(boolean recoveryEnabled) throws IOException { | ||
| secretManager = new ShuffleSecretManager(); | ||
| secretsFile = initRecoveryDb(SECRETS_RECOVERY_FILE_NAME); | ||
|
|
||
| // Make sure this is protected in case its not in the NM recovery dir | ||
| FileSystem fs = FileSystem.getLocal(_conf); | ||
| fs.mkdirs(new Path(secretsFile.getPath()), new FsPermission((short)0700)); | ||
|
|
||
| db = LevelDBProvider.initLevelDB(secretsFile, CURRENT_VERSION, mapper); | ||
| logger.info("Recovery location is: " + secretsFile.getPath()); | ||
| if (db != null) { | ||
| logger.info("Going to reload spark shuffle data"); | ||
| DBIterator itr = db.iterator(); | ||
| itr.seek(APP_CREDS_KEY_PREFIX.getBytes(StandardCharsets.UTF_8)); | ||
| while (itr.hasNext()) { | ||
| Map.Entry<byte[], byte[]> e = itr.next(); | ||
| String key = new String(e.getKey(), StandardCharsets.UTF_8); | ||
| if (!key.startsWith(APP_CREDS_KEY_PREFIX)) { | ||
| break; | ||
|
|
||
| if (recoveryEnabled) { | ||
| secretsFile = initRecoveryDb(SECRETS_RECOVERY_FILE_NAME); | ||
|
|
||
| // Make sure this is protected in case its not in the NM recovery dir | ||
| FileSystem fs = FileSystem.getLocal(_conf); | ||
| fs.mkdirs(new Path(secretsFile.getPath()), new FsPermission((short) 0700)); | ||
|
|
||
| db = LevelDBProvider.initLevelDB(secretsFile, CURRENT_VERSION, mapper); | ||
| logger.info("Recovery location is: " + secretsFile.getPath()); | ||
| if (db != null) { | ||
| logger.info("Going to reload spark shuffle data"); | ||
| DBIterator itr = db.iterator(); | ||
| itr.seek(APP_CREDS_KEY_PREFIX.getBytes(StandardCharsets.UTF_8)); | ||
| while (itr.hasNext()) { | ||
| Map.Entry<byte[], byte[]> e = itr.next(); | ||
| String key = new String(e.getKey(), StandardCharsets.UTF_8); | ||
| if (!key.startsWith(APP_CREDS_KEY_PREFIX)) { | ||
| break; | ||
| } | ||
| String id = parseDbAppKey(key); | ||
| ByteBuffer secret = mapper.readValue(e.getValue(), ByteBuffer.class); | ||
| logger.info("Reloading tokens for app: " + id); | ||
| secretManager.registerApp(id, secret); | ||
| } | ||
| String id = parseDbAppKey(key); | ||
| ByteBuffer secret = mapper.readValue(e.getValue(), ByteBuffer.class); | ||
| logger.info("Reloading tokens for app: " + id); | ||
| secretManager.registerApp(id, secret); | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -338,49 +349,41 @@ protected Path getRecoveryPath(String fileName) { | |
| * it will uses a YARN local dir. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need to update comment, probably just remove the last sentence. |
||
| */ | ||
| protected File initRecoveryDb(String dbName) { | ||
| if (_recoveryPath != null) { | ||
| File recoveryFile = new File(_recoveryPath.toUri().getPath(), dbName); | ||
| if (recoveryFile.exists()) { | ||
| return recoveryFile; | ||
| } | ||
| Preconditions.checkNotNull(_recoveryPath, | ||
| "recovery path should not be null if NM recovery is enabled"); | ||
|
|
||
| File recoveryFile = new File(_recoveryPath.toUri().getPath(), dbName); | ||
| if (recoveryFile.exists()) { | ||
| return recoveryFile; | ||
| } | ||
|
|
||
| // db doesn't exist in recovery path go check local dirs for it | ||
| String[] localDirs = _conf.getTrimmedStrings("yarn.nodemanager.local-dirs"); | ||
| for (String dir : localDirs) { | ||
| File f = new File(new Path(dir).toUri().getPath(), dbName); | ||
| if (f.exists()) { | ||
| if (_recoveryPath == null) { | ||
| // If NM recovery is not enabled, we should specify the recovery path using NM local | ||
| // dirs, which is compatible with the old code. | ||
| _recoveryPath = new Path(dir); | ||
| return f; | ||
| } else { | ||
| // If the recovery path is set then either NM recovery is enabled or another recovery | ||
| // DB has been initialized. If NM recovery is enabled and had set the recovery path | ||
| // make sure to move all DBs to the recovery path from the old NM local dirs. | ||
| // If another DB was initialized first just make sure all the DBs are in the same | ||
| // location. | ||
| Path newLoc = new Path(_recoveryPath, dbName); | ||
| Path copyFrom = new Path(f.toURI()); | ||
| if (!newLoc.equals(copyFrom)) { | ||
| logger.info("Moving " + copyFrom + " to: " + newLoc); | ||
| try { | ||
| // The move here needs to handle moving non-empty directories across NFS mounts | ||
| FileSystem fs = FileSystem.getLocal(_conf); | ||
| fs.rename(copyFrom, newLoc); | ||
| } catch (Exception e) { | ||
| // Fail to move recovery file to new path, just continue on with new DB location | ||
| logger.error("Failed to move recovery file {} to the path {}", | ||
| dbName, _recoveryPath.toString(), e); | ||
| } | ||
| // If the recovery path is set then either NM recovery is enabled or another recovery | ||
| // DB has been initialized. If NM recovery is enabled and had set the recovery path | ||
| // make sure to move all DBs to the recovery path from the old NM local dirs. | ||
| // If another DB was initialized first just make sure all the DBs are in the same | ||
| // location. | ||
| Path newLoc = new Path(_recoveryPath, dbName); | ||
| Path copyFrom = new Path(f.toURI()); | ||
| if (!newLoc.equals(copyFrom)) { | ||
| logger.info("Moving " + copyFrom + " to: " + newLoc); | ||
| try { | ||
| // The move here needs to handle moving non-empty directories across NFS mounts | ||
| FileSystem fs = FileSystem.getLocal(_conf); | ||
| fs.rename(copyFrom, newLoc); | ||
| } catch (Exception e) { | ||
| // Fail to move recovery file to new path, just continue on with new DB location | ||
| logger.error("Failed to move recovery file {} to the path {}", | ||
| dbName, _recoveryPath.toString(), e); | ||
| } | ||
| return new File(newLoc.toUri().getPath()); | ||
| } | ||
| return new File(newLoc.toUri().getPath()); | ||
| } | ||
| } | ||
| if (_recoveryPath == null) { | ||
| _recoveryPath = new Path(localDirs[0]); | ||
| } | ||
|
|
||
| return new File(_recoveryPath.toUri().getPath(), dbName); | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this in
YarnConfiguration?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me check the yarn code.