Skip to content

Commit 57cd61a

Browse files
committed
Modify the logic of shouldThrowExceptionIfLocalViewBehind method
1 parent 7a9f87c commit 57cd61a

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

hudi-timeline-service/src/main/java/org/apache/hudi/timeline/service/RequestHandler.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.apache.hudi.common.engine.HoodieEngineContext;
2222
import org.apache.hudi.common.metrics.Registry;
2323
import org.apache.hudi.common.table.marker.MarkerOperation;
24+
import org.apache.hudi.common.table.timeline.HoodieInstant;
2425
import org.apache.hudi.common.table.timeline.HoodieTimeline;
2526
import org.apache.hudi.common.table.timeline.dto.BaseFileDTO;
2627
import org.apache.hudi.common.table.timeline.dto.ClusteringOpDTO;
@@ -33,6 +34,7 @@
3334
import org.apache.hudi.common.table.view.RemoteHoodieTableFileSystemView;
3435
import org.apache.hudi.common.table.view.SyncableFileSystemView;
3536
import org.apache.hudi.common.util.HoodieTimer;
37+
import org.apache.hudi.common.util.Option;
3638
import org.apache.hudi.exception.HoodieException;
3739
import org.apache.hudi.timeline.service.handlers.BaseFileHandler;
3840
import org.apache.hudi.timeline.service.handlers.FileSliceHandler;
@@ -502,14 +504,15 @@ public void handle(@NotNull Context context) throws Exception {
502504
if (refreshCheck) {
503505
long beginFinalCheck = System.currentTimeMillis();
504506
if (isLocalViewBehind(context)) {
505-
String lastInstantTs = context.queryParam(RemoteHoodieTableFileSystemView.LAST_INSTANT_TS,
507+
String lastKnownInstantFromClient = context.queryParam(RemoteHoodieTableFileSystemView.LAST_INSTANT_TS,
506508
HoodieTimeline.INVALID_INSTANT_TS);
509+
String timelineHashFromClient = context.queryParam(RemoteHoodieTableFileSystemView.TIMELINE_HASH, "");
507510
HoodieTimeline localTimeline =
508511
viewManager.getFileSystemView(context.queryParam(RemoteHoodieTableFileSystemView.BASEPATH_PARAM)).getTimeline();
509-
if (shouldThrowExceptionIfLocalViewBehind(localTimeline, lastInstantTs)) {
512+
if (shouldThrowExceptionIfLocalViewBehind(localTimeline, timelineHashFromClient)) {
510513
String errMsg =
511514
"Last known instant from client was "
512-
+ lastInstantTs
515+
+ lastKnownInstantFromClient
513516
+ " but server has the following timeline "
514517
+ localTimeline.getInstants().collect(Collectors.toList());
515518
throw new BadRequestResponse(errMsg);
@@ -547,12 +550,12 @@ public void handle(@NotNull Context context) throws Exception {
547550
/**
548551
* Determine whether to throw an exception when local view of table's timeline is behind that of client's view.
549552
*/
550-
private boolean shouldThrowExceptionIfLocalViewBehind(HoodieTimeline localTimeline, String lastInstantTs) {
551-
HoodieTimeline afterLastInstantTimeLine = localTimeline.findInstantsAfter(lastInstantTs).filterCompletedInstants();
553+
private boolean shouldThrowExceptionIfLocalViewBehind(HoodieTimeline localTimeline, String timelineHashFromClient) {
554+
Option<HoodieInstant> lastInstant = localTimeline.lastInstant();
552555
// When performing async clean, we may have one more .clean.completed after lastInstantTs.
553556
// In this case, we do not need to throw an exception.
554-
if (afterLastInstantTimeLine.countInstants() == 1
555-
&& afterLastInstantTimeLine.filter(s -> s.getAction().equals(HoodieTimeline.CLEAN_ACTION)).countInstants() == 1) {
557+
if (lastInstant.isPresent() && lastInstant.get().getAction().equals(HoodieTimeline.CLEAN_ACTION)
558+
&& localTimeline.findInstantsBefore(lastInstant.get().getTimestamp()).getTimelineHash().equals(timelineHashFromClient)) {
556559
return false;
557560
} else {
558561
return true;

0 commit comments

Comments
 (0)