Check lower bound of replicant values for rules

This commit is contained in:
Parag Jain 2015-06-01 10:23:05 -05:00
parent 600b30566c
commit 1030899cdf
4 changed files with 11 additions and 0 deletions

View File

@ -36,6 +36,7 @@ public class ForeverLoadRule extends LoadRule
@JsonProperty("tieredReplicants") Map<String, Integer> tieredReplicants @JsonProperty("tieredReplicants") Map<String, Integer> tieredReplicants
) )
{ {
validateTieredReplicants(tieredReplicants);
this.tieredReplicants = tieredReplicants; this.tieredReplicants = tieredReplicants;
} }

View File

@ -41,6 +41,7 @@ public class IntervalLoadRule extends LoadRule
@JsonProperty("tieredReplicants") Map<String, Integer> tieredReplicants @JsonProperty("tieredReplicants") Map<String, Integer> tieredReplicants
) )
{ {
validateTieredReplicants(tieredReplicants);
this.interval = interval; this.interval = interval;
this.tieredReplicants = tieredReplicants; this.tieredReplicants = tieredReplicants;
} }

View File

@ -20,6 +20,7 @@ package io.druid.server.coordinator.rules;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.common.collect.MinMaxPriorityQueue; import com.google.common.collect.MinMaxPriorityQueue;
import com.metamx.common.IAE;
import com.metamx.emitter.EmittingLogger; import com.metamx.emitter.EmittingLogger;
import io.druid.server.coordinator.BalancerStrategy; import io.druid.server.coordinator.BalancerStrategy;
import io.druid.server.coordinator.CoordinatorStats; import io.druid.server.coordinator.CoordinatorStats;
@ -240,6 +241,13 @@ public abstract class LoadRule implements Rule
return stats; return stats;
} }
protected void validateTieredReplicants(Map<String, Integer> tieredReplicants){
for (Map.Entry<String, Integer> 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<String, Integer> getTieredReplicants(); public abstract Map<String, Integer> getTieredReplicants();
public abstract int getNumReplicants(String tier); public abstract int getNumReplicants(String tier);

View File

@ -42,6 +42,7 @@ public class PeriodLoadRule extends LoadRule
@JsonProperty("tieredReplicants") Map<String, Integer> tieredReplicants @JsonProperty("tieredReplicants") Map<String, Integer> tieredReplicants
) )
{ {
validateTieredReplicants(tieredReplicants);
this.period = period; this.period = period;
this.tieredReplicants = tieredReplicants; this.tieredReplicants = tieredReplicants;
} }