Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3.9k
[fix](cloud) Deduplicate pending one-shot warm up jobs#62384
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
Merged
gavinchou
merged 3 commits into
apache:master
from
freemandealer:task-master-pick-pr-8320-to-masterJun 3, 2026
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
210 changes: 209 additions & 1 deletion
210 fe/fe-core/src/main/java/org/apache/doris/cloud/CacheHotspotManager.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -52,6 +52,7 @@ | ||
| import org.apache.doris.thrift.TNetworkAddress; | ||
| import org.apache.doris.thrift.TStatusCode; | ||
| import com.google.common.base.Preconditions; | ||
| import com.google.common.collect.Lists; | ||
| import com.google.common.collect.Maps; | ||
| import org.apache.logging.log4j.LogManager; | ||
| @@ -67,6 +68,7 @@ | ||
| import java.util.Collections; | ||
| import java.util.Comparator; | ||
| import java.util.HashMap; | ||
| import java.util.HashSet; | ||
| import java.util.Iterator; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| @@ -82,6 +84,7 @@ | ||
| import java.util.concurrent.ThreadPoolExecutor; | ||
| import java.util.concurrent.TimeUnit; | ||
| import java.util.concurrent.TimeoutException; | ||
| import java.util.concurrent.locks.ReentrantLock; | ||
| public class CacheHotspotManager extends MasterDaemon { | ||
| public static final int MAX_SHOW_ENTRIES = 2000; | ||
| @@ -109,6 +112,9 @@ public class CacheHotspotManager extends MasterDaemon { | ||
| private ConcurrentMap<Long, CloudWarmUpJob> runnableCloudWarmUpJobs = Maps.newConcurrentMap(); | ||
| private final ConcurrentMap<OncePendingJobKey, RefCountedPendingCreateLock> oncePendingCreateLocks | ||
| = Maps.newConcurrentMap(); | ||
| private final ThreadPoolExecutor cloudWarmUpThreadPool = ThreadPoolManager.newDaemonCacheThreadPool( | ||
| Config.max_active_cloud_warm_up_job, "cloud-warm-up-pool", true); | ||
| @@ -148,10 +154,185 @@ public String toString() { | ||
| } | ||
| } | ||
| private static class OncePendingJobKey { | ||
| private final JobType jobType; | ||
| private final String srcName; | ||
| private final String dstName; | ||
| private final List<String> normalizedTables; | ||
| private final boolean force; | ||
| OncePendingJobKey(JobType jobType, String srcName, String dstName, | ||
| List<String> normalizedTables, boolean force) { | ||
| this.jobType = jobType; | ||
| this.srcName = normalizeNullableName(srcName); | ||
| this.dstName = normalizeNullableName(dstName); | ||
| this.normalizedTables = normalizedTables.isEmpty() | ||
| ? Collections.emptyList() | ||
| : Collections.unmodifiableList(new ArrayList<>(normalizedTables)); | ||
| this.force = force; | ||
| } | ||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) { | ||
| return true; | ||
| } | ||
| if (!(o instanceof OncePendingJobKey)) { | ||
| return false; | ||
| } | ||
| OncePendingJobKey jobKey = (OncePendingJobKey) o; | ||
| return force == jobKey.force | ||
| && jobType == jobKey.jobType | ||
| && Objects.equals(srcName, jobKey.srcName) | ||
| && Objects.equals(dstName, jobKey.dstName) | ||
| && Objects.equals(normalizedTables, jobKey.normalizedTables); | ||
| } | ||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(jobType, srcName, dstName, normalizedTables, force); | ||
| } | ||
| @Override | ||
| public String toString() { | ||
| return "OncePendingWarmUpJob{" | ||
| + "jobType=" + jobType | ||
| + ", src='" + srcName + '\'' | ||
| + ", dst='" + dstName + '\'' | ||
| + ", tables=" + normalizedTables | ||
| + ", force=" + force | ||
| + '}'; | ||
| } | ||
| } | ||
| private static class RefCountedPendingCreateLock { | ||
| private final ReentrantLock lock = new ReentrantLock(); | ||
| // Tracks holders and waiters that retained the entry before locking. | ||
| private volatile int refCount = 1; | ||
| void retain() { | ||
| ++refCount; | ||
| } | ||
| int release() { | ||
| Preconditions.checkState(refCount > 0, "once pending create lock ref count underflow"); | ||
| return --refCount; | ||
| } | ||
| void lock() { | ||
| lock.lock(); | ||
| } | ||
| void unlock() { | ||
| lock.unlock(); | ||
| } | ||
| } | ||
| // Tracks long-running jobs (event-driven and periodic). | ||
| // Ensures only one active job exists per <source, destination, sync_mode> tuple. | ||
| private Set<JobKey> repeatJobDetectionSet = ConcurrentHashMap.newKeySet(); | ||
| private static String normalizeNullableName(String value) { | ||
| return value == null ? "" : value; | ||
| } | ||
| private static String normalizeTableKey(Triple<String, String, String> tableTriple) { | ||
| String dbName = normalizeNullableName(tableTriple.getLeft()); | ||
| String tableName = normalizeNullableName(tableTriple.getMiddle()); | ||
| String partitionName = normalizeNullableName(tableTriple.getRight()); | ||
| if (partitionName.isEmpty()) { | ||
| return dbName + "." + tableName; | ||
| } | ||
| return dbName + "." + tableName + "." + partitionName; | ||
| } | ||
| private static List<String> normalizeTables(List<Triple<String, String, String>> tables) { | ||
| if (tables == null || tables.isEmpty()) { | ||
| return Collections.emptyList(); | ||
| } | ||
| HashSet<String> normalizedTables = new HashSet<>(); | ||
| for (Triple<String, String, String> table : tables) { | ||
| normalizedTables.add(normalizeTableKey(table)); | ||
| } | ||
| List<String> sortedTables = new ArrayList<>(normalizedTables); | ||
| Collections.sort(sortedTables); | ||
| return sortedTables; | ||
| } | ||
| private boolean isClusterOnceCommand(WarmUpClusterCommand command) { | ||
| Map<String, String> properties = command.getProperties(); | ||
| if (properties == null) { | ||
| return true; | ||
| } | ||
| String syncMode = properties.get("sync_mode"); | ||
| return !"periodic".equals(syncMode) && !"event_driven".equals(syncMode); | ||
| } | ||
| private OncePendingJobKey buildOncePendingJobKey(WarmUpClusterCommand command) { | ||
| if (command.isWarmUpWithTable()) { | ||
| return new OncePendingJobKey(JobType.TABLE, "", command.getDstCluster(), | ||
| normalizeTables(command.getTables()), command.isForce()); | ||
| } | ||
| if (!isClusterOnceCommand(command)) { | ||
| return null; | ||
| } | ||
| return new OncePendingJobKey(JobType.CLUSTER, command.getSrcCluster(), | ||
| command.getDstCluster(), Collections.emptyList(), false); | ||
| } | ||
| private OncePendingJobKey buildOncePendingJobKey(CloudWarmUpJob job) { | ||
| if (!job.isOnce()) { | ||
| return null; | ||
| } | ||
| if (job.getJobType() == JobType.TABLE) { | ||
| return new OncePendingJobKey(JobType.TABLE, "", job.getDstClusterName(), | ||
| normalizeTables(job.tables), job.force); | ||
| } | ||
| if (job.getJobType() == JobType.CLUSTER) { | ||
| return new OncePendingJobKey(JobType.CLUSTER, job.getSrcClusterName(), | ||
| job.getDstClusterName(), Collections.emptyList(), false); | ||
| } | ||
| return null; | ||
| } | ||
| private CloudWarmUpJob findExistingPendingOnceJob(OncePendingJobKey key) { | ||
| CloudWarmUpJob selectedJob = null; | ||
| for (CloudWarmUpJob job : cloudWarmUpJobs.values()) { | ||
| if (job.getJobState() != JobState.PENDING || !job.isOnce()) { | ||
| continue; | ||
| } | ||
| OncePendingJobKey existingKey = buildOncePendingJobKey(job); | ||
| if (!key.equals(existingKey)) { | ||
| continue; | ||
| } | ||
| if (selectedJob == null | ||
| || job.getCreateTimeMs() < selectedJob.getCreateTimeMs() | ||
| || (job.getCreateTimeMs() == selectedJob.getCreateTimeMs() | ||
| && job.getJobId() < selectedJob.getJobId())) { | ||
| selectedJob = job; | ||
| } | ||
| } | ||
| return selectedJob; | ||
| } | ||
| private RefCountedPendingCreateLock retainOncePendingCreateLock(OncePendingJobKey key) { | ||
| return oncePendingCreateLocks.compute(key, (ignored, existingLock) -> { | ||
| if (existingLock == null) { | ||
| return new RefCountedPendingCreateLock(); | ||
| } | ||
| existingLock.retain(); | ||
| return existingLock; | ||
| }); | ||
| } | ||
| private void releaseOncePendingCreateLock(OncePendingJobKey key, RefCountedPendingCreateLock lock) { | ||
| oncePendingCreateLocks.compute(key, (ignored, existingLock) -> { | ||
| Preconditions.checkState(existingLock == lock, "unexpected once pending create lock entry"); | ||
| return existingLock.release() == 0 ? null : existingLock; | ||
| }); | ||
| } | ||
| private void registerJobForRepeatDetection(CloudWarmUpJob job, boolean replay) throws AnalysisException { | ||
| if (job.isDone()) { | ||
| return; | ||
| @@ -781,6 +962,31 @@ public Map<Long, List<Tablet>> warmUpNewClusterByTable(long jobId, String dstClu | ||
| } | ||
| public long createJob(WarmUpClusterCommand stmt) throws AnalysisException { | ||
| OncePendingJobKey oncePendingJobKey = buildOncePendingJobKey(stmt); | ||
| if (oncePendingJobKey != null) { | ||
| RefCountedPendingCreateLock createLock = retainOncePendingCreateLock(oncePendingJobKey); | ||
| createLock.lock(); | ||
| try { | ||
| CloudWarmUpJob existingPendingJob = findExistingPendingOnceJob(oncePendingJobKey); | ||
| if (existingPendingJob != null) { | ||
freemandealer marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| long existingJobId = existingPendingJob.getJobId(); | ||
| if (stmt.isWarmUpWithTable()) { | ||
| throw new AnalysisException("Table warm up job already has a pending job, job id: " | ||
| + existingJobId + ". Please retry later."); | ||
| } | ||
| LOG.info("reuse existing pending warm up job {} for key {}", existingJobId, oncePendingJobKey); | ||
| return existingJobId; | ||
| } | ||
| return createJobInternal(stmt); | ||
| } finally { | ||
| createLock.unlock(); | ||
| releaseOncePendingCreateLock(oncePendingJobKey, createLock); | ||
| } | ||
| } | ||
| return createJobInternal(stmt); | ||
| } | ||
| private long createJobInternal(WarmUpClusterCommand stmt) throws AnalysisException { | ||
| long jobId = Env.getCurrentEnv().getNextId(); | ||
| CloudWarmUpJob warmUpJob; | ||
| if (stmt.isWarmUpWithTable()) { | ||
| @@ -800,6 +1006,9 @@ public long createJob(WarmUpClusterCommand stmt) throws AnalysisException { | ||
| .setJobType(JobType.CLUSTER); | ||
| Map<String, String> properties = stmt.getProperties(); | ||
| if (properties == null) { | ||
| properties = Collections.emptyMap(); | ||
| } | ||
| if ("periodic".equals(properties.get("sync_mode"))) { | ||
| String syncIntervalSecStr = properties.get("sync_interval_sec"); | ||
| if (syncIntervalSecStr == null) { | ||
| @@ -831,7 +1040,6 @@ public long createJob(WarmUpClusterCommand stmt) throws AnalysisException { | ||
| } | ||
| warmUpJob = builder.build(); | ||
| } | ||
| addCloudWarmUpJob(warmUpJob); | ||
| Env.getCurrentEnv().getEditLog().logModifyCloudWarmUpJob(warmUpJob); | ||
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes TABLE once-job reuse depend only on the db/table/partition names, but TABLE warm-up jobs materialize
beToTabletIdBatchesimmediately increateJobInternal()viawarmUpNewClusterByTable()and persist those batches in the pendingCloudWarmUpJob. A concrete failure is: createWARM UP TABLE db.tblwithout a partition name, the job stays PENDING, then a new partition is added (or the table/partition is dropped and recreated with the same name), and the user submits the same warm-up command again. The new command should warm the current table contents, but this dedupe path returns the old job id whose tablet batches were computed before the metadata change, so the new tablets are never warmed. Please either key TABLE dedupe on resolved stable table/partition metadata/version (and store enough of it on the job to compare), or avoid reusing TABLE jobs when the current metadata may differ from the precomputed batches.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reasonable, will inform users with that.