jihoonson commented on a change in pull request #11398:
URL: https://github.com/apache/druid/pull/11398#discussion_r674516217
##########
File path:
server/src/main/java/org/apache/druid/segment/loading/SegmentLocalCacheManager.java
##########
@@ -198,44 +216,83 @@ public File getSegmentFiles(DataSegment segment) throws
SegmentLoadingException
}
/**
- * location may fail because of IO failure, most likely in two cases:<p>
+ * If we have already reserved a location before, probably via {@link
#reserve(DataSegment)}, then only that location
+ * should be tried. Otherwise, we would fetch locations using {@link
StorageLocationSelectorStrategy} and try all
+ * of them one by one till there is success.
+ * Location may fail because of IO failure, most likely in two cases:<p>
* 1. druid don't have the write access to this location, most likely the
administrator doesn't config it correctly<p>
* 2. disk failure, druid can't read/write to this disk anymore
- *
+ * <p>
* Locations are fetched using {@link StorageLocationSelectorStrategy}.
*/
- private StorageLocation loadSegmentWithRetry(DataSegment segment, String
storageDirStr) throws SegmentLoadingException
+ private File loadSegmentWithRetry(DataSegment segment) throws
SegmentLoadingException
{
- Iterator<StorageLocation> locationsIterator = strategy.getLocations();
+ String segmentDir = getSegmentDir(segment);
+
+ // Try the already reserved location. If location has been reserved
outside, then we do not release the location
+ // here and simply delete any downloaded files. That is, we revert
anything we do in this function and nothing else.
+ for (StorageLocation loc : locations) {
+ if (loc.isReserved(segmentDir)) {
+ File storageDir = loc.segmentDirectoryAsFile(segmentDir);
+ boolean success = loadInLocationWithStartMarkerQuietly(loc, segment,
storageDir, false);
+ if (!success) {
+ throw new SegmentLoadingException("Failed to load segment %s in
reserved location [%s]", segment.getId(), loc.getPath().getAbsolutePath());
+ }
+ return storageDir;
+ }
+ }
+ // No location was reserved so we try all the locations
+ Iterator<StorageLocation> locationsIterator = strategy.getLocations();
while (locationsIterator.hasNext()) {
StorageLocation loc = locationsIterator.next();
- File storageDir = loc.reserve(storageDirStr, segment);
+ // storageDir is the file path corresponding to segment dir
+ File storageDir = loc.reserve(segmentDir, segment);
if (storageDir != null) {
- try {
- loadInLocationWithStartMarker(segment, storageDir);
- return loc;
- }
- catch (SegmentLoadingException e) {
- try {
- log.makeAlert(
- e,
- "Failed to load segment in current location [%s], try next
location if any",
- loc.getPath().getAbsolutePath()
- ).addData("location", loc.getPath().getAbsolutePath()).emit();
- }
- finally {
- loc.removeSegmentDir(storageDir, segment);
- cleanupCacheFiles(loc.getPath(), storageDir);
- }
+ boolean success = loadInLocationWithStartMarkerQuietly(loc, segment,
storageDir, true);
+ if (success) {
Review comment:
Ah got it. Thanks.
--
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]