-
Notifications
You must be signed in to change notification settings - Fork 25.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new setting to disable persistent tasks allocations (#29137)
This commit adds a new setting `cluster.persistent_tasks.allocation.enable` that can be used to enable or disable the allocation of persistent tasks. The setting accepts the values `all` (default) or `none`. When set to none, the persistent tasks that are created (or that must be reassigned) won't be assigned to a node but will reside in the cluster state with a no "executor node" and a reason describing why it is not assigned: ``` "assignment" : { "executor_node" : null, "explanation" : "persistent task [foo/bar] cannot be assigned [no persistent task assignments are allowed due to cluster settings]" } ```
- Loading branch information
Showing
11 changed files
with
699 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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 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 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
72 changes: 72 additions & 0 deletions
72
server/src/main/java/org/elasticsearch/persistent/decider/AssignmentDecision.java
This file contains 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,72 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch 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.elasticsearch.persistent.decider; | ||
|
||
import java.util.Locale; | ||
import java.util.Objects; | ||
|
||
/** | ||
* {@link AssignmentDecision} represents the decision made during the process of | ||
* assigning a persistent task to a node of the cluster. | ||
* | ||
* @see EnableAssignmentDecider | ||
*/ | ||
public final class AssignmentDecision { | ||
|
||
public static final AssignmentDecision YES = new AssignmentDecision(Type.YES, ""); | ||
|
||
private final Type type; | ||
private final String reason; | ||
|
||
public AssignmentDecision(final Type type, final String reason) { | ||
this.type = Objects.requireNonNull(type); | ||
this.reason = Objects.requireNonNull(reason); | ||
} | ||
|
||
public Type getType() { | ||
return type; | ||
} | ||
|
||
public String getReason() { | ||
return reason; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "assignment decision [type=" + type + ", reason=" + reason + "]"; | ||
} | ||
|
||
public enum Type { | ||
NO(0), YES(1); | ||
|
||
private final int id; | ||
|
||
Type(int id) { | ||
this.id = id; | ||
} | ||
|
||
public int getId() { | ||
return id; | ||
} | ||
|
||
public static Type resolve(final String s) { | ||
return Type.valueOf(s.toUpperCase(Locale.ROOT)); | ||
} | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
server/src/main/java/org/elasticsearch/persistent/decider/EnableAssignmentDecider.java
This file contains 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,101 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch 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.elasticsearch.persistent.decider; | ||
|
||
import org.elasticsearch.common.settings.ClusterSettings; | ||
import org.elasticsearch.common.settings.Setting; | ||
import org.elasticsearch.common.settings.Settings; | ||
|
||
import java.util.Locale; | ||
|
||
import static org.elasticsearch.common.settings.Setting.Property.Dynamic; | ||
import static org.elasticsearch.common.settings.Setting.Property.NodeScope; | ||
|
||
/** | ||
* {@link EnableAssignmentDecider} is used to allow/disallow the persistent tasks | ||
* to be assigned to cluster nodes. | ||
* <p> | ||
* Allocation settings can have the following values (non-casesensitive): | ||
* <ul> | ||
* <li> <code>NONE</code> - no persistent tasks can be assigned | ||
* <li> <code>ALL</code> - all persistent tasks can be assigned to nodes | ||
* </ul> | ||
* | ||
* @see Allocation | ||
*/ | ||
public class EnableAssignmentDecider { | ||
|
||
public static final Setting<Allocation> CLUSTER_TASKS_ALLOCATION_ENABLE_SETTING = | ||
new Setting<>("cluster.persistent_tasks.allocation.enable", Allocation.ALL.toString(), Allocation::fromString, Dynamic, NodeScope); | ||
|
||
private volatile Allocation enableAssignment; | ||
|
||
public EnableAssignmentDecider(final Settings settings, final ClusterSettings clusterSettings) { | ||
this.enableAssignment = CLUSTER_TASKS_ALLOCATION_ENABLE_SETTING.get(settings); | ||
clusterSettings.addSettingsUpdateConsumer(CLUSTER_TASKS_ALLOCATION_ENABLE_SETTING, this::setEnableAssignment); | ||
} | ||
|
||
public void setEnableAssignment(final Allocation enableAssignment) { | ||
this.enableAssignment = enableAssignment; | ||
} | ||
|
||
/** | ||
* Returns a {@link AssignmentDecision} whether the given persistent task can be assigned | ||
* to a node of the cluster. The decision depends on the current value of the setting | ||
* {@link EnableAssignmentDecider#CLUSTER_TASKS_ALLOCATION_ENABLE_SETTING}. | ||
* | ||
* @return the {@link AssignmentDecision} | ||
*/ | ||
public AssignmentDecision canAssign() { | ||
if (enableAssignment == Allocation.NONE) { | ||
return new AssignmentDecision(AssignmentDecision.Type.NO, "no persistent task assignments are allowed due to cluster settings"); | ||
} | ||
return AssignmentDecision.YES; | ||
} | ||
|
||
/** | ||
* Allocation values or rather their string representation to be used used with | ||
* {@link EnableAssignmentDecider#CLUSTER_TASKS_ALLOCATION_ENABLE_SETTING} | ||
* via cluster settings. | ||
*/ | ||
public enum Allocation { | ||
|
||
NONE, | ||
ALL; | ||
|
||
public static Allocation fromString(final String strValue) { | ||
if (strValue == null) { | ||
return null; | ||
} else { | ||
String value = strValue.toUpperCase(Locale.ROOT); | ||
try { | ||
return valueOf(value); | ||
} catch (IllegalArgumentException e) { | ||
throw new IllegalArgumentException("Illegal value [" + value + "] for [" | ||
+ CLUSTER_TASKS_ALLOCATION_ENABLE_SETTING.getKey() + "]"); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return name().toLowerCase(Locale.ROOT); | ||
} | ||
} | ||
} |
This file contains 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
Oops, something went wrong.