Skip to content
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

[fix][broker] Fix thread safety of loadSheddingTask and loadResourceQuotaTask fields #22660

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -517,9 +517,7 @@ public CompletableFuture<Void> closeAsync() {
}

// cancel loadShedding task and shutdown the loadManager executor before shutting down the broker
if (this.loadSheddingTask != null) {
this.loadSheddingTask.cancel();
}
cancelLoadBalancerTasks();
executorServicesShutdown.shutdown(loadManagerExecutor);

List<CompletableFuture<Void>> asyncCloseFutures = new ArrayList<>();
Expand Down Expand Up @@ -1183,20 +1181,7 @@ protected void startLeaderElectionService() {
if (state == LeaderElectionState.Leading) {
LOG.info("This broker {} was elected leader", getBrokerId());
if (getConfiguration().isLoadBalancerEnabled()) {
long resourceQuotaUpdateInterval = TimeUnit.MINUTES
.toMillis(getConfiguration().getLoadBalancerResourceQuotaUpdateIntervalMinutes());

if (loadSheddingTask != null) {
loadSheddingTask.cancel();
}
if (loadResourceQuotaTask != null) {
loadResourceQuotaTask.cancel(false);
}
loadSheddingTask = new LoadSheddingTask(loadManager, loadManagerExecutor, config);
loadSheddingTask.start();
loadResourceQuotaTask = loadManagerExecutor.scheduleAtFixedRate(
new LoadResourceQuotaUpdaterTask(loadManager), resourceQuotaUpdateInterval,
resourceQuotaUpdateInterval, TimeUnit.MILLISECONDS);
startLoadBalancerTasks();
}
} else {
if (leaderElectionService != null) {
Expand All @@ -1209,20 +1194,37 @@ protected void startLeaderElectionService() {
}

}
if (loadSheddingTask != null) {
loadSheddingTask.cancel();
loadSheddingTask = null;
}
if (loadResourceQuotaTask != null) {
loadResourceQuotaTask.cancel(false);
loadResourceQuotaTask = null;
}
cancelLoadBalancerTasks();
}
});

leaderElectionService.start();
}

private synchronized void cancelLoadBalancerTasks() {
if (loadSheddingTask != null) {
loadSheddingTask.cancel();
loadSheddingTask = null;
}
if (loadResourceQuotaTask != null) {
loadResourceQuotaTask.cancel(false);
loadResourceQuotaTask = null;
}
}

private synchronized void startLoadBalancerTasks() {
cancelLoadBalancerTasks();
if (isRunning()) {
long resourceQuotaUpdateInterval = TimeUnit.MINUTES
.toMillis(getConfiguration().getLoadBalancerResourceQuotaUpdateIntervalMinutes());
loadSheddingTask = new LoadSheddingTask(loadManager, loadManagerExecutor, config);
loadSheddingTask.start();
loadResourceQuotaTask = loadManagerExecutor.scheduleAtFixedRate(
new LoadResourceQuotaUpdaterTask(loadManager), resourceQuotaUpdateInterval,
resourceQuotaUpdateInterval, TimeUnit.MILLISECONDS);
}
}

protected void acquireSLANamespace() {
try {
// Namespace not created hence no need to unload it
Expand Down
Loading