You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hudi.apache.org by si...@apache.org on 2026/02/05 09:23:02 UTC

(hudi) branch branch-0.x updated: [HUDI-9039] Run do init table transaction only when required (#12847) (#17856)

This is an automated email from the ASF dual-hosted git repository.

sivabalan pushed a commit to branch branch-0.x
in repository https://gitbox.apache.org/repos/asf/hudi.git


The following commit(s) were added to refs/heads/branch-0.x by this push:
     new 67ae2458ae4f [HUDI-9039] Run do init table transaction only when required (#12847) (#17856)
67ae2458ae4f is described below

commit 67ae2458ae4f0721240d148aae17f8bd89a3552d
Author: Lin Liu <14...@users.noreply.github.com>
AuthorDate: Thu Feb 5 01:22:55 2026 -0800

    [HUDI-9039] Run do init table transaction only when required (#12847) (#17856)
    
    Co-authored-by: Leon Lin <52...@users.noreply.github.com>
    Co-authored-by: Leon Lin <ll...@amazon.com>
---
 .../apache/hudi/client/BaseHoodieWriteClient.java   | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/BaseHoodieWriteClient.java b/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/BaseHoodieWriteClient.java
index d4f41d4c9fd3..e1ad403c783d 100644
--- a/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/BaseHoodieWriteClient.java
+++ b/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/BaseHoodieWriteClient.java
@@ -40,6 +40,7 @@ import org.apache.hudi.common.model.ActionType;
 import org.apache.hudi.common.model.HoodieCommitMetadata;
 import org.apache.hudi.common.model.HoodieFailedWritesCleaningPolicy;
 import org.apache.hudi.common.model.HoodieKey;
+import org.apache.hudi.common.model.HoodieRecordLocation;
 import org.apache.hudi.common.model.HoodieWriteStat;
 import org.apache.hudi.common.model.TableServiceType;
 import org.apache.hudi.common.model.WriteOperationType;
@@ -1249,15 +1250,31 @@ public abstract class BaseHoodieWriteClient<T, I, K, O> extends BaseHoodieClient
     if (instantTime.isPresent()) {
       ownerInstant = Option.of(new HoodieInstant(true, CommitUtils.getCommitActionType(operationType, metaClient.getTableType()), instantTime.get()));
     }
-    this.txnManager.beginTransaction(ownerInstant, Option.empty());
-    try {
+    boolean requiresInitTable = needsUpgradeOrDowngrade(metaClient) || config.isMetadataTableEnabled();
+    if (!requiresInitTable) {
+      return;
+    }
+    executeUsingTxnManager(ownerInstant, () -> {
       tryUpgrade(metaClient, instantTime);
+      // TODO: this also does MT table management..
       initMetadataTable(instantTime, metaClient);
+    });
+  }
+
+  private void executeUsingTxnManager(Option<HoodieInstant> ownerInstant, Runnable r) {
+    this.txnManager.beginTransaction(ownerInstant, Option.empty());
+    try {
+      r.run();
     } finally {
       this.txnManager.endTransaction(ownerInstant);
     }
   }
 
+  private boolean needsUpgradeOrDowngrade(HoodieTableMetaClient metaClient) {
+    UpgradeDowngrade upgradeDowngrade = new UpgradeDowngrade(metaClient, config, context, upgradeDowngradeHelper);
+    return upgradeDowngrade.needsUpgradeOrDowngrade(HoodieTableVersion.current());
+  }
+
   /**
    * Bootstrap the metadata table.
    *