abhishekrb19 commented on code in PR #15015:
URL: https://github.com/apache/druid/pull/15015#discussion_r1332513789


##########
server/src/main/java/org/apache/druid/server/coordinator/rules/Rules.java:
##########
@@ -43,4 +48,40 @@ public static boolean eligibleForLoad(Period period, 
Interval interval, DateTime
   private Rules()
   {
   }
+
+  /**
+   * Validate rules. This method throws an exception if a rule contain an 
interval that
+   * will fully cover the next rules' interval in the list. Rules that will be 
evaluated at some point
+   * are considered to be legitimate.
+   * @param rules Datasource rules.
+   */
+  public static void validateRules(final List<Rule> rules)
+  {
+    if (rules == null) {
+      return;
+    }
+    final DateTime now = DateTimes.nowUtc();
+    for (int i = 0; i < rules.size() - 1; i++) {
+      final Rule currRule = rules.get(i);
+      final Rule nextRule = rules.get(i + 1);
+      final Interval currInterval = currRule.getEligibleInterval(now);
+      final Interval nextInterval = nextRule.getEligibleInterval(now);
+      if (currInterval.contains(nextInterval)) {
+        // If the current rule has an eternity interval, it covers everything 
following it.
+        // Or if the current rule still covers the next rule at the current 
interval boundaries, then the
+        // next rule will never fire at any time, so throw an exception.
+        if (Intervals.ETERNITY.equals(currInterval) ||
+            
(currRule.getEligibleInterval(currInterval.getStart()).contains(nextRule.getEligibleInterval(currInterval.getStart()))
+             && 
currRule.getEligibleInterval(currInterval.getEnd()).contains(nextRule.getEligibleInterval(currInterval.getEnd()))))
 {
+          throw InvalidInput.exception(
+              "Rule[%s] has an interval that contains interval for rule[%s]. 
The interval[%s] also covers interval[%s].",
+              currRule,
+              nextRule,
+              currInterval,
+              nextInterval

Review Comment:
   Yeah, let's consider a segment with an interval `2020/2022` and the 
following drop rules in order:
   
   1. `dropByInterval('2020/2021')`
   2. `dropByInterval('2021/2022')`
   3. `dropByInterval('2020/2022')`
   
   For the segment in question, only rule 3 will match as the _complete_ 
interval is 
[contained](https://github.com/apache/druid/blob/master/server/src/main/java/org/apache/druid/server/coordinator/rules/IntervalDropRule.java#L66)
 in the drop interval. 
   
   On the other hand, if we consider `loadByInterval` rules for the same 
intervals, you're right that all the rules will apply for the segment as load 
rules will fire as long as there is at least an 
[overlap](https://github.com/apache/druid/blob/master/server/src/main/java/org/apache/druid/server/coordinator/rules/Rules.java#L30).
 
   
   Hope that clarifies why we cannot detect the overlapping case without baking 
in some type awareness, but let me know if I am missing something!
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to