Skip to content

Commit

Permalink
ror数据量算法更新
Browse files Browse the repository at this point in the history
  • Loading branch information
yifuzhou committed Mar 6, 2024
1 parent dca7ab8 commit a103162
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<MigrationKeeperContainerDetailModel> allDcReadyToMigrationKeeperContainers = analyzer.getCurrentDcReadyToMigrationKeeperContainers();
Assert.assertEquals(1, allDcReadyToMigrationKeeperContainers.stream().filter(container -> !container.isKeeperPairOverload()).count());
Assert.assertEquals(3, allDcReadyToMigrationKeeperContainers.size());
}

@Test
Expand Down

0 comments on commit a103162

Please sign in to comment.