[7.10] Fix ignoring existed cluster settings in DataTierAllocationDecider (#67137) (4295d489) (#67180)
Relates to #67133. Seem to #65037. The main changes of this PR are: Modify the construction method of DataTierAllocationDecider, add a param settings like FilterAllocationDecider. Create DataTierAllocationDecider in the main method of DataTierMigrationRoutedStep and SetSingleNodeAllocateStep, and the DataTierAllocationDecider is constructed using the cluster settings in the cluster metadata, so the cluster level _tier filters can be seen when executing the steps. Add some tests for the change. Co-authored-by: bellengao <gbl_long@163.com>
This commit is contained in:
parent
a2a389afdb
commit
b2bfa9ed4f
|
@ -70,11 +70,14 @@ public class DataTierAllocationDecider extends AllocationDecider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private volatile String clusterRequire = null;
|
private volatile String clusterRequire;
|
||||||
private volatile String clusterInclude = null;
|
private volatile String clusterInclude;
|
||||||
private volatile String clusterExclude = null;
|
private volatile String clusterExclude;
|
||||||
|
|
||||||
public DataTierAllocationDecider(ClusterSettings clusterSettings) {
|
public DataTierAllocationDecider(Settings settings, ClusterSettings clusterSettings) {
|
||||||
|
clusterRequire = CLUSTER_ROUTING_REQUIRE_SETTING.get(settings);
|
||||||
|
clusterInclude = CLUSTER_ROUTING_INCLUDE_SETTING.get(settings);
|
||||||
|
clusterExclude = CLUSTER_ROUTING_EXCLUDE_SETTING.get(settings);
|
||||||
clusterSettings.addSettingsUpdateConsumer(CLUSTER_ROUTING_REQUIRE_SETTING, s -> this.clusterRequire = s);
|
clusterSettings.addSettingsUpdateConsumer(CLUSTER_ROUTING_REQUIRE_SETTING, s -> this.clusterRequire = s);
|
||||||
clusterSettings.addSettingsUpdateConsumer(CLUSTER_ROUTING_INCLUDE_SETTING, s -> this.clusterInclude = s);
|
clusterSettings.addSettingsUpdateConsumer(CLUSTER_ROUTING_INCLUDE_SETTING, s -> this.clusterInclude = s);
|
||||||
clusterSettings.addSettingsUpdateConsumer(CLUSTER_ROUTING_EXCLUDE_SETTING, s -> this.clusterExclude = s);
|
clusterSettings.addSettingsUpdateConsumer(CLUSTER_ROUTING_EXCLUDE_SETTING, s -> this.clusterExclude = s);
|
||||||
|
|
|
@ -436,7 +436,7 @@ public class XPackPlugin extends XPackClientPlugin implements ExtensiblePlugin,
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<AllocationDecider> createAllocationDeciders(Settings settings, ClusterSettings clusterSettings) {
|
public Collection<AllocationDecider> createAllocationDeciders(Settings settings, ClusterSettings clusterSettings) {
|
||||||
return Collections.singleton(new DataTierAllocationDecider(clusterSettings));
|
return Collections.singleton(new DataTierAllocationDecider(settings, clusterSettings));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -47,12 +47,6 @@ public class DataTierMigrationRoutedStep extends ClusterStateWaitStep {
|
||||||
ALL_CLUSTER_SETTINGS = allSettings;
|
ALL_CLUSTER_SETTINGS = allSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final AllocationDeciders ALLOCATION_DECIDERS = new AllocationDeciders(
|
|
||||||
org.elasticsearch.common.collect.List.of(
|
|
||||||
new DataTierAllocationDecider(new ClusterSettings(Settings.EMPTY, ALL_CLUSTER_SETTINGS))
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
DataTierMigrationRoutedStep(StepKey key, StepKey nextStepKey) {
|
DataTierMigrationRoutedStep(StepKey key, StepKey nextStepKey) {
|
||||||
super(key, nextStepKey);
|
super(key, nextStepKey);
|
||||||
}
|
}
|
||||||
|
@ -64,6 +58,12 @@ public class DataTierMigrationRoutedStep extends ClusterStateWaitStep {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result isConditionMet(Index index, ClusterState clusterState) {
|
public Result isConditionMet(Index index, ClusterState clusterState) {
|
||||||
|
AllocationDeciders allocationDeciders = new AllocationDeciders(
|
||||||
|
org.elasticsearch.common.collect.List.of(
|
||||||
|
new DataTierAllocationDecider(clusterState.getMetadata().settings(),
|
||||||
|
new ClusterSettings(Settings.EMPTY, ALL_CLUSTER_SETTINGS))
|
||||||
|
)
|
||||||
|
);
|
||||||
IndexMetadata idxMeta = clusterState.metadata().index(index);
|
IndexMetadata idxMeta = clusterState.metadata().index(index);
|
||||||
if (idxMeta == null) {
|
if (idxMeta == null) {
|
||||||
// Index must have been since deleted, ignore it
|
// Index must have been since deleted, ignore it
|
||||||
|
@ -98,7 +98,7 @@ public class DataTierMigrationRoutedStep extends ClusterStateWaitStep {
|
||||||
return new Result(true, null);
|
return new Result(true, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
int allocationPendingAllShards = getPendingAllocations(index, ALLOCATION_DECIDERS, clusterState);
|
int allocationPendingAllShards = getPendingAllocations(index, allocationDeciders, clusterState);
|
||||||
|
|
||||||
if (allocationPendingAllShards > 0) {
|
if (allocationPendingAllShards > 0) {
|
||||||
String statusMessage = availableDestinationTier.map(
|
String statusMessage = availableDestinationTier.map(
|
||||||
|
|
|
@ -75,7 +75,7 @@ public class SetSingleNodeAllocateStep extends AsyncActionStep {
|
||||||
AllocationDeciders allocationDeciders = new AllocationDeciders(Arrays.asList(
|
AllocationDeciders allocationDeciders = new AllocationDeciders(Arrays.asList(
|
||||||
new FilterAllocationDecider(clusterState.getMetadata().settings(),
|
new FilterAllocationDecider(clusterState.getMetadata().settings(),
|
||||||
new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)),
|
new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)),
|
||||||
new DataTierAllocationDecider(new ClusterSettings(Settings.EMPTY, ALL_CLUSTER_SETTINGS)),
|
new DataTierAllocationDecider(clusterState.getMetadata().settings(), new ClusterSettings(Settings.EMPTY, ALL_CLUSTER_SETTINGS)),
|
||||||
new NodeVersionAllocationDecider()
|
new NodeVersionAllocationDecider()
|
||||||
));
|
));
|
||||||
final RoutingNodes routingNodes = clusterState.getRoutingNodes();
|
final RoutingNodes routingNodes = clusterState.getRoutingNodes();
|
||||||
|
|
|
@ -53,7 +53,7 @@ public class DataTierAllocationDeciderTests extends ESAllocationTestCase {
|
||||||
private static final DiscoveryNode DATA_NODE = newNode("node-data", Collections.singleton(DiscoveryNodeRole.DATA_ROLE));
|
private static final DiscoveryNode DATA_NODE = newNode("node-data", Collections.singleton(DiscoveryNodeRole.DATA_ROLE));
|
||||||
|
|
||||||
private final ClusterSettings clusterSettings = new ClusterSettings(Settings.EMPTY, ALL_SETTINGS);
|
private final ClusterSettings clusterSettings = new ClusterSettings(Settings.EMPTY, ALL_SETTINGS);
|
||||||
private final DataTierAllocationDecider decider = new DataTierAllocationDecider(clusterSettings);
|
private final DataTierAllocationDecider decider = new DataTierAllocationDecider(Settings.EMPTY, clusterSettings);
|
||||||
private final AllocationDeciders allocationDeciders = new AllocationDeciders(
|
private final AllocationDeciders allocationDeciders = new AllocationDeciders(
|
||||||
Arrays.asList(decider,
|
Arrays.asList(decider,
|
||||||
new SameShardAllocationDecider(Settings.EMPTY, clusterSettings),
|
new SameShardAllocationDecider(Settings.EMPTY, clusterSettings),
|
||||||
|
@ -648,6 +648,59 @@ public class DataTierAllocationDeciderTests extends ESAllocationTestCase {
|
||||||
equalTo(Optional.of("data_warm")));
|
equalTo(Optional.of("data_warm")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testExistedClusterFilters() {
|
||||||
|
Settings existedSettings = Settings.builder()
|
||||||
|
.put("cluster.routing.allocation.include._tier", "data_hot,data_warm")
|
||||||
|
.put("cluster.routing.allocation.exclude._tier", "data_cold")
|
||||||
|
.build();
|
||||||
|
ClusterSettings clusterSettings = new ClusterSettings(Settings.EMPTY, ALL_SETTINGS);
|
||||||
|
DataTierAllocationDecider dataTierAllocationDecider = new DataTierAllocationDecider(existedSettings, clusterSettings);
|
||||||
|
AllocationDeciders allocationDeciders = new AllocationDeciders(Arrays.asList(dataTierAllocationDecider));
|
||||||
|
AllocationService service = new AllocationService(allocationDeciders,
|
||||||
|
new TestGatewayAllocator(), new BalancedShardsAllocator(Settings.EMPTY), EmptyClusterInfoService.INSTANCE,
|
||||||
|
EmptySnapshotsInfoService.INSTANCE);
|
||||||
|
|
||||||
|
ClusterState clusterState = prepareState(service.reroute(ClusterState.EMPTY_STATE, "initial state"));
|
||||||
|
|
||||||
|
RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, clusterState.getRoutingNodes(), clusterState,
|
||||||
|
null, null, 0);
|
||||||
|
allocation.debugDecision(true);
|
||||||
|
Decision d;
|
||||||
|
RoutingNode node;
|
||||||
|
|
||||||
|
for (DiscoveryNode n : Arrays.asList(HOT_NODE, WARM_NODE)) {
|
||||||
|
node = new RoutingNode(n.getId(), n, shard);
|
||||||
|
d = dataTierAllocationDecider.canAllocate(shard, node, allocation);
|
||||||
|
assertThat(d.type(), equalTo(Decision.Type.YES));
|
||||||
|
d = dataTierAllocationDecider.canRemain(shard, node, allocation);
|
||||||
|
assertThat(d.type(), equalTo(Decision.Type.YES));
|
||||||
|
}
|
||||||
|
|
||||||
|
node = new RoutingNode(DATA_NODE.getId(), DATA_NODE, shard);
|
||||||
|
d = dataTierAllocationDecider.canAllocate(shard, node, allocation);
|
||||||
|
assertThat(d.type(), equalTo(Decision.Type.NO));
|
||||||
|
assertThat(d.getExplanation(),
|
||||||
|
containsString("node matches any cluster setting [cluster.routing.allocation.exclude._tier] " +
|
||||||
|
"tier filters [data_cold]"));
|
||||||
|
d = dataTierAllocationDecider.canRemain(shard, node, allocation);
|
||||||
|
assertThat(d.type(), equalTo(Decision.Type.NO));
|
||||||
|
assertThat(d.getExplanation(),
|
||||||
|
containsString("node matches any cluster setting [cluster.routing.allocation.exclude._tier] " +
|
||||||
|
"tier filters [data_cold]"));
|
||||||
|
|
||||||
|
node = new RoutingNode(COLD_NODE.getId(), COLD_NODE, shard);
|
||||||
|
d = dataTierAllocationDecider.canAllocate(shard, node, allocation);
|
||||||
|
assertThat(d.type(), equalTo(Decision.Type.NO));
|
||||||
|
assertThat(d.getExplanation(),
|
||||||
|
containsString("node does not match any cluster setting [cluster.routing.allocation.include._tier] " +
|
||||||
|
"tier filters [data_hot,data_warm]"));
|
||||||
|
d = dataTierAllocationDecider.canRemain(shard, node, allocation);
|
||||||
|
assertThat(d.type(), equalTo(Decision.Type.NO));
|
||||||
|
assertThat(d.getExplanation(),
|
||||||
|
containsString("node does not match any cluster setting [cluster.routing.allocation.include._tier] " +
|
||||||
|
"tier filters [data_hot,data_warm]"));
|
||||||
|
}
|
||||||
|
|
||||||
private ClusterState prepareState(ClusterState initialState) {
|
private ClusterState prepareState(ClusterState initialState) {
|
||||||
return prepareState(initialState, Settings.EMPTY);
|
return prepareState(initialState, Settings.EMPTY);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue