Jackie-Jiang opened a new pull request, #20321:
URL: https://github.com/apache/pinot/pull/20321
`BaseTableDataManager.replaceUpsertSegment` runs on every upsert replace:
reload, refresh with a new CRC, CONSUMING to ONLINE commit, and the
ONLINE-retry rebuild in #20320. When
`PartitionUpsertMetadataManager.replaceSegment` throws partway, the keys it
already moved point at the new segment. What happens next depends on the
consistency mode:
- NONE: the new segment is never registered or destroyed, so each failure
leaks a loaded copy, and the `DOCUMENT_COUNT` / `SEGMENT_COUNT` gauges added
for it are never taken back.
- SYNC and SNAPSHOT: the `DuoSegmentDataManager` stays registered. Every
later OFFLINE to ONLINE or CONSUMING to ONLINE fails with `Cannot replace
CONSUMING segment`, and after a failed commit the consuming segment keeps the
partition's consumer permit until the segment is dropped or the server restarts.
Destroying the new segment alone would leave keys pointing at a destroyed
segment, so the metadata has to be rolled back first.
## Change
A failed replace now rolls back, leaving the old segment serving as if the
replace had not started.
- `BasePartitionUpsertMetadataManager.replaceSegment` reverts before
rethrowing:
- It finds the docs the replace moved off the old segment. Under NONE they
are the docs missing from the copy it already keeps. Under SYNC and SNAPSHOT,
which update the old bitmap in place, it now keeps a copy of the old bitmap
taken before the replace.
- A key that still points at the new segment points back at the old one,
and its valid and queryable bits move back through `replaceDocId`, so the
upsert view sees one row per key.
- Under NONE the old bitmap was never cleared, so if a key moved on since
(e.g. to a consuming segment), its old doc is invalidated.
- The keys left on the new segment are removed. These are keys it added,
or took from other segments.
- A failure of the revert is logged as `UPSERT_METADATA_REVERT_FAILED`,
counted in `UPSERT_METADATA_REVERT_FAILURES` and attached to the replace
failure.
- The per-key step is the new hook `revertReplacedKeys`.
`ConcurrentMapPartitionUpsertMetadataManager` and
`ConcurrentMapPartitionUpsertMetadataManagerForConsistentDeletes` implement it.
The consistent-deletes manager keeps the distinct segment count, which can only
be too high afterwards and so only keeps a tombstone longer than needed. The
default leaves the keys to the removal step.
- `BaseTableDataManager.replaceUpsertSegment`:
- It puts the old segment manager back in place of the
`DuoSegmentDataManager` without firing `onSegmentAdded` again.
- It untracks the new segment from the upsert view and releases it. The
new segment is destroyed, and its gauges decremented, once no query holds it.
A later reload, refresh or ONLINE transition replaces the old segment as
usual. A failed commit leaves the `RealtimeSegmentDataManager` registered, so
CONSUMING to ONLINE downloads and replaces again. The permit is released when
that succeeds or the segment is dropped.
Not covered:
- Keys the new segment took from other segments stay removed until the
replace is retried. Their rows in those segments were already invalidated, and
nothing records where they were.
- For tables with inconsistent state, previous record locations the failed
replace dropped for moved keys are not restored.
- If removing the old segment's leftover keys fails partway, the keys
already removed stay removed.
Under SYNC and SNAPSHOT every replace now copies the old segment's valid doc
ids once, as NONE already did.
## Validation
-
`ConcurrentMapPartitionUpsertMetadataManagerTest.testFailedReplaceSegmentPointsKeysBackAtOldSegment`
(NONE and SYNC) fails a replace partway. It checks that a moved key points
back at the old segment, that a key a consuming segment took meanwhile keeps
its new location with the old doc invalidated, and that a key taken from
another segment and a new key are removed.
-
`BaseTableDataManagerPartitionMetadataTest.testUpsertReplacementReadyBeforeOldSegmentOffload`
now also checks after a failure that the old manager is registered again and
the new segment is destroyed.
-
`BaseTableDataManagerPartitionMetadataTest.testFailedUpsertReplacementDestroyedAfterQueryReleasesIt`
(SYNC and SNAPSHOT) checks that the new segment is destroyed only after a
query holding the `DuoSegmentDataManager` releases it.
The consistent-deletes hook has no dedicated test. No tests or formatting,
checkstyle, or license checks were run locally.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
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]