pvary commented on code in PR #13360: URL: https://github.com/apache/iceberg/pull/13360#discussion_r2159245823
########## docs/docs/flink-table-maintenance.md: ########## @@ -0,0 +1,268 @@ +--- +title: "Flink Table Maintenance " +--- +<!-- + - 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. + --> + +# Flink Table Maintenance + +## Overview +When using **Apache Iceberg tables** in a **Flink streaming environment**, it's important to automate table maintenance operations such as `snapshot expiration`, `small file compaction`, and `orphan file cleanup`. + +Previously, these maintenance tasks were only available through **Iceberg Spark Actions**, requiring a separate Spark cluster. However, maintaining **Spark infrastructure** just for table optimization adds **complexity** and **operational overhead**. + +The `TableMaintenance` API in **Apache Iceberg** enables **Flink jobs** to execute these maintenance tasks **natively** within the same streaming job or as an independent Flink job, avoiding the need for external systems. This approach simplifies **architecture**, reduces **costs**, and improves **automation**. + +## Quick Start +Here's a simple example that sets up automated maintenance for an Iceberg table. + +```java +StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); +TableLoader tableLoader = TableLoader.fromHadoopTable("path/to/table"); +TriggerLockFactory lockFactory = TriggerLockFactory.defaultLockFactory(); + +TableMaintenance.forTable(env, tableLoader, lockFactory) + .uidSuffix("my-maintenance-job") + .rateLimit(Duration.ofMinutes(10)) + .lockCheckDelay(Duration.ofSeconds(10)) + .add(ExpireSnapshots.builder() + .scheduleOnCommitCount(10) + .maxSnapshotAge(Duration.ofMinutes(10)) + .retainLast(5) + .deleteBatchSize(5) + .parallelism(8)) + .add(RewriteDataFiles.builder() + .scheduleOnDataFileCount(10) + .targetFileSizeBytes(128 * 1024 * 1024) + .partialProgressEnabled(true) + .partialProgressMaxCommits(10)) Review Comment: I would turn this off in the main example. This becomes interesting if the table is big, and otherwise it add too many small commits -- 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-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org