[HUDI-2737] Use earliest instant by default for async compaction and clustering jobs (#3991)
Address review comments Fix test failures Co-authored-by: Sagar Sumit <sagarsumit09@gmail.com>
This commit is contained in:
@@ -274,6 +274,12 @@ public class HoodieDefaultTimeline implements HoodieTimeline {
|
||||
return Option.fromJavaOptional(instants.stream().findFirst());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Option<HoodieInstant> firstInstant(String action, State state) {
|
||||
return Option.fromJavaOptional(instants.stream()
|
||||
.filter(s -> action.equals(s.getAction()) && state.equals(s.getState())).findFirst());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Option<HoodieInstant> nthInstant(int n) {
|
||||
if (empty() || n >= countInstants()) {
|
||||
|
||||
@@ -209,6 +209,13 @@ public interface HoodieTimeline extends Serializable {
|
||||
*/
|
||||
Option<HoodieInstant> firstInstant();
|
||||
|
||||
/**
|
||||
* @param action Instant action String.
|
||||
* @param state Instant State.
|
||||
* @return first instant of a specific action and state if available
|
||||
*/
|
||||
Option<HoodieInstant> firstInstant(String action, State state);
|
||||
|
||||
/**
|
||||
* @return nth completed instant from the first completed instant
|
||||
*/
|
||||
|
||||
@@ -26,6 +26,7 @@ import org.apache.hudi.common.testutils.MockHoodieTimeline;
|
||||
import org.apache.hudi.common.util.CollectionUtils;
|
||||
import org.apache.hudi.common.util.Option;
|
||||
import org.apache.hudi.exception.HoodieException;
|
||||
|
||||
import org.apache.hadoop.fs.Path;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -176,6 +177,15 @@ public class TestHoodieActiveTimeline extends HoodieCommonTestHarness {
|
||||
assertFalse(timeline.empty());
|
||||
assertFalse(timeline.getCommitTimeline().filterPendingExcludingCompaction().empty());
|
||||
assertEquals(12, timeline.countInstants());
|
||||
assertEquals("01", timeline.firstInstant(
|
||||
HoodieTimeline.COMMIT_ACTION, State.COMPLETED).get().getTimestamp());
|
||||
assertEquals("21", timeline.firstInstant(
|
||||
HoodieTimeline.COMMIT_ACTION, State.INFLIGHT).get().getTimestamp());
|
||||
assertFalse(timeline.firstInstant(
|
||||
HoodieTimeline.COMMIT_ACTION, State.REQUESTED).isPresent());
|
||||
assertFalse(timeline.firstInstant(
|
||||
HoodieTimeline.REPLACE_COMMIT_ACTION, State.COMPLETED).isPresent());
|
||||
|
||||
HoodieTimeline activeCommitTimeline = timeline.getCommitTimeline().filterCompletedInstants();
|
||||
assertEquals(10, activeCommitTimeline.countInstants());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user