Fix reload config (#341)
This commit is contained in:
@@ -74,10 +74,9 @@ class ReloadConfigSetup(
|
||||
)
|
||||
|
||||
val upstreamsToRemove = upstreamsAnalyzeData.removed
|
||||
.plus(upstreamsAnalyzeData.reloaded)
|
||||
.filterNot { chainsToReload.contains(it.second) }
|
||||
.toSet()
|
||||
val upstreamsToAdd = upstreamsAnalyzeData.added
|
||||
.plus(upstreamsAnalyzeData.reloaded.map { it.first })
|
||||
|
||||
reloadConfigUpstreamService.reloadUpstreams(chainsToReload, upstreamsToRemove, upstreamsToAdd, newUpstreamsConfig)
|
||||
|
||||
@@ -107,9 +106,12 @@ class ReloadConfigSetup(
|
||||
}
|
||||
}
|
||||
|
||||
val added = newUpstreamsMap.minus(currentUpstreamsMap.keys).mapTo(mutableSetOf()) { it.key.first }
|
||||
val added = newUpstreamsMap
|
||||
.minus(currentUpstreamsMap.keys)
|
||||
.mapTo(mutableSetOf()) { it.key }
|
||||
.plus(reloaded)
|
||||
|
||||
return UpstreamAnalyzeData(added, removed, reloaded)
|
||||
return UpstreamAnalyzeData(added, removed.plus(reloaded))
|
||||
}
|
||||
|
||||
private fun analyzeDefaultOptions(
|
||||
@@ -158,8 +160,7 @@ class ReloadConfigSetup(
|
||||
}
|
||||
|
||||
private data class UpstreamAnalyzeData(
|
||||
val added: Set<String> = emptySet(),
|
||||
val added: Set<Pair<String, Chain>> = emptySet(),
|
||||
val removed: Set<Pair<String, Chain>> = emptySet(),
|
||||
val reloaded: Set<Pair<String, Chain>> = emptySet(),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -16,27 +16,30 @@ open class ReloadConfigUpstreamService(
|
||||
|
||||
fun reloadUpstreams(
|
||||
chainsToReload: Set<Chain>,
|
||||
upstreamsToRemove: List<Pair<String, Chain>>,
|
||||
upstreamsToAdd: Set<String>,
|
||||
upstreamsToRemove: Set<Pair<String, Chain>>,
|
||||
upstreamsToAdd: Set<Pair<String, Chain>>,
|
||||
newUpstreamsConfig: UpstreamsConfig,
|
||||
) {
|
||||
val usedChains = removeUpstreams(chainsToReload, upstreamsToRemove)
|
||||
|
||||
addUpstreams(newUpstreamsConfig, chainsToReload, upstreamsToAdd)
|
||||
addUpstreams(newUpstreamsConfig, chainsToReload, upstreamsToAdd.map { it.first }.toSet())
|
||||
|
||||
usedChains.forEach {
|
||||
multistreamHolder.getUpstream(it)
|
||||
.run {
|
||||
if (!this.haveUpstreams() && this.isRunning()) {
|
||||
usedChains.forEach { chain ->
|
||||
val upstreamsToRemovePerChain = upstreamsToRemove.filter { it.second == chain }
|
||||
val upstreamsToAddPerChain = upstreamsToAdd.filter { it.second == chain }
|
||||
|
||||
if (upstreamsToAddPerChain.isEmpty() && upstreamsToRemovePerChain.isNotEmpty()) {
|
||||
multistreamHolder.getUpstream(chain)
|
||||
.run {
|
||||
this.stop()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun removeUpstreams(
|
||||
chainsToReload: Set<Chain>,
|
||||
upstreamsToRemove: List<Pair<String, Chain>>,
|
||||
upstreamsToRemove: Set<Pair<String, Chain>>,
|
||||
): Set<Chain> {
|
||||
val usedChains = mutableSetOf<Chain>()
|
||||
|
||||
|
||||
@@ -106,10 +106,6 @@ open class GenericMultistream(
|
||||
head.removeHead(upstreamId)
|
||||
}
|
||||
|
||||
override fun isRunning(): Boolean {
|
||||
return super.isRunning() || cachingReader.isRunning()
|
||||
}
|
||||
|
||||
override fun makeLagObserver(): HeadLagObserver =
|
||||
HeadLagObserver(head, upstreams, DistanceExtractor::extractPriorityDistance, headScheduler, 6).apply {
|
||||
start()
|
||||
|
||||
Reference in New Issue
Block a user