Skip to content

Commit

Permalink
[7.10] Fix ignoring existed cluster settings in DataTierAllocationDec…
Browse files Browse the repository at this point in the history
…ider (#67137) (4295d48) (#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>
  • Loading branch information
dakrone and gaobinlong committed Jan 7, 2021
1 parent a2a389a commit b2bfa9e
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 15 deletions.
Expand Up @@ -70,11 +70,14 @@ private static void validateTierSetting(String setting) {
}
}

private volatile String clusterRequire = null;
private volatile String clusterInclude = null;
private volatile String clusterExclude = null;

public DataTierAllocationDecider(ClusterSettings clusterSettings) {
private volatile String clusterRequire;
private volatile String clusterInclude;
private volatile String clusterExclude;

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_INCLUDE_SETTING, s -> this.clusterInclude = s);
clusterSettings.addSettingsUpdateConsumer(CLUSTER_ROUTING_EXCLUDE_SETTING, s -> this.clusterExclude = s);
Expand Down
Expand Up @@ -436,7 +436,7 @@ public Set<DiscoveryNodeRole> getRoles() {

@Override
public Collection<AllocationDecider> createAllocationDeciders(Settings settings, ClusterSettings clusterSettings) {
return Collections.singleton(new DataTierAllocationDecider(clusterSettings));
return Collections.singleton(new DataTierAllocationDecider(settings, clusterSettings));
}

@Override
Expand Down
Expand Up @@ -47,12 +47,6 @@ public class DataTierMigrationRoutedStep extends ClusterStateWaitStep {
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) {
super(key, nextStepKey);
}
Expand All @@ -64,6 +58,12 @@ public boolean isRetryable() {

@Override
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);
if (idxMeta == null) {
// Index must have been since deleted, ignore it
Expand Down Expand Up @@ -98,7 +98,7 @@ public Result isConditionMet(Index index, ClusterState clusterState) {
return new Result(true, null);
}

int allocationPendingAllShards = getPendingAllocations(index, ALLOCATION_DECIDERS, clusterState);
int allocationPendingAllShards = getPendingAllocations(index, allocationDeciders, clusterState);

if (allocationPendingAllShards > 0) {
String statusMessage = availableDestinationTier.map(
Expand Down
Expand Up @@ -75,7 +75,7 @@ public void performAction(IndexMetadata indexMetadata, ClusterState clusterState
AllocationDeciders allocationDeciders = new AllocationDeciders(Arrays.asList(
new FilterAllocationDecider(clusterState.getMetadata().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()
));
final RoutingNodes routingNodes = clusterState.getRoutingNodes();
Expand Down
Expand Up @@ -53,7 +53,7 @@ public class DataTierAllocationDeciderTests extends ESAllocationTestCase {
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 DataTierAllocationDecider decider = new DataTierAllocationDecider(clusterSettings);
private final DataTierAllocationDecider decider = new DataTierAllocationDecider(Settings.EMPTY, clusterSettings);
private final AllocationDeciders allocationDeciders = new AllocationDeciders(
Arrays.asList(decider,
new SameShardAllocationDecider(Settings.EMPTY, clusterSettings),
Expand Down Expand Up @@ -648,6 +648,59 @@ public void testPreferredTierAvailable() {
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) {
return prepareState(initialState, Settings.EMPTY);
}
Expand Down

0 comments on commit b2bfa9e

Please sign in to comment.