-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Improve fetch of pending segments from metadata store #13310
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
247c4eb
Deserialize only when needed
kfaraz 7356862
Merge branch 'master' of github.com:apache/druid into get_pending_seg…
kfaraz 3713725
Update query to fetch pending segments
kfaraz e7edd5c
Revert unneeded changes
kfaraz ac9f11d
Fix query
kfaraz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -232,7 +232,10 @@ private Set<SegmentIdWithShardSpec> getPendingSegmentsForIntervalWithHandle( | |
| final ResultIterator<byte[]> dbSegments = | ||
| handle.createQuery( | ||
| StringUtils.format( | ||
| "SELECT payload FROM %1$s WHERE dataSource = :dataSource AND start <= :end and %2$send%2$s >= :start", | ||
| // 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", | ||
| dbTables.getPendingSegmentsTable(), connector.getQuoteString() | ||
| ) | ||
| ) | ||
|
|
@@ -584,7 +587,7 @@ private SegmentIdWithShardSpec allocatePendingSegmentWithSegmentLineageCheck( | |
| .asBytes() | ||
| ); | ||
|
|
||
| insertToMetastore( | ||
| insertPendingSegmentIntoMetastore( | ||
| handle, | ||
| newIdentifier, | ||
| dataSource, | ||
|
|
@@ -662,7 +665,7 @@ private SegmentIdWithShardSpec allocatePendingSegment( | |
| ); | ||
|
|
||
| // always insert empty previous sequence id | ||
| insertToMetastore(handle, newIdentifier, dataSource, interval, "", sequenceName, sequenceNamePrevIdSha1); | ||
| insertPendingSegmentIntoMetastore(handle, newIdentifier, dataSource, interval, "", sequenceName, sequenceNamePrevIdSha1); | ||
|
|
||
| log.info("Allocated pending segment [%s] for sequence[%s] in DB", newIdentifier, sequenceName); | ||
|
|
||
|
|
@@ -742,7 +745,7 @@ private static class CheckExistingSegmentIdResult | |
| } | ||
| } | ||
|
|
||
| private void insertToMetastore( | ||
| private void insertPendingSegmentIntoMetastore( | ||
| Handle handle, | ||
| SegmentIdWithShardSpec newIdentifier, | ||
| String dataSource, | ||
|
|
@@ -943,7 +946,7 @@ private SegmentIdWithShardSpec createNewSegment( | |
|
|
||
| return new SegmentIdWithShardSpec( | ||
| dataSource, | ||
| overallMaxId.getInterval(), | ||
| interval, | ||
|
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. Changed to emphasize that the |
||
| Preconditions.checkNotNull(newSegmentVersion, "newSegmentVersion"), | ||
| partialShardSpec.complete( | ||
| jsonMapper, | ||
|
|
@@ -1468,4 +1471,5 @@ public int removeDataSourceMetadataOlderThan(long timestamp, @NotNull Set<String | |
| } | ||
| ); | ||
| } | ||
|
|
||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This looks like the only material change in the patch: what's the idea behind changing
<=to<and what's the expected benefit?Uh oh!
There was an error while loading. Please reload this page.
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.
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.