danny0405 commented on code in PR #18988:
URL: https://github.com/apache/hudi/pull/18988#discussion_r3407598995


##########
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/BaseHoodieClient.java:
##########
@@ -462,4 +476,78 @@ private static Map<String, String> 
collectRollingMetadataFromTimeline(
   protected Option<Map<String, String>> updateExtraMetadata(Option<Map<String, 
String>> extraMetadata) {
     return CommitMetadataProperties.enrich(extraMetadata, config, context);
   }
+
+  /**
+   * Fire {@link HoodieWriteCommitCallback} for a commit, if enabled. Shared by
+   * {@link BaseHoodieWriteClient#postCommit} (regular auto- and 
explicit-commit paths)
+   * and {@link BaseHoodieTableServiceClient} (compaction and clustering 
completions).
+   * Lazily constructs the callback instance from {@code 
hoodie.write.commit.callback.class}.
+   *
+   * <p>Best-effort: catches and logs any exception from the user-supplied 
callback so a
+   * misbehaving observer cannot fail the commit.
+   */
+  protected void fireCommitCallback(String commitTime,
+                                    String commitActionType,
+                                    List<HoodieWriteStat> stats,
+                                    BaseFileOnlyView fsView,
+                                    Option<Map<String, String>> extraMetadata) 
{
+    if (!config.writeCommitCallbackOn()) {
+      return;
+    }
+    try {
+      if (commitCallback == null) {
+        commitCallback = HoodieCommitCallbackFactory.create(config);
+      }
+      commitCallback.call(new HoodieWriteCommitCallbackMessage(
+          commitTime, config.getTableName(), config.getBasePath(),
+          stats, Option.of(commitActionType), extraMetadata, 
resolvePrevFilePaths(stats, fsView),
+          Collections.emptyMap()));
+    } catch (Exception e) {
+      log.warn("HoodieWriteCommitCallback failed for commit {} ({}); ignoring",
+          commitTime, commitActionType, e);
+    }
+  }
+
+  /**
+   * Pre-resolve the previous base file (and bootstrap base file, if any) for 
every
+   * {@link HoodieWriteStat} that represents an update, using a populated
+   * {@link BaseFileOnlyView}. The lookup is O(1) per stat against the cached 
view, so
+   * this adds no I/O on top of what the writer already paid.
+   *
+   * <p>Used by {@link #fireCommitCallback} call sites so the callback message 
ships
+   * actual file paths rather than forcing each callback impl to rebuild a
+   * {@code FileSystemView}.
+   */
+  protected static Map<String, PrevFilePaths> 
resolvePrevFilePaths(List<HoodieWriteStat> stats,
+                                                                   
BaseFileOnlyView fsView) {

Review Comment:
   query the fsview is costly, can we make it a supplier so that it is only 
called when necessary.



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