Skip to content

Commit

Permalink
Log when instances from old RunSpec are staged after TaskReplaceActor…
Browse files Browse the repository at this point in the history
… start

JIRA: MESOS-4412
  • Loading branch information
Flavien Quesnel committed Jan 5, 2021
1 parent cc341d0 commit 453dad6
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import mesosphere.marathon.core.instance.{Goal, GoalChangeReason, Instance}
import mesosphere.marathon.core.launchqueue.LaunchQueue
import mesosphere.marathon.core.readiness.ReadinessCheckExecutor
import mesosphere.marathon.core.task.tracker.InstanceTracker
import mesosphere.marathon.state.RunSpec
import mesosphere.marathon.state.{RunSpec,Timestamp}

import scala.async.Async.{async, await}
import scala.collection.mutable
Expand All @@ -34,6 +34,7 @@ class TaskReplaceActor(

def deploymentId = status.plan.id
def pathId = runSpec.id
val actorStart = Timestamp.now

private[this] var tick: Cancellable = null

Expand Down Expand Up @@ -80,6 +81,12 @@ class TaskReplaceActor(
instancesByIncarnation._1.sortBy(_.appTask.status.stagedAt) ++ instancesByIncarnation._2
}

// find instances with tasks staged after the TaskReplaceActor started
def findInstancesStagedAfterActorStart(instances: Seq[Instance]): Seq[Instance] = {
val instancesByIncarnation = instances.partition(_.tasksMap.size != 0)
instancesByIncarnation._1.filter(_.appTask.status.stagedAt.after(actorStart))
}

// Return the number of non running old instances killed
def killNonRunningOldInstances(oldInstances: Seq[Instance]): Integer = {
val nonRunningOldInstances = oldInstances.filter(!_.isRunning).to[mutable.Queue]
Expand All @@ -101,6 +108,12 @@ class TaskReplaceActor(
return
}

val tooRecentOldInstancesCount = findInstancesStagedAfterActorStart(current_instances._2).size

if (tooRecentOldInstancesCount > 0) {
logger.info(s"Found ${tooRecentOldInstancesCount} old instances with tasks staged after a new deployment started for ${pathId}")
}

// make sure we kill in order:
// - instances with unhealthy tasks
// - instances with oldest tasks
Expand Down

0 comments on commit 453dad6

Please sign in to comment.