github-actions[bot] commented on code in PR #67527:
URL: https://github.com/apache/doris/pull/67527#discussion_r3932142810
##########
fe/fe-core/src/main/java/org/apache/doris/cloud/CacheHotspotManager.java:
##########
@@ -1504,28 +1524,86 @@ public void
cancelTableFilterJobsForClusterChange(String clusterName, String rea
}
}
- private void runCloudWarmUpJob() {
- runnableCloudWarmUpJobs.values().forEach(cloudWarmUpJob -> {
- if (cloudWarmUpJob.shouldWait()) {
- return;
+ @VisibleForTesting
+ void runCloudWarmUpJob() {
+ int maxActiveJobs = Config.max_active_cloud_warm_up_job;
+ if (maxActiveJobs <= 0) {
+ return;
+ }
+
+ if (cloudWarmUpThreadPool.getMaximumPoolSize() != maxActiveJobs) {
+ cloudWarmUpThreadPool.setMaximumPoolSize(maxActiveJobs);
+ LOG.info("resize cloud warm up thread pool to {}", maxActiveJobs);
+ }
+
+ int availableSlots = maxActiveJobs - activeCloudWarmUpJobs.size();
+ if (availableSlots <= 0) {
+ return;
+ }
+
+ // A smaller last-scheduled sequence has higher priority, and
never-scheduled jobs use sequence 0.
+ // For the same sequence, prefer ONCE jobs, then earlier creation
time, then smaller job ID.
+ Comparator<CloudWarmUpJob> schedulePriority = Comparator
+ .comparingLong((CloudWarmUpJob job) ->
+
cloudWarmUpJobLastScheduleSeq.getOrDefault(job.getJobId(), 0L))
Review Comment:
Giving every new job sequence `0` reintroduces starvation under continuous
arrivals. With `max_active_cloud_warm_up_job=1`, let A run once so it becomes
`RUNNING` with sequence 1, then add one new runnable job before each daemon
cycle. The new sequence-0 job always wins the only slot, so A never reaches
later `runRunningJob` steps—including lease renewal, batch progress,
completion, and even timeout handling. Please preserve the first-turn policy
without placing every arrival ahead of all in-progress work, and add a test
that injects arrivals while a RUNNING job must make bounded progress.
##########
fe/fe-core/src/main/java/org/apache/doris/cloud/CacheHotspotManager.java:
##########
@@ -1003,6 +1018,10 @@ private class JobDaemon extends MasterDaemon {
@Override
public void runAfterCatalogReady() {
+ if (getInterval() !=
Config.cloud_warm_up_job_scheduler_interval_millisecond) {
+
setInterval(Config.cloud_warm_up_job_scheduler_interval_millisecond);
Review Comment:
This makes the mutable value live without validating its range. `ADMIN SET
FRONTEND CONFIG` accepts `0` or a negative integer through the default config
handler; `0` makes `Daemon.run()` loop without sleeping, while
`Thread.sleep(-1)` throws an uncaught `IllegalArgumentException` outside the
daemon cycle's try/catch and permanently stops JobDaemon. Please reject
non-positive values with a config callback and cover those updates in the
scheduler tests before applying the interval.
##########
fe/fe-core/src/main/java/org/apache/doris/cloud/CacheHotspotManager.java:
##########
@@ -1504,28 +1524,86 @@ public void
cancelTableFilterJobsForClusterChange(String clusterName, String rea
}
}
- private void runCloudWarmUpJob() {
- runnableCloudWarmUpJobs.values().forEach(cloudWarmUpJob -> {
- if (cloudWarmUpJob.shouldWait()) {
- return;
+ @VisibleForTesting
+ void runCloudWarmUpJob() {
+ int maxActiveJobs = Config.max_active_cloud_warm_up_job;
+ if (maxActiveJobs <= 0) {
+ return;
+ }
+
+ if (cloudWarmUpThreadPool.getMaximumPoolSize() != maxActiveJobs) {
+ cloudWarmUpThreadPool.setMaximumPoolSize(maxActiveJobs);
+ LOG.info("resize cloud warm up thread pool to {}", maxActiveJobs);
+ }
+
+ int availableSlots = maxActiveJobs - activeCloudWarmUpJobs.size();
+ if (availableSlots <= 0) {
+ return;
+ }
+
+ // A smaller last-scheduled sequence has higher priority, and
never-scheduled jobs use sequence 0.
+ // For the same sequence, prefer ONCE jobs, then earlier creation
time, then smaller job ID.
+ Comparator<CloudWarmUpJob> schedulePriority = Comparator
+ .comparingLong((CloudWarmUpJob job) ->
+
cloudWarmUpJobLastScheduleSeq.getOrDefault(job.getJobId(), 0L))
+ .thenComparingInt(job -> job.isOnce() ? 0 : 1)
+ .thenComparingLong(CloudWarmUpJob::getCreateTimeMs)
+ .thenComparingLong(CloudWarmUpJob::getJobId);
+
+ // Keep only the highest-priority jobs needed by this cycle. The
reversed comparator keeps
+ // the lowest-priority selected job at the heap top so it can be
replaced during the scan.
+ PriorityQueue<CloudWarmUpJob> candidates = new
PriorityQueue<>(availableSlots, schedulePriority.reversed());
Review Comment:
This constructor eagerly allocates an `Object[availableSlots]` on every
scheduler cycle. Because `max_active_cloud_warm_up_job` is mutable and has no
upper bound, a high limit causes allocation proportional to the limit even when
only one job is runnable (for example, one million slots is roughly a
million-reference array each second), and a larger accepted value can
repeatedly OOM the daemon. Please use a small/candidate-bounded initial
capacity while keeping `availableSlots` only as the logical heap-size limit.
##########
fe/fe-core/src/main/java/org/apache/doris/cloud/CacheHotspotManager.java:
##########
@@ -1504,28 +1524,86 @@ public void
cancelTableFilterJobsForClusterChange(String clusterName, String rea
}
}
- private void runCloudWarmUpJob() {
- runnableCloudWarmUpJobs.values().forEach(cloudWarmUpJob -> {
- if (cloudWarmUpJob.shouldWait()) {
- return;
+ @VisibleForTesting
+ void runCloudWarmUpJob() {
+ int maxActiveJobs = Config.max_active_cloud_warm_up_job;
+ if (maxActiveJobs <= 0) {
+ return;
+ }
+
+ if (cloudWarmUpThreadPool.getMaximumPoolSize() != maxActiveJobs) {
+ cloudWarmUpThreadPool.setMaximumPoolSize(maxActiveJobs);
+ LOG.info("resize cloud warm up thread pool to {}", maxActiveJobs);
+ }
+
+ int availableSlots = maxActiveJobs - activeCloudWarmUpJobs.size();
+ if (availableSlots <= 0) {
+ return;
+ }
+
+ // A smaller last-scheduled sequence has higher priority, and
never-scheduled jobs use sequence 0.
+ // For the same sequence, prefer ONCE jobs, then earlier creation
time, then smaller job ID.
+ Comparator<CloudWarmUpJob> schedulePriority = Comparator
+ .comparingLong((CloudWarmUpJob job) ->
+
cloudWarmUpJobLastScheduleSeq.getOrDefault(job.getJobId(), 0L))
+ .thenComparingInt(job -> job.isOnce() ? 0 : 1)
+ .thenComparingLong(CloudWarmUpJob::getCreateTimeMs)
+ .thenComparingLong(CloudWarmUpJob::getJobId);
+
+ // Keep only the highest-priority jobs needed by this cycle. The
reversed comparator keeps
+ // the lowest-priority selected job at the heap top so it can be
replaced during the scan.
+ PriorityQueue<CloudWarmUpJob> candidates = new
PriorityQueue<>(availableSlots, schedulePriority.reversed());
+ for (CloudWarmUpJob job : runnableCloudWarmUpJobs.values()) {
+ if (job.shouldWait() || job.isDone() ||
activeCloudWarmUpJobs.containsKey(job.getJobId())) {
+ continue;
}
- if (!cloudWarmUpJob.isDone() &&
!activeCloudWarmUpJobs.containsKey(cloudWarmUpJob.getJobId())
- && activeCloudWarmUpJobs.size() <
Config.max_active_cloud_warm_up_job) {
- if (FeConstants.runningUnitTest) {
- cloudWarmUpJob.run();
- } else {
- cloudWarmUpThreadPool.submit(() -> {
- if
(activeCloudWarmUpJobs.putIfAbsent(cloudWarmUpJob.getJobId(), cloudWarmUpJob)
== null) {
- try {
- cloudWarmUpJob.run();
- } finally {
-
activeCloudWarmUpJobs.remove(cloudWarmUpJob.getJobId());
- }
- }
- });
+ if (candidates.size() < availableSlots) {
+ candidates.offer(job);
+ } else if (schedulePriority.compare(job, candidates.peek()) < 0) {
+ candidates.poll();
+ candidates.offer(job);
+ }
+ }
+
+ List<CloudWarmUpJob> jobsToSchedule = new ArrayList<>(candidates);
+ jobsToSchedule.sort(schedulePriority);
+
+ for (CloudWarmUpJob job : jobsToSchedule) {
+ if (availableSlots <= 0) {
+ break;
+ }
+ long jobId = job.getJobId();
+ if (activeCloudWarmUpJobs.putIfAbsent(jobId, job) != null) {
+ continue;
+ }
+
+ if (FeConstants.runningUnitTest) {
+ cloudWarmUpJobLastScheduleSeq.put(jobId,
cloudWarmUpJobScheduleSeq.incrementAndGet());
+ try {
+ job.run();
+ } finally {
+ activeCloudWarmUpJobs.remove(jobId, job);
}
+ --availableSlots;
+ continue;
}
- });
+
+ try {
+ cloudWarmUpThreadPool.execute(() -> {
Review Comment:
Sorting the `execute()` calls does not guarantee the advertised ONCE-first
useful turn in production. A PENDING ONCE job and a PENDING PERIODIC job may
legally share a destination; the core-0 `SynchronousQueue` pool starts separate
workers, and the worker for the later-submitted periodic job can reach
`tryRegisterRunningJob()` first. It then holds the destination registration
across later RUNNING steps, leaving the preferred ONCE job blocked. The
synchronous Mockito executor makes this inversion impossible. Please
reserve/admit a destination in comparator order and cover the
delayed-first-worker interleaving with a real concurrent-executor test.
##########
fe/fe-core/src/test/java/org/apache/doris/cloud/CacheHotspotManagerSchedulerTest.java:
##########
@@ -0,0 +1,149 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.cloud;
+
+import org.apache.doris.cloud.system.CloudSystemInfoService;
+import org.apache.doris.common.Config;
+import org.apache.doris.common.FeConstants;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.concurrent.RejectedExecutionException;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class CacheHotspotManagerSchedulerTest {
+ private boolean originalRunningUnitTest;
+ private int originalMaxActiveCloudWarmUpJob;
+ private ThreadPoolExecutor executor;
+ private CacheHotspotManager manager;
+
+ @Before
+ public void setUp() {
+ originalRunningUnitTest = FeConstants.runningUnitTest;
+ originalMaxActiveCloudWarmUpJob = Config.max_active_cloud_warm_up_job;
+ FeConstants.runningUnitTest = false;
+ Config.max_active_cloud_warm_up_job = 2;
+
+ executor = Mockito.mock(ThreadPoolExecutor.class);
Review Comment:
All scheduler tests inject a mocked executor, and the rejection test throws
directly from that mock. This does not protect the production wiring the fix
depends on: if the public constructor regresses to the old silent-discard
cached pool, saturated `execute()` returns normally, the scheduler records
history, and the discarded runnable never reaches `finally` to remove its
reservation—yet every test here still passes. Please add a real one-worker
`SynchronousQueue`/throwing-policy test with latches to force rejection and
retry, or at least assert the public constructor's queue and rejection handler.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]