diff --git a/redis/redis-checker/src/main/java/com/ctrip/xpipe/redis/checker/healthcheck/actions/keeper/info/RedisUsedMemoryCollector.java b/redis/redis-checker/src/main/java/com/ctrip/xpipe/redis/checker/healthcheck/actions/keeper/info/RedisUsedMemoryCollector.java index 724a1943d..e7d899272 100644 --- a/redis/redis-checker/src/main/java/com/ctrip/xpipe/redis/checker/healthcheck/actions/keeper/info/RedisUsedMemoryCollector.java +++ b/redis/redis-checker/src/main/java/com/ctrip/xpipe/redis/checker/healthcheck/actions/keeper/info/RedisUsedMemoryCollector.java @@ -6,6 +6,7 @@ import com.ctrip.xpipe.redis.checker.healthcheck.impl.DefaultRedisInstanceInfo; import com.ctrip.xpipe.redis.checker.model.DcClusterShard; import com.ctrip.xpipe.redis.core.protocal.cmd.InfoResultExtractor; +import com.ctrip.xpipe.utils.StringUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; @@ -38,24 +39,21 @@ private long getUsedMemory(InfoResultExtractor extractor) { Long usedMemory = extractor.getUsedMemory(); Long dbSize = extractor.getSwapUsedDbSize(); - if (dbSize == null || usedMemory < maxMemory) return usedMemory; - - if (dbSize < maxMemory >> 1) return maxMemory; + if (dbSize == null) return usedMemory; String keysSpaceDb0 = extractor.extract("db0"); - if (keysSpaceDb0 == null) return maxMemory * 3; - + if (StringUtil.isEmpty(keysSpaceDb0)) return 0; String[] keySpaces = keysSpaceDb0.split(","); String[] keys1 = keySpaces[0].split("="); String[] keys2 = keySpaces[1].split("="); if (!keys1[0].equalsIgnoreCase("keys") || !keys2[0].equalsIgnoreCase("evicts")) { - return maxMemory * 3; + return usedMemory + dbSize * 3; } long evicts = Long.parseLong(keys2[1]); long keys = Long.parseLong(keys1[1]); - return keys == 0 ? maxMemory * 3 : (keys + evicts) / keys * maxMemory; + return keys == 0 ? dbSize * 3 : (keys + evicts) / keys * maxMemory; } @Override diff --git a/redis/redis-checker/src/test/java/com/ctrip/xpipe/redis/checker/healthcheck/actions/keeper/info/RedisUsedMemoryCollectorTest.java b/redis/redis-checker/src/test/java/com/ctrip/xpipe/redis/checker/healthcheck/actions/keeper/info/RedisUsedMemoryCollectorTest.java index 9a86bac10..f9c950c91 100644 --- a/redis/redis-checker/src/test/java/com/ctrip/xpipe/redis/checker/healthcheck/actions/keeper/info/RedisUsedMemoryCollectorTest.java +++ b/redis/redis-checker/src/test/java/com/ctrip/xpipe/redis/checker/healthcheck/actions/keeper/info/RedisUsedMemoryCollectorTest.java @@ -141,18 +141,6 @@ public void before() throws Exception { instance = newRandomRedisHealthCheckInstance(FoundationService.DEFAULT.getDataCenter(), ClusterType.ONE_WAY, randomPort()); } - @Test - public void testGetUsedMemoryInfoWithRor() { - // test used_memory < maxmemory - context = new RedisInfoActionContext(instance, INFO_RESPONSE_OF_ROR); - listener.onAction(context); - Assert.assertTrue(listener.worksfor(context)); - Assert.assertEquals(1, listener.getDcClusterShardUsedMemory().size()); - Assert.assertEquals(109632408, (long) listener.getDcClusterShardUsedMemory().get(new DcClusterShard("jq", "cluster", "shard"))); - - } - - @Test public void testGetUsedMemoryInfoWithRor2() { // test dbSize < maxmemory * 0.5 @@ -175,51 +163,6 @@ public void testGetUsedMemoryInfoWithRor3() { } - @Test - public void testGetUsedMemoryInfoWithRor4() { - // test dbSize >= maxmemory * 0.5, keyspace Exception db0 == null - context = new RedisInfoActionContext(instance, INFO_RESPONSE_OF_ROR4); - listener.onAction(context); - Assert.assertTrue(listener.worksfor(context)); - Assert.assertEquals(1, listener.getDcClusterShardUsedMemory().size()); - Assert.assertEquals(2415919104L * 3, (long) listener.getDcClusterShardUsedMemory().get(new DcClusterShard("jq", "cluster", "shard"))); - - } - - @Test - public void testGetUsedMemoryInfoWithRor5() { - // test dbSize >= maxmemory * 0.5, keyspace Exception keys==null - context = new RedisInfoActionContext(instance, INFO_RESPONSE_OF_ROR5); - listener.onAction(context); - Assert.assertTrue(listener.worksfor(context)); - Assert.assertEquals(1, listener.getDcClusterShardUsedMemory().size()); - Assert.assertEquals(2415919104L * 3, (long) listener.getDcClusterShardUsedMemory().get(new DcClusterShard("jq", "cluster", "shard"))); - - } - - @Test - public void testGetUsedMemoryInfoWithRor6() { - // test dbSize >= maxmemory * 0.5, keyspace Exception evict==null - context = new RedisInfoActionContext(instance, INFO_RESPONSE_OF_ROR6); - listener.onAction(context); - Assert.assertTrue(listener.worksfor(context)); - Assert.assertEquals(1, listener.getDcClusterShardUsedMemory().size()); - Assert.assertEquals(2415919104L * 3, (long) listener.getDcClusterShardUsedMemory().get(new DcClusterShard("jq", "cluster", "shard"))); - - } - - - @Test - public void testGetUsedMemoryInfoWithRor7() { - // test dbSize >= maxmemory * 0.5, keyspace Exception keys == 0 - context = new RedisInfoActionContext(instance, INFO_RESPONSE_OF_ROR7); - listener.onAction(context); - Assert.assertTrue(listener.worksfor(context)); - Assert.assertEquals(1, listener.getDcClusterShardUsedMemory().size()); - Assert.assertEquals(2415919104L * 3, (long) listener.getDcClusterShardUsedMemory().get(new DcClusterShard("jq", "cluster", "shard"))); - - } - @Test public void testGetUsedMemoryInfoWithRedis() { context = new RedisInfoActionContext(instance, INFO_RESPONSE_OF_REDIS); diff --git a/redis/redis-console/src/test/java/com/ctrip/xpipe/redis/console/AppTest.java b/redis/redis-console/src/test/java/com/ctrip/xpipe/redis/console/AppTest.java index e05fdd37d..7594e114e 100644 --- a/redis/redis-console/src/test/java/com/ctrip/xpipe/redis/console/AppTest.java +++ b/redis/redis-console/src/test/java/com/ctrip/xpipe/redis/console/AppTest.java @@ -53,7 +53,7 @@ public void startUp() { public void startConsole8080() throws IOException, SQLException { System.setProperty("server.port", "8080"); - System.setProperty(KEY_SERVER_MODE, ConsoleServerModeCondition.SERVER_MODE.CONSOLE.name()); + System.setProperty(KEY_SERVER_MODE, ConsoleServerModeCondition.SERVER_MODE.CONSOLE_CHECKER.name()); start(); } diff --git a/redis/redis-console/src/test/java/com/ctrip/xpipe/redis/console/keeper/impl/DefaultKeeperUsedInfoAnalyzerTest.java b/redis/redis-console/src/test/java/com/ctrip/xpipe/redis/console/keeper/impl/DefaultKeeperUsedInfoAnalyzerTest.java index 23c77b456..cecefacba 100644 --- a/redis/redis-console/src/test/java/com/ctrip/xpipe/redis/console/keeper/impl/DefaultKeeperUsedInfoAnalyzerTest.java +++ b/redis/redis-console/src/test/java/com/ctrip/xpipe/redis/console/keeper/impl/DefaultKeeperUsedInfoAnalyzerTest.java @@ -438,14 +438,14 @@ public void testGetAllDcReadyToMigrationKeeperContainersWithMixed() { .createKeeper(Cluster5, Shard1, true, 9, 9) .createKeeper(Cluster5, Shard2, false, 9, 9); - createKeeperContainer(models, IP3, 9, 9) + createKeeperContainer(models, IP4, 9, 9) .createKeeper(Cluster5, Shard2, true, 9, 9) .createKeeper(Cluster5, Shard1, false, 9, 9); analyzer.getCurrentDcKeeperContainerUsedInfoModelsMap().putAll(models); analyzer.analyzeKeeperContainerUsedInfo(); List allDcReadyToMigrationKeeperContainers = analyzer.getCurrentDcReadyToMigrationKeeperContainers(); - Assert.assertEquals(1, allDcReadyToMigrationKeeperContainers.stream().filter(container -> !container.isKeeperPairOverload()).count()); + Assert.assertEquals(3, allDcReadyToMigrationKeeperContainers.size()); } @Test