[HUDI-4055]refactor ratelimiter to avoid stack overflow (#5530)
This commit is contained in:
@@ -53,19 +53,22 @@ public class RateLimiter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean tryAcquire(int numPermits) {
|
public boolean tryAcquire(int numPermits) {
|
||||||
if (numPermits > maxPermits) {
|
int remainingPermits = numPermits;
|
||||||
acquire(maxPermits);
|
while (remainingPermits > 0) {
|
||||||
return tryAcquire(numPermits - maxPermits);
|
if (remainingPermits > maxPermits) {
|
||||||
} else {
|
acquire(maxPermits);
|
||||||
return acquire(numPermits);
|
remainingPermits -= maxPermits;
|
||||||
|
} else {
|
||||||
|
return acquire(remainingPermits);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean acquire(int numOps) {
|
public boolean acquire(int numOps) {
|
||||||
try {
|
try {
|
||||||
if (!semaphore.tryAcquire(numOps)) {
|
while (!semaphore.tryAcquire(numOps)) {
|
||||||
Thread.sleep(WAIT_BEFORE_NEXT_ACQUIRE_PERMIT_IN_MS);
|
Thread.sleep(WAIT_BEFORE_NEXT_ACQUIRE_PERMIT_IN_MS);
|
||||||
return acquire(numOps);
|
|
||||||
}
|
}
|
||||||
LOG.debug(String.format("acquire permits: %s, maxPremits: %s", numOps, maxPermits));
|
LOG.debug(String.format("acquire permits: %s, maxPremits: %s", numOps, maxPermits));
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user