Hi everyone Question about offline upsert (1.5.x)...
# troubleshooting
h
Hi everyone Question about offline upsert (1.5.x) and primary key cleanup. We’re evaluating an OFFLINE Upsert table for a batch pipeline that pushes daily deltas. The full history has over 1B primary keys (~145 B/PK with MURMUR3), but updates only hit recent dates, so we need the upsert metadata to stay bounded on the heap. It looks like
metadataTTL
never expires primary keys on OFFLINE tables: •
removeExpiredPrimaryKeys()
/
takeSnapshot()
are only triggered when a REALTIME consuming segment commits • deleting a segment that’s out of TTL logs “Skip removing segment ... out of TTL” and its PKs stay in the map • on 1.5.1 the TTL only trims at server restart; on master, not even then, since OFFLINE never persists the watermark Details and code pointers: https://github.com/apache/pinot/issues/20196 Questions: 1. Is there a supported way today to clean up PKs on an OFFLINE upsert table, other than deleting segments (which, without
metadataTTL
, frees their PKs right away) ? 2. Is anyone already working on TTL / snapshots for OFFLINE upsert, or is it planned ? 3. If not, would a PR be welcome that triggers snapshot + TTL sweep for OFFLINE tables (after segment add/replace or from a periodic task) and persists the watermark? Any preference on the approach ? Thanks !
@Mayank Anyone who can help on this ?
m
@Kartik Khare @Chaitanya Deepthi Chadalavada ^^
c
Yeah metadataTTL is not supported for OFFLINE Upserts yet. Today valid doc snapshots and cleanup happens only taken after consuming segment commit and for offline upserts, we don’t have such concept. We could do the cleanup after segment replacement happens but since lot of segments get replaced, we need to list out all the cases clearly on what happens during restart, segment deletions and in future when we support minion tasks, and see if we break any assumption or cause duplicates. When you say 1 B keys, are you saying updates will no longer hit most of your pks and they keep growing correct?
h
Yes, exactly. Most of the older PKs are unlikely to receive updates over time, while the number of new PKs keeps growing. Our goal is not to retain all PKs indefinitely in the upsert metadata, but rather to keep resource consumption and infrastructure costs under control. We want to ensure that the memory footprint remains bounded as the data volume grows, without having to continuously scale resources just to maintain historical PKs that are no longer relevant for upserts. That’s why having metadataTTL support for OFFLINE Upserts would be particularly valuable for our use case.
We are currently exploring a workaround using custom Minion task plugins. The idea is to merge segments together to force the removal of older PKs from the upsert metadata. However, we are still investigating whether this approach would actually work.
@Xiang Fu Any idea ? 😁
c
Having doing the minion task to work for removal of older pks and also merge the segments could be two diffferent implementations in one. For this, how would you ensure the valid docs are consistent?
h
We keep them as two separate things: our task only merges. The merged segment holds exactly the valid row of each key of its sources, so the number of keys does not change. Removing keys stays outside the task: • on the server, that would be metadataTTL eviction for OFFLINE (apache/pinot#20196); • on our side, by deleting whole (date, partition) groups. Deleting every segment that holds a key frees it exactly. Deleting only the segment with its latest version hides the key until a restart (measured on 1.5.1). The task refuses tables with metadataTTL or deletedKeysTTL. On OFFLINE, a replaced segment that is out of TTL is not removed from the metadata (“Skip removing segment ... out of TTL”), so its keys stay in heap. Today the two features conflict. For the valid docs, we reuse the UpsertCompactMergeTask checks and add a few: 1. One task = one (date, partition) group. The table is partitioned on a primary key column with strict replica groups, and the date is part of the primary key. So every version of a key is in the group and on the same servers. 2. Generator: it only takes routed segments (lineage filtered) pushed before bufferTimePeriod. They must be ONLINE on every replica, with the ZK CRC and a GOOD status on every server, and the same valid doc count on every replica. The table is skipped while a task runs or a lineage entry is IN_PROGRESS. 3. Executor: the downloaded CRCs must equal the ones the generator saw. validDocIds are read IN_MEMORY (OFFLINE has no snapshot) with the EQUAL consensus. 4. Self-check before building: a key has at most one valid row, and it is the row with the greatest comparison value among the inputs. When the task covers the whole group, every key must have a valid row; otherwise a key was lost and merging would make it final. If a check fails, the task fails without uploading and is not retried. The next run starts from the current state. A delta pushed during the task is not an input: the comparison column decides between it and the merged segment, whatever the load order. 5. Swap: startReplaceSegments with forceCleanup=false. The base executor passes true, which reverts an overlapping IN_PROGRESS entry and deletes its merged segment, keys included. Source CRCs are checked again before the start and before the end. The merged segment owns the keys as soon as it loads, while brokers still route the sources, so newSegmentTrackingTimeMs is set above the task timeout. 6. Dead task: after a grace period, the generator ends the entry if the merged segment records the current CRC of every source. Otherwise it reverts the entry, waits until the merged segment leaves the external view, then reloads the sources with forceDownload. Reloading them before that lost keys in our tests. Not covered: a source refreshed in the few ms between the last CRC check and endReplaceSegments. We have only validated this on a local 1.5.1 cluster with one controller, not at production volume.
c
Yup! First we can add the checkpoint after each upload to take the snapshots and enable TTL. Next we can focus on the minion tasks.
x
I think in this case if your PK cannot be recycled by the segment retention then the only way is the segment compaction task ?
oh, the compaction alone won’t work here, unless we proactively detect and delete PKs, otherwise, they will be there.
h
Thanks both ! @Chaitanya Deepthi Chadalavada, sounds good. When the checkpoint lands, here is what we’ll test on our bench (1.5.1, ~1M keys, 2 replica groups, concurrent pushes and restarts): • Restart: out-of-TTL segments load from their snapshot, and the persisted watermark gives the #19832 load-time skip something to compare against. Today, with metadataTTL set, a restart serves duplicates for any out-of-TTL date that has more than one segment. • Delete/replace: removeSegment skips out-of-TTL segments (“Skip removing segment ... out of TTL”), which is only safe once their keys were evicted. Today those keys stay in heap until a restart. • Question: will the checkpoint also run on refreshes and lineage replacements, or only on new segments ? @Xiang Fu, agreed: compaction keeps every key. In our case time retention can’t recycle them, because old dates must stay queryable. So today we delete keys by whole (date, partition) group: we copy the group to a non-upsert table, then delete all its upsert segments, which frees exactly their keys. Deleting only the segment that holds a key’s latest version hides the key until a restart instead. TTL would bound the heap for dates that no longer change, but as on REALTIME, a late update to an evicted key would still be a duplicate. For the minion tasks, happy to share what we hit while porting the UpsertCompactMergeTask safeguards to OFFLINE: forceCleanup on startReplaceSegments, reload order after a revert, newSegmentTrackingTimeMs during the swap, and re-pushes of a replaced segment name.
@Chaitanya Deepthi Chadalavada A question on timing, since we’re planning our Pinot upgrade around this fix: 1. Could it be backported to a patch release, 1.5.x or 1.6.x ? We noticed 1.5.1 only carried CVE fixes, so we’d like to know whether that’s an option at all. 2. If not, what’s a rough timeline: when do you expect it on apache/pinot master, and would 1.7.0 be the first release to ship it ? Roughly when is 1.7.0 expected ?
c
Let me check with Xiang if we can do the back port for this fix or need a new release. Relatively this PR should be simple, I will have one for valid docId snapshots and TTL support complete by end of this month is what I am planning to do with some good amount of testing. Keep a buffer of extra 1-2 weeks.
x
I would go with 1.7.0 release. But if you are on 1.6.0, we could create a custom image for that always
h
We are on 1.4.0 and we plan to go to 1.5.x
x
ok, then it’s a long way to go 🙂
h
1.6.0 is a possibility we will discuss tomorrow with our Ops team
👍 1
x
Cool. Usually from the community side, we always fix forward and won’t back port unless it’s critical CVEs or severe bugs impact core engine.
➕ 2
h
Seems legit
We start evaluating the impact to go from pinot 1.4. to 1.6. A custom 1.6 image would be great !
Thanks @Xiang Fu