diff --git a/redis/redis-checker/src/main/java/com/ctrip/xpipe/redis/checker/healthcheck/actions/sentinel/collector/command/ResetSentinels.java b/redis/redis-checker/src/main/java/com/ctrip/xpipe/redis/checker/healthcheck/actions/sentinel/collector/command/ResetSentinels.java index 7b33cdd7a3..f220b025b4 100644 --- a/redis/redis-checker/src/main/java/com/ctrip/xpipe/redis/checker/healthcheck/actions/sentinel/collector/command/ResetSentinels.java +++ b/redis/redis-checker/src/main/java/com/ctrip/xpipe/redis/checker/healthcheck/actions/sentinel/collector/command/ResetSentinels.java @@ -16,7 +16,6 @@ import com.ctrip.xpipe.redis.core.protocal.pojo.Role; import com.ctrip.xpipe.redis.core.protocal.pojo.Sentinel; import com.google.common.collect.Sets; -import com.google.common.util.concurrent.RateLimiter; import java.util.ArrayList; import java.util.HashSet; @@ -26,6 +25,7 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; import static com.ctrip.xpipe.redis.checker.healthcheck.actions.sentinel.SentinelHelloCheckAction.LOG_TITLE; @@ -37,7 +37,7 @@ public class ResetSentinels extends AbstractSentinelHelloCollectCommand { private ScheduledExecutorService scheduled; private ExecutorService resetExecutor; private CheckerConfig checkerConfig; - private RateLimiter rateLimiter; + private AtomicInteger resetSentinelCounts = new AtomicInteger(); public ResetSentinels(SentinelHelloCollectContext context, MetaCache metaCache, XpipeNettyClientKeyedObjectPool keyedObjectPool, @@ -50,10 +50,6 @@ public ResetSentinels(SentinelHelloCollectContext context, MetaCache metaCache, this.resetExecutor = resetExecutor; this.sentinelManager = sentinelManager; this.checkerConfig = checkerConfig; - int sentinelQuorum = checkerConfig.getDefaultSentinelQuorumConfig().getQuorum(); - double checkIntervalInSec = (double) checkerConfig.getSentinelCheckIntervalMilli() / 1000; - double rate = (double) (sentinelQuorum - 1) / checkIntervalInSec; - this.rateLimiter = RateLimiter.create(rate); } @Override @@ -105,7 +101,7 @@ private Set tooManyKeepers(List slaves) { } - private Set unknownInstances(List slaves, String clusterId, String shardId) { + private Set unknownInstances(List slaves) { Set unknownInstances = Sets.newHashSet(slaves); unknownInstances.removeAll(context.getShardInstances()); slaves.removeAll(unknownInstances); @@ -116,7 +112,7 @@ private Set unknownInstances(List slaves, String clusterId, private static final int EXPECTED_MASTER_COUNT = 1; boolean shouldReset(List slaves, String clusterId, String shardId, String sentinelMonitorName, HostPort sentinelAddr) { Set toManyKeepers = tooManyKeepers(slaves); - Set unknownSlaves = unknownInstances(slaves, clusterId, shardId); + Set unknownSlaves = unknownInstances(slaves); if (toManyKeepers.isEmpty() && unknownSlaves.isEmpty()) return false; @@ -235,7 +231,7 @@ protected void doExecute() throws Throwable { if (shouldReset(slaves, clusterId, shardId, sentinelMonitorName, sentinelAddr)) { - if (rateLimiter.tryAcquire()) { + if (resetSentinelCounts.incrementAndGet() < checkerConfig.getDefaultSentinelQuorumConfig().getQuorum()) { CatEventMonitor.DEFAULT.logEvent("Sentinel.Hello.Collector.Reset", sentinelMonitorName); sentinelManager.reset(sentinel, sentinelMonitorName).execute().getOrHandle(1000, TimeUnit.MILLISECONDS, throwable -> { logger.error("[{}-{}+{}][reset]{}, {}", LOG_TITLE, clusterId, shardId, sentinelMonitorName, sentinelAddr, throwable); diff --git a/redis/redis-checker/src/test/java/com/ctrip/xpipe/redis/checker/healthcheck/actions/sentinel/collector/command/ResetSentinelsTest.java b/redis/redis-checker/src/test/java/com/ctrip/xpipe/redis/checker/healthcheck/actions/sentinel/collector/command/ResetSentinelsTest.java index 854e69d83b..104faf057e 100644 --- a/redis/redis-checker/src/test/java/com/ctrip/xpipe/redis/checker/healthcheck/actions/sentinel/collector/command/ResetSentinelsTest.java +++ b/redis/redis-checker/src/test/java/com/ctrip/xpipe/redis/checker/healthcheck/actions/sentinel/collector/command/ResetSentinelsTest.java @@ -7,7 +7,6 @@ import com.ctrip.xpipe.redis.checker.config.CheckerConfig; import com.ctrip.xpipe.redis.checker.healthcheck.RedisHealthCheckInstance; import com.ctrip.xpipe.redis.core.meta.MetaCache; -import com.ctrip.xpipe.redis.core.meta.QuorumConfig; import com.ctrip.xpipe.simpleserver.Server; import com.ctrip.xpipe.tuple.Pair; import com.google.common.collect.Lists; @@ -46,8 +45,6 @@ public class ResetSentinelsTest extends AbstractCheckerTest { @Before public void init() throws Exception { - when(checkerConfig.getSentinelCheckIntervalMilli()).thenReturn(15000); - when(checkerConfig.getDefaultSentinelQuorumConfig()).thenReturn(new QuorumConfig()); resetSentinels = new ResetSentinels(new SentinelHelloCollectContext(), metaCache, keyedObjectPool, scheduled, resetExecutor,sentinelManager,checkerConfig); resetSentinels.setKeyedObjectPool(getXpipeNettyClientKeyedObjectPool()).setScheduled(scheduled);