in xtable-core/src/main/java/org/apache/xtable/iceberg/IcebergConversionTarget.java [282:312]
private void rollbackCorruptCommits() {
if (table == null) {
// there is no existing table so exit early
return;
}
// There are cases when using the HadoopTables API where the table metadata json is updated but
// the manifest file is not written, causing corruption. This is a workaround to fix the issue.
if (catalogConfig == null && table.currentSnapshot() != null) {
boolean validSnapshot = false;
while (!validSnapshot) {
try {
table.currentSnapshot().allManifests(table.io());
validSnapshot = true;
} catch (NotFoundException ex) {
Snapshot currentSnapshot = table.currentSnapshot();
log.warn(
"Corrupt snapshot detected for table: {} snapshotId: {}. Rolling back to previous snapshot: {}.",
tableIdentifier,
currentSnapshot.snapshotId(),
currentSnapshot.parentId());
// if we need to rollback, we must also clear the last sync state since that sync is no
// longer considered valid. This will force InternalTable to fall back to a snapshot sync
// in the subsequent sync round.
table.manageSnapshots().rollbackTo(currentSnapshot.parentId()).commit();
Transaction transaction = table.newTransaction();
transaction.updateProperties().remove(TableSyncMetadata.XTABLE_METADATA).commit();
transaction.commitTransaction();
}
}
}
}