Fix reload config (#341)

This commit is contained in:
KirillPamPam
2023-11-15 17:44:21 +04:00
committed by GitHub
parent 2e80da58df
commit 8de6a8ceb5
4 changed files with 68 additions and 33 deletions

View File

@@ -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(),
)
}

View File

@@ -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>()

View File

@@ -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()