Search in sources :

Example 1 with DevNullClusterInfo

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

the class DiskThresholdDeciderUnitTests method testSizeShrinkIndex.

@Test
public void testSizeShrinkIndex() {
    ImmutableOpenMap.Builder<String, Long> shardSizes = ImmutableOpenMap.builder();
    shardSizes.put("[test][0][p]", 10L);
    shardSizes.put("[test][1][p]", 100L);
    shardSizes.put("[test][2][p]", 500L);
    shardSizes.put("[test][3][p]", 500L);
    ClusterInfo info = new DevNullClusterInfo(ImmutableOpenMap.of(), ImmutableOpenMap.of(), shardSizes.build());
    Metadata.Builder metaBuilder = Metadata.builder();
    metaBuilder.put(IndexMetadata.builder("test").settings(settings(Version.CURRENT).put("index.uuid", "1234")).numberOfShards(4).numberOfReplicas(0));
    metaBuilder.put(IndexMetadata.builder("target").settings(settings(Version.CURRENT).put("index.uuid", "5678").put(IndexMetadata.INDEX_RESIZE_SOURCE_NAME_KEY, "test").put(IndexMetadata.INDEX_RESIZE_SOURCE_UUID_KEY, "1234")).numberOfShards(1).numberOfReplicas(0));
    metaBuilder.put(IndexMetadata.builder("target2").settings(settings(Version.CURRENT).put("index.uuid", "9101112").put(IndexMetadata.INDEX_RESIZE_SOURCE_NAME_KEY, "test").put(IndexMetadata.INDEX_RESIZE_SOURCE_UUID_KEY, "1234")).numberOfShards(2).numberOfReplicas(0));
    Metadata metadata = metaBuilder.build();
    RoutingTable.Builder routingTableBuilder = RoutingTable.builder();
    routingTableBuilder.addAsNew(metadata.index("test"));
    routingTableBuilder.addAsNew(metadata.index("target"));
    routingTableBuilder.addAsNew(metadata.index("target2"));
    ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metadata(metadata).routingTable(routingTableBuilder.build()).build();
    AllocationService allocationService = createAllocationService();
    clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1"))).build();
    clusterState = allocationService.reroute(clusterState, "foo");
    clusterState = startShardsAndReroute(allocationService, clusterState, clusterState.getRoutingTable().index("test").shardsWithState(ShardRoutingState.UNASSIGNED));
    RoutingAllocation allocation = new RoutingAllocation(null, clusterState.getRoutingNodes(), clusterState, info, 0);
    final Index index = new Index("test", "1234");
    ShardRouting test_0 = ShardRouting.newUnassigned(new ShardId(index, 0), true, LocalShardsRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"));
    test_0 = ShardRoutingHelper.initialize(test_0, "node1");
    test_0 = ShardRoutingHelper.moveToStarted(test_0);
    ShardRouting test_1 = ShardRouting.newUnassigned(new ShardId(index, 1), true, LocalShardsRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"));
    test_1 = ShardRoutingHelper.initialize(test_1, "node2");
    test_1 = ShardRoutingHelper.moveToStarted(test_1);
    ShardRouting test_2 = ShardRouting.newUnassigned(new ShardId(index, 2), true, LocalShardsRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"));
    test_2 = ShardRoutingHelper.initialize(test_2, "node1");
    ShardRouting test_3 = ShardRouting.newUnassigned(new ShardId(index, 3), true, LocalShardsRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"));
    test_3 = ShardRoutingHelper.initialize(test_3, "node1");
    assertEquals(500L, getExpectedShardSize(test_3, 0L, allocation));
    assertEquals(500L, getExpectedShardSize(test_2, 0L, allocation));
    assertEquals(100L, getExpectedShardSize(test_1, 0L, allocation));
    assertEquals(10L, getExpectedShardSize(test_0, 0L, allocation));
    ShardRouting target = ShardRouting.newUnassigned(new ShardId(new Index("target", "5678"), 0), true, LocalShardsRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"));
    assertEquals(1110L, getExpectedShardSize(target, 0L, allocation));
    ShardRouting target2 = ShardRouting.newUnassigned(new ShardId(new Index("target2", "9101112"), 0), true, LocalShardsRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"));
    assertEquals(110L, getExpectedShardSize(target2, 0L, allocation));
    target2 = ShardRouting.newUnassigned(new ShardId(new Index("target2", "9101112"), 1), true, LocalShardsRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"));
    assertEquals(1000L, getExpectedShardSize(target2, 0L, allocation));
    // check that the DiskThresholdDecider still works even if the source index has been deleted
    ClusterState clusterStateWithMissingSourceIndex = ClusterState.builder(clusterState).metadata(Metadata.builder(metadata).remove("test")).routingTable(RoutingTable.builder(clusterState.routingTable()).remove("test").build()).build();
    allocationService.reroute(clusterState, "foo");
    RoutingAllocation allocationWithMissingSourceIndex = new RoutingAllocation(null, clusterStateWithMissingSourceIndex.getRoutingNodes(), clusterStateWithMissingSourceIndex, info, 0);
    assertEquals(42L, getExpectedShardSize(target, 42L, allocationWithMissingSourceIndex));
    assertEquals(42L, getExpectedShardSize(target2, 42L, allocationWithMissingSourceIndex));
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) UnassignedInfo(org.elasticsearch.cluster.routing.UnassignedInfo) DevNullClusterInfo(org.elasticsearch.cluster.routing.allocation.decider.DiskThresholdDeciderTests.DevNullClusterInfo) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) Metadata(org.elasticsearch.cluster.metadata.Metadata) Index(org.elasticsearch.index.Index) Matchers.containsString(org.hamcrest.Matchers.containsString) ImmutableOpenMap(org.elasticsearch.common.collect.ImmutableOpenMap) ShardId(org.elasticsearch.index.shard.ShardId) DevNullClusterInfo(org.elasticsearch.cluster.routing.allocation.decider.DiskThresholdDeciderTests.DevNullClusterInfo) ClusterInfo(org.elasticsearch.cluster.ClusterInfo) RoutingTable(org.elasticsearch.cluster.routing.RoutingTable) RoutingAllocation(org.elasticsearch.cluster.routing.allocation.RoutingAllocation) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) AllocationService(org.elasticsearch.cluster.routing.allocation.AllocationService) Test(org.junit.Test)

Example 2 with DevNullClusterInfo

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

the class DiskThresholdDeciderUnitTests method testShardSizeAndRelocatingSize.

@Test
public void testShardSizeAndRelocatingSize() {
    ImmutableOpenMap.Builder<String, Long> shardSizes = ImmutableOpenMap.builder();
    shardSizes.put("[test][0][r]", 10L);
    shardSizes.put("[test][1][r]", 100L);
    shardSizes.put("[test][2][r]", 1000L);
    shardSizes.put("[other][0][p]", 10000L);
    ClusterInfo info = new DevNullClusterInfo(ImmutableOpenMap.of(), ImmutableOpenMap.of(), shardSizes.build());
    Metadata.Builder metaBuilder = Metadata.builder();
    metaBuilder.put(IndexMetadata.builder("test").settings(settings(Version.CURRENT).put("index.uuid", "1234")).numberOfShards(3).numberOfReplicas(1));
    metaBuilder.put(IndexMetadata.builder("other").settings(settings(Version.CURRENT).put("index.uuid", "5678")).numberOfShards(1).numberOfReplicas(1));
    Metadata metadata = metaBuilder.build();
    RoutingTable.Builder routingTableBuilder = RoutingTable.builder();
    routingTableBuilder.addAsNew(metadata.index("test"));
    routingTableBuilder.addAsNew(metadata.index("other"));
    ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metadata(metadata).routingTable(routingTableBuilder.build()).build();
    RoutingAllocation allocation = new RoutingAllocation(null, null, clusterState, info, 0);
    final Index index = new Index("test", "1234");
    ShardRouting test_0 = ShardRouting.newUnassigned(new ShardId(index, 0), false, PeerRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"));
    test_0 = ShardRoutingHelper.initialize(test_0, "node1");
    test_0 = ShardRoutingHelper.moveToStarted(test_0);
    test_0 = ShardRoutingHelper.relocate(test_0, "node2");
    ShardRouting test_1 = ShardRouting.newUnassigned(new ShardId(index, 1), false, PeerRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"));
    test_1 = ShardRoutingHelper.initialize(test_1, "node2");
    test_1 = ShardRoutingHelper.moveToStarted(test_1);
    test_1 = ShardRoutingHelper.relocate(test_1, "node1");
    ShardRouting test_2 = ShardRouting.newUnassigned(new ShardId(index, 2), false, PeerRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"));
    test_2 = ShardRoutingHelper.initialize(test_2, "node1");
    test_2 = ShardRoutingHelper.moveToStarted(test_2);
    assertEquals(1000L, getExpectedShardSize(test_2, 0L, allocation));
    assertEquals(100L, getExpectedShardSize(test_1, 0L, allocation));
    assertEquals(10L, getExpectedShardSize(test_0, 0L, allocation));
    RoutingNode node = new RoutingNode("node1", new DiscoveryNode("node1", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT), test_0, test_1.getTargetRelocatingShard(), test_2);
    assertEquals(100L, sizeOfRelocatingShards(allocation, node, false, "/dev/null"));
    assertEquals(90L, sizeOfRelocatingShards(allocation, node, true, "/dev/null"));
    assertEquals(0L, sizeOfRelocatingShards(allocation, node, true, "/dev/some/other/dev"));
    assertEquals(0L, sizeOfRelocatingShards(allocation, node, true, "/dev/some/other/dev"));
    ShardRouting test_3 = ShardRouting.newUnassigned(new ShardId(index, 3), false, PeerRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"));
    test_3 = ShardRoutingHelper.initialize(test_3, "node1");
    test_3 = ShardRoutingHelper.moveToStarted(test_3);
    assertEquals(0L, getExpectedShardSize(test_3, 0L, allocation));
    ShardRouting other_0 = ShardRouting.newUnassigned(new ShardId("other", "5678", 0), randomBoolean(), PeerRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"));
    other_0 = ShardRoutingHelper.initialize(other_0, "node2");
    other_0 = ShardRoutingHelper.moveToStarted(other_0);
    other_0 = ShardRoutingHelper.relocate(other_0, "node1");
    node = new RoutingNode("node1", new DiscoveryNode("node1", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT), test_0, test_1.getTargetRelocatingShard(), test_2, other_0.getTargetRelocatingShard());
    if (other_0.primary()) {
        assertEquals(10100L, sizeOfRelocatingShards(allocation, node, false, "/dev/null"));
        assertEquals(10090L, sizeOfRelocatingShards(allocation, node, true, "/dev/null"));
    } else {
        assertEquals(100L, sizeOfRelocatingShards(allocation, node, false, "/dev/null"));
        assertEquals(90L, sizeOfRelocatingShards(allocation, node, true, "/dev/null"));
    }
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) UnassignedInfo(org.elasticsearch.cluster.routing.UnassignedInfo) DevNullClusterInfo(org.elasticsearch.cluster.routing.allocation.decider.DiskThresholdDeciderTests.DevNullClusterInfo) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) Metadata(org.elasticsearch.cluster.metadata.Metadata) Index(org.elasticsearch.index.Index) Matchers.containsString(org.hamcrest.Matchers.containsString) ImmutableOpenMap(org.elasticsearch.common.collect.ImmutableOpenMap) ShardId(org.elasticsearch.index.shard.ShardId) DevNullClusterInfo(org.elasticsearch.cluster.routing.allocation.decider.DiskThresholdDeciderTests.DevNullClusterInfo) ClusterInfo(org.elasticsearch.cluster.ClusterInfo) RoutingTable(org.elasticsearch.cluster.routing.RoutingTable) RoutingNode(org.elasticsearch.cluster.routing.RoutingNode) RoutingAllocation(org.elasticsearch.cluster.routing.allocation.RoutingAllocation) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) Test(org.junit.Test)

Aggregations

ClusterInfo (org.elasticsearch.cluster.ClusterInfo)2 ClusterState (org.elasticsearch.cluster.ClusterState)2 IndexMetadata (org.elasticsearch.cluster.metadata.IndexMetadata)2 Metadata (org.elasticsearch.cluster.metadata.Metadata)2 RoutingTable (org.elasticsearch.cluster.routing.RoutingTable)2 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)2 UnassignedInfo (org.elasticsearch.cluster.routing.UnassignedInfo)2 RoutingAllocation (org.elasticsearch.cluster.routing.allocation.RoutingAllocation)2 DevNullClusterInfo (org.elasticsearch.cluster.routing.allocation.decider.DiskThresholdDeciderTests.DevNullClusterInfo)2 ImmutableOpenMap (org.elasticsearch.common.collect.ImmutableOpenMap)2 Index (org.elasticsearch.index.Index)2 ShardId (org.elasticsearch.index.shard.ShardId)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 Test (org.junit.Test)2 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)1 RoutingNode (org.elasticsearch.cluster.routing.RoutingNode)1 AllocationService (org.elasticsearch.cluster.routing.allocation.AllocationService)1