leaves12138 commented on code in PR #8880: URL: https://github.com/apache/paimon/pull/8880#discussion_r3662428000
########## paimon-core/src/main/java/org/apache/paimon/lookup/local/LocalKvListMergeOperator.java: ########## @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.paimon.lookup.local; + +import org.apache.paimon.lookup.sort.db.LocalKvDb; +import org.apache.paimon.memory.MemorySlice; + +import java.io.IOException; +import java.util.List; + +/** + * Combines ListState fragments with the same logical key when writing SST files. + * + * <p>When TTL is enabled, merging includes expired fragments and re-encodes the result with a new + * expiration time, matching RocksDB's TTL merge behavior. + */ +final class LocalKvListMergeOperator implements LocalKvDb.MergeOperator { + + private final LocalKvValueCodec valueCodec; + private final ThreadLocal<LocalKvListValueCodec> listValueCodec = + ThreadLocal.withInitial(LocalKvListValueCodec::new); + + LocalKvListMergeOperator(LocalKvValueCodec valueCodec) { + this.valueCodec = valueCodec; + } + + @Override + public boolean canMerge(MemorySlice firstKey, MemorySlice nextKey) { Review Comment: `RecordCombiningWriter` flushes the pending merge group whenever it encounters a tombstone, but an earlier list flush creates exactly such tombstones for every consumed sequence key. Those synthetic tombstones can therefore prevent this operator from seeing older and newer fragments of the same logical list together during the next compaction. With TTL this causes data loss. I reproduced this sequence with a 100 ms TTL: add `10, 20`; flush (leaving the merged value at seq 0 and a tombstone at seq 1); advance 50 ms; add `30`; flush; advance another 50 ms; compact. The seq-1 tombstone splits seq 0 from seq 2, so the expired `[10, 20]` fragment is filtered before it can be merged/refreshed with `[30]`, and `get(1)` returns only `[30]`. This also conflicts with the intended "merge expired fragments and refresh TTL" behavior tested below. Please make list compaction absorb/ignore these synthetic tombstones while grouping all fragments for the logical key (or use a layout that does not create sequence gaps), and add a repeated-flush TTL regression test. -- 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]
