You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@fluss.apache.org by "Copilot (via GitHub)" <gi...@apache.org> on 2026/08/11 03:46:31 UTC

Re: [PR] [lake] Support partition mark-done for lakehouse tiering (processing-time) [fluss]

Copilot commented on code in PR #3635:
URL: https://github.com/apache/fluss/pull/3635#discussion_r3755093622


##########
fluss-lake/fluss-lake-paimon/src/main/java/org/apache/fluss/lake/paimon/tiering/PaimonPartitionMarkDone.java:
##########
@@ -0,0 +1,365 @@
+/*
+ * 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.fluss.lake.paimon.tiering;
+
+import org.apache.fluss.config.AutoPartitionTimeUnit;
+import org.apache.fluss.metadata.ResolvedPartitionSpec;
+import org.apache.fluss.metadata.TableInfo;
+import org.apache.fluss.utils.AutoPartitionStrategy;
+import org.apache.fluss.utils.IOUtils;
+import org.apache.fluss.utils.PartitionUtils;
+
+import org.apache.paimon.data.BinaryRow;
+import org.apache.paimon.manifest.PartitionEntry;
+import org.apache.paimon.options.ConfigOption;
+import org.apache.paimon.options.ConfigOptions;
+import org.apache.paimon.options.Options;
+import org.apache.paimon.partition.PartitionTimeExtractor;
+import org.apache.paimon.partition.actions.PartitionMarkDoneAction;
+import org.apache.paimon.table.FileStoreTable;
+import org.apache.paimon.table.sink.CommitMessage;
+import org.apache.paimon.utils.InternalRowPartitionComputer;
+import org.apache.paimon.utils.PartitionPathUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.annotation.Nullable;
+
+import java.time.Duration;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
+import java.time.format.DateTimeFormatterBuilder;
+import java.time.temporal.ChronoField;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import static org.apache.fluss.utils.Preconditions.checkNotNull;
+import static org.apache.fluss.utils.Preconditions.checkState;
+
+/**
+ * Judges and marks idle partitions of a Paimon lake table as done during tiering. The judgment
+ * ({@code done <=> now - max(lastUpdateTime, partitionEndTime) > partition.idle-time-to-done}) is
+ * delegated to {@link PartitionMarkDoneTrigger} copied from Paimon. It reuses Paimon's options
+ * ({@code partition.idle-time-to-done}, {@code partition.time-interval}, {@code
+ * partition.timestamp-pattern/formatter}, {@code partition.mark-done-action}) and executes the
+ * idempotent Paimon mark-done actions. For auto-partitioned tables the partition end time is
+ * derived from the auto-partition time unit instead of {@code partition.time-interval}. See {@link
+ * MarkDoneState} for the state model.
+ */
+public class PaimonPartitionMarkDone implements AutoCloseable {
+
+    private static final Logger LOG = LoggerFactory.getLogger(PaimonPartitionMarkDone.class);
+
+    /** Snapshot property key storing the mark-done state JSON. */
+    public static final String MARK_DONE_STATE_PROPERTY = "fluss.tiering.mark-done-state";
+
+    /** Same option as Paimon's FlinkConnectorOptions#PARTITION_IDLE_TIME_TO_DONE. */
+    private static final ConfigOption<Duration> PARTITION_IDLE_TIME_TO_DONE =
+            ConfigOptions.key("partition.idle-time-to-done").durationType().noDefaultValue();
+
+    /** Same option as Paimon's FlinkConnectorOptions#PARTITION_TIME_INTERVAL. */
+    private static final ConfigOption<Duration> PARTITION_TIME_INTERVAL =
+            ConfigOptions.key("partition.time-interval").durationType().noDefaultValue();
+
+    private final FileStoreTable fileStoreTable;
+    private final TableInfo tableInfo;
+    private final List<String> partitionKeys;
+    private final long idleTimeToDoneMillis;
+    // partition end time interval for non auto-partitioned tables, null means idle judgment
+    // is not possible (same as Paimon which requires partition.time-interval)
+    @Nullable private final Long timeIntervalMillis;
+    private final AutoPartitionStrategy autoPartitionStrategy;
+    private final PartitionTimeExtractor partitionTimeExtractor;
+    private final InternalRowPartitionComputer partitionComputer;
+    private final List<PartitionMarkDoneAction> markDoneActions;
+
+    public PaimonPartitionMarkDone(FileStoreTable fileStoreTable, TableInfo tableInfo) {
+        checkState(
+                isEnabled(tableInfo, fileStoreTable),
+                "Partition mark-done is not enabled for table %s.",
+                tableInfo.getTablePath());
+        this.fileStoreTable = fileStoreTable;
+        this.tableInfo = tableInfo;
+        this.partitionKeys = tableInfo.getPartitionKeys();
+        Options options = Options.fromMap(fileStoreTable.options());
+        this.idleTimeToDoneMillis = options.get(PARTITION_IDLE_TIME_TO_DONE).toMillis();
+        Duration timeInterval = options.get(PARTITION_TIME_INTERVAL);
+        this.timeIntervalMillis = timeInterval == null ? null : timeInterval.toMillis();
+        this.autoPartitionStrategy = tableInfo.getTableConfig().getAutoPartitionStrategy();

Review Comment:
   For non auto-partitioned tables, if 'partition.time-interval' is not configured, timeIntervalMillis stays null and the feature silently never marks partitions done (and can keep growing state). Since the class comment says idle judgment requires this option (same as Paimon), fail fast with a clear message when auto-partition is disabled and the interval is missing.



##########
fluss-lake/fluss-lake-paimon/src/test/java/org/apache/fluss/lake/paimon/tiering/PaimonPartitionMarkDoneTest.java:
##########
@@ -0,0 +1,368 @@
+/*
+ * 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.fluss.lake.paimon.tiering;
+
+import org.apache.fluss.config.AutoPartitionTimeUnit;
+import org.apache.fluss.config.ConfigOptions;
+import org.apache.fluss.config.Configuration;
+import org.apache.fluss.lake.committer.CommittedLakeSnapshot;
+import org.apache.fluss.lake.committer.CommitterInitContext;
+import org.apache.fluss.lake.committer.LakeCommitter;
+import org.apache.fluss.lake.committer.PartitionMarkDoneMaintainer;
+import org.apache.fluss.lake.writer.LakeWriter;
+import org.apache.fluss.lake.writer.WriterInitContext;
+import org.apache.fluss.metadata.TableBucket;
+import org.apache.fluss.metadata.TableDescriptor;
+import org.apache.fluss.metadata.TableInfo;
+import org.apache.fluss.metadata.TablePath;
+import org.apache.fluss.record.ChangeType;
+import org.apache.fluss.record.GenericRecord;
+import org.apache.fluss.row.BinaryString;
+import org.apache.fluss.row.GenericRow;
+
+import org.apache.paimon.CoreOptions;
+import org.apache.paimon.catalog.Catalog;
+import org.apache.paimon.catalog.CatalogContext;
+import org.apache.paimon.catalog.CatalogFactory;
+import org.apache.paimon.options.Options;
+import org.apache.paimon.schema.Schema;
+import org.apache.paimon.schema.SchemaChange;
+import org.apache.paimon.table.FileStoreTable;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import javax.annotation.Nullable;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.apache.fluss.lake.committer.LakeCommitter.FLUSS_LAKE_SNAP_BUCKET_OFFSET_PROPERTY;
+import static org.apache.fluss.lake.paimon.tiering.PaimonPartitionMarkDone.MARK_DONE_STATE_PROPERTY;
+import static org.apache.fluss.lake.paimon.utils.PaimonConversions.toPaimon;
+import static org.apache.fluss.metadata.TableDescriptor.BUCKET_COLUMN_NAME;
+import static org.apache.fluss.metadata.TableDescriptor.OFFSET_COLUMN_NAME;
+import static org.apache.fluss.metadata.TableDescriptor.TIMESTAMP_COLUMN_NAME;
+import static org.apache.fluss.record.TestData.DEFAULT_REMOTE_DATA_DIR;
+import static org.assertj.core.api.Assertions.assertThat;
+
+/** The UT for partition mark-done during tiering to Paimon. */
+class PaimonPartitionMarkDoneTest {
+
+    private static final String DATABASE = "paimon";
+    private static final String IDLE_TIME_KEY = "partition.idle-time-to-done";
+    private static final String TIME_INTERVAL_KEY = "partition.time-interval";
+
+    private @TempDir File tempWarehouseDir;
+    private PaimonLakeTieringFactory paimonLakeTieringFactory;
+    private Catalog paimonCatalog;
+
+    @BeforeEach
+    void beforeEach() {
+        Configuration configuration = new Configuration();
+        configuration.setString("warehouse", tempWarehouseDir.toString());
+        paimonLakeTieringFactory = new PaimonLakeTieringFactory(configuration);
+        paimonCatalog =
+                CatalogFactory.createCatalog(
+                        CatalogContext.create(Options.fromMap(configuration.toMap())));
+    }
+
+    @Test
+    void testMarkDoneLifecycle() throws Exception {
+        TablePath tablePath = TablePath.of(DATABASE, "test_mark_done_lifecycle");
+        createPaimonTable(tablePath, markDoneOptions());
+        TableInfo tableInfo = tableInfo(tablePath, false);
+
+        // first data commit: cold start along with the commit, all time-parsable partitions
+        // pending; the illegal partition 'px' (no time can be extracted) is dropped without
+        // marking done, same as Paimon
+        long snapshot1 = writeAndCommit(tablePath, tableInfo, "2024-01-01", "2024-01-02", "px");
+        MarkDoneState state = getMarkDoneState(tablePath, snapshot1);
+        assertThat(state.isInitialized()).isTrue();
+        assertThat(state.getPendingPartitions()).containsOnlyKeys("2024-01-01", "2024-01-02");
+
+        // empty round: idle partitions are marked done via a properties-only snapshot which
+        // carries over previous offsets
+        Thread.sleep(50);
+        try (LakeCommitter<PaimonWriteResult, PaimonCommittable> lakeCommitter =
+                createLakeCommitter(tablePath, tableInfo)) {
+            CommittedLakeSnapshot maintenanceSnapshot = commitMarkDoneMaintenance(lakeCommitter);
+            assertThat(maintenanceSnapshot).isNotNull();
+            assertThat(maintenanceSnapshot.getLakeSnapshotId()).isEqualTo(snapshot1 + 1);
+            assertThat(maintenanceSnapshot.getSnapshotProperties())
+                    .containsEntry(FLUSS_LAKE_SNAP_BUCKET_OFFSET_PROPERTY, "offsets");
+            assertThat(getSnapshotProperties(tablePath, snapshot1 + 1))
+                    .isEqualTo(maintenanceSnapshot.getSnapshotProperties());
+        }
+        MarkDoneState state2 = getMarkDoneState(tablePath, snapshot1 + 1);
+        assertThat(state2.isInitialized()).isTrue();
+        assertThat(state2.getPendingPartitions()).isEmpty();
+        // the default success-file action wrote _SUCCESS files
+        assertThat(successFile(tablePath, "2024-01-01")).exists();
+        assertThat(successFile(tablePath, "2024-01-02")).exists();
+        assertThat(successFile(tablePath, "px")).doesNotExist();
+
+        // another empty round: state unchanged, no snapshot created
+        try (LakeCommitter<PaimonWriteResult, PaimonCommittable> lakeCommitter =
+                createLakeCommitter(tablePath, tableInfo)) {
+            assertThat(commitMarkDoneMaintenance(lakeCommitter)).isNull();
+        }
+
+        // late data for 2024-01-01: re-added to pending and marked done again later
+        long snapshot3 = writeAndCommit(tablePath, tableInfo, "2024-01-01");
+        assertThat(getMarkDoneState(tablePath, snapshot3).getPendingPartitions())
+                .containsOnlyKeys("2024-01-01");
+
+        Thread.sleep(50);
+        try (LakeCommitter<PaimonWriteResult, PaimonCommittable> lakeCommitter =
+                createLakeCommitter(tablePath, tableInfo)) {
+            assertThat(commitMarkDoneMaintenance(lakeCommitter)).isNotNull();
+        }
+        assertThat(getMarkDoneState(tablePath, snapshot3 + 1).getPendingPartitions()).isEmpty();
+        assertThat(successFile(tablePath, "2024-01-01")).exists();
+    }
+
+    @Test
+    void testColdStartBackfill() throws Exception {
+        TablePath tablePath = TablePath.of(DATABASE, "test_mark_done_cold_start");
+        // first tier data without the mark-done option
+        createPaimonTable(tablePath, Collections.singletonMap(TIME_INTERVAL_KEY, "1 d"));
+        TableInfo tableInfo = tableInfo(tablePath, false);
+        long snapshot1 = writeAndCommit(tablePath, tableInfo, "2024-01-01", "2024-01-02");
+        assertThat(getSnapshotProperties(tablePath, snapshot1))
+                .doesNotContainKey(MARK_DONE_STATE_PROPERTY);
+
+        // then enable mark-done: the cold start backfills the existing idle partitions
+        Thread.sleep(50);
+        paimonCatalog.alterTable(
+                toPaimon(tablePath),
+                Collections.singletonList(SchemaChange.setOption(IDLE_TIME_KEY, "1 ms")),
+                false);
+        try (LakeCommitter<PaimonWriteResult, PaimonCommittable> lakeCommitter =
+                createLakeCommitter(tablePath, tableInfo)) {
+            assertThat(commitMarkDoneMaintenance(lakeCommitter)).isNotNull();
+        }
+        MarkDoneState state = getMarkDoneState(tablePath, snapshot1 + 1);
+        assertThat(state.isInitialized()).isTrue();
+        assertThat(state.getPendingPartitions()).isEmpty();
+        assertThat(successFile(tablePath, "2024-01-01")).exists();
+        assertThat(successFile(tablePath, "2024-01-02")).exists();
+    }
+
+    @Test
+    void testPartitionEndTimeGuardsFuturePartition() throws Exception {
+        TablePath tablePath = TablePath.of(DATABASE, "test_mark_done_partition_end_time");
+        createPaimonTable(tablePath, Collections.singletonMap(IDLE_TIME_KEY, "1 ms"));
+        // auto-partitioned by day: partition end time is derived from the partition name
+        TableInfo tableInfo = tableInfo(tablePath, true);
+
+        long snapshot1 = writeAndCommit(tablePath, tableInfo, "20200101", "99991231");
+        Thread.sleep(50);
+        try (LakeCommitter<PaimonWriteResult, PaimonCommittable> lakeCommitter =
+                createLakeCommitter(tablePath, tableInfo)) {
+            assertThat(commitMarkDoneMaintenance(lakeCommitter)).isNotNull();
+        }
+        // the ancient partition is done, the future partition is guarded by its end time
+        MarkDoneState state = getMarkDoneState(tablePath, snapshot1 + 1);
+        assertThat(state.getPendingPartitions()).containsOnlyKeys("99991231");
+        assertThat(successFile(tablePath, "20200101")).exists();
+        assertThat(successFile(tablePath, "99991231")).doesNotExist();
+    }
+
+    @Test
+    void testStateJsonSerde() {
+        // round trip
+        Map<String, Long> pending = new HashMap<>();
+        pending.put("20240101", 1234L);
+        pending.put("region$2024", -1L);
+        MarkDoneState state = new MarkDoneState(true, pending);

Review Comment:
   This test uses a pending partition key containing '$' ("region$2024"), but Fluss partition names use '$' as the partition-value separator (see ResolvedPartitionSpec.PARTITION_SPEC_SEPARATOR). Using '$' here makes the test exercise an impossible/invalid partition name and could mask real-world parsing constraints.



##########
fluss-lake/fluss-lake-paimon/src/main/java/org/apache/fluss/lake/paimon/tiering/MarkDoneState.java:
##########
@@ -0,0 +1,83 @@
+/*
+ * 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.fluss.lake.paimon.tiering;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * The partition mark-done state persisted as JSON in the lake snapshot properties committed by the
+ * tiering service. It only keeps a table-level {@code initialized} cold-start flag and the pending
+ * (not yet done) partitions mapped to their last update time. The done fact itself is not stored:
+ * done partitions are removed (done-is-delete), it lives in the lake via the idempotent mark-done
+ * actions.
+ */
+public class MarkDoneState {
+
+    private final boolean initialized;
+    // partition name -> last time the tiering service wrote data into the partition
+    private final Map<String, Long> pendingPartitions;
+
+    public MarkDoneState(boolean initialized, Map<String, Long> pendingPartitions) {
+        this.initialized = initialized;
+        this.pendingPartitions = pendingPartitions;
+    }

Review Comment:
   MarkDoneState stores the provided pendingPartitions map by reference, so callers can mutate the state after construction (breaking the class’ implied immutability and potentially invalidating equals/hashCode behavior). Make a defensive copy in the constructor so the state is stable once created.



-- 
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: issues-unsubscribe@fluss.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org