xiangfu0 commented on code in PR #20320:
URL: https://github.com/apache/pinot/pull/20320#discussion_r4636882767
##########
pinot-core/src/main/java/org/apache/pinot/core/data/manager/BaseTableDataManager.java:
##########
@@ -540,6 +540,26 @@ protected void
replaceSegmentIfCrcMismatch(SegmentDataManager segmentDataManager
_logger.info("Replaced segment: {} with new CRC: {}", segmentName,
zkMetadata.getCrc());
}
+ /// Returns whether the registered segment is an upsert segment whose upsert
metadata is not initialized. A new upsert
+ /// segment is registered before its metadata is initialized, so a failed
add leaves it registered with partial valid
+ /// docs while its CRC still matches ZK.
+ protected boolean hasUninitializedUpsertMetadata(SegmentDataManager
segmentDataManager) {
+ return isUpsertEnabled()
+ && segmentDataManager instanceof ImmutableSegmentDataManager
immutableSegmentDataManager
+ && !immutableSegmentDataManager.isPartitionMetadataInitialized();
+ }
+
+ /// Rebuilds the upsert metadata of a registered segment by reloading the
segment, from the local index directory when
+ /// its CRC matches ZK. The reloaded segment replaces the registered one
with its upsert metadata initialized.
+ protected void reloadUninitializedUpsertSegment(SegmentDataManager
segmentDataManager, SegmentZKMetadata zkMetadata,
+ IndexLoadingConfig indexLoadingConfig)
+ throws Exception {
+ String segmentName = segmentDataManager.getSegmentName();
+ _logger.info("Reloading segment: {} because its upsert metadata is not
initialized", segmentName);
+ SegmentMetadata localMetadata =
segmentDataManager.getSegment().getSegmentMetadata();
+ reloadSegment(segmentName, indexLoadingConfig, zkMetadata, localMetadata,
false);
Review Comment:
**[P1] Preserve tombstone counts when retrying a partial add**
With `enableDeletedKeysCompactionConsistency`, suppose an older segment
contains a live row for K and the first add of this segment fails before it
counts K's newer tombstone. The retry adds the tombstone and increments the
count from 1 to 2. Replacement then scans every key in the failed copy and
decrements K back to 1, even though that copy never contributed to the count.
Once the tombstone ages out, TTL cleanup can remove it while the older row
still exists, so compaction and restart can bring K back.
Can the recovery path undo only the contributions the failed add actually
made? A regression test should check that the tombstone survives a TTL sweep
while the older copy remains. [Replacement
accounting](https://github.com/apache/pinot/blob/1d6b9a9dbde0ef97ea87849319e91ed32b67f0b2/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/upsert/ConcurrentMapPartitionUpsertMetadataManagerForConsistentDeletes.java#L301-L343)
· [TTL
cleanup](https://github.com/apache/pinot/blob/1d6b9a9dbde0ef97ea87849319e91ed32b67f0b2/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/upsert/ConcurrentMapPartitionUpsertMetadataManagerForConsistentDeletes.java#L435-L459)
##########
pinot-core/src/main/java/org/apache/pinot/core/data/manager/BaseTableDataManager.java:
##########
@@ -540,6 +540,26 @@ protected void
replaceSegmentIfCrcMismatch(SegmentDataManager segmentDataManager
_logger.info("Replaced segment: {} with new CRC: {}", segmentName,
zkMetadata.getCrc());
}
+ /// Returns whether the registered segment is an upsert segment whose upsert
metadata is not initialized. A new upsert
+ /// segment is registered before its metadata is initialized, so a failed
add leaves it registered with partial valid
+ /// docs while its CRC still matches ZK.
+ protected boolean hasUninitializedUpsertMetadata(SegmentDataManager
segmentDataManager) {
+ return isUpsertEnabled()
+ && segmentDataManager instanceof ImmutableSegmentDataManager
immutableSegmentDataManager
+ && !immutableSegmentDataManager.isPartitionMetadataInitialized();
+ }
+
+ /// Rebuilds the upsert metadata of a registered segment by reloading the
segment, from the local index directory when
+ /// its CRC matches ZK. The reloaded segment replaces the registered one
with its upsert metadata initialized.
+ protected void reloadUninitializedUpsertSegment(SegmentDataManager
segmentDataManager, SegmentZKMetadata zkMetadata,
Review Comment:
**[P2] Keep the committed-copy download path available when the CRC changes**
If an initial add fails on a pauseless local copy and ZK reaches `DONE` with
a different CRC before the reset, this helper takes the manual reload path. On
a TTL table with snapshots enabled, that path rejects the CRC mismatch before
checking whether a snapshot file exists. Every reset then fails on the same
guard. The existing ONLINE path can download the authoritative copy in this
case.
Can the retry preserve the completed CRC-mismatch download path and avoid
carrying a bitmap across different segment contents? [Reload
guard](https://github.com/apache/pinot/blob/1d6b9a9dbde0ef97ea87849319e91ed32b67f0b2/pinot-core/src/main/java/org/apache/pinot/core/data/manager/BaseTableDataManager.java#L1333-L1353)
##########
pinot-core/src/main/java/org/apache/pinot/core/data/manager/BaseTableDataManager.java:
##########
@@ -540,6 +540,26 @@ protected void
replaceSegmentIfCrcMismatch(SegmentDataManager segmentDataManager
_logger.info("Replaced segment: {} with new CRC: {}", segmentName,
zkMetadata.getCrc());
}
+ /// Returns whether the registered segment is an upsert segment whose upsert
metadata is not initialized. A new upsert
+ /// segment is registered before its metadata is initialized, so a failed
add leaves it registered with partial valid
+ /// docs while its CRC still matches ZK.
+ protected boolean hasUninitializedUpsertMetadata(SegmentDataManager
segmentDataManager) {
+ return isUpsertEnabled()
+ && segmentDataManager instanceof ImmutableSegmentDataManager
immutableSegmentDataManager
+ && !immutableSegmentDataManager.isPartitionMetadataInitialized();
+ }
+
+ /// Rebuilds the upsert metadata of a registered segment by reloading the
segment, from the local index directory when
+ /// its CRC matches ZK. The reloaded segment replaces the registered one
with its upsert metadata initialized.
+ protected void reloadUninitializedUpsertSegment(SegmentDataManager
segmentDataManager, SegmentZKMetadata zkMetadata,
+ IndexLoadingConfig indexLoadingConfig)
+ throws Exception {
+ String segmentName = segmentDataManager.getSegmentName();
+ _logger.info("Reloading segment: {} because its upsert metadata is not
initialized", segmentName);
+ SegmentMetadata localMetadata =
segmentDataManager.getSegment().getSegmentMetadata();
Review Comment:
**[P1] Rebuild from the first-add scan policy on TTL tables**
On a TTL table, a matching-CRC reload can reuse the on-disk `validDocIds`
snapshot. That bitmap can predate the first ONLINE attempt. For example, a
snapshot excludes K because a newer segment owned it. If that newer segment is
gone before the server loads this copy again, the first add can install K in
memory and then fail on a later row. The retry scans only the old snapshot,
removes K as an unreplaced key, and marks the segment initialized.
Can the repair use the same scan eligibility as the initial add? Please
cover a stale snapshot with the real metadata manager. [Initial
add](https://github.com/apache/pinot/blob/1d6b9a9dbde0ef97ea87849319e91ed32b67f0b2/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/upsert/BasePartitionUpsertMetadataManager.java#L419-L432)
· [Snapshot scan and
cleanup](https://github.com/apache/pinot/blob/1d6b9a9dbde0ef97ea87849319e91ed32b67f0b2/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/upsert/BasePartitionUpsertMetadataManager.java#L669-L760)
##########
pinot-core/src/main/java/org/apache/pinot/core/data/manager/realtime/RealtimeTableDataManager.java:
##########
@@ -539,6 +539,9 @@ protected void doAddOnlineSegment(String segmentName)
} finally {
releaseSegment(segmentDataManager);
}
+ } else if (hasUninitializedUpsertMetadata(segmentDataManager)) {
Review Comment:
**[P1] Keep a failed rebuild from reporting ONLINE**
In `SYNC` or `SNAPSHOT`, the rebuild publishes a `DuoSegmentDataManager`
before replacing the upsert metadata. If replacement throws, ERROR → OFFLINE
leaves that Duo registered. On the next retry, this predicate rejects the Duo
and the completed-status branch is skipped while ZK is still `COMMITTING`. The
transition returns successfully with incomplete metadata. Once ZK reaches
`DONE`, the CRC path instead throws on its immutable-manager check.
Can we leave the manager in a retryable state after replacement fails and
cover a second ONLINE retry while the commit is still in progress? [Duo
publication](https://github.com/apache/pinot/blob/1d6b9a9dbde0ef97ea87849319e91ed32b67f0b2/pinot-core/src/main/java/org/apache/pinot/core/data/manager/BaseTableDataManager.java#L1083-L1104)
##########
pinot-core/src/main/java/org/apache/pinot/core/data/manager/BaseTableDataManager.java:
##########
@@ -1048,7 +1068,8 @@ protected void handleUpsert(ImmutableSegment
immutableSegment, @Nullable Segment
// When adding a new segment, register it *before*
partitionUpsertMetadataManager.addSegment() fully initializes
// the validDocIds bitmap. This lets queries access the new segment
immediately while the bitmap is being built.
// Without early registration, docs in existing segments that get
invalidated by this new segment would become
- // invisible to queries until addSegment() completes.
+ // invisible to queries until addSegment() completes. If addSegment()
fails, the segment stays registered with
+ // partial metadata until the retried ONLINE transition rebuilds it (see
hasUninitializedUpsertMetadata()).
Review Comment:
**[P2] Keep the rebuilt rows visible while upsert moves them**
The initial add publishes the segment before invalidating docs in other
segments. With consistency mode `NONE`, the retry can invalidate a previously
untouched key in another segment before publishing the rebuilt copy. The
registered partial copy has never seen that key, so a concurrent query can miss
it until the scan finishes. With `SYNC` or `SNAPSHOT`, the Duo makes the copy
available locally, but the original `trackNewlyAddedSegment` entry can expire
before an operator resets the segment. A broker still routing without the
recovering segment then has the same gap.
Can the repair preserve the initial add's publication order and refresh the
segment's optional routing entry before moving any keys? [Replacement
order](https://github.com/apache/pinot/blob/1d6b9a9dbde0ef97ea87849319e91ed32b67f0b2/pinot-core/src/main/java/org/apache/pinot/core/data/manager/BaseTableDataManager.java#L1083-L1104)
· [Optional segment
routing](https://github.com/apache/pinot/blob/1d6b9a9dbde0ef97ea87849319e91ed32b67f0b2/pinot-core/src/main/java/org/apache/pinot/core/query/executor/SingleTableExecutionInfo.java#L101-L113)
--
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]