-
Notifications
You must be signed in to change notification settings - Fork 3.8k
perf: Skip download of upgraded segments on historicals #19676
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
Draft
kfaraz
wants to merge
1
commit into
apache:master
Choose a base branch
from
kfaraz:skip_download_upgraded_segments
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
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
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 |
|---|---|---|
|
|
@@ -1387,6 +1387,8 @@ private final class CompleteSegmentCacheEntry implements SegmentCacheEntry | |
| private final SegmentCacheEntryIdentifier id; | ||
| private final DataSegment dataSegment; | ||
| private final String relativePathString; | ||
| @Nullable | ||
| private final SegmentId upgradedFromSegmentId; | ||
| private SegmentLazyLoadFailCallback lazyLoadCallback = SegmentLazyLoadFailCallback.NOOP; | ||
| private StorageLocation location; | ||
| private File storageDir; | ||
|
|
@@ -1401,6 +1403,7 @@ private CompleteSegmentCacheEntry(final DataSegment dataSegment) | |
| this.dataSegment = dataSegment; | ||
| this.id = new SegmentCacheEntryIdentifier(dataSegment.getId()); | ||
| this.relativePathString = dataSegment.getId().toString(); | ||
| this.upgradedFromSegmentId = dataSegment.getUpgradedFromSegmentId(); | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -1479,7 +1482,12 @@ public void mount(StorageLocation mountLocation) throws SegmentLoadingException | |
| } | ||
| } | ||
| if (needsLoad) { | ||
| loadInLocationWithStartMarker(dataSegment, storageDir); | ||
| final File baseDir = findCachedBaseSegmentDir(mountLocation); | ||
| if (baseDir != null) { | ||
| copyFromBaseSegmentDir(baseDir, storageDir); | ||
| } else { | ||
| loadInLocationWithStartMarker(dataSegment, storageDir); | ||
| } | ||
| } | ||
| final SegmentizerFactory factory = getSegmentFactory(storageDir); | ||
|
|
||
|
|
@@ -1663,6 +1671,71 @@ public File toPotentialLocation(final File location) | |
| return new File(location, relativePathString); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the cache directory of the base segment (the segment this one was upgraded from) on the given storage | ||
| * location if it is present and not corrupted, or null otherwise. | ||
| */ | ||
| @GuardedBy("entryLock") | ||
| @Nullable | ||
| private File findCachedBaseSegmentDir(final StorageLocation mountLocation) | ||
| { | ||
| if (upgradedFromSegmentId == null) { | ||
| return null; | ||
| } | ||
| final File baseDir = new File(mountLocation.getPath(), upgradedFromSegmentId.toString()); | ||
| if (baseDir.exists() && !isPossiblyCorrupted(baseDir)) { | ||
| return baseDir; | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| /** | ||
| * Copies files from the base segment's cache directory into the upgraded segment's cache directory, | ||
| * avoiding a deep-storage download. Uses a start-marker for crash safety, consistent with | ||
| * {@link #loadInLocationWithStartMarker}. | ||
| */ | ||
| @GuardedBy("entryLock") | ||
| private void copyFromBaseSegmentDir(final File baseDir, final File destDir) | ||
|
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. This method needs to hold the |
||
| throws SegmentLoadingException | ||
| { | ||
| final File downloadStartMarker = new File(destDir, DOWNLOAD_START_MARKER_FILE_NAME); | ||
| try { | ||
| FileUtils.mkdirp(destDir); | ||
| if (!downloadStartMarker.createNewFile()) { | ||
| throw new SegmentLoadingException( | ||
| "Was not able to create new download marker for [%s]", destDir | ||
| ); | ||
| } | ||
| log.info( | ||
| "Segment[%s] was upgraded from segment[%s] which is already cached; " | ||
| + "copying files from [%s] instead of downloading from deep storage.", | ||
| dataSegment.getId(), | ||
| upgradedFromSegmentId, | ||
| baseDir | ||
| ); | ||
| final File[] files = baseDir.listFiles(); | ||
| if (files != null) { | ||
| for (File file : files) { | ||
| if (!file.getName().equals(DOWNLOAD_START_MARKER_FILE_NAME)) { | ||
| Files.copy(file.toPath(), new File(destDir, file.getName()).toPath()); | ||
| } | ||
| } | ||
| } | ||
| if (!downloadStartMarker.delete()) { | ||
| throw new SegmentLoadingException("Unable to remove marker file for [%s]", destDir); | ||
| } | ||
| } | ||
| catch (IOException e) { | ||
| throw new SegmentLoadingException( | ||
| e, | ||
| "Failed to copy base segment[%s] files from [%s] to [%s]", | ||
| upgradedFromSegmentId, | ||
| baseDir, | ||
| destDir | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| @GuardedBy("entryLock") | ||
| private void loadInLocationWithStartMarker(final DataSegment segment, final File storageDir) | ||
| throws SegmentLoadingException | ||
|
|
||
Oops, something went wrong.
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 doesn't seem correct, the base segment could be in some other location too.