[HUDI-3899] Drop index to delete pending index instants from timeline if applicable (#5342)
Co-authored-by: sivabalan <n.siva.b@gmail.com>
This commit is contained in:
@@ -18,13 +18,9 @@
|
||||
|
||||
package org.apache.hudi.metadata;
|
||||
|
||||
import org.apache.avro.specific.SpecificRecordBase;
|
||||
import org.apache.hadoop.conf.Configuration;
|
||||
import org.apache.hadoop.fs.FileStatus;
|
||||
import org.apache.hadoop.fs.FileSystem;
|
||||
import org.apache.hadoop.fs.Path;
|
||||
import org.apache.hudi.avro.model.HoodieCleanMetadata;
|
||||
import org.apache.hudi.avro.model.HoodieIndexPartitionInfo;
|
||||
import org.apache.hudi.avro.model.HoodieIndexPlan;
|
||||
import org.apache.hudi.avro.model.HoodieInstantInfo;
|
||||
import org.apache.hudi.avro.model.HoodieMetadataRecord;
|
||||
import org.apache.hudi.avro.model.HoodieRestoreMetadata;
|
||||
@@ -70,6 +66,12 @@ import org.apache.hudi.config.metrics.HoodieMetricsJmxConfig;
|
||||
import org.apache.hudi.exception.HoodieException;
|
||||
import org.apache.hudi.exception.HoodieIndexException;
|
||||
import org.apache.hudi.exception.HoodieMetadataException;
|
||||
|
||||
import org.apache.avro.specific.SpecificRecordBase;
|
||||
import org.apache.hadoop.conf.Configuration;
|
||||
import org.apache.hadoop.fs.FileStatus;
|
||||
import org.apache.hadoop.fs.FileSystem;
|
||||
import org.apache.hadoop.fs.Path;
|
||||
import org.apache.log4j.LogManager;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
@@ -88,6 +90,9 @@ import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.apache.hudi.common.table.HoodieTableConfig.ARCHIVELOG_FOLDER;
|
||||
import static org.apache.hudi.common.table.timeline.HoodieInstant.State.REQUESTED;
|
||||
import static org.apache.hudi.common.table.timeline.HoodieTimeline.getIndexInflightInstant;
|
||||
import static org.apache.hudi.common.table.timeline.TimelineMetadataUtils.deserializeIndexPlan;
|
||||
import static org.apache.hudi.common.util.StringUtils.EMPTY_STRING;
|
||||
import static org.apache.hudi.metadata.HoodieTableMetadata.METADATA_TABLE_NAME_SUFFIX;
|
||||
import static org.apache.hudi.metadata.HoodieTableMetadata.SOLO_COMMIT_TIMESTAMP;
|
||||
@@ -727,9 +732,33 @@ public abstract class HoodieBackedTableMetadataWriter implements HoodieTableMeta
|
||||
HoodieTableConfig.update(dataMetaClient.getFs(), new Path(dataMetaClient.getMetaPath()), dataMetaClient.getTableConfig().getProps());
|
||||
LOG.warn("Deleting Metadata Table partitions: " + partitionPath);
|
||||
dataMetaClient.getFs().delete(new Path(metadataWriteConfig.getBasePath(), partitionPath), true);
|
||||
// delete corresponding pending indexing instant file in the timeline
|
||||
LOG.warn("Deleting pending indexing instant from the timeline for partition: " + partitionPath);
|
||||
deletePendingIndexingInstant(dataMetaClient, partitionPath);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes any pending indexing instant, if it exists.
|
||||
* It reads the plan from indexing.requested file and deletes both requested and inflight instants,
|
||||
* if the partition path in the plan matches with the given partition path.
|
||||
*/
|
||||
private static void deletePendingIndexingInstant(HoodieTableMetaClient metaClient, String partitionPath) {
|
||||
metaClient.reloadActiveTimeline().filterPendingIndexTimeline().getInstants().filter(instant -> REQUESTED.equals(instant.getState()))
|
||||
.forEach(instant -> {
|
||||
try {
|
||||
HoodieIndexPlan indexPlan = deserializeIndexPlan(metaClient.getActiveTimeline().readIndexPlanAsBytes(instant).get());
|
||||
if (indexPlan.getIndexPartitionInfos().stream()
|
||||
.anyMatch(indexPartitionInfo -> indexPartitionInfo.getMetadataPartitionPath().equals(partitionPath))) {
|
||||
metaClient.getActiveTimeline().deleteInstantFileIfExists(instant);
|
||||
metaClient.getActiveTimeline().deleteInstantFileIfExists(getIndexInflightInstant(instant.getTimestamp()));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
LOG.error("Failed to delete the instant file corresponding to " + instant);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private MetadataRecordsGenerationParams getRecordsGenerationParams() {
|
||||
return new MetadataRecordsGenerationParams(
|
||||
dataMetaClient,
|
||||
|
||||
Reference in New Issue
Block a user