Search in sources :

Example 26 with MetaData

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

the class GatewayIndexStateIT method testArchiveBrokenClusterSettings.

public void testArchiveBrokenClusterSettings() throws Exception {
    logger.info("--> starting one node");
    internalCluster().startNode();
    client().prepareIndex("test", "type1", "1").setSource("field1", "value1").setRefreshPolicy(IMMEDIATE).get();
    logger.info("--> waiting for green status");
    if (usually()) {
        ensureYellow();
    } else {
        internalCluster().startNode();
        client().admin().cluster().health(Requests.clusterHealthRequest().waitForGreenStatus().waitForEvents(Priority.LANGUID).waitForNoRelocatingShards(true).waitForNodes("2")).actionGet();
    }
    ClusterState state = client().admin().cluster().prepareState().get().getState();
    MetaData metaData = state.getMetaData();
    for (NodeEnvironment nodeEnv : internalCluster().getInstances(NodeEnvironment.class)) {
        MetaData brokenMeta = MetaData.builder(metaData).persistentSettings(Settings.builder().put(metaData.persistentSettings()).put("this.is.unknown", true).put(ElectMasterService.DISCOVERY_ZEN_MINIMUM_MASTER_NODES_SETTING.getKey(), "broken").build()).build();
        MetaData.FORMAT.write(brokenMeta, nodeEnv.nodeDataPaths());
    }
    internalCluster().fullRestart();
    // wait for state recovery
    ensureYellow("test");
    state = client().admin().cluster().prepareState().get().getState();
    assertEquals("true", state.metaData().persistentSettings().get("archived.this.is.unknown"));
    assertEquals("broken", state.metaData().persistentSettings().get("archived." + ElectMasterService.DISCOVERY_ZEN_MINIMUM_MASTER_NODES_SETTING.getKey()));
    // delete these settings
    client().admin().cluster().prepareUpdateSettings().setPersistentSettings(Settings.builder().putNull("archived.*")).get();
    state = client().admin().cluster().prepareState().get().getState();
    assertNull(state.metaData().persistentSettings().get("archived.this.is.unknown"));
    assertNull(state.metaData().persistentSettings().get("archived." + ElectMasterService.DISCOVERY_ZEN_MINIMUM_MASTER_NODES_SETTING.getKey()));
    assertHitCount(client().prepareSearch().setQuery(matchAllQuery()).get(), 1L);
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) NodeEnvironment(org.elasticsearch.env.NodeEnvironment) MetaData(org.elasticsearch.cluster.metadata.MetaData) MappingMetaData(org.elasticsearch.cluster.metadata.MappingMetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 27 with MetaData

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

the class MetaDataStateFormatTests method randomMeta.

private MetaData randomMeta() throws IOException {
    int numIndices = randomIntBetween(1, 10);
    MetaData.Builder mdBuilder = MetaData.builder();
    mdBuilder.generateClusterUuidIfNeeded();
    for (int i = 0; i < numIndices; i++) {
        mdBuilder.put(indexBuilder(randomAsciiOfLength(10) + "idx-" + i));
    }
    int numDelIndices = randomIntBetween(0, 5);
    final IndexGraveyard.Builder graveyard = IndexGraveyard.builder();
    for (int i = 0; i < numDelIndices; i++) {
        graveyard.addTombstone(new Index(randomAsciiOfLength(10) + "del-idx-" + i, UUIDs.randomBase64UUID()));
    }
    mdBuilder.indexGraveyard(graveyard.build());
    return mdBuilder.build();
}
Also used : IndexGraveyard(org.elasticsearch.cluster.metadata.IndexGraveyard) MetaData(org.elasticsearch.cluster.metadata.MetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) Index(org.elasticsearch.index.Index)

Example 28 with MetaData

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

the class MetaDataWriteDataNodesIT method getIndicesMetaDataOnNode.

private ImmutableOpenMap<String, IndexMetaData> getIndicesMetaDataOnNode(String nodeName) throws Exception {
    GatewayMetaState nodeMetaState = ((InternalTestCluster) cluster()).getInstance(GatewayMetaState.class, nodeName);
    MetaData nodeMetaData = nodeMetaState.loadMetaState();
    return nodeMetaData.getIndices();
}
Also used : MetaData(org.elasticsearch.cluster.metadata.MetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) InternalTestCluster(org.elasticsearch.test.InternalTestCluster)

Example 29 with MetaData

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

the class GatewayMetaStateTests method testRemoveCustomMetaDataOnUpgrade.

public void testRemoveCustomMetaDataOnUpgrade() throws Exception {
    MetaData metaData = randomMetaData(new CustomMetaData1("data"));
    MetaDataUpgrader metaDataUpgrader = new MetaDataUpgrader(Collections.singletonList(customs -> {
        customs.remove(CustomMetaData1.TYPE);
        return customs;
    }));
    MetaData upgrade = GatewayMetaState.upgradeMetaData(metaData, new MockMetaDataIndexUpgradeService(false), metaDataUpgrader);
    assertTrue(upgrade != metaData);
    assertFalse(MetaData.isGlobalStateEquals(upgrade, metaData));
    assertNull(upgrade.custom(CustomMetaData1.TYPE));
}
Also used : MetaData(org.elasticsearch.cluster.metadata.MetaData) ESAllocationTestCase(org.elasticsearch.cluster.ESAllocationTestCase) Arrays(java.util.Arrays) MetaDataUpgrader(org.elasticsearch.plugins.MetaDataUpgrader) AllocationService(org.elasticsearch.cluster.routing.allocation.AllocationService) INITIALIZING(org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING) HashMap(java.util.HashMap) Index(org.elasticsearch.index.Index) ClusterState(org.elasticsearch.cluster.ClusterState) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) Settings(org.elasticsearch.common.settings.Settings) ClusterRebalanceAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllocationDecider) EnumSet(java.util.EnumSet) Before(org.junit.Before) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) Iterator(java.util.Iterator) Collections.emptySet(java.util.Collections.emptySet) Set(java.util.Set) ClusterChangedEvent(org.elasticsearch.cluster.ClusterChangedEvent) TestCustomMetaData(org.elasticsearch.test.TestCustomMetaData) Version(org.elasticsearch.Version) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) MetaDataIndexUpgradeService(org.elasticsearch.cluster.metadata.MetaDataIndexUpgradeService) RoutingTable(org.elasticsearch.cluster.routing.RoutingTable) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Collections(java.util.Collections) MetaDataUpgrader(org.elasticsearch.plugins.MetaDataUpgrader) MetaData(org.elasticsearch.cluster.metadata.MetaData) TestCustomMetaData(org.elasticsearch.test.TestCustomMetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 30 with MetaData

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

the class GatewayMetaStateTests method assertState.

public void assertState(ClusterChangedEvent event, boolean stateInMemory, boolean expectMetaData) throws Exception {
    MetaData inMemoryMetaData = null;
    Set<Index> oldIndicesList = emptySet();
    if (stateInMemory) {
        inMemoryMetaData = event.previousState().metaData();
        oldIndicesList = GatewayMetaState.getRelevantIndices(event.previousState(), event.previousState(), oldIndicesList);
    }
    Set<Index> newIndicesList = GatewayMetaState.getRelevantIndices(event.state(), event.previousState(), oldIndicesList);
    // third, get the actual write info
    Iterator<GatewayMetaState.IndexMetaWriteInfo> indices = GatewayMetaState.resolveStatesToBeWritten(oldIndicesList, newIndicesList, inMemoryMetaData, event.state().metaData()).iterator();
    if (expectMetaData) {
        assertThat(indices.hasNext(), equalTo(true));
        assertThat(indices.next().getNewMetaData().getIndex().getName(), equalTo("test"));
        assertThat(indices.hasNext(), equalTo(false));
    } else {
        assertThat(indices.hasNext(), equalTo(false));
    }
}
Also used : MetaData(org.elasticsearch.cluster.metadata.MetaData) TestCustomMetaData(org.elasticsearch.test.TestCustomMetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) Index(org.elasticsearch.index.Index)

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