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


##########
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/transaction/TransactionManager.java:
##########
@@ -41,40 +46,166 @@ public class TransactionManager implements Serializable, 
AutoCloseable {
   protected final LockManager lockManager;
   @Getter
   protected final boolean isLockRequired;
+  private final transient TimeGenerator timeGenerator;
+  private volatile long lockHolderId; // lock holder ID
+  private int permits;                // allows for nested transaction
   protected Option<HoodieInstant> changeActionInstant = Option.empty();
   private Option<HoodieInstant> lastCompletedActionInstant = Option.empty();
 
   public TransactionManager(HoodieWriteConfig config, HoodieStorage storage) {
-    this(new LockManager(config, storage), config.isLockRequired());
+    this(config, new LockManager(config, storage));
   }
 
-  protected TransactionManager(LockManager lockManager, boolean 
isLockRequired) {
+  protected TransactionManager(HoodieWriteConfig writeConfig, LockManager 
lockManager) {
+    this(lockManager, writeConfig.isLockRequired(), 
TimeGenerators.getTimeGenerator(writeConfig.getTimeGeneratorConfig()));
+  }
+
+  public TransactionManager(LockManager lockManager, boolean isLockRequired, 
TimeGenerator timeGenerator) {
     this.lockManager = lockManager;
     this.isLockRequired = isLockRequired;
+    this.timeGenerator = timeGenerator;
+    this.lockHolderId = -1;
+    this.permits = 0;
+  }
+
+  /**
+   * Caution: the invoker needs to ensure that API called within a lock 
context.
+   */
+  public String generateInstantTime() {
+    if (lockHolderId < 0 && isLockRequired) {
+      throw new HoodieLockException("Cannot create instant without acquiring a 
lock first.");
+    }
+    return HoodieInstantTimeGenerator.createNewInstantTime(timeGenerator, 0L);
+  }
+
+  /**
+   * Generates an instant time and executes an action that requires that 
instant time within a lock.
+   * @param instantTimeConsumingAction a function that takes the generated 
instant time and performs some action
+   * @return the result of the action
+   * @param <T> type of the result
+   */
+  public <T> T executeStateChangeWithInstant(Function<String, T> 
instantTimeConsumingAction) {
+    return executeStateChangeWithInstant(Option.empty(), Option.empty(), 
instantTimeConsumingAction);

Review Comment:
   added



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