Skip to content

Commit

Permalink
fix(cache): remove hardcoded scanSize (#2451)
Browse files Browse the repository at this point in the history
  • Loading branch information
asher committed Mar 23, 2018
1 parent 9aa9b42 commit 144b8bf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package com.netflix.spinnaker.clouddriver.core

import com.netflix.spinnaker.cats.agent.ExecutionInstrumentation
import com.netflix.spinnaker.cats.agent.NoopExecutionInstrumentation
import com.netflix.spinnaker.cats.redis.cache.RedisCacheOptions
import com.netflix.spinnaker.clouddriver.cache.CacheConfig
import com.netflix.spinnaker.clouddriver.cache.NoopOnDemandCacheUpdater
import com.netflix.spinnaker.clouddriver.cache.OnDemandCacheUpdater
Expand Down Expand Up @@ -258,9 +259,11 @@ class CloudDriverConfig {
}

@Bean
CoreProvider coreProvider(RedisClientDelegate redisClientDelegate, ApplicationContext applicationContext) {
CoreProvider coreProvider(RedisCacheOptions redisCacheOptions,
RedisClientDelegate redisClientDelegate,
ApplicationContext applicationContext) {
return new CoreProvider([
new CleanupPendingOnDemandCachesAgent(redisClientDelegate, applicationContext)
new CleanupPendingOnDemandCachesAgent(redisCacheOptions, redisClientDelegate, applicationContext)
])
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.netflix.spinnaker.cats.agent.RunnableAgent;
import com.netflix.spinnaker.cats.module.CatsModule;
import com.netflix.spinnaker.cats.provider.Provider;
import com.netflix.spinnaker.cats.redis.cache.RedisCacheOptions;
import com.netflix.spinnaker.clouddriver.cache.CustomScheduledAgent;
import com.netflix.spinnaker.clouddriver.core.provider.CoreProvider;
import com.netflix.spinnaker.kork.jedis.RedisClientDelegate;
Expand All @@ -41,20 +42,24 @@ public class CleanupPendingOnDemandCachesAgent implements RunnableAgent, CustomS
private static final long DEFAULT_POLL_INTERVAL_MILLIS = TimeUnit.MINUTES.toMillis(30);
private static final long DEFAULT_TIMEOUT_MILLIS = TimeUnit.MINUTES.toMillis(5);

private final RedisCacheOptions redisCacheOptions;
private final RedisClientDelegate redisClientDelegate;
private final ApplicationContext applicationContext;
private final long pollIntervalMillis;
private final long timeoutMillis;

public CleanupPendingOnDemandCachesAgent(RedisClientDelegate redisClientDelegate,
public CleanupPendingOnDemandCachesAgent(RedisCacheOptions redisCacheOptions,
RedisClientDelegate redisClientDelegate,
ApplicationContext applicationContext) {
this(redisClientDelegate, applicationContext, DEFAULT_POLL_INTERVAL_MILLIS, DEFAULT_TIMEOUT_MILLIS);
this(redisCacheOptions, redisClientDelegate, applicationContext, DEFAULT_POLL_INTERVAL_MILLIS, DEFAULT_TIMEOUT_MILLIS);
}

private CleanupPendingOnDemandCachesAgent(RedisClientDelegate redisClientDelegate,
private CleanupPendingOnDemandCachesAgent(RedisCacheOptions redisCacheOptions,
RedisClientDelegate redisClientDelegate,
ApplicationContext applicationContext,
long pollIntervalMillis,
long timeoutMillis) {
this.redisCacheOptions = redisCacheOptions;
this.redisClientDelegate = redisClientDelegate;
this.applicationContext = applicationContext;
this.pollIntervalMillis = pollIntervalMillis;
Expand Down Expand Up @@ -126,7 +131,7 @@ public long getTimeoutMillis() {
private Set<String> scanMembers(String setKey) {
return redisClientDelegate.withCommandsClient(client -> {
final Set<String> matches = new HashSet<>();
final ScanParams scanParams = new ScanParams().count(25000);
final ScanParams scanParams = new ScanParams().count(redisCacheOptions.getScanSize());
String cursor = "0";
while (true) {
final ScanResult<String> scanResult = client.sscan(setKey, cursor, scanParams);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.netflix.spinnaker.clouddriver.core.agent

import com.netflix.spinnaker.cats.redis.cache.RedisCacheOptions
import com.netflix.spinnaker.clouddriver.core.provider.CoreProvider
import com.netflix.spinnaker.kork.jedis.EmbeddedRedis
import com.netflix.spinnaker.kork.jedis.JedisClientDelegate
Expand All @@ -30,11 +31,12 @@ class CleanupPendingOnDemandCachesAgentSpec extends Specification {
@AutoCleanup("destroy")
EmbeddedRedis embeddedRedis = EmbeddedRedis.embed()

def redisCacheOptions = new RedisCacheOptions(50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, true)
def redisClientDelegate = new JedisClientDelegate(embeddedRedis.pool as JedisPool)

def "should cleanup onDemand:members set for a provider"() {
given:
def agent = new CleanupPendingOnDemandCachesAgent(redisClientDelegate, Stub(ApplicationContext))
def agent = new CleanupPendingOnDemandCachesAgent(redisCacheOptions, redisClientDelegate, Stub(ApplicationContext))
def providers = [
new CoreProvider([])
]
Expand Down

0 comments on commit 144b8bf

Please sign in to comment.