Search in sources :

Example 21 with MetaData

use of org.elasticsearch.cluster.metadata.MetaData in project elasticsearch by elastic.

the class PublishClusterStateActionTests method testSimpleClusterStatePublishing.

public void testSimpleClusterStatePublishing() throws Exception {
    MockNode nodeA = createMockNode("nodeA").setAsMaster();
    MockNode nodeB = createMockNode("nodeB");
    // Initial cluster state
    ClusterState clusterState = nodeA.clusterState;
    // cluster state update - add nodeB
    DiscoveryNodes discoveryNodes = DiscoveryNodes.builder(clusterState.nodes()).add(nodeB.discoveryNode).build();
    ClusterState previousClusterState = clusterState;
    clusterState = ClusterState.builder(clusterState).nodes(discoveryNodes).incrementVersion().build();
    publishStateAndWait(nodeA.action, clusterState, previousClusterState);
    assertSameStateFromFull(nodeB.clusterState, clusterState);
    // cluster state update - add block
    previousClusterState = clusterState;
    clusterState = ClusterState.builder(clusterState).blocks(ClusterBlocks.builder().addGlobalBlock(MetaData.CLUSTER_READ_ONLY_BLOCK)).incrementVersion().build();
    publishStateAndWait(nodeA.action, clusterState, previousClusterState);
    assertSameStateFromDiff(nodeB.clusterState, clusterState);
    assertThat(nodeB.clusterState.blocks().global().size(), equalTo(1));
    // cluster state update - remove block
    previousClusterState = clusterState;
    clusterState = ClusterState.builder(clusterState).blocks(ClusterBlocks.EMPTY_CLUSTER_BLOCK).incrementVersion().build();
    publishStateAndWait(nodeA.action, clusterState, previousClusterState);
    assertSameStateFromDiff(nodeB.clusterState, clusterState);
    assertTrue(nodeB.clusterState.wasReadFromDiff());
    // Adding new node - this node should get full cluster state while nodeB should still be getting diffs
    MockNode nodeC = createMockNode("nodeC");
    // cluster state update 3 - register node C
    previousClusterState = clusterState;
    discoveryNodes = DiscoveryNodes.builder(discoveryNodes).add(nodeC.discoveryNode).build();
    clusterState = ClusterState.builder(clusterState).nodes(discoveryNodes).incrementVersion().build();
    publishStateAndWait(nodeA.action, clusterState, previousClusterState);
    assertSameStateFromDiff(nodeB.clusterState, clusterState);
    // First state
    assertSameStateFromFull(nodeC.clusterState, clusterState);
    // cluster state update 4 - update settings
    previousClusterState = clusterState;
    MetaData metaData = MetaData.builder(clusterState.metaData()).transientSettings(Settings.builder().put("foo", "bar").build()).build();
    clusterState = ClusterState.builder(clusterState).metaData(metaData).incrementVersion().build();
    publishStateAndWait(nodeA.action, clusterState, previousClusterState);
    assertSameStateFromDiff(nodeB.clusterState, clusterState);
    assertThat(nodeB.clusterState.blocks().global().size(), equalTo(0));
    assertSameStateFromDiff(nodeC.clusterState, clusterState);
    assertThat(nodeC.clusterState.blocks().global().size(), equalTo(0));
    // cluster state update - skipping one version change - should request full cluster state
    previousClusterState = ClusterState.builder(clusterState).incrementVersion().build();
    clusterState = ClusterState.builder(clusterState).incrementVersion().build();
    publishStateAndWait(nodeA.action, clusterState, previousClusterState);
    assertSameStateFromFull(nodeB.clusterState, clusterState);
    assertSameStateFromFull(nodeC.clusterState, clusterState);
    assertFalse(nodeC.clusterState.wasReadFromDiff());
    // node A steps down from being master
    nodeA.resetMasterId();
    nodeB.resetMasterId();
    nodeC.resetMasterId();
    // node B becomes the master and sends a version of the cluster state that goes back
    discoveryNodes = DiscoveryNodes.builder(discoveryNodes).add(nodeA.discoveryNode).add(nodeB.discoveryNode).add(nodeC.discoveryNode).masterNodeId(nodeB.discoveryNode.getId()).localNodeId(nodeB.discoveryNode.getId()).build();
    previousClusterState = ClusterState.builder(new ClusterName("test")).nodes(discoveryNodes).build();
    clusterState = ClusterState.builder(clusterState).nodes(discoveryNodes).incrementVersion().build();
    publishStateAndWait(nodeB.action, clusterState, previousClusterState);
    assertSameStateFromFull(nodeA.clusterState, clusterState);
    assertSameStateFromFull(nodeC.clusterState, clusterState);
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) MetaData(org.elasticsearch.cluster.metadata.MetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) ClusterName(org.elasticsearch.cluster.ClusterName) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes)

Example 22 with MetaData

use of org.elasticsearch.cluster.metadata.MetaData in project elasticsearch by elastic.

the class DanglingIndicesStateTests method testInvalidIndexFolder.

public void testInvalidIndexFolder() throws Exception {
    try (NodeEnvironment env = newNodeEnvironment()) {
        MetaStateService metaStateService = new MetaStateService(Settings.EMPTY, env, xContentRegistry());
        DanglingIndicesState danglingState = createDanglingIndicesState(env, metaStateService);
        MetaData metaData = MetaData.builder().build();
        final String uuid = "test1UUID";
        final Settings.Builder settings = Settings.builder().put(indexSettings).put(IndexMetaData.SETTING_INDEX_UUID, uuid);
        IndexMetaData dangledIndex = IndexMetaData.builder("test1").settings(settings).build();
        metaStateService.writeIndex("test_write", dangledIndex);
        for (Path path : env.resolveIndexFolder(uuid)) {
            if (Files.exists(path)) {
                Files.move(path, path.resolveSibling("invalidUUID"), StandardCopyOption.ATOMIC_MOVE);
            }
        }
        try {
            danglingState.findNewDanglingIndices(metaData);
            fail("no exception thrown for invalid folder name");
        } catch (IllegalStateException e) {
            assertThat(e.getMessage(), equalTo("[invalidUUID] invalid index folder name, rename to [test1UUID]"));
        }
    }
}
Also used : Path(java.nio.file.Path) NodeEnvironment(org.elasticsearch.env.NodeEnvironment) MetaData(org.elasticsearch.cluster.metadata.MetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) Settings(org.elasticsearch.common.settings.Settings) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 23 with MetaData

use of org.elasticsearch.cluster.metadata.MetaData in project elasticsearch by elastic.

the class DanglingIndicesStateTests method testDanglingProcessing.

public void testDanglingProcessing() throws Exception {
    try (NodeEnvironment env = newNodeEnvironment()) {
        MetaStateService metaStateService = new MetaStateService(Settings.EMPTY, env, xContentRegistry());
        DanglingIndicesState danglingState = createDanglingIndicesState(env, metaStateService);
        MetaData metaData = MetaData.builder().build();
        final Settings.Builder settings = Settings.builder().put(indexSettings).put(IndexMetaData.SETTING_INDEX_UUID, "test1UUID");
        IndexMetaData dangledIndex = IndexMetaData.builder("test1").settings(settings).build();
        metaStateService.writeIndex("test_write", dangledIndex);
        // check that several runs when not in the metadata still keep the dangled index around
        int numberOfChecks = randomIntBetween(1, 10);
        for (int i = 0; i < numberOfChecks; i++) {
            Map<Index, IndexMetaData> newDanglingIndices = danglingState.findNewDanglingIndices(metaData);
            assertThat(newDanglingIndices.size(), equalTo(1));
            assertThat(newDanglingIndices.keySet(), Matchers.hasItems(dangledIndex.getIndex()));
            assertTrue(danglingState.getDanglingIndices().isEmpty());
        }
        for (int i = 0; i < numberOfChecks; i++) {
            danglingState.findNewAndAddDanglingIndices(metaData);
            assertThat(danglingState.getDanglingIndices().size(), equalTo(1));
            assertThat(danglingState.getDanglingIndices().keySet(), Matchers.hasItems(dangledIndex.getIndex()));
        }
        // simulate allocation to the metadata
        metaData = MetaData.builder(metaData).put(dangledIndex, true).build();
        // check that several runs when in the metadata, but not cleaned yet, still keeps dangled
        for (int i = 0; i < numberOfChecks; i++) {
            Map<Index, IndexMetaData> newDanglingIndices = danglingState.findNewDanglingIndices(metaData);
            assertTrue(newDanglingIndices.isEmpty());
            assertThat(danglingState.getDanglingIndices().size(), equalTo(1));
            assertThat(danglingState.getDanglingIndices().keySet(), Matchers.hasItems(dangledIndex.getIndex()));
        }
        danglingState.cleanupAllocatedDangledIndices(metaData);
        assertTrue(danglingState.getDanglingIndices().isEmpty());
    }
}
Also used : NodeEnvironment(org.elasticsearch.env.NodeEnvironment) MetaData(org.elasticsearch.cluster.metadata.MetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) Index(org.elasticsearch.index.Index) Settings(org.elasticsearch.common.settings.Settings) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 24 with MetaData

use of org.elasticsearch.cluster.metadata.MetaData in project elasticsearch by elastic.

the class DanglingIndicesStateTests method testDanglingIndicesNotImportedWhenTombstonePresent.

public void testDanglingIndicesNotImportedWhenTombstonePresent() throws Exception {
    try (NodeEnvironment env = newNodeEnvironment()) {
        MetaStateService metaStateService = new MetaStateService(Settings.EMPTY, env, xContentRegistry());
        DanglingIndicesState danglingState = createDanglingIndicesState(env, metaStateService);
        final Settings.Builder settings = Settings.builder().put(indexSettings).put(IndexMetaData.SETTING_INDEX_UUID, "test1UUID");
        IndexMetaData dangledIndex = IndexMetaData.builder("test1").settings(settings).build();
        metaStateService.writeIndex("test_write", dangledIndex);
        final IndexGraveyard graveyard = IndexGraveyard.builder().addTombstone(dangledIndex.getIndex()).build();
        final MetaData metaData = MetaData.builder().indexGraveyard(graveyard).build();
        assertThat(danglingState.findNewDanglingIndices(metaData).size(), equalTo(0));
    }
}
Also used : NodeEnvironment(org.elasticsearch.env.NodeEnvironment) IndexGraveyard(org.elasticsearch.cluster.metadata.IndexGraveyard) MetaData(org.elasticsearch.cluster.metadata.MetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) Settings(org.elasticsearch.common.settings.Settings) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 25 with MetaData

use of org.elasticsearch.cluster.metadata.MetaData in project elasticsearch by elastic.

the class DanglingIndicesStateTests method testCleanupWhenEmpty.

public void testCleanupWhenEmpty() throws Exception {
    try (NodeEnvironment env = newNodeEnvironment()) {
        MetaStateService metaStateService = new MetaStateService(Settings.EMPTY, env, xContentRegistry());
        DanglingIndicesState danglingState = createDanglingIndicesState(env, metaStateService);
        assertTrue(danglingState.getDanglingIndices().isEmpty());
        MetaData metaData = MetaData.builder().build();
        danglingState.cleanupAllocatedDangledIndices(metaData);
        assertTrue(danglingState.getDanglingIndices().isEmpty());
    }
}
Also used : NodeEnvironment(org.elasticsearch.env.NodeEnvironment) MetaData(org.elasticsearch.cluster.metadata.MetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Aggregations

MetaData (org.elasticsearch.cluster.metadata.MetaData)244 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)223 ClusterState (org.elasticsearch.cluster.ClusterState)179 RoutingTable (org.elasticsearch.cluster.routing.RoutingTable)138 RoutingNodes (org.elasticsearch.cluster.routing.RoutingNodes)52 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)48 Settings (org.elasticsearch.common.settings.Settings)43 AllocationService (org.elasticsearch.cluster.routing.allocation.AllocationService)32 IndexShardRoutingTable (org.elasticsearch.cluster.routing.IndexShardRoutingTable)30 DiscoveryNodes (org.elasticsearch.cluster.node.DiscoveryNodes)27 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)26 ClusterSettings (org.elasticsearch.common.settings.ClusterSettings)26 Index (org.elasticsearch.index.Index)25 Matchers.containsString (org.hamcrest.Matchers.containsString)23 IndexRoutingTable (org.elasticsearch.cluster.routing.IndexRoutingTable)21 HashMap (java.util.HashMap)19 HashSet (java.util.HashSet)18 ShardId (org.elasticsearch.index.shard.ShardId)17 TestGatewayAllocator (org.elasticsearch.test.gateway.TestGatewayAllocator)17 ArrayList (java.util.ArrayList)15