cshuo commented on code in PR #19971:
URL: https://github.com/apache/hudi/pull/19971#discussion_r4026198834


##########
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/heartbeat/HoodieHeartbeatClient.java:
##########
@@ -144,14 +146,45 @@ public void start(String instantTime) {
     Heartbeat newHeartbeat = new Heartbeat();
     newHeartbeat.setHeartbeatStarted(true);
     instantToHeartbeatMap.put(instantTime, newHeartbeat);
-    // Ensure heartbeat is generated for the first time with this blocking 
call.
-    // Since scheduler submits the task to a thread, no guarantee when that 
thread will get CPU
-    // cycles to generate the first heartbeat.
+    // Attempt the first heartbeat synchronously. A timed-out write is retried 
by the scheduler;
+    // callers that need a confirmed heartbeat before proceeding can use 
awaitHeartbeat().

Review Comment:
   > the updateHeartbeat(String instantTime) already sets up the heartbat time 
through heartbeat.setLastHeartbeatTime(newHeartbeatTime);
   
   The timestamp is assigned only after the storage write succeeds without 
timeout exception. The relevant execution order in `updateHeartbeat()` is:
   
   ```java
   try {
     writeHeartbeatFile(instantTime); // May throw TimeoutException.
     // ...
     heartbeat.setLastHeartbeatTime(newHeartbeatTime); // Skipped on timeout.
   } catch (TimeoutException te) {
     // Log the timeout without updating the timestamp; retry on the next tick.
   }
   ```
   
   If the **initial write** times out, `updateHeartbeat()` catches the 
exception and returns normally, leaving `lastHeartbeatTime` null. `start()` 
then schedules retries and returns.
   
   The coordinator can proceed directly to `recommit` before a retry succeeds. 
Even though it uses the same heartbeat client, the timestamp has never been 
set. `isHeartbeatExpired()` therefore falls back to storage; if the heartbeat 
file is absent, it reads `0` and rejects the commit:
   
   ```text
   Caused by: org.apache.hudi.exception.HoodieException:
   Heartbeat for instant XXX has expired, last heartbeat 0
       at 
org.apache.hudi.client.heartbeat.WriterHeartbeatUtils.abortIfHeartbeatExpired(WriterHeartbeatUtils.java:101)
       at 
org.apache.hudi.client.BaseHoodieWriteClient.commitStats(BaseHoodieWriteClient.java:277)
       at 
org.apache.hudi.client.BaseHoodieWriteClient.commitStats(BaseHoodieWriteClient.java:252)
   ```



-- 
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]

Reply via email to