This repository has been archived by the owner on Oct 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 841
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refine logic on how to treat instances that shall be killed.
Summary: This will transition unreachable or reachable stateful instances to Reserved when they're about to be killed. Fixes #5207 Also-By: tharper@mesosphere.com Test Plan: sbt test Reviewers: unterstein, jasongilanfarr, jenkins, meichstedt Reviewed By: jenkins Subscribers: jdef, marathon-team Differential Revision: https://phabricator.mesosphere.com/D529
- Loading branch information
1 parent
0205b29
commit ef6bd77
Showing
11 changed files
with
292 additions
and
50 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
34 changes: 34 additions & 0 deletions
34
src/main/scala/mesosphere/marathon/core/task/termination/impl/KillAction.scala
This file contains 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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package mesosphere.marathon | ||
package core.task.termination.impl | ||
|
||
/** | ||
* Possible actions that can be chosen in order to `kill` a given instance. | ||
* Depending on the instance's state this can be one of | ||
* - [[KillAction.ExpungeFromState]] | ||
* - [[KillAction.TransitionToReserved]] | ||
* - [[KillAction.IssueKillRequest]] | ||
*/ | ||
private[termination] sealed trait KillAction | ||
|
||
private[termination] object KillAction { | ||
/** | ||
* Any normal, reachable and stateless instance will simply be killed via the scheduler driver. | ||
*/ | ||
case object IssueKillRequest extends KillAction | ||
|
||
/** | ||
* If an instance has associated reservations and persistent volumes, killing it should transition | ||
* to the Reserved state. Marathon will thus retain knowledge about the reserved resources and will | ||
* be able to re-use them when trying to launch a new instance. | ||
*/ | ||
case object TransitionToReserved extends KillAction | ||
|
||
/** | ||
* In case of an instance being Unreachable, killing the related Mesos task is impossible. | ||
* In order to get rid of the instance, processing this action expunges the metadata from | ||
* state. If the instance is reported to be non-terminal in the future, it will be killed. | ||
* | ||
* Note: stateful instances with associated reservations must be treated using [[TransitionToReserved]]. | ||
*/ | ||
case object ExpungeFromState extends KillAction | ||
} |
45 changes: 45 additions & 0 deletions
45
src/main/scala/mesosphere/marathon/core/task/termination/impl/KillActionResolver.scala
This file contains 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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package mesosphere.marathon | ||
package core.task.termination.impl | ||
|
||
import com.typesafe.scalalogging.StrictLogging | ||
|
||
/** | ||
* Responsible for resolving the relevant [[KillAction]] for an instance that should be killed. | ||
*/ | ||
private[termination] object KillActionResolver extends StrictLogging { | ||
|
||
/** | ||
* Computes the [[KillAction]] based on the instance's state. | ||
*/ | ||
def computeAction(toKill: ToKill): KillAction = { | ||
val instanceId = toKill.instanceId | ||
val taskIds = toKill.taskIdsToKill | ||
val hasReservations = toKill.maybeInstance.fold(false)(_.hasReservation) | ||
|
||
// TODO(PODS): align this with other Terminal/Unreachable/whatever extractors | ||
val isLost = toKill.maybeInstance.fold(false) { instance => | ||
instance.isGone || instance.isUnknown || instance.isDropped || instance.isUnreachable || instance.isUnreachableInactive | ||
} | ||
|
||
// An instance will be expunged once all tasks are terminal. Therefore, this case is | ||
// highly unlikely. Should it ever occur, this will still expunge the instance to clean up. | ||
val allTerminal: Boolean = taskIds.isEmpty | ||
|
||
if (isLost || allTerminal) { | ||
val msg = if (isLost) "it is lost" else "all its tasks are terminal" | ||
if (hasReservations) { | ||
logger.info(s"Transitioning ${instanceId} to Reserved because it has reservations and ${msg}") | ||
// we will eventually be notified of a taskStatusUpdate after the instance has been updated | ||
KillAction.TransitionToReserved | ||
} else { | ||
logger.warn(s"Expunging ${instanceId} from state because ${msg}") | ||
// we will eventually be notified of a taskStatusUpdate after the instance has been expunged | ||
KillAction.ExpungeFromState | ||
} | ||
} else { | ||
val knownOrNot = if (toKill.maybeInstance.isDefined) "known" else "unknown" | ||
logger.warn("Killing {} {} of instance {}", knownOrNot, taskIds.mkString(","), instanceId) | ||
KillAction.IssueKillRequest | ||
} | ||
} | ||
} |
This file contains 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
23 changes: 23 additions & 0 deletions
23
src/main/scala/mesosphere/marathon/core/task/termination/impl/ToKill.scala
This file contains 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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package mesosphere.marathon | ||
package core.task.termination.impl | ||
|
||
import mesosphere.marathon.Seq | ||
import mesosphere.marathon.core.instance.Instance | ||
import mesosphere.marathon.core.task.Task | ||
import mesosphere.marathon.state.Timestamp | ||
|
||
/** | ||
* Metadata used to track which instances to kill and how many attempts have been made | ||
* | ||
* @param instanceId id of the instance to kill | ||
* @param taskIdsToKill ids of the tasks to kill | ||
* @param maybeInstance the instance, if available | ||
* @param attempts the number of kill attempts | ||
* @param issued the time of the last issued kill request | ||
*/ | ||
private[termination] case class ToKill( | ||
instanceId: Instance.Id, | ||
taskIdsToKill: Seq[Task.Id], | ||
maybeInstance: Option[Instance], | ||
attempts: Int, | ||
issued: Timestamp = Timestamp.zero) |
This file contains 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
Oops, something went wrong.