From 1030899cdfe78b740d957e9819141b2e8df6d40f Mon Sep 17 00:00:00 2001 From: Parag Jain Date: Mon, 1 Jun 2015 10:23:05 -0500 Subject: [PATCH] Check lower bound of replicant values for rules --- .../druid/server/coordinator/rules/ForeverLoadRule.java | 1 + .../druid/server/coordinator/rules/IntervalLoadRule.java | 1 + .../java/io/druid/server/coordinator/rules/LoadRule.java | 8 ++++++++ .../io/druid/server/coordinator/rules/PeriodLoadRule.java | 1 + 4 files changed, 11 insertions(+) diff --git a/server/src/main/java/io/druid/server/coordinator/rules/ForeverLoadRule.java b/server/src/main/java/io/druid/server/coordinator/rules/ForeverLoadRule.java index a29b5a566a3..018f7cb48ec 100644 --- a/server/src/main/java/io/druid/server/coordinator/rules/ForeverLoadRule.java +++ b/server/src/main/java/io/druid/server/coordinator/rules/ForeverLoadRule.java @@ -36,6 +36,7 @@ public class ForeverLoadRule extends LoadRule @JsonProperty("tieredReplicants") Map tieredReplicants ) { + validateTieredReplicants(tieredReplicants); this.tieredReplicants = tieredReplicants; } diff --git a/server/src/main/java/io/druid/server/coordinator/rules/IntervalLoadRule.java b/server/src/main/java/io/druid/server/coordinator/rules/IntervalLoadRule.java index 157dc563b8d..f423fd2bbcb 100644 --- a/server/src/main/java/io/druid/server/coordinator/rules/IntervalLoadRule.java +++ b/server/src/main/java/io/druid/server/coordinator/rules/IntervalLoadRule.java @@ -41,6 +41,7 @@ public class IntervalLoadRule extends LoadRule @JsonProperty("tieredReplicants") Map tieredReplicants ) { + validateTieredReplicants(tieredReplicants); this.interval = interval; this.tieredReplicants = tieredReplicants; } diff --git a/server/src/main/java/io/druid/server/coordinator/rules/LoadRule.java b/server/src/main/java/io/druid/server/coordinator/rules/LoadRule.java index 845522929e5..8d06f1ef80a 100644 --- a/server/src/main/java/io/druid/server/coordinator/rules/LoadRule.java +++ b/server/src/main/java/io/druid/server/coordinator/rules/LoadRule.java @@ -20,6 +20,7 @@ package io.druid.server.coordinator.rules; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.MinMaxPriorityQueue; +import com.metamx.common.IAE; import com.metamx.emitter.EmittingLogger; import io.druid.server.coordinator.BalancerStrategy; import io.druid.server.coordinator.CoordinatorStats; @@ -240,6 +241,13 @@ public abstract class LoadRule implements Rule return stats; } + protected void validateTieredReplicants(Map tieredReplicants){ + for (Map.Entry entry: tieredReplicants.entrySet()) { + if (entry.getValue() < 0) + throw new IAE("Replicant value [%d] is less than 0, which is not allowed", entry.getValue()); + } + } + public abstract Map getTieredReplicants(); public abstract int getNumReplicants(String tier); diff --git a/server/src/main/java/io/druid/server/coordinator/rules/PeriodLoadRule.java b/server/src/main/java/io/druid/server/coordinator/rules/PeriodLoadRule.java index b4aef69c81c..6e6fdef52af 100644 --- a/server/src/main/java/io/druid/server/coordinator/rules/PeriodLoadRule.java +++ b/server/src/main/java/io/druid/server/coordinator/rules/PeriodLoadRule.java @@ -42,6 +42,7 @@ public class PeriodLoadRule extends LoadRule @JsonProperty("tieredReplicants") Map tieredReplicants ) { + validateTieredReplicants(tieredReplicants); this.period = period; this.tieredReplicants = tieredReplicants; }