Skip to content

Commit

Permalink
refactor(cats/sql): made sharding configuration for sql based schedul…
Browse files Browse the repository at this point in the history
…er consistent with redis based scheduler (#5512)

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
kirangodishala and mergify[bot] committed Sep 13, 2021
1 parent f99fe92 commit 3c946fc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
Expand Up @@ -24,6 +24,7 @@ import com.netflix.spinnaker.cats.cluster.ShardingFilter
import com.netflix.spinnaker.cats.sql.SqlUtil
import com.netflix.spinnaker.clouddriver.core.provider.CoreProvider
import com.netflix.spinnaker.config.ConnectionPools
import com.netflix.spinnaker.kork.dynamicconfig.DynamicConfigService
import com.netflix.spinnaker.kork.sql.routing.withPool
import org.jooq.DSLContext
import org.jooq.impl.DSL
Expand All @@ -40,14 +41,16 @@ class SqlCachingPodsObserver (
private val jooq: DSLContext,
private val nodeIdentity: NodeIdentity,
private val tableNamespace: String? = null,
private val liveReplicasRecheckIntervalSeconds : Long? = null,
private val dynamicConfigService : DynamicConfigService,
private val liveReplicasScheduler: ScheduledExecutorService = Executors.newSingleThreadScheduledExecutor(
ThreadFactoryBuilder().setNameFormat(SqlCachingPodsObserver::class.java.simpleName + "-%d").build()
)
) : ShardingFilter, Runnable{
private val log = LoggerFactory.getLogger(javaClass)
private var podCount: Int = 0
private var podIndex: Int = -1
private var ttlSeconds = dynamicConfigService.getConfig(Long::class.java, "cache-sharding.replica-ttl-seconds", 60)

companion object {
private val POOL_NAME = ConnectionPools.CACHE_WRITER.value
const val LAST_HEARTBEAT_TIME = "last_heartbeat_time"
Expand All @@ -66,8 +69,9 @@ class SqlCachingPodsObserver (
SqlUtil.createTableLike(jooq, replicasTable, replicasReferenceTable)
}
}
refreshHeartbeat(TimeUnit.SECONDS.toMillis(60))
val recheckInterval = liveReplicasRecheckIntervalSeconds ?: 30L
refreshHeartbeat(TimeUnit.SECONDS.toMillis(ttlSeconds))
val recheckInterval =
dynamicConfigService.getConfig(Long::class.java, "cache-sharding.heartbeat-interval-seconds", 30)
liveReplicasScheduler.scheduleAtFixedRate(this, 0, recheckInterval, TimeUnit.SECONDS)
log.info("Account based sharding across caching pods is enabled.")
}
Expand Down
Expand Up @@ -18,11 +18,10 @@
package com.netflix.spinnaker.config

import com.netflix.spinnaker.cats.cluster.DefaultNodeIdentity
import com.netflix.spinnaker.cats.cluster.NodeIdentity
import com.netflix.spinnaker.cats.sql.cluster.SqlCachingPodsObserver
import com.netflix.spinnaker.kork.dynamicconfig.DynamicConfigService
import org.jooq.DSLContext
import org.springframework.beans.factory.annotation.Value
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
Expand All @@ -36,18 +35,19 @@ class SqlShardingFilterConfiguration {
value = [
"sql.enabled",
"sql.scheduler.enabled",
"caching.sharding-enabled"
"cache-sharding.enabled"
]
)
fun shardingFilter(
jooq: DSLContext,
@Value("\${sql.table-namespace:#{null}}") tableNamespace: String?,
sqlAgentProperties: SqlAgentProperties): SqlCachingPodsObserver {
dynamicConfigService: DynamicConfigService
): SqlCachingPodsObserver {
return SqlCachingPodsObserver(
jooq = jooq,
nodeIdentity = DefaultNodeIdentity(),
tableNamespace = tableNamespace,
liveReplicasRecheckIntervalSeconds = sqlAgentProperties.poll.intervalSeconds
dynamicConfigService = dynamicConfigService
)
}

Expand Down

0 comments on commit 3c946fc

Please sign in to comment.