-
Notifications
You must be signed in to change notification settings - Fork 25.3k
Create a new monitor for node-level write load #131560
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
DiannaHohensee
merged 5 commits into
elastic:main
from
DiannaHohensee:2025/07/18/node-thread-pool-monitor
Jul 22, 2025
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a1899a3
Create a new monitor for node-level write load
DiannaHohensee 9bcf8ab
[CI] Auto commit changes from spotless
14454c1
rename class
DiannaHohensee 19460b5
Merge branch 'main' into 2025/07/18/node-thread-pool-monitor
DiannaHohensee 8bd66fe
comment touch up
DiannaHohensee 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
88 changes: 88 additions & 0 deletions
88
...rc/main/java/org/elasticsearch/cluster/routing/allocation/WriteLoadConstraintMonitor.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 |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
package org.elasticsearch.cluster.routing.allocation; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.elasticsearch.action.ActionListener; | ||
import org.elasticsearch.cluster.ClusterInfo; | ||
import org.elasticsearch.cluster.ClusterInfoService; | ||
import org.elasticsearch.cluster.ClusterState; | ||
import org.elasticsearch.cluster.routing.RerouteService; | ||
import org.elasticsearch.common.Priority; | ||
import org.elasticsearch.common.settings.ClusterSettings; | ||
import org.elasticsearch.gateway.GatewayService; | ||
|
||
import java.util.function.LongSupplier; | ||
import java.util.function.Supplier; | ||
|
||
/** | ||
* Monitors the node-level write thread pool usage across the cluster and initiates (coming soon) a rebalancing round (via | ||
* {@link RerouteService#reroute}) whenever a node crosses the node-level write load thresholds. | ||
* | ||
* TODO (ES-11992): implement | ||
*/ | ||
public class WriteLoadConstraintMonitor { | ||
private static final Logger logger = LogManager.getLogger(WriteLoadConstraintMonitor.class); | ||
private final WriteLoadConstraintSettings writeLoadConstraintSettings; | ||
private final Supplier<ClusterState> clusterStateSupplier; | ||
private final LongSupplier currentTimeMillisSupplier; | ||
private final RerouteService rerouteService; | ||
|
||
public WriteLoadConstraintMonitor( | ||
ClusterSettings clusterSettings, | ||
LongSupplier currentTimeMillisSupplier, | ||
Supplier<ClusterState> clusterStateSupplier, | ||
RerouteService rerouteService | ||
) { | ||
this.writeLoadConstraintSettings = new WriteLoadConstraintSettings(clusterSettings); | ||
this.clusterStateSupplier = clusterStateSupplier; | ||
this.currentTimeMillisSupplier = currentTimeMillisSupplier; | ||
this.rerouteService = rerouteService; | ||
} | ||
|
||
/** | ||
* Receives a copy of the latest {@link ClusterInfo} whenever the {@link ClusterInfoService} collects it. Processes the new | ||
* {@link org.elasticsearch.cluster.NodeUsageStatsForThreadPools} and initiates rebalancing, via reroute, if a node in the cluster | ||
* exceeds thread pool usage thresholds. | ||
*/ | ||
public void onNewInfo(ClusterInfo clusterInfo) { | ||
final ClusterState state = clusterStateSupplier.get(); | ||
if (state.blocks().hasGlobalBlock(GatewayService.STATE_NOT_RECOVERED_BLOCK)) { | ||
logger.debug("skipping monitor as the cluster state is not recovered yet"); | ||
return; | ||
} | ||
|
||
if (writeLoadConstraintSettings.getWriteLoadConstraintEnabled() == WriteLoadConstraintSettings.WriteLoadDeciderStatus.DISABLED) { | ||
logger.trace("skipping monitor because the write load decider is disabled"); | ||
return; | ||
} | ||
|
||
logger.trace("processing new cluster info"); | ||
|
||
boolean reroute = false; | ||
String explanation = ""; | ||
final long currentTimeMillis = currentTimeMillisSupplier.getAsLong(); | ||
|
||
// TODO (ES-11992): implement | ||
|
||
if (reroute) { | ||
logger.debug("rerouting shards: [{}]", explanation); | ||
rerouteService.reroute("disk threshold monitor", Priority.NORMAL, ActionListener.wrap(ignored -> { | ||
final var reroutedClusterState = clusterStateSupplier.get(); | ||
|
||
// TODO (ES-11992): implement | ||
|
||
}, e -> logger.debug("reroute failed", e))); | ||
} else { | ||
logger.trace("no reroute required"); | ||
} | ||
} | ||
} |
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
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.
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.
We can follow disk allocator naming too, WriteLoadThresholdSettings and WriteLoadThresholdMonitor. I dont see reason for Constraint or Threshold wording here, it's implicit in the name of Monitor. If we monitor something that means there is a value and threshold for this value.
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.
I was hoping to convey the notion of resource constrained shard allocation decisions.
Monitor by itself doesn't imply thresholds or constraints. It says we're watching for something. In the case of WriteLoadMonitor, we're monitoring write load, but we aren't saying for what.
A significant part of this is simply consistency in naming. For example, you can find all the
DiskThreshold*
files with the same prefix. Similarly here,WriteLoadConstraint*
. If we settle on something other than theWriteLoadConstraint*
prefix, I'm inclined to put that in a separate PR to rename the other file as well. The new heap decider logic also follows a prefix pattern -- they in fact did a followup PR for renaming.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.
Went ahead with pushing this so as not to block ES-11992.