Search in sources :

Example 91 with IndexMetadata

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

the class IndexSettingsTests method testSettingsUpdateValidator.

public void testSettingsUpdateValidator() {
    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, (i) -> {
        if (i == 42)
            throw new AssertionError("boom");
    });
    assertEquals(version, settings.getIndexVersionCreated());
    assertEquals("0xdeadbeef", settings.getUUID());
    assertFalse(settings.updateIndexMetaData(metaData));
    assertEquals(metaData.getSettings().getAsMap(), settings.getSettings().getAsMap());
    assertEquals(0, integer.get());
    expectThrows(IllegalArgumentException.class, () -> settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(theSettings).put("index.test.setting.int", 42).build())));
    assertTrue(settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(theSettings).put("index.test.setting.int", 41).build())));
    assertEquals(41, 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)

Example 92 with IndexMetadata

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

the class IndexSettingsTests method testIsWarmerEnabled.

public void testIsWarmerEnabled() {
    IndexMetaData metaData = newIndexMeta("index", Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put(IndexSettings.INDEX_WARMER_ENABLED_SETTING.getKey(), false).build());
    IndexSettings settings = new IndexSettings(metaData, Settings.EMPTY);
    assertFalse(settings.isWarmerEnabled());
    settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(IndexSettings.INDEX_WARMER_ENABLED_SETTING.getKey(), "true").build()));
    assertTrue(settings.isWarmerEnabled());
    metaData = newIndexMeta("index", Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build());
    settings = new IndexSettings(metaData, Settings.EMPTY);
    assertTrue(settings.isWarmerEnabled());
}
Also used : IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 93 with IndexMetadata

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

the class IndexSettingsTests method testMaxResultWindow.

public void testMaxResultWindow() {
    IndexMetaData metaData = newIndexMeta("index", Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put(IndexSettings.MAX_RESULT_WINDOW_SETTING.getKey(), 15).build());
    IndexSettings settings = new IndexSettings(metaData, Settings.EMPTY);
    assertEquals(15, settings.getMaxResultWindow());
    settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(IndexSettings.MAX_RESULT_WINDOW_SETTING.getKey(), 42).build()));
    assertEquals(42, settings.getMaxResultWindow());
    settings.updateIndexMetaData(newIndexMeta("index", Settings.EMPTY));
    assertEquals(IndexSettings.MAX_RESULT_WINDOW_SETTING.get(Settings.EMPTY).intValue(), settings.getMaxResultWindow());
    metaData = newIndexMeta("index", Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build());
    settings = new IndexSettings(metaData, Settings.EMPTY);
    assertEquals(IndexSettings.MAX_RESULT_WINDOW_SETTING.get(Settings.EMPTY).intValue(), settings.getMaxResultWindow());
}
Also used : IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 94 with IndexMetadata

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

the class IndexSettingsTests method testMaxAdjacencyMatrixFiltersSetting.

public void testMaxAdjacencyMatrixFiltersSetting() {
    IndexMetaData metaData = newIndexMeta("index", Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put(IndexSettings.MAX_ADJACENCY_MATRIX_FILTERS_SETTING.getKey(), 15).build());
    IndexSettings settings = new IndexSettings(metaData, Settings.EMPTY);
    assertEquals(15, settings.getMaxAdjacencyMatrixFilters());
    settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(IndexSettings.MAX_ADJACENCY_MATRIX_FILTERS_SETTING.getKey(), 42).build()));
    assertEquals(42, settings.getMaxAdjacencyMatrixFilters());
    settings.updateIndexMetaData(newIndexMeta("index", Settings.EMPTY));
    assertEquals(IndexSettings.MAX_ADJACENCY_MATRIX_FILTERS_SETTING.get(Settings.EMPTY).intValue(), settings.getMaxAdjacencyMatrixFilters());
    metaData = newIndexMeta("index", Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build());
    settings = new IndexSettings(metaData, Settings.EMPTY);
    assertEquals(IndexSettings.MAX_ADJACENCY_MATRIX_FILTERS_SETTING.get(Settings.EMPTY).intValue(), settings.getMaxAdjacencyMatrixFilters());
}
Also used : IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 95 with IndexMetadata

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

the class IndexSettingsTests method testSettingsConsistency.

public void testSettingsConsistency() {
    Version version = VersionUtils.getPreviousVersion();
    IndexMetaData metaData = newIndexMeta("index", Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build());
    IndexSettings settings = new IndexSettings(metaData, Settings.EMPTY);
    assertEquals(version, settings.getIndexVersionCreated());
    assertEquals("_na_", settings.getUUID());
    try {
        settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put("index.test.setting.int", 42).build()));
        fail("version has changed");
    } catch (IllegalArgumentException ex) {
        assertTrue(ex.getMessage(), ex.getMessage().startsWith("version mismatch on settings update expected: "));
    }
    // use version number that is unknown
    metaData = newIndexMeta("index", Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.fromId(999999)).build());
    settings = new IndexSettings(metaData, Settings.EMPTY);
    assertEquals(Version.fromId(999999), settings.getIndexVersionCreated());
    assertEquals("_na_", settings.getUUID());
    settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.fromId(999999)).put("index.test.setting.int", 42).build()));
    metaData = newIndexMeta("index", Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put(IndexMetaData.SETTING_INDEX_UUID, "0xdeadbeef").build());
    settings = new IndexSettings(metaData, Settings.EMPTY);
    try {
        settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put("index.test.setting.int", 42).build()));
        fail("uuid missing/change");
    } catch (IllegalArgumentException ex) {
        assertEquals("uuid mismatch on settings update expected: 0xdeadbeef but was: _na_", ex.getMessage());
    }
    assertEquals(metaData.getSettings().getAsMap(), settings.getSettings().getAsMap());
}
Also used : Version(org.elasticsearch.Version) 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