Search in sources :

Example 86 with IndexMetadata

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

the class GatewayMetaStateTests method testNoMetaDataUpgrade.

public void testNoMetaDataUpgrade() throws Exception {
    MetaData metaData = randomMetaData(new CustomMetaData1("data"));
    MetaDataUpgrader metaDataUpgrader = new MetaDataUpgrader(Collections.emptyList());
    MetaData upgrade = GatewayMetaState.upgradeMetaData(metaData, new MockMetaDataIndexUpgradeService(false), metaDataUpgrader);
    assertTrue(upgrade == metaData);
    assertTrue(MetaData.isGlobalStateEquals(upgrade, metaData));
    for (IndexMetaData indexMetaData : upgrade) {
        assertTrue(metaData.hasIndexMetaData(indexMetaData));
    }
}
Also used : MetaDataUpgrader(org.elasticsearch.plugins.MetaDataUpgrader) MetaData(org.elasticsearch.cluster.metadata.MetaData) TestCustomMetaData(org.elasticsearch.test.TestCustomMetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 87 with IndexMetadata

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

the class IndexingSlowLogTests method testSetLevels.

public void testSetLevels() {
    IndexMetaData metaData = newIndexMeta("index", Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put(IndexingSlowLog.INDEX_INDEXING_SLOWLOG_THRESHOLD_INDEX_TRACE_SETTING.getKey(), "100ms").put(IndexingSlowLog.INDEX_INDEXING_SLOWLOG_THRESHOLD_INDEX_DEBUG_SETTING.getKey(), "200ms").put(IndexingSlowLog.INDEX_INDEXING_SLOWLOG_THRESHOLD_INDEX_INFO_SETTING.getKey(), "300ms").put(IndexingSlowLog.INDEX_INDEXING_SLOWLOG_THRESHOLD_INDEX_WARN_SETTING.getKey(), "400ms").build());
    IndexSettings settings = new IndexSettings(metaData, Settings.EMPTY);
    IndexingSlowLog log = new IndexingSlowLog(settings);
    assertEquals(TimeValue.timeValueMillis(100).nanos(), log.getIndexTraceThreshold());
    assertEquals(TimeValue.timeValueMillis(200).nanos(), log.getIndexDebugThreshold());
    assertEquals(TimeValue.timeValueMillis(300).nanos(), log.getIndexInfoThreshold());
    assertEquals(TimeValue.timeValueMillis(400).nanos(), log.getIndexWarnThreshold());
    settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(IndexingSlowLog.INDEX_INDEXING_SLOWLOG_THRESHOLD_INDEX_TRACE_SETTING.getKey(), "120ms").put(IndexingSlowLog.INDEX_INDEXING_SLOWLOG_THRESHOLD_INDEX_DEBUG_SETTING.getKey(), "220ms").put(IndexingSlowLog.INDEX_INDEXING_SLOWLOG_THRESHOLD_INDEX_INFO_SETTING.getKey(), "320ms").put(IndexingSlowLog.INDEX_INDEXING_SLOWLOG_THRESHOLD_INDEX_WARN_SETTING.getKey(), "420ms").build()));
    assertEquals(TimeValue.timeValueMillis(120).nanos(), log.getIndexTraceThreshold());
    assertEquals(TimeValue.timeValueMillis(220).nanos(), log.getIndexDebugThreshold());
    assertEquals(TimeValue.timeValueMillis(320).nanos(), log.getIndexInfoThreshold());
    assertEquals(TimeValue.timeValueMillis(420).nanos(), log.getIndexWarnThreshold());
    metaData = newIndexMeta("index", Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build());
    settings.updateIndexMetaData(metaData);
    assertEquals(TimeValue.timeValueMillis(-1).nanos(), log.getIndexTraceThreshold());
    assertEquals(TimeValue.timeValueMillis(-1).nanos(), log.getIndexDebugThreshold());
    assertEquals(TimeValue.timeValueMillis(-1).nanos(), log.getIndexInfoThreshold());
    assertEquals(TimeValue.timeValueMillis(-1).nanos(), log.getIndexWarnThreshold());
    settings = new IndexSettings(metaData, Settings.EMPTY);
    log = new IndexingSlowLog(settings);
    assertEquals(TimeValue.timeValueMillis(-1).nanos(), log.getIndexTraceThreshold());
    assertEquals(TimeValue.timeValueMillis(-1).nanos(), log.getIndexDebugThreshold());
    assertEquals(TimeValue.timeValueMillis(-1).nanos(), log.getIndexInfoThreshold());
    assertEquals(TimeValue.timeValueMillis(-1).nanos(), log.getIndexWarnThreshold());
    try {
        settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(IndexingSlowLog.INDEX_INDEXING_SLOWLOG_THRESHOLD_INDEX_TRACE_SETTING.getKey(), "NOT A TIME VALUE").build()));
        fail();
    } catch (IllegalArgumentException ex) {
        assertEquals(ex.getMessage(), "failed to parse setting [index.indexing.slowlog.threshold.index.trace] with value [NOT A TIME VALUE] as a time value: unit is missing or unrecognized");
    }
    try {
        settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(IndexingSlowLog.INDEX_INDEXING_SLOWLOG_THRESHOLD_INDEX_DEBUG_SETTING.getKey(), "NOT A TIME VALUE").build()));
        fail();
    } catch (IllegalArgumentException ex) {
        assertEquals(ex.getMessage(), "failed to parse setting [index.indexing.slowlog.threshold.index.debug] with value [NOT A TIME VALUE] as a time value: unit is missing or unrecognized");
    }
    try {
        settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(IndexingSlowLog.INDEX_INDEXING_SLOWLOG_THRESHOLD_INDEX_INFO_SETTING.getKey(), "NOT A TIME VALUE").build()));
        fail();
    } catch (IllegalArgumentException ex) {
        assertEquals(ex.getMessage(), "failed to parse setting [index.indexing.slowlog.threshold.index.info] with value [NOT A TIME VALUE] as a time value: unit is missing or unrecognized");
    }
    try {
        settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(IndexingSlowLog.INDEX_INDEXING_SLOWLOG_THRESHOLD_INDEX_WARN_SETTING.getKey(), "NOT A TIME VALUE").build()));
        fail();
    } catch (IllegalArgumentException ex) {
        assertEquals(ex.getMessage(), "failed to parse setting [index.indexing.slowlog.threshold.index.warn] with value [NOT A TIME VALUE] as a time value: unit is missing or unrecognized");
    }
}
Also used : IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 88 with IndexMetadata

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

the class IndexingSlowLogTests method newIndexMeta.

private IndexMetaData newIndexMeta(String name, Settings indexSettings) {
    Settings build = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1).put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1).put(indexSettings).build();
    IndexMetaData metaData = IndexMetaData.builder(name).settings(build).build();
    return metaData;
}
Also used : Settings(org.elasticsearch.common.settings.Settings) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 89 with IndexMetadata

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

the class IndexingSlowLogTests method testReformatSetting.

public void testReformatSetting() {
    IndexMetaData metaData = newIndexMeta("index", Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put(IndexingSlowLog.INDEX_INDEXING_SLOWLOG_REFORMAT_SETTING.getKey(), false).build());
    IndexSettings settings = new IndexSettings(metaData, Settings.EMPTY);
    IndexingSlowLog log = new IndexingSlowLog(settings);
    assertFalse(log.isReformat());
    settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(IndexingSlowLog.INDEX_INDEXING_SLOWLOG_REFORMAT_SETTING.getKey(), "true").build()));
    assertTrue(log.isReformat());
    settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(IndexingSlowLog.INDEX_INDEXING_SLOWLOG_REFORMAT_SETTING.getKey(), "false").build()));
    assertFalse(log.isReformat());
    settings.updateIndexMetaData(newIndexMeta("index", Settings.EMPTY));
    assertTrue(log.isReformat());
    metaData = newIndexMeta("index", Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build());
    settings = new IndexSettings(metaData, Settings.EMPTY);
    log = new IndexingSlowLog(settings);
    assertTrue(log.isReformat());
    try {
        settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(IndexingSlowLog.INDEX_INDEXING_SLOWLOG_REFORMAT_SETTING.getKey(), "NOT A BOOLEAN").build()));
        fail();
    } catch (IllegalArgumentException ex) {
        assertEquals(ex.getMessage(), "Failed to parse value [NOT A BOOLEAN] as only [true] or [false] are allowed.");
    }
    assertTrue(log.isReformat());
}
Also used : IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 90 with IndexMetadata

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

the class IndexSettingsTests method testRunListener.

public void testRunListener() {
    Version version = VersionUtils.getPreviousVersion();
    Settings theSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).put(IndexMetaData.SETTING_INDEX_UUID, "0xdeadbeef").build();
    final AtomicInteger integer = new AtomicInteger(0);
    Setting<Integer> integerSetting = Setting.intSetting("index.test.setting.int", -1, Property.Dynamic, Property.IndexScope);
    IndexMetaData metaData = newIndexMeta("index", theSettings);
    IndexSettings settings = newIndexSettings(newIndexMeta("index", theSettings), Settings.EMPTY, integerSetting);
    settings.getScopedSettings().addSettingsUpdateConsumer(integerSetting, integer::set);
    assertEquals(version, settings.getIndexVersionCreated());
    assertEquals("0xdeadbeef", settings.getUUID());
    assertFalse(settings.updateIndexMetaData(metaData));
    assertEquals(metaData.getSettings().getAsMap(), settings.getSettings().getAsMap());
    assertEquals(0, integer.get());
    assertTrue(settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(theSettings).put("index.test.setting.int", 42).build())));
    assertEquals(42, integer.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Version(org.elasticsearch.Version) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IndexScopedSettings(org.elasticsearch.common.settings.IndexScopedSettings) Settings(org.elasticsearch.common.settings.Settings) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Aggregations

IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)253 IndexMetadata (org.elasticsearch.cluster.metadata.IndexMetadata)194 ClusterState (org.elasticsearch.cluster.ClusterState)124 Settings (org.elasticsearch.common.settings.Settings)104 Index (org.elasticsearch.index.Index)100 Test (org.junit.Test)90 ShardId (org.elasticsearch.index.shard.ShardId)71 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)68 IOException (java.io.IOException)65 Metadata (org.elasticsearch.cluster.metadata.Metadata)62 IndexSettings (org.elasticsearch.index.IndexSettings)62 RoutingTable (org.elasticsearch.cluster.routing.RoutingTable)60 MetaData (org.elasticsearch.cluster.metadata.MetaData)58 HashSet (java.util.HashSet)56 HashMap (java.util.HashMap)54 IndexShardRoutingTable (org.elasticsearch.cluster.routing.IndexShardRoutingTable)54 Map (java.util.Map)50 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)49 ArrayList (java.util.ArrayList)47 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)44