-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[improvement](tablet scheduler) fix higher priority tablet add failed due to pending queue full #41076
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
Merged
[improvement](tablet scheduler) fix higher priority tablet add failed due to pending queue full #41076
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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 |
|---|---|---|
|
|
@@ -71,6 +71,7 @@ | |
| import com.google.common.collect.ImmutableMap; | ||
| import com.google.common.collect.Lists; | ||
| import com.google.common.collect.Maps; | ||
| import com.google.common.collect.MinMaxPriorityQueue; | ||
| import com.google.common.collect.Sets; | ||
| import com.google.common.collect.Table; | ||
| import org.apache.logging.log4j.LogManager; | ||
|
|
@@ -81,7 +82,6 @@ | |
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Optional; | ||
| import java.util.PriorityQueue; | ||
| import java.util.Queue; | ||
| import java.util.Set; | ||
|
|
||
|
|
@@ -120,7 +120,7 @@ public class TabletScheduler extends MasterDaemon { | |
| * | ||
| * pendingTablets, allTabletTypes, runningTablets and schedHistory are protected by 'synchronized' | ||
| */ | ||
| private PriorityQueue<TabletSchedCtx> pendingTablets = new PriorityQueue<>(); | ||
| private MinMaxPriorityQueue<TabletSchedCtx> pendingTablets = MinMaxPriorityQueue.create(); | ||
| private Map<Long, TabletSchedCtx.Type> allTabletTypes = Maps.newHashMap(); | ||
| // contains all tabletCtxs which state are RUNNING | ||
| private Map<Long, TabletSchedCtx> runningTablets = Maps.newHashMap(); | ||
|
|
@@ -149,6 +149,7 @@ public enum AddResult { | |
| ADDED, // success to add | ||
| ALREADY_IN, // already added, skip | ||
| LIMIT_EXCEED, // number of pending tablets exceed the limit | ||
| REPLACE_ADDED, // succ to add, and envit a lowest task | ||
| DISABLED // scheduler has been disabled. | ||
| } | ||
|
|
||
|
|
@@ -274,12 +275,22 @@ public synchronized AddResult addTablet(TabletSchedCtx tablet, boolean force) { | |
| return AddResult.ALREADY_IN; | ||
| } | ||
|
|
||
| AddResult addResult = AddResult.ADDED; | ||
| // if this is not a force add, | ||
| // and number of scheduling tablets exceed the limit, | ||
| // refuse to add. | ||
| if (!force && (pendingTablets.size() > Config.max_scheduling_tablets | ||
| || runningTablets.size() > Config.max_scheduling_tablets)) { | ||
| return AddResult.LIMIT_EXCEED; | ||
| if (!force && (pendingTablets.size() >= Config.max_scheduling_tablets | ||
| || runningTablets.size() >= Config.max_scheduling_tablets)) { | ||
| // For a sched tablet, if its compare value is bigger, it will be more close to queue's tail position, | ||
| // and its priority is lower. | ||
| TabletSchedCtx lowestPriorityTablet = pendingTablets.peekLast(); | ||
| if (lowestPriorityTablet == null || lowestPriorityTablet.compareTo(tablet) <= 0) { | ||
|
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. add comment
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. added |
||
| return AddResult.LIMIT_EXCEED; | ||
| } | ||
| addResult = AddResult.REPLACE_ADDED; | ||
| pendingTablets.pollLast(); | ||
| finalizeTabletCtx(lowestPriorityTablet, TabletSchedCtx.State.CANCELLED, Status.UNRECOVERABLE, | ||
| "envit lower priority sched tablet because pending queue is full"); | ||
| } | ||
|
|
||
| if (!contains || tablet.getType() == TabletSchedCtx.Type.REPAIR) { | ||
|
|
@@ -291,7 +302,7 @@ public synchronized AddResult addTablet(TabletSchedCtx tablet, boolean force) { | |
| LOG.info("Add tablet to pending queue, {}", tablet); | ||
| } | ||
|
|
||
| return AddResult.ADDED; | ||
| return addResult; | ||
| } | ||
|
|
||
|
|
||
|
|
@@ -312,11 +323,12 @@ public synchronized void cancelRebalanceDisk(AdminCancelRebalanceDiskStmt stmt) | |
| * Iterate current tablets, change their priority to VERY_HIGH if necessary. | ||
| */ | ||
| public synchronized void changeTabletsPriorityToVeryHigh(long dbId, long tblId, List<Long> partitionIds) { | ||
| PriorityQueue<TabletSchedCtx> newPendingTablets = new PriorityQueue<>(); | ||
| MinMaxPriorityQueue<TabletSchedCtx> newPendingTablets = MinMaxPriorityQueue.create(); | ||
| for (TabletSchedCtx tabletCtx : pendingTablets) { | ||
| if (tabletCtx.getDbId() == dbId && tabletCtx.getTblId() == tblId | ||
| && partitionIds.contains(tabletCtx.getPartitionId())) { | ||
| tabletCtx.setPriority(Priority.VERY_HIGH); | ||
| tabletCtx.setLastVisitedTime(1L); | ||
| } | ||
| newPendingTablets.add(tabletCtx); | ||
| } | ||
|
|
@@ -1750,7 +1762,7 @@ private synchronized List<TabletSchedCtx> getNextTabletCtxBatch() { | |
| slotNum = 1; | ||
| } | ||
| while (list.size() < Config.schedule_batch_size && slotNum > 0) { | ||
| TabletSchedCtx tablet = pendingTablets.poll(); | ||
| TabletSchedCtx tablet = pendingTablets.pollFirst(); | ||
| if (tablet == null) { | ||
| // no more tablets | ||
| break; | ||
|
|
@@ -1952,6 +1964,11 @@ public void handleRunningTablets() { | |
| }); | ||
| } | ||
|
|
||
| // only use for fe ut | ||
| public MinMaxPriorityQueue<TabletSchedCtx> getPendingTabletQueue() { | ||
| return pendingTablets; | ||
| } | ||
|
|
||
| public List<List<String>> getPendingTabletsInfo(int limit) { | ||
| return collectTabletCtx(getPendingTablets(limit)); | ||
| } | ||
|
|
||
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
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.
Uh oh!
There was an error while loading. Please reload this page.