Search in sources :

Example 1 with NodeVersionAllocationDecider

use of org.elasticsearch.cluster.routing.allocation.decider.NodeVersionAllocationDecider in project elasticsearch by elastic.

the class ClusterModule method createAllocationDeciders.

// TODO: this is public so allocation benchmark can access the default deciders...can we do that in another way?
/** Return a new {@link AllocationDecider} instance with builtin deciders as well as those from plugins. */
public static Collection<AllocationDecider> createAllocationDeciders(Settings settings, ClusterSettings clusterSettings, List<ClusterPlugin> clusterPlugins) {
    // collect deciders by class so that we can detect duplicates
    Map<Class, AllocationDecider> deciders = new LinkedHashMap<>();
    addAllocationDecider(deciders, new MaxRetryAllocationDecider(settings));
    addAllocationDecider(deciders, new ReplicaAfterPrimaryActiveAllocationDecider(settings));
    addAllocationDecider(deciders, new RebalanceOnlyWhenActiveAllocationDecider(settings));
    addAllocationDecider(deciders, new ClusterRebalanceAllocationDecider(settings, clusterSettings));
    addAllocationDecider(deciders, new ConcurrentRebalanceAllocationDecider(settings, clusterSettings));
    addAllocationDecider(deciders, new EnableAllocationDecider(settings, clusterSettings));
    addAllocationDecider(deciders, new NodeVersionAllocationDecider(settings));
    addAllocationDecider(deciders, new SnapshotInProgressAllocationDecider(settings));
    addAllocationDecider(deciders, new FilterAllocationDecider(settings, clusterSettings));
    addAllocationDecider(deciders, new SameShardAllocationDecider(settings, clusterSettings));
    addAllocationDecider(deciders, new DiskThresholdDecider(settings, clusterSettings));
    addAllocationDecider(deciders, new ThrottlingAllocationDecider(settings, clusterSettings));
    addAllocationDecider(deciders, new ShardsLimitAllocationDecider(settings, clusterSettings));
    addAllocationDecider(deciders, new AwarenessAllocationDecider(settings, clusterSettings));
    clusterPlugins.stream().flatMap(p -> p.createAllocationDeciders(settings, clusterSettings).stream()).forEach(d -> addAllocationDecider(deciders, d));
    return deciders.values();
}
Also used : MetaData(org.elasticsearch.cluster.metadata.MetaData) DelayedAllocationService(org.elasticsearch.cluster.routing.DelayedAllocationService) IngestMetadata(org.elasticsearch.ingest.IngestMetadata) AwarenessAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.AwarenessAllocationDecider) Property(org.elasticsearch.common.settings.Setting.Property) SameShardAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.SameShardAllocationDecider) AllocationService(org.elasticsearch.cluster.routing.allocation.AllocationService) Reader(org.elasticsearch.common.io.stream.Writeable.Reader) ConcurrentRebalanceAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.ConcurrentRebalanceAllocationDecider) ClusterPlugin(org.elasticsearch.plugins.ClusterPlugin) Settings(org.elasticsearch.common.settings.Settings) SnapshotInProgressAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.SnapshotInProgressAllocationDecider) Map(java.util.Map) TaskResultsService(org.elasticsearch.tasks.TaskResultsService) ParseField(org.elasticsearch.common.ParseField) NamedXContentRegistry(org.elasticsearch.common.xcontent.NamedXContentRegistry) ShardsLimitAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.ShardsLimitAllocationDecider) MappingUpdatedAction(org.elasticsearch.cluster.action.index.MappingUpdatedAction) BalancedShardsAllocator(org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator) Setting(org.elasticsearch.common.settings.Setting) AbstractModule(org.elasticsearch.common.inject.AbstractModule) DiskThresholdDecider(org.elasticsearch.cluster.routing.allocation.decider.DiskThresholdDecider) Collection(java.util.Collection) NodeMappingRefreshAction(org.elasticsearch.cluster.action.index.NodeMappingRefreshAction) Objects(java.util.Objects) RebalanceOnlyWhenActiveAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.RebalanceOnlyWhenActiveAllocationDecider) List(java.util.List) ShardStateAction(org.elasticsearch.cluster.action.shard.ShardStateAction) AllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.AllocationDecider) NodeVersionAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.NodeVersionAllocationDecider) FilterAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.FilterAllocationDecider) ThrottlingAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.ThrottlingAllocationDecider) MetaDataCreateIndexService(org.elasticsearch.cluster.metadata.MetaDataCreateIndexService) ReplicaAfterPrimaryActiveAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.ReplicaAfterPrimaryActiveAllocationDecider) MaxRetryAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.MaxRetryAllocationDecider) ClusterService(org.elasticsearch.cluster.service.ClusterService) NamedWriteable(org.elasticsearch.common.io.stream.NamedWriteable) IndexGraveyard(org.elasticsearch.cluster.metadata.IndexGraveyard) HashMap(java.util.HashMap) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) MetaDataUpdateSettingsService(org.elasticsearch.cluster.metadata.MetaDataUpdateSettingsService) NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) AllocationDeciders(org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders) ClusterRebalanceAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllocationDecider) EnableAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider) RepositoriesMetaData(org.elasticsearch.cluster.metadata.RepositoriesMetaData) MetaDataIndexAliasesService(org.elasticsearch.cluster.metadata.MetaDataIndexAliasesService) ShardsAllocator(org.elasticsearch.cluster.routing.allocation.allocator.ShardsAllocator) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) MetaDataIndexTemplateService(org.elasticsearch.cluster.metadata.MetaDataIndexTemplateService) ScriptMetaData(org.elasticsearch.script.ScriptMetaData) MetaDataMappingService(org.elasticsearch.cluster.metadata.MetaDataMappingService) RoutingService(org.elasticsearch.cluster.routing.RoutingService) MetaDataDeleteIndexService(org.elasticsearch.cluster.metadata.MetaDataDeleteIndexService) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) Writeable(org.elasticsearch.common.io.stream.Writeable) GatewayAllocator(org.elasticsearch.gateway.GatewayAllocator) MetaDataIndexStateService(org.elasticsearch.cluster.metadata.MetaDataIndexStateService) Entry(org.elasticsearch.common.io.stream.NamedWriteableRegistry.Entry) SnapshotInProgressAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.SnapshotInProgressAllocationDecider) EnableAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider) RebalanceOnlyWhenActiveAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.RebalanceOnlyWhenActiveAllocationDecider) ThrottlingAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.ThrottlingAllocationDecider) MaxRetryAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.MaxRetryAllocationDecider) ReplicaAfterPrimaryActiveAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.ReplicaAfterPrimaryActiveAllocationDecider) LinkedHashMap(java.util.LinkedHashMap) ClusterRebalanceAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllocationDecider) SameShardAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.SameShardAllocationDecider) FilterAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.FilterAllocationDecider) DiskThresholdDecider(org.elasticsearch.cluster.routing.allocation.decider.DiskThresholdDecider) ShardsLimitAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.ShardsLimitAllocationDecider) AwarenessAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.AwarenessAllocationDecider) NodeVersionAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.NodeVersionAllocationDecider) AwarenessAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.AwarenessAllocationDecider) SameShardAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.SameShardAllocationDecider) ConcurrentRebalanceAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.ConcurrentRebalanceAllocationDecider) SnapshotInProgressAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.SnapshotInProgressAllocationDecider) ShardsLimitAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.ShardsLimitAllocationDecider) RebalanceOnlyWhenActiveAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.RebalanceOnlyWhenActiveAllocationDecider) AllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.AllocationDecider) NodeVersionAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.NodeVersionAllocationDecider) FilterAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.FilterAllocationDecider) ThrottlingAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.ThrottlingAllocationDecider) ReplicaAfterPrimaryActiveAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.ReplicaAfterPrimaryActiveAllocationDecider) MaxRetryAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.MaxRetryAllocationDecider) ClusterRebalanceAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllocationDecider) EnableAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider) ConcurrentRebalanceAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.ConcurrentRebalanceAllocationDecider)

Example 2 with NodeVersionAllocationDecider

use of org.elasticsearch.cluster.routing.allocation.decider.NodeVersionAllocationDecider in project elasticsearch by elastic.

the class NodeVersionAllocationDeciderTests method testRebalanceDoesNotAllocatePrimaryAndReplicasOnDifferentVersionNodes.

public void testRebalanceDoesNotAllocatePrimaryAndReplicasOnDifferentVersionNodes() {
    ShardId shard1 = new ShardId("test1", "_na_", 0);
    ShardId shard2 = new ShardId("test2", "_na_", 0);
    final DiscoveryNode newNode = new DiscoveryNode("newNode", buildNewFakeTransportAddress(), emptyMap(), MASTER_DATA_ROLES, Version.CURRENT);
    final DiscoveryNode oldNode1 = new DiscoveryNode("oldNode1", buildNewFakeTransportAddress(), emptyMap(), MASTER_DATA_ROLES, VersionUtils.getPreviousVersion());
    final DiscoveryNode oldNode2 = new DiscoveryNode("oldNode2", buildNewFakeTransportAddress(), emptyMap(), MASTER_DATA_ROLES, VersionUtils.getPreviousVersion());
    AllocationId allocationId1P = AllocationId.newInitializing();
    AllocationId allocationId1R = AllocationId.newInitializing();
    AllocationId allocationId2P = AllocationId.newInitializing();
    AllocationId allocationId2R = AllocationId.newInitializing();
    MetaData metaData = MetaData.builder().put(IndexMetaData.builder(shard1.getIndexName()).settings(settings(Version.CURRENT).put(Settings.EMPTY)).numberOfShards(1).numberOfReplicas(1).putInSyncAllocationIds(0, Sets.newHashSet(allocationId1P.getId(), allocationId1R.getId()))).put(IndexMetaData.builder(shard2.getIndexName()).settings(settings(Version.CURRENT).put(Settings.EMPTY)).numberOfShards(1).numberOfReplicas(1).putInSyncAllocationIds(0, Sets.newHashSet(allocationId2P.getId(), allocationId2R.getId()))).build();
    RoutingTable routingTable = RoutingTable.builder().add(IndexRoutingTable.builder(shard1.getIndex()).addIndexShard(new IndexShardRoutingTable.Builder(shard1).addShard(TestShardRouting.newShardRouting(shard1.getIndexName(), shard1.getId(), newNode.getId(), null, true, ShardRoutingState.STARTED, allocationId1P)).addShard(TestShardRouting.newShardRouting(shard1.getIndexName(), shard1.getId(), oldNode1.getId(), null, false, ShardRoutingState.STARTED, allocationId1R)).build())).add(IndexRoutingTable.builder(shard2.getIndex()).addIndexShard(new IndexShardRoutingTable.Builder(shard2).addShard(TestShardRouting.newShardRouting(shard2.getIndexName(), shard2.getId(), newNode.getId(), null, true, ShardRoutingState.STARTED, allocationId2P)).addShard(TestShardRouting.newShardRouting(shard2.getIndexName(), shard2.getId(), oldNode1.getId(), null, false, ShardRoutingState.STARTED, allocationId2R)).build())).build();
    ClusterState state = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).nodes(DiscoveryNodes.builder().add(newNode).add(oldNode1).add(oldNode2)).build();
    AllocationDeciders allocationDeciders = new AllocationDeciders(Settings.EMPTY, Collections.singleton(new NodeVersionAllocationDecider(Settings.EMPTY)));
    AllocationService strategy = new MockAllocationService(Settings.EMPTY, allocationDeciders, new TestGatewayAllocator(), new BalancedShardsAllocator(Settings.EMPTY), EmptyClusterInfoService.INSTANCE);
    state = strategy.reroute(state, new AllocationCommands(), true, false).getClusterState();
    // the two indices must stay as is, the replicas cannot move to oldNode2 because versions don't match
    assertThat(state.routingTable().index(shard2.getIndex()).shardsWithState(ShardRoutingState.RELOCATING).size(), equalTo(0));
    assertThat(state.routingTable().index(shard1.getIndex()).shardsWithState(ShardRoutingState.RELOCATING).size(), equalTo(0));
}
Also used : TestGatewayAllocator(org.elasticsearch.test.gateway.TestGatewayAllocator) IndexShardRoutingTable(org.elasticsearch.cluster.routing.IndexShardRoutingTable) ClusterState(org.elasticsearch.cluster.ClusterState) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) BalancedShardsAllocator(org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator) AllocationId(org.elasticsearch.cluster.routing.AllocationId) AllocationDeciders(org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders) AllocationCommands(org.elasticsearch.cluster.routing.allocation.command.AllocationCommands) ShardId(org.elasticsearch.index.shard.ShardId) IndexShardRoutingTable(org.elasticsearch.cluster.routing.IndexShardRoutingTable) IndexRoutingTable(org.elasticsearch.cluster.routing.IndexRoutingTable) RoutingTable(org.elasticsearch.cluster.routing.RoutingTable) MetaData(org.elasticsearch.cluster.metadata.MetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) NodeVersionAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.NodeVersionAllocationDecider)

Example 3 with NodeVersionAllocationDecider

use of org.elasticsearch.cluster.routing.allocation.decider.NodeVersionAllocationDecider in project crate by crate.

the class NodeVersionAllocationDeciderTests method testRestoreDoesNotAllocateSnapshotOnOlderNodes.

public void testRestoreDoesNotAllocateSnapshotOnOlderNodes() {
    final DiscoveryNode newNode = new DiscoveryNode("newNode", buildNewFakeTransportAddress(), emptyMap(), MASTER_DATA_ROLES, Version.CURRENT);
    final DiscoveryNode oldNode1 = new DiscoveryNode("oldNode1", buildNewFakeTransportAddress(), emptyMap(), MASTER_DATA_ROLES, VersionUtils.getPreviousVersion());
    final DiscoveryNode oldNode2 = new DiscoveryNode("oldNode2", buildNewFakeTransportAddress(), emptyMap(), MASTER_DATA_ROLES, VersionUtils.getPreviousVersion());
    int numberOfShards = randomIntBetween(1, 3);
    final IndexMetadata.Builder indexMetadata = IndexMetadata.builder("test").settings(settings(Version.CURRENT).put(AutoExpandReplicas.SETTING.getKey(), false)).numberOfShards(numberOfShards).numberOfReplicas(randomIntBetween(0, 3));
    for (int i = 0; i < numberOfShards; i++) {
        indexMetadata.putInSyncAllocationIds(i, Collections.singleton("_test_"));
    }
    Metadata metadata = Metadata.builder().put(indexMetadata).build();
    ClusterState state = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metadata(metadata).routingTable(RoutingTable.builder().addAsRestore(metadata.index("test"), new SnapshotRecoverySource(UUIDs.randomBase64UUID(), new Snapshot("rep1", new SnapshotId("snp1", UUIDs.randomBase64UUID())), Version.CURRENT, "test")).build()).nodes(DiscoveryNodes.builder().add(newNode).add(oldNode1).add(oldNode2)).build();
    AllocationDeciders allocationDeciders = new AllocationDeciders(Arrays.asList(new ReplicaAfterPrimaryActiveAllocationDecider(), new NodeVersionAllocationDecider()));
    AllocationService strategy = new MockAllocationService(allocationDeciders, new TestGatewayAllocator(), new BalancedShardsAllocator(Settings.EMPTY), EmptyClusterInfoService.INSTANCE);
    state = strategy.reroute(state, new AllocationCommands(), true, false).getClusterState();
    // Make sure that primary shards are only allocated on the new node
    for (int i = 0; i < numberOfShards; i++) {
        assertEquals("newNode", state.routingTable().index("test").getShards().get(i).primaryShard().currentNodeId());
    }
}
Also used : TestGatewayAllocator(org.elasticsearch.test.gateway.TestGatewayAllocator) ClusterState(org.elasticsearch.cluster.ClusterState) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) BalancedShardsAllocator(org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) Metadata(org.elasticsearch.cluster.metadata.Metadata) AllocationDeciders(org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders) ReplicaAfterPrimaryActiveAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.ReplicaAfterPrimaryActiveAllocationDecider) AllocationCommands(org.elasticsearch.cluster.routing.allocation.command.AllocationCommands) Snapshot(org.elasticsearch.snapshots.Snapshot) SnapshotId(org.elasticsearch.snapshots.SnapshotId) SnapshotRecoverySource(org.elasticsearch.cluster.routing.RecoverySource.SnapshotRecoverySource) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) NodeVersionAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.NodeVersionAllocationDecider)

Example 4 with NodeVersionAllocationDecider

use of org.elasticsearch.cluster.routing.allocation.decider.NodeVersionAllocationDecider in project crate by crate.

the class NodeVersionAllocationDeciderTests method testRebalanceDoesNotAllocatePrimaryAndReplicasOnDifferentVersionNodes.

public void testRebalanceDoesNotAllocatePrimaryAndReplicasOnDifferentVersionNodes() {
    ShardId shard1 = new ShardId("test1", "_na_", 0);
    ShardId shard2 = new ShardId("test2", "_na_", 0);
    final DiscoveryNode newNode = new DiscoveryNode("newNode", buildNewFakeTransportAddress(), emptyMap(), MASTER_DATA_ROLES, Version.CURRENT);
    final DiscoveryNode oldNode1 = new DiscoveryNode("oldNode1", buildNewFakeTransportAddress(), emptyMap(), MASTER_DATA_ROLES, VersionUtils.getPreviousVersion());
    final DiscoveryNode oldNode2 = new DiscoveryNode("oldNode2", buildNewFakeTransportAddress(), emptyMap(), MASTER_DATA_ROLES, VersionUtils.getPreviousVersion());
    AllocationId allocationId1P = AllocationId.newInitializing();
    AllocationId allocationId1R = AllocationId.newInitializing();
    AllocationId allocationId2P = AllocationId.newInitializing();
    AllocationId allocationId2R = AllocationId.newInitializing();
    Metadata metadata = Metadata.builder().put(IndexMetadata.builder(shard1.getIndexName()).settings(settings(Version.CURRENT).put(Settings.EMPTY)).numberOfShards(1).numberOfReplicas(1).putInSyncAllocationIds(0, Set.of(allocationId1P.getId(), allocationId1R.getId()))).put(IndexMetadata.builder(shard2.getIndexName()).settings(settings(Version.CURRENT).put(Settings.EMPTY)).numberOfShards(1).numberOfReplicas(1).putInSyncAllocationIds(0, Set.of(allocationId2P.getId(), allocationId2R.getId()))).build();
    RoutingTable routingTable = RoutingTable.builder().add(IndexRoutingTable.builder(shard1.getIndex()).addIndexShard(new IndexShardRoutingTable.Builder(shard1).addShard(TestShardRouting.newShardRouting(shard1.getIndexName(), shard1.getId(), newNode.getId(), null, true, ShardRoutingState.STARTED, allocationId1P)).addShard(TestShardRouting.newShardRouting(shard1.getIndexName(), shard1.getId(), oldNode1.getId(), null, false, ShardRoutingState.STARTED, allocationId1R)).build())).add(IndexRoutingTable.builder(shard2.getIndex()).addIndexShard(new IndexShardRoutingTable.Builder(shard2).addShard(TestShardRouting.newShardRouting(shard2.getIndexName(), shard2.getId(), newNode.getId(), null, true, ShardRoutingState.STARTED, allocationId2P)).addShard(TestShardRouting.newShardRouting(shard2.getIndexName(), shard2.getId(), oldNode1.getId(), null, false, ShardRoutingState.STARTED, allocationId2R)).build())).build();
    ClusterState state = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metadata(metadata).routingTable(routingTable).nodes(DiscoveryNodes.builder().add(newNode).add(oldNode1).add(oldNode2)).build();
    AllocationDeciders allocationDeciders = new AllocationDeciders(Collections.singleton(new NodeVersionAllocationDecider()));
    AllocationService strategy = new MockAllocationService(allocationDeciders, new TestGatewayAllocator(), new BalancedShardsAllocator(Settings.EMPTY), EmptyClusterInfoService.INSTANCE);
    state = strategy.reroute(state, new AllocationCommands(), true, false).getClusterState();
    // the two indices must stay as is, the replicas cannot move to oldNode2 because versions don't match
    assertThat(state.routingTable().index(shard2.getIndex()).shardsWithState(ShardRoutingState.RELOCATING).size(), equalTo(0));
    assertThat(state.routingTable().index(shard1.getIndex()).shardsWithState(ShardRoutingState.RELOCATING).size(), equalTo(0));
}
Also used : TestGatewayAllocator(org.elasticsearch.test.gateway.TestGatewayAllocator) IndexShardRoutingTable(org.elasticsearch.cluster.routing.IndexShardRoutingTable) ClusterState(org.elasticsearch.cluster.ClusterState) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) BalancedShardsAllocator(org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator) AllocationId(org.elasticsearch.cluster.routing.AllocationId) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) Metadata(org.elasticsearch.cluster.metadata.Metadata) AllocationDeciders(org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders) AllocationCommands(org.elasticsearch.cluster.routing.allocation.command.AllocationCommands) ShardId(org.elasticsearch.index.shard.ShardId) IndexShardRoutingTable(org.elasticsearch.cluster.routing.IndexShardRoutingTable) IndexRoutingTable(org.elasticsearch.cluster.routing.IndexRoutingTable) RoutingTable(org.elasticsearch.cluster.routing.RoutingTable) NodeVersionAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.NodeVersionAllocationDecider)

Example 5 with NodeVersionAllocationDecider

use of org.elasticsearch.cluster.routing.allocation.decider.NodeVersionAllocationDecider in project elasticsearch by elastic.

the class NodeVersionAllocationDeciderTests method testRestoreDoesNotAllocateSnapshotOnOlderNodes.

public void testRestoreDoesNotAllocateSnapshotOnOlderNodes() {
    final DiscoveryNode newNode = new DiscoveryNode("newNode", buildNewFakeTransportAddress(), emptyMap(), MASTER_DATA_ROLES, Version.CURRENT);
    final DiscoveryNode oldNode1 = new DiscoveryNode("oldNode1", buildNewFakeTransportAddress(), emptyMap(), MASTER_DATA_ROLES, VersionUtils.getPreviousVersion());
    final DiscoveryNode oldNode2 = new DiscoveryNode("oldNode2", buildNewFakeTransportAddress(), emptyMap(), MASTER_DATA_ROLES, VersionUtils.getPreviousVersion());
    int numberOfShards = randomIntBetween(1, 3);
    final IndexMetaData.Builder indexMetaData = IndexMetaData.builder("test").settings(settings(Version.CURRENT)).numberOfShards(numberOfShards).numberOfReplicas(randomIntBetween(0, 3));
    for (int i = 0; i < numberOfShards; i++) {
        indexMetaData.putInSyncAllocationIds(i, Collections.singleton("_test_"));
    }
    MetaData metaData = MetaData.builder().put(indexMetaData).build();
    ClusterState state = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(RoutingTable.builder().addAsRestore(metaData.index("test"), new SnapshotRecoverySource(new Snapshot("rep1", new SnapshotId("snp1", UUIDs.randomBase64UUID())), Version.CURRENT, "test")).build()).nodes(DiscoveryNodes.builder().add(newNode).add(oldNode1).add(oldNode2)).build();
    AllocationDeciders allocationDeciders = new AllocationDeciders(Settings.EMPTY, Arrays.asList(new ReplicaAfterPrimaryActiveAllocationDecider(Settings.EMPTY), new NodeVersionAllocationDecider(Settings.EMPTY)));
    AllocationService strategy = new MockAllocationService(Settings.EMPTY, allocationDeciders, new TestGatewayAllocator(), new BalancedShardsAllocator(Settings.EMPTY), EmptyClusterInfoService.INSTANCE);
    state = strategy.reroute(state, new AllocationCommands(), true, false).getClusterState();
    // Make sure that primary shards are only allocated on the new node
    for (int i = 0; i < numberOfShards; i++) {
        assertEquals("newNode", state.routingTable().index("test").getShards().get(i).primaryShard().currentNodeId());
    }
}
Also used : TestGatewayAllocator(org.elasticsearch.test.gateway.TestGatewayAllocator) ClusterState(org.elasticsearch.cluster.ClusterState) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) BalancedShardsAllocator(org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator) AllocationDeciders(org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders) ReplicaAfterPrimaryActiveAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.ReplicaAfterPrimaryActiveAllocationDecider) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) AllocationCommands(org.elasticsearch.cluster.routing.allocation.command.AllocationCommands) Snapshot(org.elasticsearch.snapshots.Snapshot) SnapshotId(org.elasticsearch.snapshots.SnapshotId) SnapshotRecoverySource(org.elasticsearch.cluster.routing.RecoverySource.SnapshotRecoverySource) MetaData(org.elasticsearch.cluster.metadata.MetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) NodeVersionAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.NodeVersionAllocationDecider)

Aggregations

NodeVersionAllocationDecider (org.elasticsearch.cluster.routing.allocation.decider.NodeVersionAllocationDecider)8 BalancedShardsAllocator (org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator)7 AllocationDeciders (org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders)7 ClusterState (org.elasticsearch.cluster.ClusterState)6 Metadata (org.elasticsearch.cluster.metadata.Metadata)5 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)5 TestGatewayAllocator (org.elasticsearch.test.gateway.TestGatewayAllocator)5 IndexMetadata (org.elasticsearch.cluster.metadata.IndexMetadata)4 IndexRoutingTable (org.elasticsearch.cluster.routing.IndexRoutingTable)4 IndexShardRoutingTable (org.elasticsearch.cluster.routing.IndexShardRoutingTable)4 RoutingTable (org.elasticsearch.cluster.routing.RoutingTable)4 ReplicaAfterPrimaryActiveAllocationDecider (org.elasticsearch.cluster.routing.allocation.decider.ReplicaAfterPrimaryActiveAllocationDecider)4 ShardId (org.elasticsearch.index.shard.ShardId)4 MetaData (org.elasticsearch.cluster.metadata.MetaData)3 AllocationCommands (org.elasticsearch.cluster.routing.allocation.command.AllocationCommands)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2