|
19 | 19 |
|
20 | 20 | package org.elasticsearch.cluster; |
21 | 21 |
|
22 | | -import org.elasticsearch.action.admin.indices.create.CreateIndexClusterStateUpdateRequest; |
23 | | -import org.elasticsearch.cluster.metadata.IndexTemplateFilter; |
24 | | -import org.elasticsearch.cluster.metadata.IndexTemplateMetaData; |
25 | 22 | import org.elasticsearch.cluster.node.DiscoveryNode; |
26 | 23 | import org.elasticsearch.cluster.routing.ShardRouting; |
27 | 24 | import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; |
28 | | -import org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator; |
29 | 25 | import org.elasticsearch.cluster.routing.allocation.allocator.ShardsAllocator; |
30 | 26 | import org.elasticsearch.cluster.routing.allocation.decider.AllocationDecider; |
31 | | -import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; |
| 27 | +import org.elasticsearch.cluster.routing.allocation.decider.AwarenessAllocationDecider; |
| 28 | +import org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllocationDecider; |
| 29 | +import org.elasticsearch.cluster.routing.allocation.decider.ConcurrentRebalanceAllocationDecider; |
| 30 | +import org.elasticsearch.cluster.routing.allocation.decider.DiskThresholdDecider; |
32 | 31 | import org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider; |
| 32 | +import org.elasticsearch.cluster.routing.allocation.decider.FilterAllocationDecider; |
| 33 | +import org.elasticsearch.cluster.routing.allocation.decider.MaxRetryAllocationDecider; |
| 34 | +import org.elasticsearch.cluster.routing.allocation.decider.NodeVersionAllocationDecider; |
| 35 | +import org.elasticsearch.cluster.routing.allocation.decider.RebalanceOnlyWhenActiveAllocationDecider; |
| 36 | +import org.elasticsearch.cluster.routing.allocation.decider.ReplicaAfterPrimaryActiveAllocationDecider; |
| 37 | +import org.elasticsearch.cluster.routing.allocation.decider.SameShardAllocationDecider; |
| 38 | +import org.elasticsearch.cluster.routing.allocation.decider.ShardsLimitAllocationDecider; |
| 39 | +import org.elasticsearch.cluster.routing.allocation.decider.SnapshotInProgressAllocationDecider; |
| 40 | +import org.elasticsearch.cluster.routing.allocation.decider.ThrottlingAllocationDecider; |
33 | 41 | import org.elasticsearch.cluster.service.ClusterService; |
34 | 42 | import org.elasticsearch.common.inject.ModuleTestCase; |
35 | 43 | import org.elasticsearch.common.settings.ClusterSettings; |
|
40 | 48 | import org.elasticsearch.common.settings.SettingsModule; |
41 | 49 | import org.elasticsearch.plugins.ClusterPlugin; |
42 | 50 |
|
| 51 | +import java.util.Arrays; |
43 | 52 | import java.util.Collection; |
44 | 53 | import java.util.Collections; |
45 | 54 | import java.util.HashMap; |
| 55 | +import java.util.Iterator; |
| 56 | +import java.util.List; |
46 | 57 | import java.util.Map; |
47 | 58 | import java.util.function.Supplier; |
48 | 59 |
|
@@ -156,4 +167,34 @@ public void testShardsAllocatorFactoryNull() { |
156 | 167 | NullPointerException e = expectThrows(NullPointerException.class, () -> |
157 | 168 | newClusterModuleWithShardsAllocator(settings, "bad", () -> null)); |
158 | 169 | } |
| 170 | + |
| 171 | + // makes sure that the allocation deciders are setup in the correct order, such that the |
| 172 | + // slower allocation deciders come last and we can exit early if there is a NO decision without |
| 173 | + // running them. If the order of the deciders is changed for a valid reason, the order should be |
| 174 | + // changed in the test too. |
| 175 | + public void testAllocationDeciderOrder() { |
| 176 | + List<Class<? extends AllocationDecider>> expectedDeciders = Arrays.asList( |
| 177 | + MaxRetryAllocationDecider.class, |
| 178 | + ReplicaAfterPrimaryActiveAllocationDecider.class, |
| 179 | + RebalanceOnlyWhenActiveAllocationDecider.class, |
| 180 | + ClusterRebalanceAllocationDecider.class, |
| 181 | + ConcurrentRebalanceAllocationDecider.class, |
| 182 | + EnableAllocationDecider.class, |
| 183 | + NodeVersionAllocationDecider.class, |
| 184 | + SnapshotInProgressAllocationDecider.class, |
| 185 | + FilterAllocationDecider.class, |
| 186 | + SameShardAllocationDecider.class, |
| 187 | + DiskThresholdDecider.class, |
| 188 | + ThrottlingAllocationDecider.class, |
| 189 | + ShardsLimitAllocationDecider.class, |
| 190 | + AwarenessAllocationDecider.class); |
| 191 | + Collection<AllocationDecider> deciders = ClusterModule.createAllocationDeciders(Settings.EMPTY, |
| 192 | + new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), Collections.emptyList()); |
| 193 | + Iterator<AllocationDecider> iter = deciders.iterator(); |
| 194 | + int idx = 0; |
| 195 | + while (iter.hasNext()) { |
| 196 | + AllocationDecider decider = iter.next(); |
| 197 | + assertSame(decider.getClass(), expectedDeciders.get(idx++)); |
| 198 | + } |
| 199 | + } |
159 | 200 | } |
0 commit comments