danny0405 commented on code in PR #20651:
URL: https://github.com/apache/hudi/pull/20651#discussion_r4695860290
##########
hudi-timeline-service/src/main/java/org/apache/hudi/timeline/service/RequestHandler.java:
##########
@@ -768,18 +779,35 @@ private boolean syncIfLocalViewBehind(Context ctx) {
SyncableFileSystemView view = viewManager.getFileSystemView(basePath);
synchronized (view) {
HoodieTimeline localTimeline = view.getTimeline();
+ String timelineHashFromClient = getTimelineHashParam(ctx);
// The final check already accepts a trailing clean with an otherwise
matching timeline.
// Other extensions still need a sync: restore may have deleted their
extra instants.
- if (!shouldThrowExceptionIfLocalViewBehind(localTimeline,
getTimelineHashParam(ctx))) {
+ if (!shouldThrowExceptionIfLocalViewBehind(localTimeline,
timelineHashFromClient)) {
return false;
}
if (isLocalViewBehind(ctx)) {
String lastKnownInstantFromClient = getLastInstantTsParam(ctx);
- if (log.isInfoEnabled()) {
- log.info("Syncing view as client passed last known instant {} as
last known instant but server has the following last instant on timeline: {}",
- lastKnownInstantFromClient, localTimeline.lastInstant());
+ String clientTimeline = basePath + ":" + timelineHashFromClient;
+ boolean hasLocalFallback = hasLocalFallback(ctx);
+ // The client timeline does not change. If a sync did not make the
local view match it, one more sync cannot.
+ boolean unmatched =
unmatchedClientTimelines.contains(clientTimeline);
+ if (!unmatched || !hasLocalFallback) {
+ if (log.isInfoEnabled()) {
+ log.info("Syncing view as client passed last known instant {} as
last known instant but server has the following last instant on timeline: {}",
+ lastKnownInstantFromClient, localTimeline.lastInstant());
+ }
+ view.sync();
+ unmatched = isLocalViewBehind(ctx) &&
shouldThrowExceptionIfLocalViewBehind(view.getTimeline(),
timelineHashFromClient);
Review Comment:
Could we extract `hasTimelineMismatch(serverTimeline, lastClientInstant,
clientHash)` and use it before sync, after sync, and in the final check after
the listing? Inverting `shouldThrowExceptionIfLocalViewBehind` to
`matchesAfterRemovingTrailingClean` would make the exception easier to read.
Each call could pass the current `view.getTimeline()` so the post-sync check
uses the refreshed snapshot.
##########
hudi-timeline-service/src/main/java/org/apache/hudi/timeline/service/RequestHandler.java:
##########
@@ -768,18 +779,35 @@ private boolean syncIfLocalViewBehind(Context ctx) {
SyncableFileSystemView view = viewManager.getFileSystemView(basePath);
synchronized (view) {
HoodieTimeline localTimeline = view.getTimeline();
+ String timelineHashFromClient = getTimelineHashParam(ctx);
// The final check already accepts a trailing clean with an otherwise
matching timeline.
// Other extensions still need a sync: restore may have deleted their
extra instants.
- if (!shouldThrowExceptionIfLocalViewBehind(localTimeline,
getTimelineHashParam(ctx))) {
+ if (!shouldThrowExceptionIfLocalViewBehind(localTimeline,
timelineHashFromClient)) {
return false;
}
if (isLocalViewBehind(ctx)) {
String lastKnownInstantFromClient = getLastInstantTsParam(ctx);
- if (log.isInfoEnabled()) {
- log.info("Syncing view as client passed last known instant {} as
last known instant but server has the following last instant on timeline: {}",
- lastKnownInstantFromClient, localTimeline.lastInstant());
+ String clientTimeline = basePath + ":" + timelineHashFromClient;
+ boolean hasLocalFallback = hasLocalFallback(ctx);
+ // The client timeline does not change. If a sync did not make the
local view match it, one more sync cannot.
+ boolean unmatched =
unmatchedClientTimelines.contains(clientTimeline);
+ if (!unmatched || !hasLocalFallback) {
Review Comment:
Could we handle the cache hit with an early 400 here? Once we know the
current view mismatches, `if (hasLocalFallback &&
unmatchedClientTimelines.contains(clientTimeline))` can reject immediately. The
rest of the method can sync once and record a mismatch if it persists, all
under the existing view lock. That removes the mutable `unmatched` flag, which
currently means a cache hit here and a fresh comparison result below.
##########
hudi-timeline-service/src/main/java/org/apache/hudi/timeline/service/RequestHandler.java:
##########
@@ -768,18 +779,35 @@ private boolean syncIfLocalViewBehind(Context ctx) {
SyncableFileSystemView view = viewManager.getFileSystemView(basePath);
synchronized (view) {
HoodieTimeline localTimeline = view.getTimeline();
+ String timelineHashFromClient = getTimelineHashParam(ctx);
// The final check already accepts a trailing clean with an otherwise
matching timeline.
// Other extensions still need a sync: restore may have deleted their
extra instants.
- if (!shouldThrowExceptionIfLocalViewBehind(localTimeline,
getTimelineHashParam(ctx))) {
+ if (!shouldThrowExceptionIfLocalViewBehind(localTimeline,
timelineHashFromClient)) {
return false;
}
if (isLocalViewBehind(ctx)) {
String lastKnownInstantFromClient = getLastInstantTsParam(ctx);
- if (log.isInfoEnabled()) {
- log.info("Syncing view as client passed last known instant {} as
last known instant but server has the following last instant on timeline: {}",
- lastKnownInstantFromClient, localTimeline.lastInstant());
+ String clientTimeline = basePath + ":" + timelineHashFromClient;
+ boolean hasLocalFallback = hasLocalFallback(ctx);
Review Comment:
Do we want a repeated `REMOTE_ONLY` request with the same cached mismatch to
trigger another sync? If returning a cached 400 is acceptable for that client
too, we could drop the `localfallback` request parameter entirely and let each
client handle the 400. That would change the existing `REMOTE_ONLY` test from
three syncs to one, with all three requests still failing. If the retry is
intentional, keeping the flag on the early rejection makes that policy explicit.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]