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

[hudi] branch master updated: [HUDI-4055]refactor ratelimiter to avoid stack overflow (#5530)

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

danny0405 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hudi.git


The following commit(s) were added to refs/heads/master by this push:
     new 75eaa0bffe [HUDI-4055]refactor ratelimiter to avoid stack overflow (#5530)
75eaa0bffe is described below

commit 75eaa0bffe86306c5df7a52c42ee41b7c7dc24c1
Author: guanziyue <30...@users.noreply.github.com>
AuthorDate: Mon May 9 10:27:37 2022 +0800

    [HUDI-4055]refactor ratelimiter to avoid stack overflow (#5530)
---
 .../java/org/apache/hudi/common/util/RateLimiter.java   | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/hudi-common/src/main/java/org/apache/hudi/common/util/RateLimiter.java b/hudi-common/src/main/java/org/apache/hudi/common/util/RateLimiter.java
index e156ccffdb..4915e454af 100644
--- a/hudi-common/src/main/java/org/apache/hudi/common/util/RateLimiter.java
+++ b/hudi-common/src/main/java/org/apache/hudi/common/util/RateLimiter.java
@@ -53,19 +53,22 @@ public class RateLimiter {
   }
 
   public boolean tryAcquire(int numPermits) {
-    if (numPermits > maxPermits) {
-      acquire(maxPermits);
-      return tryAcquire(numPermits - maxPermits);
-    } else {
-      return acquire(numPermits);
+    int remainingPermits = numPermits;
+    while (remainingPermits > 0) {
+      if (remainingPermits > maxPermits) {
+        acquire(maxPermits);
+        remainingPermits -= maxPermits;
+      } else {
+        return acquire(remainingPermits);
+      }
     }
+    return true;
   }
 
   public boolean acquire(int numOps) {
     try {
-      if (!semaphore.tryAcquire(numOps)) {
+      while (!semaphore.tryAcquire(numOps)) {
         Thread.sleep(WAIT_BEFORE_NEXT_ACQUIRE_PERMIT_IN_MS);
-        return acquire(numOps);
       }
       LOG.debug(String.format("acquire permits: %s, maxPremits: %s", numOps, maxPermits));
     } catch (InterruptedException e) {