-
Notifications
You must be signed in to change notification settings - Fork 3.8k
make populateUncoveredIntervals a configuration in query context #2332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -166,33 +166,54 @@ public Sequence<T> run(final Query<T> query, final Map<String, Object> responseC | |
| Set<Pair<ServerSelector, SegmentDescriptor>> segments = Sets.newLinkedHashSet(); | ||
|
|
||
| List<TimelineObjectHolder<String, ServerSelector>> serversLookup = Lists.newLinkedList(); | ||
| List<Interval> uncoveredIntervals = Lists.newLinkedList(); | ||
|
|
||
| for (Interval interval : query.getIntervals()) { | ||
| Iterable<TimelineObjectHolder<String, ServerSelector>> lookup = timeline.lookup(interval); | ||
| long startMillis = interval.getStartMillis(); | ||
| long endMillis = interval.getEndMillis(); | ||
| for (TimelineObjectHolder<String, ServerSelector> holder : lookup) { | ||
| Interval holderInterval = holder.getInterval(); | ||
| long intervalStart = holderInterval.getStartMillis(); | ||
| if (startMillis != intervalStart) { | ||
| uncoveredIntervals.add(new Interval(startMillis, intervalStart)); | ||
|
|
||
| // Note that enabling this leads to putting uncovered intervals information in the response headers | ||
| // and might blow up in some cases https://github.com/druid-io/druid/issues/2108 | ||
| int uncoveredIntervalsLimit = BaseQuery.getContextUncoveredIntervalsLimit(query, 0); | ||
|
|
||
| if (uncoveredIntervalsLimit > 0) { | ||
| List<Interval> uncoveredIntervals = Lists.newArrayListWithCapacity(uncoveredIntervalsLimit); | ||
| boolean uncoveredIntervalsOverflowed = false; | ||
|
|
||
| for (Interval interval : query.getIntervals()) { | ||
| Iterable<TimelineObjectHolder<String, ServerSelector>> lookup = timeline.lookup(interval); | ||
| long startMillis = interval.getStartMillis(); | ||
| long endMillis = interval.getEndMillis(); | ||
| for (TimelineObjectHolder<String, ServerSelector> holder : lookup) { | ||
| Interval holderInterval = holder.getInterval(); | ||
| long intervalStart = holderInterval.getStartMillis(); | ||
| if (!uncoveredIntervalsOverflowed && startMillis != intervalStart) { | ||
| if (uncoveredIntervalsLimit > uncoveredIntervals.size()) { | ||
| uncoveredIntervals.add(new Interval(startMillis, intervalStart)); | ||
| } else { | ||
| uncoveredIntervalsOverflowed = true; | ||
| } | ||
| } | ||
| startMillis = holderInterval.getEndMillis(); | ||
| serversLookup.add(holder); | ||
| } | ||
| startMillis = holderInterval.getEndMillis(); | ||
| serversLookup.add(holder); | ||
| } | ||
|
|
||
| if (startMillis < endMillis) { | ||
| uncoveredIntervals.add(new Interval(startMillis, endMillis)); | ||
| if (!uncoveredIntervalsOverflowed && startMillis < endMillis) { | ||
| if (uncoveredIntervalsLimit > uncoveredIntervals.size()) { | ||
| uncoveredIntervals.add(new Interval(startMillis, endMillis)); | ||
| } else { | ||
| uncoveredIntervalsOverflowed = true; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (!uncoveredIntervals.isEmpty()) { | ||
| // This returns intervals for which NO segment is present. | ||
| // Which is not necessarily an indication that the data doesn't exist or is | ||
| // incomplete. The data could exist and just not be loaded yet. In either | ||
| // case, though, this query will not include any data from the identified intervals. | ||
| responseContext.put("uncoveredIntervals", uncoveredIntervals); | ||
| if (!uncoveredIntervals.isEmpty()) { | ||
| // This returns intervals for which NO segment is present. | ||
| // Which is not necessarily an indication that the data doesn't exist or is | ||
| // incomplete. The data could exist and just not be loaded yet. In either | ||
| // case, though, this query will not include any data from the identified intervals. | ||
| responseContext.put("uncoveredIntervals", uncoveredIntervals); | ||
| responseContext.put("uncoveredIntervalsOverflowed", uncoveredIntervalsOverflowed); | ||
| } | ||
| } else { | ||
| for (Interval interval : query.getIntervals()) { | ||
| Iterables.addAll(serversLookup, timeline.lookup(interval)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is racy between the other
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there is only one call ... the code flows are different when uncoveredIntervals are to be populated and not populated. its simpler this way bcoz the code for uncoveredIntervals disabled (else on line 213) is simple and better on its own.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. my bad, will look at it closer here.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. timeline.lookup doesn't have a contract about always guaranteeing to return non-null but it does seem to. I'm adding a test for sanity validation of it in another PR. |
||
| } | ||
| } | ||
|
|
||
| // Let tool chest filter out unneeded segments | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do tests hit both branches here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tests in CachingClusteredClientTest and CachingClusteredClientFunctionalityTest together hit both paths.