-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[HUDI-1502] MOR rollback and restore support for metadata sync #2421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
7d2d385
2bec2d3
6244bc6
0227058
0a198d8
24ea51a
69b4b80
6df8662
c2647c3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,6 +32,7 @@ | |
| import org.apache.hudi.config.HoodieWriteConfig; | ||
| import org.apache.hudi.exception.HoodieIOException; | ||
| import org.apache.hudi.table.HoodieTable; | ||
|
|
||
| import org.apache.log4j.LogManager; | ||
| import org.apache.log4j.Logger; | ||
|
|
||
|
|
@@ -53,9 +54,9 @@ public abstract class AbstractMarkerBasedRollbackStrategy<T extends HoodieRecord | |
|
|
||
| protected final HoodieWriteConfig config; | ||
|
|
||
| private final String basePath; | ||
| protected final String basePath; | ||
|
|
||
| private final String instantTime; | ||
| protected final String instantTime; | ||
|
|
||
| public AbstractMarkerBasedRollbackStrategy(HoodieTable<T, I, K, O> table, HoodieEngineContext context, HoodieWriteConfig config, String instantTime) { | ||
| this.table = table; | ||
|
|
@@ -90,6 +91,7 @@ protected HoodieRollbackStat undoAppend(String appendBaseFilePath, HoodieInstant | |
| String fileId = FSUtils.getFileIdFromFilePath(baseFilePathForAppend); | ||
| String baseCommitTime = FSUtils.getCommitTime(baseFilePathForAppend.getName()); | ||
| String partitionPath = FSUtils.getRelativePartitionPath(new Path(basePath), new Path(basePath, appendBaseFilePath).getParent()); | ||
| final Map<FileStatus, Long> probableLogFileMap = getProbableFileSizeMap(partitionPath, baseCommitTime); | ||
|
|
||
| HoodieLogFormat.Writer writer = null; | ||
| try { | ||
|
|
@@ -129,9 +131,23 @@ protected HoodieRollbackStat undoAppend(String appendBaseFilePath, HoodieInstant | |
| 1L); | ||
| } | ||
|
|
||
| return HoodieRollbackStat.newBuilder() | ||
| HoodieRollbackStat.Builder builder = HoodieRollbackStat.newBuilder() | ||
| .withPartitionPath(partitionPath) | ||
| .withRollbackBlockAppendResults(filesToNumBlocksRollback) | ||
| .build(); | ||
| .withRollbackBlockAppendResults(filesToNumBlocksRollback); | ||
| if (probableLogFileMap != null) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should return an empty map from the method, instead of relying on null. |
||
| builder.withProbableLogFileToSizeMap(probableLogFileMap); | ||
| } | ||
| return builder.build(); | ||
| } | ||
|
|
||
| /** | ||
| * Returns probable log files for the respective baseCommitTime to assist in metadata table syncing. | ||
| * @param partitionPath partition path of interest | ||
| * @param baseCommitTime base commit time of interest | ||
| * @return Map<FileStatus, File size> | ||
| * @throws IOException | ||
| */ | ||
| protected Map<FileStatus, Long> getProbableFileSizeMap(String partitionPath, String baseCommitTime) throws IOException { | ||
|
nsivabalan marked this conversation as resolved.
Outdated
|
||
| return null; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Collections.EMPTY_MAP |
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -98,8 +98,9 @@ public List<HoodieRollbackStat> collectRollbackStats(HoodieEngineContext context | |
| * @return stats collected with or w/o actual deletions. | ||
| */ | ||
| JavaPairRDD<String, HoodieRollbackStat> maybeDeleteAndCollectStats(HoodieEngineContext context, HoodieInstant instantToRollback, List<ListingBasedRollbackRequest> rollbackRequests, | ||
| int sparkPartitions, boolean doDelete) { | ||
| int sparkPartitions, boolean doDelete) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. revert this? |
||
| JavaSparkContext jsc = HoodieSparkEngineContext.getSparkContext(context); | ||
|
|
||
| return jsc.parallelize(rollbackRequests, sparkPartitions).mapToPair(rollbackRequest -> { | ||
| switch (rollbackRequest.getType()) { | ||
| case DELETE_DATA_FILES_ONLY: { | ||
|
|
@@ -116,14 +117,31 @@ JavaPairRDD<String, HoodieRollbackStat> maybeDeleteAndCollectStats(HoodieEngineC | |
| .withDeletedFileResults(filesToDeletedStatus).build()); | ||
| } | ||
| case APPEND_ROLLBACK_BLOCK: { | ||
| // collect all log files that is supposed to be deleted with this rollback | ||
| String baseCommit = rollbackRequest.getLatestBaseInstant().get(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. all of this code is pretty much replaced by FSUtils.getAllLogFiles()?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Existing FSUtils.getAllLogFiles() expects fileId to be passed in. Hence have created a new method in FSUtils which lists all files disregarding fileId, but later filters for basecommit passed in. |
||
| SerializablePathFilter filter = (path) -> { | ||
| if (FSUtils.isLogFile(path)) { | ||
| // Since the baseCommitTime is the only commit for new log files, it's okay here | ||
| String fileCommitTime = FSUtils.getBaseCommitTimeFromLogPath(path); | ||
| return baseCommit.equals(fileCommitTime); | ||
| } | ||
| return false; | ||
| }; | ||
|
|
||
| final Map<FileStatus, Long> probableLogFileMap = new HashMap<>(); | ||
| FileSystem fs = metaClient.getFs(); | ||
| FileStatus[] probableLogFiles = fs.listStatus(FSUtils.getPartitionPath(config.getBasePath(), rollbackRequest.getPartitionPath()), filter); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guess, there is no way to avoid this listing per se. |
||
| for (FileStatus fileStatus : probableLogFiles) { | ||
| probableLogFileMap.put(fileStatus, fileStatus.getLen()); | ||
| } | ||
|
|
||
| Writer writer = null; | ||
| try { | ||
| writer = HoodieLogFormat.newWriterBuilder() | ||
| .onParentPath(FSUtils.getPartitionPath(metaClient.getBasePath(), rollbackRequest.getPartitionPath())) | ||
| .withFileId(rollbackRequest.getFileId().get()) | ||
| .overBaseCommit(rollbackRequest.getLatestBaseInstant().get()).withFs(metaClient.getFs()) | ||
| .withFileExtension(HoodieLogFile.DELTA_EXTENSION).build(); | ||
|
|
||
| // generate metadata | ||
| if (doDelete) { | ||
| Map<HeaderMetadataType, String> header = generateHeader(instantToRollback.getTimestamp()); | ||
|
|
@@ -151,15 +169,15 @@ JavaPairRDD<String, HoodieRollbackStat> maybeDeleteAndCollectStats(HoodieEngineC | |
| ); | ||
| return new Tuple2<>(rollbackRequest.getPartitionPath(), | ||
| HoodieRollbackStat.newBuilder().withPartitionPath(rollbackRequest.getPartitionPath()) | ||
| .withRollbackBlockAppendResults(filesToNumBlocksRollback).build()); | ||
| .withRollbackBlockAppendResults(filesToNumBlocksRollback) | ||
| .withProbableLogFileToSizeMap(probableLogFileMap).build()); | ||
| } | ||
| default: | ||
| throw new IllegalStateException("Unknown Rollback action " + rollbackRequest); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Common method used for cleaning out base files under a partition path during rollback of a set of commits. | ||
| */ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets answer this and either resolve and fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the cleanest way to have a marker per file created. That way we can avoid listing anything at all. We can just compute the files from the marker folder directly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets have a follow on JIRA for this. We should ideally fix so that marker files exist for all log files. and we are able to just add the actual writtenLogFiles ..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
created a follow up ticket https://issues.apache.org/jira/browse/HUDI-1517. not fixing in this release