File tree Expand file tree Collapse file tree 2 files changed +18
-3
lines changed
core/src/main/scala/org/apache/spark Expand file tree Collapse file tree 2 files changed +18
-3
lines changed Original file line number Diff line number Diff line change 18
18
package org .apache .spark
19
19
20
20
import java .io .File
21
- import java .net .Socket
21
+ import java .net .{ InetAddress , Socket }
22
22
import java .util .Locale
23
23
24
24
import scala .collection .JavaConverters ._
@@ -207,11 +207,15 @@ object SparkEnv extends Logging {
207
207
numCores : Int ,
208
208
ioEncryptionKey : Option [Array [Byte ]],
209
209
isLocal : Boolean ): SparkEnv = {
210
+ var hostnameFinal = hostname
211
+ if (conf.getBoolean(" spark.lyft.resolve" , false )) {
212
+ hostnameFinal = InetAddress .getByName(hostname).getHostAddress
213
+ }
210
214
val env = create(
211
215
conf,
212
216
executorId,
213
217
bindAddress,
214
- hostname ,
218
+ hostnameFinal ,
215
219
None ,
216
220
isLocal,
217
221
numCores,
Original file line number Diff line number Diff line change @@ -2220,9 +2220,16 @@ private[spark] object Utils
2220
2220
* privileged ports.
2221
2221
*/
2222
2222
def userPort (base : Int , offset : Int ): Int = {
2223
- (base + offset - 1024 ) % (65536 - 1024 ) + 1024
2223
+ (base + offset - 1024 ) % (65536 - 1024 ) + 1024
2224
2224
}
2225
2225
2226
+ def randPort (base : Int , offset : Int , maxRand : Int ): Int = {
2227
+ val rand = new scala.util.Random
2228
+ val r = rand.nextInt(maxRand)
2229
+ (base + offset + r) % 65535
2230
+ }
2231
+
2232
+
2226
2233
/**
2227
2234
* Attempt to start a service on the given port, or fail after a number of attempts.
2228
2235
* Each subsequent attempt uses 1 + the port used in the previous attempt (unless the port is 0).
@@ -2249,6 +2256,10 @@ private[spark] object Utils
2249
2256
// Do not increment port if startPort is 0, which is treated as a special port
2250
2257
val tryPort = if (startPort == 0 ) {
2251
2258
startPort
2259
+ } else if (offset > 0 && conf.getInt(" spark.lyft.maxrand" , 0 ) > 0 )
2260
+ {
2261
+ logInfo(s " Using randPort " )
2262
+ randPort(startPort, offset, conf.getInt(" spark.lyft.maxrand" , 0 ))
2252
2263
} else {
2253
2264
userPort(startPort, offset)
2254
2265
}
You can’t perform that action at this time.
0 commit comments