[HUDI-3799] Fixing not deleting empty instants w/o archiving (#5261)
This commit is contained in:
committed by
GitHub
parent
3d8fc78c66
commit
f91e9e63e1
@@ -889,12 +889,19 @@ public class TestHoodieTimelineArchiver extends HoodieClientTestHarness {
|
||||
metaClient = HoodieTableMetaClient.reload(metaClient);
|
||||
|
||||
int startInstant = 1;
|
||||
List<HoodieInstant> expectedArchivedInstants = new ArrayList<>();
|
||||
for (int i = 0; i < maxInstantsToKeep + 1; i++, startInstant++) {
|
||||
createCleanMetadata(startInstant + "", false, isEmpty || i % 2 == 0);
|
||||
createCleanMetadata(startInstant + "", false, false, isEmpty || i % 2 == 0);
|
||||
expectedArchivedInstants.add(new HoodieInstant(State.REQUESTED, HoodieTimeline.CLEAN_ACTION, startInstant + ""));
|
||||
expectedArchivedInstants.add(new HoodieInstant(State.INFLIGHT, HoodieTimeline.CLEAN_ACTION, startInstant + ""));
|
||||
expectedArchivedInstants.add(new HoodieInstant(State.COMPLETED, HoodieTimeline.CLEAN_ACTION, startInstant + ""));
|
||||
}
|
||||
|
||||
for (int i = 0; i < maxInstantsToKeep + 1; i++, startInstant += 2) {
|
||||
createCommitAndRollbackFile(startInstant + 1 + "", startInstant + "", false, isEmpty || i % 2 == 0);
|
||||
expectedArchivedInstants.add(new HoodieInstant(State.REQUESTED, HoodieTimeline.ROLLBACK_ACTION, startInstant + ""));
|
||||
expectedArchivedInstants.add(new HoodieInstant(State.INFLIGHT, HoodieTimeline.ROLLBACK_ACTION, startInstant + ""));
|
||||
expectedArchivedInstants.add(new HoodieInstant(State.COMPLETED, HoodieTimeline.ROLLBACK_ACTION, startInstant + ""));
|
||||
}
|
||||
|
||||
if (enableMetadataTable) {
|
||||
@@ -916,6 +923,14 @@ public class TestHoodieTimelineArchiver extends HoodieClientTestHarness {
|
||||
|
||||
assertTrue(actionInstantMap.containsKey("rollback"), "Rollback Action key must be preset");
|
||||
assertEquals(minInstantsToKeep, actionInstantMap.get("rollback").size(), "Should have min instant");
|
||||
|
||||
// verify all expected instants are part of archived timeline
|
||||
metaClient.getArchivedTimeline().loadCompletedInstantDetailsInMemory();
|
||||
HoodieInstant firstInstant = metaClient.reloadActiveTimeline().firstInstant().get();
|
||||
expectedArchivedInstants = expectedArchivedInstants.stream()
|
||||
.filter(entry -> HoodieTimeline.compareTimestamps(entry.getTimestamp(), HoodieTimeline.LESSER_THAN, firstInstant.getTimestamp()
|
||||
)).collect(Collectors.toList());
|
||||
expectedArchivedInstants.forEach(entry -> assertTrue(metaClient.getArchivedTimeline().containsInstant(entry)));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@@ -1271,7 +1286,8 @@ public class TestHoodieTimelineArchiver extends HoodieClientTestHarness {
|
||||
|
||||
private List<HoodieInstant> getArchivedInstants(HoodieInstant instant) {
|
||||
List<HoodieInstant> instants = new ArrayList<>();
|
||||
if (instant.getAction() == HoodieTimeline.COMMIT_ACTION || instant.getAction() == HoodieTimeline.DELTA_COMMIT_ACTION || instant.getAction() == HoodieTimeline.CLEAN_ACTION) {
|
||||
if (instant.getAction().equals(HoodieTimeline.COMMIT_ACTION) || instant.getAction().equals(HoodieTimeline.DELTA_COMMIT_ACTION)
|
||||
|| instant.getAction().equals(HoodieTimeline.CLEAN_ACTION) || instant.getAction().equals(HoodieTimeline.ROLLBACK_ACTION)) {
|
||||
instants.add(new HoodieInstant(State.REQUESTED, instant.getAction(), instant.getTimestamp()));
|
||||
}
|
||||
instants.add(new HoodieInstant(State.INFLIGHT, instant.getAction(), instant.getTimestamp()));
|
||||
|
||||
@@ -744,7 +744,7 @@ public class TestCleaner extends HoodieClientTestBase {
|
||||
|
||||
for (int i = 0; i < cleanCount; i++, startInstant++) {
|
||||
String commitTime = makeNewCommitTime(startInstant, "%09d");
|
||||
createCleanMetadata(commitTime + "", false, true);
|
||||
createEmptyCleanMetadata(commitTime + "", false);
|
||||
}
|
||||
|
||||
int instantClean = startInstant;
|
||||
|
||||
@@ -696,10 +696,14 @@ public abstract class HoodieClientTestHarness extends HoodieCommonTestHarness im
|
||||
}
|
||||
|
||||
public HoodieInstant createCleanMetadata(String instantTime, boolean inflightOnly) throws IOException {
|
||||
return createCleanMetadata(instantTime, inflightOnly, false);
|
||||
return createCleanMetadata(instantTime, inflightOnly, false, false);
|
||||
}
|
||||
|
||||
public HoodieInstant createCleanMetadata(String instantTime, boolean inflightOnly, boolean isEmpty) throws IOException {
|
||||
public HoodieInstant createEmptyCleanMetadata(String instantTime, boolean inflightOnly) throws IOException {
|
||||
return createCleanMetadata(instantTime, inflightOnly, true, true);
|
||||
}
|
||||
|
||||
public HoodieInstant createCleanMetadata(String instantTime, boolean inflightOnly, boolean isEmptyForAll, boolean isEmptyCompleted) throws IOException {
|
||||
HoodieCleanerPlan cleanerPlan = new HoodieCleanerPlan(new HoodieActionInstant("", "", ""), "", new HashMap<>(),
|
||||
CleanPlanV2MigrationHandler.VERSION, new HashMap<>(), new ArrayList<>());
|
||||
if (inflightOnly) {
|
||||
@@ -713,7 +717,7 @@ public abstract class HoodieClientTestHarness extends HoodieCommonTestHarness im
|
||||
Collections.emptyList(),
|
||||
instantTime);
|
||||
HoodieCleanMetadata cleanMetadata = convertCleanMetadata(instantTime, Option.of(0L), Collections.singletonList(cleanStats));
|
||||
HoodieTestTable.of(metaClient).addClean(instantTime, cleanerPlan, cleanMetadata, isEmpty);
|
||||
HoodieTestTable.of(metaClient).addClean(instantTime, cleanerPlan, cleanMetadata, isEmptyForAll, isEmptyCompleted);
|
||||
}
|
||||
return new HoodieInstant(inflightOnly, "clean", instantTime);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user