Skip to content

Commit

Permalink
fix(cats/sql) Zombie agents cleanup (#5332)
Browse files Browse the repository at this point in the history
Co-authored-by: Iulian Titiriga <titiriga@adobe.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Apr 16, 2021
1 parent 12abd4d commit 689fa12
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ class SqlClusteredAgentScheduler(
}

private fun findCandidateAgentLocks(): Map<String, AgentExecutionAction> {
cleanupZombieAgents()
val skip = HashMap(activeAgents).entries
val maxConcurrentAgents = dynamicConfigService.getConfig(Int::class.java, "sql.agent.max-concurrent-agents", 100)
val availableAgents = maxConcurrentAgents - skip.size
Expand Down Expand Up @@ -233,6 +234,16 @@ class SqlClusteredAgentScheduler(
return trimmedCandidates
}

private fun cleanupZombieAgents() {
val zombieAgentThreshold = dynamicConfigService.getConfig(Long::class.java, "sql.agent.zombie-threshold-ms", 3600000)
activeAgents
.filter { it.value.currentTime < System.currentTimeMillis() - zombieAgentThreshold }
.forEach {
log.warn("Found zombie agent {}, removing it", it.key)
activeAgents.remove(it.key, it.value)
}
}

private fun tryAcquireSingle(agentType: String, now: Long, timeout: Long): Boolean {
try {
withPool(POOL_NAME) {
Expand Down

0 comments on commit 689fa12

Please sign in to comment.