Class MetadataCleanup
Object
io.delta.kernel.internal.snapshot.MetadataCleanup
-
Method Summary
Modifier and TypeMethodDescriptionstatic longcleanupExpiredLogs(Engine engine, Clock clock, Path tablePath, long retentionMillis) Delete the Delta log files (delta and checkpoint files) that are expired according to the table metadata retention settings.
-
Method Details
-
cleanupExpiredLogs
public static long cleanupExpiredLogs(Engine engine, Clock clock, Path tablePath, long retentionMillis) throws IOException Delete the Delta log files (delta and checkpoint files) that are expired according to the table metadata retention settings. While deleting the log files, it makes sure the time travel continues to work for all unexpired table versions.Here is algorithm:
- Initial the potential delete file list: `potentialFilesToDelete` as an empty list
- Initialize the last seen checkpoint file list: `lastSeenCheckpointFiles`. There could be one or more checkpoint files for a given version.
- List the delta log files starting with prefix "00000000000000000000." (%020d). For each
file:
- Step 1: Check if the `lastSeenCheckpointFiles` contains a complete checkpoint, then
- Step 1.1: delete all files in `potentialFilesToDelete`. Now we know there is a checkpoint that contains the compacted Delta log up to the checkpoint version and all commit/checkpoint files before this checkpoint version are not needed.
- Step 1.2: add `lastCheckpointFiles` to `potentialFileStoDelete` list. This checkpoint is potential candidate to delete later if we find another checkpoint
- Step 2: If the timestamp falls within the retention period, stop
- Step 3: If the file is a delta log file, add it to the `potentialFilesToDelete` list
- Step 4: If the file is a checkpoint file, add it to the `lastSeenCheckpointFiles`
- Step 1: Check if the `lastSeenCheckpointFiles` contains a complete checkpoint, then
- Parameters:
engine-Engineinstance to delete the expired log filesclock-Clockinstance to get the current time. Useful in testing to mock the current time.tablePath- Table locationretentionMillis- Log file retention period in milliseconds- Returns:
- number of log files deleted
- Throws:
IOException- if an error occurs while deleting the log files
-