diff --git a/common/src/main/java/org/astraea/common/cost/MigrationCost.java b/common/src/main/java/org/astraea/common/cost/MigrationCost.java index 5083fced65..46df3bb27c 100644 --- a/common/src/main/java/org/astraea/common/cost/MigrationCost.java +++ b/common/src/main/java/org/astraea/common/cost/MigrationCost.java @@ -126,6 +126,10 @@ public static Map brokerMigrationSecond( Map.Entry::getKey, brokerSize -> brokerSize.getValue() / brokerOutRate.get(brokerSize.getKey()).orElse(0))); + brokerInRate.forEach( + (b, rate) -> System.out.println("broker: " + b + " inRate: " + rate.orElse(0))); + brokerOutRate.forEach( + (b, rate) -> System.out.println("broker: " + b + " OutRate: " + rate.orElse(0))); return Stream.concat(before.nodes().stream(), after.nodes().stream()) .map(NodeInfo::id) .distinct() diff --git a/common/src/main/java/org/astraea/common/cost/PartitionMigrateTimeCost.java b/common/src/main/java/org/astraea/common/cost/PartitionMigrateTimeCost.java index de58591d6c..86f3665740 100644 --- a/common/src/main/java/org/astraea/common/cost/PartitionMigrateTimeCost.java +++ b/common/src/main/java/org/astraea/common/cost/PartitionMigrateTimeCost.java @@ -76,20 +76,20 @@ public MetricSensor metricSensor() { var inRate = maxRateSensor.measure(REPLICATION_IN_RATE); var outRate = maxRateSensor.measure(REPLICATION_OUT_RATE); return List.of( - (MaxReplicationInRateBean) + new MaxReplicationInRateBean( () -> new BeanObject( newInMetrics.beanObject().domainName(), newInMetrics.beanObject().properties(), Map.of(STATISTICS_RATE_KEY, Math.max(oldInRate.orElse(0), inRate)), - current.toMillis()), - (MaxReplicationOutRateBean) + current.toMillis())), + new MaxReplicationOutRateBean( () -> new BeanObject( newOutMetrics.beanObject().domainName(), newOutMetrics.beanObject().properties(), Map.of(STATISTICS_RATE_KEY, Math.max(oldOutRate.orElse(0), outRate)), - current.toMillis())); + current.toMillis()))); }; } @@ -103,7 +103,17 @@ public MoveCost moveCost(ClusterInfo before, ClusterInfo after, ClusterBean clus return () -> planMigrateSecond > this.maxMigrateTime.getSeconds(); } - public interface MaxReplicationInRateBean extends HasMaxRate {} + public record MaxReplicationInRateBean(HasMaxRate hasMaxRate) implements HasMaxRate { + @Override + public BeanObject beanObject() { + return hasMaxRate.beanObject(); + } + } - public interface MaxReplicationOutRateBean extends HasMaxRate {} + public record MaxReplicationOutRateBean(HasMaxRate hasMaxRate) implements HasMaxRate { + @Override + public BeanObject beanObject() { + return hasMaxRate.beanObject(); + } + } } diff --git a/common/src/test/java/org/astraea/common/cost/PartitionMigrateTimeCostTest.java b/common/src/test/java/org/astraea/common/cost/PartitionMigrateTimeCostTest.java index 93a542cc52..52e4a2fa44 100644 --- a/common/src/test/java/org/astraea/common/cost/PartitionMigrateTimeCostTest.java +++ b/common/src/test/java/org/astraea/common/cost/PartitionMigrateTimeCostTest.java @@ -168,15 +168,15 @@ private static ClusterBean clusterBean() { Map.of( 0, List.of( - (PartitionMigrateTimeCost.MaxReplicationInRateBean) () -> inBean0, - (PartitionMigrateTimeCost.MaxReplicationOutRateBean) () -> outBean0), + new PartitionMigrateTimeCost.MaxReplicationInRateBean(() -> inBean0), + new PartitionMigrateTimeCost.MaxReplicationOutRateBean(() -> outBean0)), 1, List.of( - (PartitionMigrateTimeCost.MaxReplicationInRateBean) () -> inBean1, - (PartitionMigrateTimeCost.MaxReplicationOutRateBean) () -> outBean1), + new PartitionMigrateTimeCost.MaxReplicationInRateBean(() -> inBean1), + new PartitionMigrateTimeCost.MaxReplicationOutRateBean(() -> outBean1)), 2, List.of( - (PartitionMigrateTimeCost.MaxReplicationInRateBean) () -> inBean2, - (PartitionMigrateTimeCost.MaxReplicationOutRateBean) () -> outBean2))); + new PartitionMigrateTimeCost.MaxReplicationInRateBean(() -> inBean2), + new PartitionMigrateTimeCost.MaxReplicationOutRateBean(() -> outBean2)))); } }