Skip to content

Commit

Permalink
change expired metadata handler
Browse files Browse the repository at this point in the history
  • Loading branch information
javsanbel2 committed Nov 27, 2024
1 parent c2e0b3f commit 07174b2
Showing 1 changed file with 19 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import com.expediagroup.beekeeper.cleanup.metadata.CleanerClientFactory;
import com.expediagroup.beekeeper.cleanup.metadata.MetadataCleaner;
import com.expediagroup.beekeeper.cleanup.path.PathCleaner;
import com.expediagroup.beekeeper.core.error.BeekeeperException;
import com.expediagroup.beekeeper.core.error.BeekeeperIcebergException;
import com.expediagroup.beekeeper.core.model.HousekeepingMetadata;
import com.expediagroup.beekeeper.core.model.HousekeepingStatus;
import com.expediagroup.beekeeper.core.repository.HousekeepingMetadataRepository;
Expand Down Expand Up @@ -78,6 +78,11 @@ public void cleanupMetadata(HousekeepingMetadata housekeepingMetadata, LocalDate
if (deleted && !dryRunEnabled) {
updateAttemptsAndStatus(housekeepingMetadata, DELETED);
}
} catch (BeekeeperIcebergException e) {
updateAttemptsAndStatus(housekeepingMetadata, SKIPPED);
log
.warn("Table \"{}.{}\" is skipped because is iceberg or could not be identified ",
housekeepingMetadata.getDatabaseName(), housekeepingMetadata.getTableName(), e);
} catch (Exception e) {
updateAttemptsAndStatus(housekeepingMetadata, FAILED);
log
Expand Down Expand Up @@ -114,42 +119,35 @@ private boolean cleanUpTable(CleanerClient client, HousekeepingMetadata housekee
String tableName = housekeepingMetadata.getTableName();
log.info("Cleaning up metadata for \"{}.{}\"", databaseName, tableName);
if (metadataCleaner.tableExists(client, databaseName, tableName)) {
try {
metadataCleaner.dropTable(housekeepingMetadata, client);
pathCleaner.cleanupPath(housekeepingMetadata);
} catch (BeekeeperException e) {
log.warn("Skipping cleanup for Iceberg table \"{}.{}\": {}", databaseName, tableName, e.getMessage());
updateStatus(housekeepingMetadata, SKIPPED, dryRunEnabled);
return false;
}
metadataCleaner.dropTable(housekeepingMetadata, client);
pathCleaner.cleanupPath(housekeepingMetadata);
} else {
log.info("Cannot drop table \"{}.{}\". Table does not exist.", databaseName, tableName);
}
return true;
}

private boolean cleanupPartition(CleanerClient client, HousekeepingMetadata housekeepingMetadata, boolean dryRunEnabled) {
private boolean cleanupPartition(
CleanerClient client,
HousekeepingMetadata housekeepingMetadata,
boolean dryRunEnabled) {
if (!S3PathValidator.validPartitionPath(housekeepingMetadata.getPath())) {
log.warn("Will not clean up partition path \"{}\" because it is not valid.", housekeepingMetadata.getPath());
updateStatus(housekeepingMetadata, SKIPPED, dryRunEnabled);
return false;
}
String databaseName = housekeepingMetadata.getDatabaseName();
String tableName = housekeepingMetadata.getTableName();
log.info("Cleaning up metadata for partition \"{}\" in table \"{}.{}\"", housekeepingMetadata.getPartitionName(), databaseName, tableName);
log.info("Cleaning up metadata for \"{}.{}\"", databaseName, tableName);
if (metadataCleaner.tableExists(client, databaseName, tableName)) {
try {
boolean partitionDeleted = metadataCleaner.dropPartition(housekeepingMetadata, client);
if (partitionDeleted) {
pathCleaner.cleanupPath(housekeepingMetadata);
}
} catch (BeekeeperException e) {
log.warn("Skipping cleanup for Iceberg partition \"{}\" in table \"{}.{}\": {}", housekeepingMetadata.getPartitionName(), databaseName, tableName, e.getMessage());
updateStatus(housekeepingMetadata, SKIPPED, dryRunEnabled);
return false;
boolean partitionDeleted = metadataCleaner.dropPartition(housekeepingMetadata, client);
if (partitionDeleted) {
pathCleaner.cleanupPath(housekeepingMetadata);
}
} else {
log.info("Cannot drop partition \"{}\" from table \"{}.{}\". Table does not exist.", housekeepingMetadata.getPartitionName(), databaseName, tableName);
log
.info("Cannot drop partition \"{}\" from table \"{}.{}\". Table does not exist.",
housekeepingMetadata.getPartitionName(), databaseName, tableName);
}
return true;
}
Expand Down

0 comments on commit 07174b2

Please sign in to comment.