Skip to content

Commit 7b71d8f

Browse files
author
Andrew Or
committed
Add detailed java docs + reword a few comments
1 parent d1124e4 commit 7b71d8f

File tree

2 files changed

+35
-20
lines changed

2 files changed

+35
-20
lines changed

network/shuffle/src/main/java/org/apache/spark/network/sasl/ShuffleSecretManager.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,18 @@ public class ShuffleSecretManager implements SecretKeyHolder {
4141
private static final String SPARK_SASL_USER = "sparkSaslUser";
4242

4343
/**
44-
* Convert the given string to a byte buffer that can be converted back to a string
45-
* through {@link #bytesToString(ByteBuffer)}. This is used if the external shuffle
46-
* service represents shuffle secrets as bytes buffers instead of strings.
44+
* Convert the given string to a byte buffer. The resulting buffer can be converted back to
45+
* the same string through {@link #bytesToString(ByteBuffer)}. This is used if the external
46+
* shuffle service represents shuffle secrets as bytes buffers instead of strings.
4747
*/
4848
public static ByteBuffer stringToBytes(String s) {
4949
return ByteBuffer.wrap(s.getBytes(UTF8_CHARSET));
5050
}
5151

5252
/**
53-
* Convert the given byte buffer to a string that can be converted back to a byte
54-
* buffer through {@link #stringToBytes(String)}. This is used if the external shuffle
55-
* service represents shuffle secrets as bytes buffers instead of strings.
53+
* Convert the given byte buffer to a string. The resulting string can be converted back to
54+
* the same byte buffer through {@link #stringToBytes(String)}. This is used if the external
55+
* shuffle service represents shuffle secrets as bytes buffers instead of strings.
5656
*/
5757
public static String bytesToString(ByteBuffer b) {
5858
return new String(b.array(), UTF8_CHARSET);
@@ -63,9 +63,9 @@ public ShuffleSecretManager() {
6363
}
6464

6565
/**
66-
* Register the specified application with its secret.
66+
* Register an application with its secret.
6767
* Executors need to first authenticate themselves with the same secret before
68-
* the fetching shuffle files written by other executors in this application.
68+
* fetching shuffle files written by other executors in this application.
6969
*/
7070
public void registerApp(String appId, String shuffleSecret) {
7171
if (!shuffleSecretMap.contains(appId)) {
@@ -77,15 +77,15 @@ public void registerApp(String appId, String shuffleSecret) {
7777
}
7878

7979
/**
80-
* Register the specified application with its secret specified as a byte buffer.
80+
* Register an application with its secret specified as a byte buffer.
8181
*/
8282
public void registerApp(String appId, ByteBuffer shuffleSecret) {
8383
registerApp(appId, bytesToString(shuffleSecret));
8484
}
8585

8686
/**
87-
* Unregister the specified application along with its secret.
88-
* This is called when an application terminates.
87+
* Unregister an application along with its secret.
88+
* This is called when the application terminates.
8989
*/
9090
public void unregisterApp(String appId) {
9191
if (shuffleSecretMap.contains(appId)) {
@@ -105,10 +105,10 @@ public String getSaslUser(String appId) {
105105
}
106106

107107
/**
108-
* Return the secret key registered with the specified application.
109-
* This key is used to authenticate the executors in the application
110-
* before they can fetch shuffle files from the external shuffle service.
111-
* If the application is not registered, return null.
108+
* Return the secret key registered with the given application.
109+
* This key is used to authenticate the executors before they can fetch shuffle files
110+
* written by this application from the external shuffle service. If the specified
111+
* application is not registered, return null.
112112
*/
113113
@Override
114114
public String getSecretKey(String appId) {

network/yarn/src/main/java/org/apache/spark/network/yarn/YarnShuffleService.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,22 @@
4141
import org.apache.spark.network.yarn.util.HadoopConfigProvider;
4242

4343
/**
44-
* External shuffle service used by Spark on Yarn.
44+
* An external shuffle service used by Spark on Yarn.
45+
*
46+
* This is intended to be a long-running auxiliary service that runs in the NodeManager process.
47+
* A Spark application may connect to this service by setting `spark.shuffle.service.enabled`.
48+
* The application also automatically derives the service port through `spark.shuffle.service.port`
49+
* specified in the Yarn configuration. This is so that both the clients and the server agree on
50+
* the same port to communicate on.
51+
*
52+
* The service also optionally supports authentication. This ensures that executors from one
53+
* application cannot read the shuffle files written by those from another. This feature can be
54+
* enabled by setting `spark.authenticate` in the Yarn configuration before starting the NM.
55+
* Note that the Spark application must also set `spark.authenticate` manually and, unlike in
56+
* the case of the service port, will not inherit this setting from the Yarn configuration. This
57+
* is because an application running on the same Yarn cluster may choose to not use the external
58+
* shuffle service, in which case its setting of `spark.authenticate` should be independent of
59+
* the service's.
4560
*/
4661
public class YarnShuffleService extends AuxiliaryService {
4762
private final Logger logger = LoggerFactory.getLogger(YarnShuffleService.class);
@@ -58,12 +73,12 @@ public class YarnShuffleService extends AuxiliaryService {
5873
// This is used only if authentication is enabled
5974
private ShuffleSecretManager secretManager;
6075

61-
// Actual server that serves the shuffle files
76+
// The actual server that serves shuffle files
6277
private TransportServer shuffleServer = null;
6378

6479
public YarnShuffleService() {
6580
super("spark_shuffle");
66-
logger.info("Initializing Yarn shuffle service for Spark");
81+
logger.info("Initializing YARN shuffle service for Spark");
6782
}
6883

6984
/**
@@ -96,10 +111,10 @@ protected void serviceInit(Configuration conf) {
96111
TransportContext transportContext = new TransportContext(transportConf, rpcHandler);
97112
shuffleServer = transportContext.createServer(port);
98113
String authEnabledString = authEnabled ? "enabled" : "not enabled";
99-
logger.info("Started Yarn shuffle service for Spark on port {}. " +
114+
logger.info("Started YARN shuffle service for Spark on port {}. " +
100115
"Authentication is {}.", port, authEnabledString);
101116
} catch (Exception e) {
102-
logger.error("Exception in starting Yarn shuffle service for Spark", e);
117+
logger.error("Exception in starting YARN shuffle service for Spark", e);
103118
}
104119
}
105120

0 commit comments

Comments
 (0)