J-HowHuang commented on code in PR #20367:
URL: https://github.com/apache/pinot/pull/20367#discussion_r4706219906


##########
pinot-core/src/main/java/org/apache/pinot/core/data/manager/BaseTableDataManager.java:
##########
@@ -1415,13 +1435,48 @@ protected boolean 
isSegmentStatusCompleted(SegmentZKMetadata zkMetadata) {
         || zkMetadata.getStatus() == 
CommonConstants.Segment.Realtime.Status.UPLOADED;
   }
 
-  protected boolean canReuseExistingDirectoryForReload(SegmentZKMetadata 
segmentZKMetadata, String currentSegmentTier,
-      SegmentDirectory segmentDirectory, IndexLoadingConfig indexLoadingConfig)
+  /// Returns a directory that a reload without download can load as is, or 
null when the reload must copy the current
+  /// directory out and reprocess it, e.g. to move the segment to another tier.
+  ///
+  /// `currentDirectory` is the segment's directory on its current tier. The 
default returns it when the segment stays
+  /// on that tier and needs no reprocessing.
+  ///
+  /// Extensions may return another directory, e.g. a copy of the segment that 
another replica already prepared on the
+  /// target tier. Such a directory must hold the segment with the CRC in 
`zkMetadata`, be opened for the target tier
+  /// (`zkMetadata.getTier()`), and need no reprocessing for it. The reload 
then closes `currentDirectory`, loads the
+  /// returned directory, and removes the local copy on the current tier. A 
table that restores the validDocIds bitmap
+  /// on reload never loads another directory, since the bitmap lives only in 
the local copy.
+  ///
+  /// Called under the segment lock.
+  @Nullable
+  protected SegmentDirectory getReusableDirectoryForReload(SegmentZKMetadata 
zkMetadata,
+      @Nullable String currentSegmentTier, SegmentDirectory currentDirectory, 
IndexLoadingConfig indexLoadingConfig)
       throws Exception {
     SegmentDirectoryLoader segmentDirectoryLoader =
         
SegmentDirectoryLoaderRegistry.getSegmentDirectoryLoader(indexLoadingConfig.getSegmentDirectoryLoader());
-    return 
!segmentDirectoryLoader.needsTierMigration(segmentZKMetadata.getTier(), 
currentSegmentTier)
-        && !ImmutableSegmentLoader.needPreprocess(segmentDirectory, 
indexLoadingConfig);
+    boolean canReuse = 
!segmentDirectoryLoader.needsTierMigration(zkMetadata.getTier(), 
currentSegmentTier)
+        && !ImmutableSegmentLoader.needPreprocess(currentDirectory, 
indexLoadingConfig);
+    return canReuse ? currentDirectory : null;
+  }
+
+  /// Loads a directory other than the current one, returned by 
[#getReusableDirectoryForReload], in place of the
+  /// segment. The directory serves the segment on its target tier, so the 
local copy on the current tier is moved to
+  /// the backup directory first. If loading fails, the caller's reload 
failure recovery restores it; once the segment
+  /// is replaced, it is removed, so that no later load of the segment finds 
it.
+  private void loadReusedDirectory(File indexDir, SegmentDirectory 
segmentDirectory,
+      IndexLoadingConfig indexLoadingConfig, SegmentZKMetadata zkMetadata)
+      throws Exception {
+    ImmutableSegment segment;
+    try {
+      createBackup(indexDir);
+      segment = ImmutableSegmentLoader.load(segmentDirectory, 
indexLoadingConfig.copyWithSegmentTier(

Review Comment:
   good point. updated so that it now falls back to use the original local copy 
to reload



-- 
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]

Reply via email to