File tree Expand file tree Collapse file tree
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client Expand file tree Collapse file tree Original file line number Diff line number Diff line change 7272import java .util .ArrayList ;
7373import java .util .Arrays ;
7474import java .util .Collection ;
75- import java .util .Collections ;
7675import java .util .Comparator ;
7776import java .util .HashMap ;
7877import 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 }
You can’t perform that action at this time.
0 commit comments