Improve fetch of pending segments from metadata store#13310
Improve fetch of pending segments from metadata store#13310gianm merged 5 commits intoapache:masterfrom
Conversation
| return new SegmentIdWithShardSpec( | ||
| dataSource, | ||
| overallMaxId.getInterval(), | ||
| interval, |
There was a problem hiding this comment.
Changed to emphasize that the interval used in the SegmentIdWithShardSpec is always the same as the one passed to the method createNewSegment.
abhishekagarwal87
left a comment
There was a problem hiding this comment.
LGTM. are there tests already for this method?
|
Regarding the suggested query improvement, I think |
|
Thanks for the suggestion, @rohangarg ! |
|
With the suggested change to the query, I don't think we even need the other changes. What do you think @abhishekagarwal87 , @AmatyaAvadhanula ? |
|
I feel that there might be some nuances being missed here. The comparison in java code, that @rohangarg is referring to, is done on long |
|
That makes sense, @abhishekagarwal87 . Looking at the other linked PR though, it is possible that even the current query would fail for dates with years that have more or less than 4 digits or even negative years (which would happen with ALL granularity). I will put all of this to the test and fix up the PR accordingly. |
|
It seems like |
| // This query might fail if the year has a different number of digits | ||
| // See https://github.com/apache/druid/pull/11582 for a similar issue | ||
| // Using long for these timestamps instead of varchar would give correct time comparisons | ||
| "SELECT start, %2$send%2$s, payload FROM %1$s " |
There was a problem hiding this comment.
Nit: Do start and end still need to be selected in the query?
There was a problem hiding this comment.
Thanks for catching it, yeah, we can remove this now.
|
It looks like this PR has changed a bunch since the original description; it doesn't accurately describe the change anymore. @kfaraz could you please update it? |
| // This query might fail if the year has a different number of digits | ||
| // See https://github.com/apache/druid/pull/11582 for a similar issue | ||
| // Using long for these timestamps instead of varchar would give correct time comparisons | ||
| "SELECT payload FROM %1$s WHERE dataSource = :dataSource AND start < :end and %2$send%2$s > :start", |
There was a problem hiding this comment.
This looks like the only material change in the patch: what's the idea behind changing <= to < and what's the expected benefit?
There was a problem hiding this comment.
We are trying to avoid selecting segments with intervals that only abut the search interval and don't have an actual overlap. Such intervals eventually get filtered out via the check on interval.overlaps(identifier.getInterval()) but only after the costly deserialization.
I have updated the description, which gives an example of such an interval.
This is still not a complete fix as the query can return incorrect results in cases where a string comparison of the two intervals is not feasible.
The fetch of pending segments happens behind a lock and can cause others threads to remain stuck while deserializing the payload fetched from the metadata store.
The query to fetch the payload uses a
<=and>=on the start and end intervals.This might often end up fetching more segments than would actually have an overlap.
For example, when searching for the interval
10am to 11am, a segment with interval9am to 10amwould also satisfy this query.But in reality, the interval
9am to 10amdoesn't have any overlap with our search interval10am to 11am.This is because the end time of a segment interval is always exclusive.
Such results eventually get filtered out by the check on interval
interval.overlaps(identifier.getInterval())but only after the costly deserialization.
Changes:
Use the same condition as present in Interval.overlaps
Notes:
This query (and also the original query) can give incorrect results in cases where a string comparison
of the two intervals is not feasible, typically if the search year and interval year are far apart.
See #11582 for a related fix.
A long-term fix for this could be to migrate these timestamps to use longs rather than varchars.
This PR has: