-
Notifications
You must be signed in to change notification settings - Fork 15.1k
KAFKA-15265: Integrate RLMQuotaManager for throttling copies to remote storage #15820
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -96,6 +96,7 @@ | |
| import java.nio.charset.StandardCharsets; | ||
| import java.nio.file.Path; | ||
| import java.security.PrivilegedAction; | ||
| import java.time.Duration; | ||
| import java.util.ArrayList; | ||
| import java.util.Collection; | ||
| import java.util.Collections; | ||
|
|
@@ -122,6 +123,8 @@ | |
| import java.util.concurrent.ThreadFactory; | ||
| import java.util.concurrent.TimeUnit; | ||
| import java.util.concurrent.atomic.AtomicInteger; | ||
| import java.util.concurrent.locks.Condition; | ||
| import java.util.concurrent.locks.ReentrantLock; | ||
| import java.util.function.BiConsumer; | ||
| import java.util.function.Consumer; | ||
| import java.util.function.Function; | ||
|
|
@@ -158,6 +161,8 @@ public class RemoteLogManager implements Closeable { | |
|
|
||
| private final RemoteLogMetadataManager remoteLogMetadataManager; | ||
|
|
||
| private final ReentrantLock copyQuotaManagerLock = new ReentrantLock(true); | ||
| private final Condition copyQuotaManagerLockCondition = copyQuotaManagerLock.newCondition(); | ||
| private final RLMQuotaManager rlmCopyQuotaManager; | ||
| private final RLMQuotaManager rlmFetchQuotaManager; | ||
|
|
||
|
|
@@ -244,6 +249,13 @@ private void removeMetrics() { | |
| remoteStorageReaderThreadPool.removeMetrics(); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the timeout for the RLM Tasks to wait for the quota to be available | ||
| */ | ||
| Duration quotaTimeout() { | ||
| return Duration.ofSeconds(1); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you use the declared constant value?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I want to override this method to have a smaller timeout for tests. That is the reason I did not use a constant value. |
||
| } | ||
|
|
||
| RLMQuotaManager createRLMCopyQuotaManager() { | ||
| return new RLMQuotaManager(copyQuotaManagerConfig(rlmConfig), metrics, QuotaType.RLMCopy$.MODULE$, | ||
| "Tracking copy byte-rate for Remote Log Manager", time); | ||
|
|
@@ -757,6 +769,23 @@ public void copyLogSegmentsToRemote(UnifiedLog log) throws InterruptedException | |
| isCancelled(), isLeader()); | ||
| return; | ||
| } | ||
|
|
||
| copyQuotaManagerLock.lock(); | ||
| try { | ||
| while (rlmCopyQuotaManager.isQuotaExceeded()) { | ||
|
satishd marked this conversation as resolved.
|
||
| logger.debug("Quota exceeded for copying log segments, waiting for the quota to be available."); | ||
| // If the thread gets interrupted while waiting, the InterruptedException is thrown | ||
| // back to the caller. It's important to note that the task being executed is already | ||
| // cancelled before the executing thread is interrupted. The caller is responsible | ||
| // for handling the exception gracefully by checking if the task is already cancelled. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you cover shutdown when the quota gets breached as unit test?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will add.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
| boolean ignored = copyQuotaManagerLockCondition.await(quotaTimeout().toMillis(), TimeUnit.MILLISECONDS); | ||
| } | ||
| rlmCopyQuotaManager.record(candidateLogSegment.logSegment.log().sizeInBytes()); | ||
| // Signal waiting threads to check the quota again | ||
| copyQuotaManagerLockCondition.signalAll(); | ||
| } finally { | ||
| copyQuotaManagerLock.unlock(); | ||
| } | ||
| copyLogSegment(log, candidateLogSegment.logSegment, candidateLogSegment.nextSegmentOffset); | ||
| } | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.