Github user junyangq commented on a diff in the pull request:
https://github.com/apache/spark/pull/14666#discussion_r75232295
--- Diff: R/pkg/R/sparkR.R ---
@@ -159,55 +159,81 @@ sparkR.sparkContext <- function(
warning(paste("sparkPackages has no effect when using spark-submit
or sparkR shell",
" please use the --packages commandline instead", sep
= ","))
}
+ host <- "localhost"
backendPort <- existingPort
} else {
- path <- tempfile(pattern = "backend_port")
- submitOps <- getClientModeSparkSubmitOpts(
+
+ if (!nzchar(master) || is_master_local(master)) {
+ path <- tempfile(pattern = "backend_port")
+ submitOps <- getClientModeSparkSubmitOpts(
Sys.getenv("SPARKR_SUBMIT_ARGS", "sparkr-shell"),
sparkEnvirMap)
- launchBackend(
+ launchBackend(
args = path,
sparkHome = sparkHome,
jars = jars,
sparkSubmitOpts = submitOps,
packages = packages)
- # wait atmost 100 seconds for JVM to launch
- wait <- 0.1
- for (i in 1:25) {
- Sys.sleep(wait)
- if (file.exists(path)) {
- break
+ # wait atmost 100 seconds for JVM to launch
+ wait <- 0.1
+ for (i in 1:25) {
+ Sys.sleep(wait)
+ if (file.exists(path)) {
+ break
+ }
+ wait <- wait * 1.25
}
- wait <- wait * 1.25
- }
- if (!file.exists(path)) {
- stop("JVM is not ready after 10 seconds")
- }
- f <- file(path, open = "rb")
- backendPort <- readInt(f)
- monitorPort <- readInt(f)
- rLibPath <- readString(f)
- close(f)
- file.remove(path)
- if (length(backendPort) == 0 || backendPort == 0 ||
- length(monitorPort) == 0 || monitorPort == 0 ||
- length(rLibPath) != 1) {
- stop("JVM failed to launch")
+ if (!file.exists(path)) {
+ stop("JVM is not ready after 10 seconds")
+ }
+ f <- file(path, open = "rb")
+ backendPort <- readInt(f)
+ monitorPort <- readInt(f)
+ rLibPath <- readString(f)
+ close(f)
+ file.remove(path)
+ if (length(backendPort) == 0 || backendPort == 0 ||
+ length(monitorPort) == 0 || monitorPort == 0 ||
+ length(rLibPath) != 1) {
+ stop("JVM failed to launch")
+ }
+ if (rLibPath != "") {
+ assign(".libPath", rLibPath, envir = .sparkREnv)
+ .libPaths(c(rLibPath, .libPaths()))
+ }
+ host <- "localhost"
+ } else {
+ backendPort <- if (!is.null(sparkEnvirMap[["backend.port"]])) {
+ sparkEnvirMap[["backend.port"]]
+ } else {
+ "8000"
+ }
+ monitorPort <- if (!is.null(sparkEnvirMap[["monitor.port"]])) {
+ sparkEnvirMap[["monitor.port"]]
+ } else {
+ "8001"
+ }
+ host <- getRemoteMasterInfo(master)$host
+ port <- getRemoteMasterInfo(master)$port
+ if (is.null(port)) {
+ message(sprintf("Use backend port %s.", backendPort))
+ } else {
+ message(sprintf("Use backedn port %s parsed from master.", port))
+ backendPort <- port
+ }
+ master <- "local" # have connected to RBackend, use local mode
}
- assign(".monitorConn", socketConnection(port = monitorPort), envir =
.sparkREnv)
+ assign(".monitorConn", socketConnection(host = host, port =
monitorPort),
+ envir = .sparkREnv)
assign(".backendLaunched", 1, envir = .sparkREnv)
- if (rLibPath != "") {
- assign(".libPath", rLibPath, envir = .sparkREnv)
- .libPaths(c(rLibPath, .libPaths()))
- }
}
.sparkREnv$backendPort <- backendPort
tryCatch({
- connectBackend("localhost", backendPort)
+ connectBackend(host, backendPort)
},
error = function(err) {
- stop("Failed to connect JVM\n")
+ stop(paste0("Failed to connect JVM\n", existingPort))
--- End diff --
Oh this shouldn't have been changed in this PR...
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]