Skip to content

Commit eb21901

Browse files
authored
[HUDI-4145] Archives the metadata file in HoodieInstant.State sequence (#5669)
1 parent c05ebf2 commit eb21901

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/HoodieTimelineArchiver.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@
7272
import java.util.ArrayList;
7373
import java.util.Arrays;
7474
import java.util.Collection;
75-
import java.util.Collections;
7675
import java.util.Comparator;
7776
import java.util.HashMap;
7877
import java.util.List;
@@ -507,10 +506,16 @@ private Stream<HoodieInstant> getInstantsToArchive() {
507506
List<HoodieInstant> instantsToStream = groupByTsAction.get(Pair.of(hoodieInstant.getTimestamp(),
508507
HoodieInstant.getComparableAction(hoodieInstant.getAction())));
509508
if (instantsToStream != null) {
510-
return instantsToStream.stream();
509+
// sorts the instants in natural order to make sure the metadata files be removed
510+
// in HoodieInstant.State sequence: requested -> inflight -> completed,
511+
// this is important because when a COMPLETED metadata file is removed first,
512+
// other monitors on the timeline(such as the compaction or clustering services) would
513+
// mistakenly recognize the pending file as a pending operation,
514+
// then all kinds of weird bugs occur.
515+
return instantsToStream.stream().sorted();
511516
} else {
512517
// if a concurrent writer archived the instant
513-
return Collections.EMPTY_LIST.stream();
518+
return Stream.empty();
514519
}
515520
});
516521
}

0 commit comments

Comments
 (0)