xiangfu0 commented on code in PR #20367:
URL: https://github.com/apache/pinot/pull/20367#discussion_r4685541069
##########
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:
**P2. Fall back to the healthy source if the candidate fails to load.** A
peer copy can pass `needPreprocess` and still have an unreadable index. The
catch below restores the local directory through the caller, but the reload
fails. Retrying can pick the same peer copy indefinitely. Please keep the
current directory available until the candidate loads, then use the ordinary
copy/rebuild path on a recoverable failure before registration.
`testReloadSegmentRestoresLocalCopyWhenReusableDirectoryFailsToLoad` could
check that the migration succeeds from the local copy. Interrupts should still
propagate.
##########
pinot-core/src/main/java/org/apache/pinot/core/data/manager/BaseTableDataManager.java:
##########
@@ -1359,14 +1359,34 @@ public void reloadSegment(String segmentName,
IndexLoadingConfig indexLoadingCon
SegmentDirectory segmentDirectory =
initSegmentDirectory(segmentName, zkMetadata.getCrc(),
indexLoadingConfig, zkMetadata);
// We should first try to reuse existing segment directory
- if (canReuseExistingDirectoryForReload(zkMetadata, segmentTier,
segmentDirectory, indexLoadingConfig)) {
+ SegmentDirectory reusableDirectory;
+ try {
+ reusableDirectory =
+ getReusableDirectoryForReload(zkMetadata, segmentTier,
segmentDirectory, indexLoadingConfig);
+ } catch (Exception e) {
+ closeSegmentDirectoryQuietly(segmentDirectory);
+ throw e;
+ }
+ if (reusableDirectory == segmentDirectory) {
_logger.info("Reloading segment: {} using existing segment
directory as no reprocessing needed",
segmentName);
// No reprocessing needed, reuse the same segment
ImmutableSegment segment =
ImmutableSegmentLoader.load(segmentDirectory, indexLoadingConfig);
addSegment(segment, zkMetadata);
return;
}
+ if (reusableDirectory != null) {
Review Comment:
**P1. Preserve the local segment when CRC checking is disabled.** Suppose
this replica serves CRC A, ZooKeeper has CRC B, and
`instance.check.crc.on.segment.load=false`. The reload above deliberately keeps
A. An extension can now return a prepared B from the target tier, and this
branch installs B and deletes the local A. Previously migration copied A and
the file loader used A’s CRC. Please gate alternate-directory reuse on
`crcMatch` and keep the ordinary copy path on a mismatch. A regression test
with different contents for A and B would catch the switch.
##########
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,
Review Comment:
**P2. Preserve the existing reload override for custom table managers.** A
subclass compiled against `canReuseExistingDirectoryForReload` can still load,
but its override stops participating in reloads. An existing call to
`super.canReuseExistingDirectoryForReload(...)` can also throw
`NoSuchMethodError`. Please retain the protected boolean method as deprecated
and have the default implementation here delegate to it. That preserves the old
override and lets new extensions return an alternate directory.
--
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]