This is an automated email from the ASF dual-hosted git repository.
zaynt4606 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/celeborn.git
The following commit(s) were added to refs/heads/main by this push:
new bd8607856e [CELEBORN-2445] Support overriding decommission
forceExitTimeout via the worker exit API
bd8607856e is described below
commit bd8607856e45681f96f72bf1660ccc120834145d
Author: sychen <[email protected]>
AuthorDate: Sat Nov 14 19:46:11 2026 +0800
[CELEBORN-2445] Support overriding decommission forceExitTimeout via the
worker exit API
### What changes were proposed in this pull request?
Allow overriding `celeborn.worker.decommission.forceExitTimeout` **per
decommission** via an optional `timeout` parameter on the worker `exit` API —
root `/exit`, v1 `/api/v1/workers/exit`, and the CLI `--exit-timeout` option —
without restarting the worker or editing configuration.
### Why are the changes needed?
`celeborn.worker.decommission.forceExitTimeout` (default `6h`) is **not
dynamically changeable**: it is read once at decommission start and baked into
both the `ShutdownHookManager` hook ceiling and the `decommissionWorker` drain
loop. There is currently no way to shorten it for a single decommission other
than editing the config + restarting, and
once a decommission is running the value is fixed.
### Does this PR resolve a correctness bug?
- [ ] Yes
### Does this PR introduce _any_ user-facing change?
- [ ] Yes
### How was this patch tested?
Closes #3828 from cxzl25/CELEBORN-2445.
Lead-authored-by: sychen <[email protected]>
Co-authored-by: cxzl25 <[email protected]>
Co-authored-by: zhengtao <[email protected]>
Signed-off-by: zhengtao <[email protected]>
AI-Contributed/Feature: 0/195
AI-Contributed/UT: 0/184
---
.../apache/celeborn/cli/worker/WorkerOptions.scala | 28 +++-
.../celeborn/cli/worker/WorkerSubcommandImpl.scala | 16 +-
.../celeborn/cli/TestCelebornCliCommands.scala | 17 +++
docs/celeborn_cli.md | 16 +-
docs/decommissioning.md | 11 ++
docs/restapi.md | 2 +-
.../celeborn/rest/v1/model/WorkerExitRequest.java | 37 ++++-
.../src/main/openapi3/worker_rest_v1.yaml | 5 +
.../celeborn/server/common/HttpService.scala | 2 +
.../celeborn/service/deploy/worker/Worker.scala | 49 +++++-
.../deploy/worker/WorkerStatusManager.scala | 13 +-
.../deploy/worker/http/api/ApiWorkerResource.scala | 10 +-
.../deploy/worker/http/api/v1/WorkerResource.scala | 6 +-
.../service/deploy/worker/WorkerExitSuite.scala | 167 +++++++++++++++++++++
14 files changed, 346 insertions(+), 33 deletions(-)
diff --git
a/cli/src/main/scala/org/apache/celeborn/cli/worker/WorkerOptions.scala
b/cli/src/main/scala/org/apache/celeborn/cli/worker/WorkerOptions.scala
index 3d0ec71223..905def37e9 100644
--- a/cli/src/main/scala/org/apache/celeborn/cli/worker/WorkerOptions.scala
+++ b/cli/src/main/scala/org/apache/celeborn/cli/worker/WorkerOptions.scala
@@ -17,7 +17,7 @@
package org.apache.celeborn.cli.worker
-import picocli.CommandLine.Option
+import picocli.CommandLine.{ArgGroup, Option}
final class WorkerOptions {
@@ -55,11 +55,8 @@ final class WorkerOptions {
description = Array("Check if the system is registered"))
private[worker] var isRegistered: Boolean = _
- @Option(
- names = Array("--exit"),
- paramLabel = "exit_type",
- description = Array("Exit the application with a specified type"))
- private[worker] var exitType: String = _
+ @ArgGroup(exclusive = false)
+ private[worker] var exitOptions: WorkerExitOptions = _
@Option(names = Array("--show-conf"), description = Array("Show worker
conf"))
private[worker] var showConf: Boolean = _
@@ -86,3 +83,22 @@ final class WorkerOptions {
private[worker] var setLogLevel: Boolean = _
}
+
+final class WorkerExitOptions {
+
+ @Option(
+ names = Array("--exit"),
+ required = true,
+ paramLabel = "exit_type",
+ description = Array("Exit the application with a specified type"))
+ private[worker] var exitType: String = _
+
+ @Option(
+ names = Array("--exit-timeout"),
+ paramLabel = "duration",
+ description = Array(
+ "Optional decommission forceExitTimeout override for --exit DECOMMISSION
" +
+ "(e.g. 600s/30m/1h); ignored for other exit types."))
+ private[worker] var exitTimeout: String = _
+
+}
diff --git
a/cli/src/main/scala/org/apache/celeborn/cli/worker/WorkerSubcommandImpl.scala
b/cli/src/main/scala/org/apache/celeborn/cli/worker/WorkerSubcommandImpl.scala
index f8f31615cf..34160b6152 100644
---
a/cli/src/main/scala/org/apache/celeborn/cli/worker/WorkerSubcommandImpl.scala
+++
b/cli/src/main/scala/org/apache/celeborn/cli/worker/WorkerSubcommandImpl.scala
@@ -34,7 +34,7 @@ class WorkerSubcommandImpl extends WorkerSubcommand {
if (workerOptions.isShutdown) log(runIsShutdown)
if (workerOptions.isDecommissioning) log(runIsDecommissioning)
if (workerOptions.isRegistered) log(runIsRegistered)
- if (workerOptions.exitType != null && workerOptions.exitType.nonEmpty)
log(runExit)
+ if (workerOptions.exitOptions != null) log(runExit)
if (workerOptions.showConf) log(runShowConf)
if (workerOptions.showContainerInfo) log(runShowContainerInfo)
if (workerOptions.showDynamicConf) log(runShowDynamicConf)
@@ -67,9 +67,17 @@ class WorkerSubcommandImpl extends WorkerSubcommand {
private[worker] def runIsRegistered: Boolean =
runShowWorkerInfo.getIsRegistered
private[worker] def runExit: HandleResponse = {
- val workerExitType: TypeEnum = TypeEnum.valueOf(workerOptions.exitType)
- val workerExitRequest: WorkerExitRequest = new
WorkerExitRequest().`type`(workerExitType)
- logInfo(s"Sending worker exit type: ${workerExitType.getValue}")
+ val exitOptions = workerOptions.exitOptions
+ val workerExitType: TypeEnum = TypeEnum.valueOf(exitOptions.exitType)
+ val workerExitRequest: WorkerExitRequest =
+ new WorkerExitRequest().`type`(workerExitType)
+ if (exitOptions.exitTimeout != null) {
+ workerExitRequest.timeout(exitOptions.exitTimeout)
+ logInfo(s"Sending worker exit type: ${workerExitType.getValue}, " +
+ s"timeout: ${exitOptions.exitTimeout}")
+ } else {
+ logInfo(s"Sending worker exit type: ${workerExitType.getValue}")
+ }
workerApi.workerExit(workerExitRequest, commonOptions.getAuthHeader)
}
diff --git
a/cli/src/test/scala/org/apache/celeborn/cli/TestCelebornCliCommands.scala
b/cli/src/test/scala/org/apache/celeborn/cli/TestCelebornCliCommands.scala
index 40841b032b..631dcde38b 100644
--- a/cli/src/test/scala/org/apache/celeborn/cli/TestCelebornCliCommands.scala
+++ b/cli/src/test/scala/org/apache/celeborn/cli/TestCelebornCliCommands.scala
@@ -138,6 +138,23 @@ class TestCelebornCliCommands extends CelebornFunSuite
with MiniClusterFeature {
captureOutputAndValidateResponse(args, "true")
}
+ test("worker --exit with --exit-timeout") {
+ val args = Array(
+ "worker",
+ "--hostport",
+ "localhost:1",
+ "--exit",
+ "DECOMMISSION",
+ "--exit-timeout",
+ "30m")
+ captureOutputAndValidateResponse(args, "Sending worker exit type:
DECOMMISSION, timeout: 30m")
+ }
+
+ test("worker --exit-timeout without --exit is rejected") {
+ val args = prepareWorkerArgs() ++ Array("--exit-timeout", "30m")
+ captureErrorAndValidateResponse(args, "Missing required argument(s):
--exit=exit_type")
+ }
+
test("worker --show-conf") {
val args = prepareWorkerArgs() :+ "--show-conf"
captureOutputAndValidateResponse(args, "ConfResponse")
diff --git a/docs/celeborn_cli.md b/docs/celeborn_cli.md
index 31b893f3a7..6dbca7ccc5 100644
--- a/docs/celeborn_cli.md
+++ b/docs/celeborn_cli.md
@@ -205,17 +205,17 @@ Usage: celeborn-cli worker [-hV] [--apps=appId]
[--auth-header=authHeader]
[--config-name=username] [--config-tenant=tenant_id]
[--delete-configs=c1,c2,c3...] [--host-list=h1,h2,
h3...] [--hostport=host:port] [--logger-level=level]
- [--logger-name=logger_name] [--upsert-configs=k1:
- v1,k2:v2,k3:v3...] [--worker-ids=w1,w2,w3...]
+ [--logger-name=logger_name] [--upsert-configs=k1:v1,
+ k2:v2,k3:v3...] [--worker-ids=w1,w2,w3...]
(--show-worker-info | --show-apps-on-worker |
--show-shuffles-on-worker |
--show-partition-location-info |
--show-unavailable-peers | --is-shutdown |
- --is-decommissioning | --is-registered |
- --exit=exit_type | --show-conf |
- --show-container-info | --show-dynamic-conf |
+ --is-decommissioning | --is-registered | --show-conf
+ | --show-container-info | --show-dynamic-conf |
--upsert-dynamic-conf | --delete-dynamic-conf |
- --show-thread-dump | --show-loggers |
--set-loglevel)
+ --show-thread-dump | --show-loggers | --set-loglevel
+ | [--exit=exit_type [--exit-timeout=duration]])
--apps=appId The application Id list separated by comma.
--auth-header=authHeader
The http `Authorization` header for
@@ -232,6 +232,10 @@ Usage: celeborn-cli worker [-hV] [--apps=appId]
[--auth-header=authHeader]
The comma separated dynamic configs to delete.
--delete-dynamic-conf Delete dynamic worker conf
--exit=exit_type Exit the application with a specified type
+ --exit-timeout=duration
+ Optional decommission forceExitTimeout override
+ for --exit DECOMMISSION (e.g. 600s/30m/1h);
+ ignored for other exit types.
-h, --help Show this help message and exit.
--host-list=h1,h2,h3...
List of hosts to pass to the command
diff --git a/docs/decommissioning.md b/docs/decommissioning.md
index 2802034d82..d65f5bebfd 100644
--- a/docs/decommissioning.md
+++ b/docs/decommissioning.md
@@ -54,6 +54,11 @@ to meet varying workload demands.
| celeborn.worker.decommission.forceExitTimeout | 6h |
| celeborn.worker.decommission.checkInterval | 30s |
+> `forceExitTimeout` is read once at decommission start and is **not
dynamically changeable**
+> for the running decommission. You can override it **per decommission** via
the `timeout`
+> field/param of the worker `exit` API (see below) or the CLI `--exit-timeout`
option, without
+> restarting the worker or editing configuration.
+
## Perform Decommissioning
@@ -63,6 +68,12 @@ Administrators perform decommissioning operation in two
approaches:
```shell
curl -X POST -H "Content-Type: application/json" -d
'{"type":"Decommission"}' http://ip:port/api/v1/workers/exit
```
+ You can override `celeborn.worker.decommission.forceExitTimeout` for this
single decommission
+ by passing an optional `timeout` duration (e.g. `600s`/`30m`/`1h`); if
omitted, the config
+ value (default `6h`) is used:
+ ```shell
+ curl -X POST -H "Content-Type: application/json" -d
'{"type":"Decommission","timeout":"30m"}' http://ip:port/api/v1/workers/exit
+ ```
2. Via Celeborn Master(Leader) REST API endpoint:
```shell
curl -X POST -H "Content-Type: application/json" -d
'{"eventType":"Decommission","workers":[{"host":"192.168.15.140","rpcPort":"37359","pushPort":"38303","fetchPort":"37569","replicatePort":"37093"},{"host":"192.168.15.141","rpcPort":"37359","pushPort":"38303","fetchPort":"37569","replicatePort":"37093"}]}'
http://ip:port/api/v1/workers/events
diff --git a/docs/restapi.md b/docs/restapi.md
index 73e00b9a45..60eba907b1 100644
--- a/docs/restapi.md
+++ b/docs/restapi.md
@@ -111,7 +111,7 @@ See the [migration guide](migration.md) for API mappings.
| /threadDump | GET |
| List the current thread dump of the worker.
|
| /unavailablePeers | GET |
| List the unavailable peers of the worker, this always means the worker
connect to the peer failed.
|
| /workerInfo | GET |
| List the worker information of the worker.
|
-| /exit | POST | type=${EXIT_TYPE}
| Trigger this worker to exit. Legal `type`s are 'Decommission',
'Graceful' and 'Immediately'.
|
+| /exit | POST | type=${EXIT_TYPE}&timeout=${TIMEOUT}
| Trigger this worker to exit. Legal `type`s are 'Decommission',
'Graceful' and 'Immediately'. Optional `timeout` (e.g. 600s/30m/1h) overrides
`celeborn.worker.decommission.forceExitTimeout` for this single Decommission
exit; ignored for other types. |
### `/api/v1` APIs (Since 0.6.0)
diff --git
a/openapi/openapi-client/src/main/java/org/apache/celeborn/rest/v1/model/WorkerExitRequest.java
b/openapi/openapi-client/src/main/java/org/apache/celeborn/rest/v1/model/WorkerExitRequest.java
index 7530cb196e..1090b6214c 100644
---
a/openapi/openapi-client/src/main/java/org/apache/celeborn/rest/v1/model/WorkerExitRequest.java
+++
b/openapi/openapi-client/src/main/java/org/apache/celeborn/rest/v1/model/WorkerExitRequest.java
@@ -32,7 +32,8 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
* WorkerExitRequest
*/
@JsonPropertyOrder({
- WorkerExitRequest.JSON_PROPERTY_TYPE
+ WorkerExitRequest.JSON_PROPERTY_TYPE,
+ WorkerExitRequest.JSON_PROPERTY_TIMEOUT
})
@javax.annotation.Generated(value =
"org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator
version: 7.8.0")
public class WorkerExitRequest {
@@ -78,6 +79,9 @@ public class WorkerExitRequest {
public static final String JSON_PROPERTY_TYPE = "type";
private TypeEnum type = TypeEnum.NONE;
+ public static final String JSON_PROPERTY_TIMEOUT = "timeout";
+ private String timeout;
+
public WorkerExitRequest() {
}
@@ -106,6 +110,31 @@ public class WorkerExitRequest {
this.type = type;
}
+ public WorkerExitRequest timeout(String timeout) {
+
+ this.timeout = timeout;
+ return this;
+ }
+
+ /**
+ * Optional decommission forceExitTimeout override for this single
decommission (e.g. 600s/30m/1h); ignored for non-Decommission types.
+ * @return timeout
+ */
+ @javax.annotation.Nullable
+ @JsonProperty(JSON_PROPERTY_TIMEOUT)
+ @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
+
+ public String getTimeout() {
+ return timeout;
+ }
+
+
+ @JsonProperty(JSON_PROPERTY_TIMEOUT)
+ @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
+ public void setTimeout(String timeout) {
+ this.timeout = timeout;
+ }
+
@Override
public boolean equals(Object o) {
if (this == o) {
@@ -115,12 +144,13 @@ public class WorkerExitRequest {
return false;
}
WorkerExitRequest workerExitRequest = (WorkerExitRequest) o;
- return Objects.equals(this.type, workerExitRequest.type);
+ return Objects.equals(this.type, workerExitRequest.type) &&
+ Objects.equals(this.timeout, workerExitRequest.timeout);
}
@Override
public int hashCode() {
- return Objects.hash(type);
+ return Objects.hash(type, timeout);
}
@Override
@@ -128,6 +158,7 @@ public class WorkerExitRequest {
StringBuilder sb = new StringBuilder();
sb.append("class WorkerExitRequest {\n");
sb.append(" type: ").append(toIndentedString(type)).append("\n");
+ sb.append(" timeout: ").append(toIndentedString(timeout)).append("\n");
sb.append("}");
return sb.toString();
}
diff --git a/openapi/openapi-client/src/main/openapi3/worker_rest_v1.yaml
b/openapi/openapi-client/src/main/openapi3/worker_rest_v1.yaml
index 1cb04ddcbc..30b936bbe7 100644
--- a/openapi/openapi-client/src/main/openapi3/worker_rest_v1.yaml
+++ b/openapi/openapi-client/src/main/openapi3/worker_rest_v1.yaml
@@ -759,6 +759,11 @@ components:
- GRACEFUL
- IMMEDIATELY
- NONE
+ timeout:
+ type: string
+ description: >-
+ Optional decommission forceExitTimeout override for this single
decommission
+ (e.g. 600s/30m/1h); ignored for non-Decommission types.
LoggerInfo:
type: object
diff --git
a/service/src/main/scala/org/apache/celeborn/server/common/HttpService.scala
b/service/src/main/scala/org/apache/celeborn/server/common/HttpService.scala
index 4f06075986..a7fe9fd335 100644
--- a/service/src/main/scala/org/apache/celeborn/server/common/HttpService.scala
+++ b/service/src/main/scala/org/apache/celeborn/server/common/HttpService.scala
@@ -185,6 +185,8 @@ abstract class HttpService extends Service with Logging {
def exit(exitType: String): String = throw new
UnsupportedOperationException()
+ def exit(exitType: String, timeout: String): String = exit(exitType)
+
/**
* Whether the service is able to serve, along with the reason when it is
not. Intended to back
* the `/healthz` endpoint consumed by readiness probes.
diff --git
a/worker/src/main/scala/org/apache/celeborn/service/deploy/worker/Worker.scala
b/worker/src/main/scala/org/apache/celeborn/service/deploy/worker/Worker.scala
index c1576b1d48..3755ed166c 100644
---
a/worker/src/main/scala/org/apache/celeborn/service/deploy/worker/Worker.scala
+++
b/worker/src/main/scala/org/apache/celeborn/service/deploy/worker/Worker.scala
@@ -613,6 +613,8 @@ private[celeborn] class Worker(
}
override def initialize(): Unit = {
+ // Exit requests can arrive as soon as the HTTP server or heartbeats start.
+ workerStatusManager.init(this)
super.initialize()
logInfo(s"Starting Worker $host:$pushPort:$fetchPort:$replicatePort" +
s" with ${workerInfo.diskInfos} slots.")
@@ -664,7 +666,6 @@ private[celeborn] class Worker(
pushDataHandler.init(this)
replicateHandler.init(this)
fetchHandler.init(this)
- workerStatusManager.init(this)
controller.init(this)
rpcEnv.setupEndpoint(RpcNameConstants.WORKER_EP, controller)
@@ -1079,13 +1080,47 @@ private[celeborn] class Worker(
sb.toString()
}
- override def exit(exitType: String): String = {
+ @volatile private var effectiveDecommissionTimeoutMs: Long =
+ conf.workerDecommissionForceExitTimeout
+
+ private[worker] def decommissionTimeoutMs: Long =
effectiveDecommissionTimeoutMs
+
+ // Called under the status manager's lock, only for an accepted decommission
request.
+ private[worker] def configureDecommissionTimeout(timeoutMs: Option[Long]):
Unit = {
+ val effectiveTimeoutMs =
timeoutMs.getOrElse(conf.workerDecommissionForceExitTimeout)
+ effectiveDecommissionTimeoutMs = effectiveTimeoutMs
+ ShutdownHookManager.get().updateTimeout(effectiveTimeoutMs,
TimeUnit.MILLISECONDS)
+ logInfo(s"Worker decommission with
forceExitTimeout=${effectiveTimeoutMs}ms " +
+ s"(source=${if (timeoutMs.isDefined) "exit API" else "config"}).")
+ }
+
+ override def exit(exitType: String): String = exit(exitType, null)
+
+ override def exit(exitType: String, timeout: String): String = {
exitType.toUpperCase(Locale.ROOT) match {
case "DECOMMISSION" =>
- ShutdownHookManager.get().updateTimeout(
- conf.workerDecommissionForceExitTimeout,
- TimeUnit.MILLISECONDS)
- workerStatusManager.doTransition(WorkerEventType.Decommission)
+ val overrideMs: Option[Long] =
+ if (timeout != null && timeout.nonEmpty) {
+ try {
+ val ms = Utils.timeStringAsMs(timeout)
+ if (ms > 0) Some(ms)
+ else {
+ logWarning(s"Invalid exit timeout '$timeout', falling back to
config. " +
+ "Use a positive duration like 600s / 30m / 1h.")
+ None
+ }
+ } catch {
+ case NonFatal(e) =>
+ logWarning(
+ s"Unparseable exit timeout '$timeout', falling back to
config. " +
+ "Use a positive duration like 600s / 30m / 1h.",
+ e)
+ None
+ }
+ } else {
+ None
+ }
+ workerStatusManager.doTransition(WorkerEventType.Decommission,
overrideMs)
case "GRACEFUL" =>
workerStatusManager.doTransition(WorkerEventType.Graceful)
case "IMMEDIATELY" =>
@@ -1161,7 +1196,7 @@ private[celeborn] class Worker(
sendWorkerDecommissionToMaster()
shutdown.set(true)
val interval = conf.workerDecommissionCheckInterval
- val timeout = conf.workerDecommissionForceExitTimeout
+ val timeout = decommissionTimeoutMs
var waitTimes = 0
def waitTime: Long = waitTimes * interval
diff --git
a/worker/src/main/scala/org/apache/celeborn/service/deploy/worker/WorkerStatusManager.scala
b/worker/src/main/scala/org/apache/celeborn/service/deploy/worker/WorkerStatusManager.scala
index 52dfe075ac..500f08f6f2 100644
---
a/worker/src/main/scala/org/apache/celeborn/service/deploy/worker/WorkerStatusManager.scala
+++
b/worker/src/main/scala/org/apache/celeborn/service/deploy/worker/WorkerStatusManager.scala
@@ -76,7 +76,11 @@ private[celeborn] class WorkerStatusManager(conf:
CelebornConf) extends Logging
storageManager = worker.storageManager
}
- def doTransition(eventType: WorkerEventType): Unit = this.synchronized {
+ def doTransition(eventType: WorkerEventType): Unit = doTransition(eventType,
None)
+
+ def doTransition(
+ eventType: WorkerEventType,
+ decommissionTimeoutMs: Option[Long]): Unit = this.synchronized {
if (inExitStatus()) {
logDebug(s"Worker receive event: $eventType, but in exit State:
${getWorkerState()} ")
} else {
@@ -90,6 +94,9 @@ private[celeborn] class WorkerStatusManager(conf:
CelebornConf) extends Logging
if currentState == State.InDecommissionThenIdle || currentState ==
State.Idle =>
recommissionWorker()
case WorkerEventType.Graceful | WorkerEventType.Immediately |
WorkerEventType.Decommission =>
+ if (eventType == WorkerEventType.Decommission) {
+ worker.configureDecommissionTimeout(decommissionTimeoutMs)
+ }
exit(eventType)
case _ =>
logDebug(s"Worker receive event: $eventType, and has nothing to do ")
@@ -114,6 +121,10 @@ private[celeborn] class WorkerStatusManager(conf:
CelebornConf) extends Logging
case _ => // ignore
}
+ startExitThread()
+ }
+
+ protected def startExitThread(): Unit = {
// Compatible with current exit logic
// trigger shutdown hook to exit
ThreadUtils.newThread(
diff --git
a/worker/src/main/scala/org/apache/celeborn/service/deploy/worker/http/api/ApiWorkerResource.scala
b/worker/src/main/scala/org/apache/celeborn/service/deploy/worker/http/api/ApiWorkerResource.scala
index 087bc89e32..a2ec4e64c1 100644
---
a/worker/src/main/scala/org/apache/celeborn/service/deploy/worker/http/api/ApiWorkerResource.scala
+++
b/worker/src/main/scala/org/apache/celeborn/service/deploy/worker/http/api/ApiWorkerResource.scala
@@ -79,13 +79,17 @@ class ApiWorkerResource extends ApiRequestContext {
@Path("/exit")
@Operation(description =
- "Trigger this worker to exit. Legal types are 'Decommission', 'Graceful'
and 'Immediately'.")
+ "Trigger this worker to exit. Legal types are 'Decommission', 'Graceful'
and 'Immediately'. " +
+ "Optional 'timeout' (e.g. 600s/30m/1h) overrides the decommission
forceExitTimeout " +
+ "for this single decommission; ignored for non-Decommission types.")
@ApiResponse(
responseCode = "200",
content = Array(new Content(
mediaType = MediaType.APPLICATION_FORM_URLENCODED)))
@POST
- def exit(@FormParam("type") exitType: String): String = {
- httpService.exit(normalizeParam(exitType))
+ def exit(
+ @FormParam("type") exitType: String,
+ @FormParam("timeout") timeout: String): String = {
+ httpService.exit(normalizeParam(exitType), normalizeParam(timeout))
}
}
diff --git
a/worker/src/main/scala/org/apache/celeborn/service/deploy/worker/http/api/v1/WorkerResource.scala
b/worker/src/main/scala/org/apache/celeborn/service/deploy/worker/http/api/v1/WorkerResource.scala
index 38a745a432..e21db8b4d1 100644
---
a/worker/src/main/scala/org/apache/celeborn/service/deploy/worker/http/api/v1/WorkerResource.scala
+++
b/worker/src/main/scala/org/apache/celeborn/service/deploy/worker/http/api/v1/WorkerResource.scala
@@ -72,7 +72,9 @@ class WorkerResource extends ApiRequestContext {
}
@Operation(description =
- "Trigger this worker to exit. Legal exit types are 'DECOMMISSION',
'GRACEFUL' and 'IMMEDIATELY'.")
+ "Trigger this worker to exit. Legal exit types are 'DECOMMISSION',
'GRACEFUL' and 'IMMEDIATELY'. " +
+ "Optional 'timeout' (e.g. 600s/30m/1h) overrides the decommission
forceExitTimeout " +
+ "for this single decommission; ignored for non-Decommission types.")
@ApiResponse(
responseCode = "200",
content = Array(new Content(
@@ -83,6 +85,6 @@ class WorkerResource extends ApiRequestContext {
def exit(request: WorkerExitRequest): HandleResponse = {
new HandleResponse()
.success(true)
- .message(httpService.exit(request.getType.toString))
+ .message(httpService.exit(request.getType.toString, request.getTimeout))
}
}
diff --git
a/worker/src/test/scala/org/apache/celeborn/service/deploy/worker/WorkerExitSuite.scala
b/worker/src/test/scala/org/apache/celeborn/service/deploy/worker/WorkerExitSuite.scala
new file mode 100644
index 0000000000..5d4d75751e
--- /dev/null
+++
b/worker/src/test/scala/org/apache/celeborn/service/deploy/worker/WorkerExitSuite.scala
@@ -0,0 +1,167 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.celeborn.service.deploy.worker
+
+import java.util.concurrent.{Callable, ConcurrentLinkedQueue, CyclicBarrier,
Executors, TimeUnit}
+import java.util.concurrent.atomic.AtomicBoolean
+
+import org.mockito.ArgumentMatchers.any
+import org.mockito.Mockito
+import org.mockito.MockitoSugar._
+import org.scalatest.funsuite.AnyFunSuite
+
+import org.apache.celeborn.common.CelebornConf
+import org.apache.celeborn.common.meta.WorkerInfo
+import org.apache.celeborn.common.protocol.PbWorkerStatus.State
+import org.apache.celeborn.common.protocol.WorkerEventType
+import org.apache.celeborn.common.util.ShutdownHookManager
+import org.apache.celeborn.service.deploy.worker.storage.StorageManager
+
+class WorkerExitSuite extends AnyFunSuite {
+ private val configuredTimeoutMs = TimeUnit.HOURS.toMillis(6)
+ private val requestedTimeoutMs = TimeUnit.MINUTES.toMillis(30)
+
+ private class ExitFixture {
+ val conf = new CelebornConf()
+ .set(CelebornConf.WORKER_DECOMMISSION_FORCE_EXIT_TIMEOUT.key, "6h")
+ val worker = mock[Worker]
+ val shutdownHooks = mock[ShutdownHookManager]
+ val exitTimeouts = new ConcurrentLinkedQueue[Long]()
+ val statusManager = new WorkerStatusManager(conf) {
+ override protected def startExitThread(): Unit = {
+ // Keep the real transition but do not start a thread that terminates
the test JVM.
+ exitTimeouts.add(ExitFixture.this.worker.decommissionTimeoutMs)
+ }
+ }
+
+ when(worker.conf).thenReturn(conf)
+ when(worker.workerStatusManager).thenReturn(statusManager)
+ when(worker.workerInfo).thenReturn(mock[WorkerInfo])
+ when(worker.shutdown).thenReturn(new AtomicBoolean())
+ when(worker.storageManager).thenReturn(mock[StorageManager])
+ Mockito.doCallRealMethod().when(worker).exit(any[String](), any[String]())
+
Mockito.doCallRealMethod().when(worker).configureDecommissionTimeout(any[Option[Long]]())
+ Mockito.doCallRealMethod().when(worker).decommissionTimeoutMs
+ statusManager.init(worker)
+
+ def withShutdownHooks(body: => Unit): Unit = {
+ // Static mocks are local to the calling thread, including concurrent
HTTP requests below.
+ val mocked = Mockito.mockStatic(classOf[ShutdownHookManager])
+ try {
+ mocked.when[ShutdownHookManager](() =>
ShutdownHookManager.get()).thenReturn(shutdownHooks)
+ body
+ } finally {
+ mocked.close()
+ }
+ }
+
+ def exit(exitType: String, timeout: String): Unit = withShutdownHooks {
+ worker.exit(exitType, timeout)
+ }
+
+ def assertDecommissionTimeout(expected: Long): Unit = {
+ assert(statusManager.getWorkerState() == State.InDecommission)
+ assert(worker.decommissionTimeoutMs == expected)
+ // The timeout is installed before the exit thread can start.
+ assert(exitTimeouts.size() == 1)
+ assert(exitTimeouts.peek() == expected)
+ verify(shutdownHooks).updateTimeout(expected, TimeUnit.MILLISECONDS)
+ verifyNoMoreInteractions(shutdownHooks)
+ }
+ }
+
+ test("decommission installs the requested timeout before starting shutdown")
{
+ val fixture = new ExitFixture
+ fixture.exit("DECOMMISSION", "30m")
+ fixture.assertDecommissionTimeout(requestedTimeoutMs)
+ }
+
+ for (timeout <- Seq(null, "", "invalid", "0s", "-1s")) {
+ test(s"decommission uses the configured timeout for '$timeout'") {
+ val fixture = new ExitFixture
+ fixture.exit("DECOMMISSION", timeout)
+ fixture.assertDecommissionTimeout(configuredTimeoutMs)
+ }
+ }
+
+ test("ignored decommission requests cannot overwrite the accepted timeout") {
+ val fixture = new ExitFixture
+ fixture.exit("DECOMMISSION", "30m")
+ val acceptedStatus = fixture.statusManager.currentWorkerStatus
+
+ Seq(null, "5s", "invalid").foreach { timeout =>
+ fixture.exit("DECOMMISSION", timeout)
+ assert(fixture.statusManager.currentWorkerStatus eq acceptedStatus)
+ fixture.assertDecommissionTimeout(requestedTimeoutMs)
+ }
+ }
+
+ test("concurrent decommission requests configure only the accepted timeout")
{
+ val fixture = new ExitFixture
+ val barrier = new CyclicBarrier(2)
+ val executor = Executors.newFixedThreadPool(2)
+ try {
+ val requests = Seq("30m", "5s").map { timeout =>
+ executor.submit(new Callable[Unit] {
+ override def call(): Unit = {
+ barrier.await(10, TimeUnit.SECONDS)
+ fixture.exit("DECOMMISSION", timeout)
+ }
+ })
+ }
+ requests.foreach(_.get(10, TimeUnit.SECONDS))
+ val acceptedTimeout = fixture.exitTimeouts.peek()
+ assert(Set(requestedTimeoutMs, 5000L).contains(acceptedTimeout))
+ fixture.assertDecommissionTimeout(acceptedTimeout)
+ } finally {
+ executor.shutdownNow()
+ }
+ }
+
+ for ((exitType, state) <- Seq("GRACEFUL" -> State.InGraceFul, "IMMEDIATELY"
-> State.InExit)) {
+ test(s"decommission cannot alter the timeout after $exitType is accepted")
{
+ val fixture = new ExitFixture
+ fixture.exit(exitType, null)
+ fixture.exit("DECOMMISSION", "5s")
+
+ assert(fixture.statusManager.getWorkerState() == state)
+ assert(fixture.exitTimeouts.size() == 1)
+ verify(fixture.worker,
never).configureDecommissionTimeout(any[Option[Long]]())
+ Mockito.verifyNoInteractions(fixture.shutdownHooks)
+ }
+ }
+
+ test("heartbeat decommission uses the configured timeout and ignores later
API overrides") {
+ val fixture = new ExitFixture
+ fixture.withShutdownHooks {
+ fixture.statusManager.doTransition(WorkerEventType.Decommission)
+ }
+ fixture.exit("DECOMMISSION", "5s")
+ fixture.assertDecommissionTimeout(configuredTimeoutMs)
+ }
+
+ test("heartbeat events cannot change a decommission timeout accepted through
the API") {
+ val fixture = new ExitFixture
+ fixture.exit("DECOMMISSION", "30m")
+ fixture.withShutdownHooks {
+ fixture.statusManager.doTransition(WorkerEventType.Decommission)
+ fixture.statusManager.doTransition(WorkerEventType.Graceful)
+ }
+ fixture.assertDecommissionTimeout(requestedTimeoutMs)
+ }
+}