Batch Mode Maintenance
Rewrite Files Action
Iceberg provides an API to rewrite small files into larger files by submitting Flink batch jobs. The behavior is the same as Spark’srewriteDataFiles action.
Streaming Mode Maintenance
Overview
TheTableMaintenance API in Apache Iceberg empowers Flink jobs to execute maintenance tasks natively, either embedded within existing streaming pipelines or deployed as standalone Flink jobs. This eliminates dependencies on external systems like Spark.
Benefits:
- Streamlined architecture
- Reduced operational costs
- Enhanced automation capabilities
- No dependency on Spark infrastructure
Supported Features
ExpireSnapshots
Removes old snapshots and their files. Internally usescleanExpiredFiles(true) when committing.
RewriteDataFiles
Compacts small files to optimize file sizes. Supports partial progress commits and limiting maximum rewritten bytes per run.DeleteOrphanFiles
Removes files which are not referenced in any metadata files of an Iceberg table.Lock Management
TheTriggerLockFactory is essential for coordinating maintenance tasks. It prevents concurrent maintenance operations on the same table.
JDBC Lock Factory
Uses a database table to manage distributed locks:ZooKeeper Lock Factory
Uses Apache ZooKeeper for distributed locks:Quick Start Example
The following example demonstrates automated maintenance for an Iceberg table:Configuration Options
TableMaintenance Builder
Common Task Options
ExpireSnapshots Options
RewriteDataFiles Options
DeleteOrphanFiles Options
Post-Commit Integration
Automatic execution of maintenance tasks after data is committed usingaddPostCommitTopology(...):
SQL Examples
Enable maintenance using SQL:Best Practices
Resource Management
- Use dedicated slot sharing groups for maintenance tasks
- Set appropriate parallelism based on cluster resources
- Enable checkpointing for fault tolerance
Scheduling Strategy
- Avoid too frequent executions with
rateLimit - Use
scheduleOnCommitCountfor write-heavy tables - Use
scheduleOnDataFileCountfor fine-grained control
Performance Tuning
- Adjust
deleteBatchSizebased on storage performance - Enable
partialProgressEnabledfor large rewrite operations - Set reasonable
maxRewriteByteslimits - Set appropriate
maxFileGroupSizeBytesfor parallel processing
Troubleshooting
OutOfMemoryError during file deletion
Cause: Large number of files being deleted in a single batch. Solution: Reduce the batch size:Lock conflicts
Cause: Multiple jobs attempting maintenance simultaneously. Solution: Increase lock check delay and rate limit:Slow rewrite operations
Cause: Too much data being rewritten in a single run. Solution: Enable partial progress and limit bytes:Complete Production Example
Next Steps
Configuration
Configure Flink for Iceberg
Writes
Learn about writing data with Flink