Search in sources :

Example 1 with Setting

use of org.opensearch.common.settings.Setting in project OpenSearch by opensearch-project.

the class IndexSettingsTests method testMergedSettingsArePassed.

public void testMergedSettingsArePassed() {
    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);
    final StringBuilder builder = new StringBuilder();
    Setting<Integer> integerSetting = Setting.intSetting("index.test.setting.int", -1, Property.Dynamic, Property.IndexScope);
    Setting<String> notUpdated = new Setting<>("index.not.updated", "", Function.identity(), Property.Dynamic, Property.IndexScope);
    IndexSettings settings = newIndexSettings(newIndexMeta("index", theSettings), Settings.EMPTY, integerSetting, notUpdated);
    settings.getScopedSettings().addSettingsUpdateConsumer(integerSetting, integer::set);
    settings.getScopedSettings().addSettingsUpdateConsumer(notUpdated, builder::append);
    assertEquals(0, integer.get());
    assertEquals("", builder.toString());
    IndexMetadata newMetadata = newIndexMeta("index", Settings.builder().put(settings.getIndexMetadata().getSettings()).put("index.test.setting.int", 42).build());
    assertTrue(settings.updateIndexMetadata(newMetadata));
    assertSame(settings.getIndexMetadata(), newMetadata);
    assertEquals(42, integer.get());
    assertEquals("", builder.toString());
    integer.set(0);
    assertTrue(settings.updateIndexMetadata(newIndexMeta("index", Settings.builder().put(settings.getIndexMetadata().getSettings()).put("index.not.updated", "boom").build())));
    assertEquals("boom", builder.toString());
    assertEquals("not updated - we preserve the old settings", 0, integer.get());
}
Also used : Setting(org.opensearch.common.settings.Setting) HasToString.hasToString(org.hamcrest.object.HasToString.hasToString) StringContains.containsString(org.hamcrest.core.StringContains.containsString) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Version(org.opensearch.Version) LegacyESVersion(org.opensearch.LegacyESVersion) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) IndexScopedSettings(org.opensearch.common.settings.IndexScopedSettings) AbstractScopedSettings(org.opensearch.common.settings.AbstractScopedSettings) Settings(org.opensearch.common.settings.Settings)

Example 2 with Setting

use of org.opensearch.common.settings.Setting in project OpenSearch by opensearch-project.

the class MetadataCreateIndexServiceTests method runPrepareResizeIndexSettingsTest.

private void runPrepareResizeIndexSettingsTest(final Settings sourceSettings, final Settings requestSettings, final Collection<Setting<?>> additionalIndexScopedSettings, final boolean copySettings, final Consumer<Settings> consumer) {
    final String indexName = randomAlphaOfLength(10);
    final Settings indexSettings = Settings.builder().put("index.blocks.write", true).put("index.routing.allocation.require._name", "node1").put(sourceSettings).build();
    final ClusterState initialClusterState = ClusterState.builder(createClusterState(indexName, randomIntBetween(2, 10), 0, indexSettings)).nodes(DiscoveryNodes.builder().add(newNode("node1"))).build();
    final AllocationService service = new AllocationService(new AllocationDeciders(singleton(new MaxRetryAllocationDecider())), new TestGatewayAllocator(), new BalancedShardsAllocator(Settings.EMPTY), EmptyClusterInfoService.INSTANCE, EmptySnapshotsInfoService.INSTANCE);
    final RoutingTable initialRoutingTable = service.reroute(initialClusterState, "reroute").routingTable();
    final ClusterState routingTableClusterState = ClusterState.builder(initialClusterState).routingTable(initialRoutingTable).build();
    // now we start the shard
    final RoutingTable routingTable = OpenSearchAllocationTestCase.startInitializingShardsAndReroute(service, routingTableClusterState, indexName).routingTable();
    final ClusterState clusterState = ClusterState.builder(routingTableClusterState).routingTable(routingTable).build();
    final Settings.Builder indexSettingsBuilder = Settings.builder().put("index.number_of_shards", 1).put(requestSettings);
    final Set<Setting<?>> settingsSet = Stream.concat(IndexScopedSettings.BUILT_IN_INDEX_SETTINGS.stream(), additionalIndexScopedSettings.stream()).collect(Collectors.toSet());
    MetadataCreateIndexService.prepareResizeIndexSettings(clusterState, indexSettingsBuilder, clusterState.metadata().index(indexName).getIndex(), "target", ResizeType.SHRINK, copySettings, new IndexScopedSettings(Settings.EMPTY, settingsSet));
    consumer.accept(indexSettingsBuilder.build());
}
Also used : TestGatewayAllocator(org.opensearch.test.gateway.TestGatewayAllocator) ClusterState(org.opensearch.cluster.ClusterState) IndexScopedSettings(org.opensearch.common.settings.IndexScopedSettings) BalancedShardsAllocator(org.opensearch.cluster.routing.allocation.allocator.BalancedShardsAllocator) Setting(org.opensearch.common.settings.Setting) AllocationDeciders(org.opensearch.cluster.routing.allocation.decider.AllocationDeciders) MaxRetryAllocationDecider(org.opensearch.cluster.routing.allocation.decider.MaxRetryAllocationDecider) RoutingTable(org.opensearch.cluster.routing.RoutingTable) IndexScopedSettings(org.opensearch.common.settings.IndexScopedSettings) Settings(org.opensearch.common.settings.Settings) MetadataCreateIndexService.aggregateIndexSettings(org.opensearch.cluster.metadata.MetadataCreateIndexService.aggregateIndexSettings) IndexSettings(org.opensearch.index.IndexSettings) AllocationService(org.opensearch.cluster.routing.allocation.AllocationService)

Example 3 with Setting

use of org.opensearch.common.settings.Setting in project OpenSearch by opensearch-project.

the class OpenSearchExecutorsTests method runProcessorsBoundTest.

private void runProcessorsBoundTest(final Setting<Integer> processorsSetting) {
    final int available = Runtime.getRuntime().availableProcessors();
    final int processors = randomIntBetween(available + 1, Integer.MAX_VALUE);
    final Settings settings = Settings.builder().put(processorsSetting.getKey(), processors).build();
    processorsSetting.get(settings);
    final Setting<?>[] deprecatedSettings;
    if (processorsSetting.getProperties().contains(Setting.Property.Deprecated)) {
        deprecatedSettings = new Setting<?>[] { processorsSetting };
    } else {
        deprecatedSettings = new Setting<?>[0];
    }
    final String expectedWarning = String.format(Locale.ROOT, "setting [%s] to value [%d] which is more than available processors [%d] is deprecated", processorsSetting.getKey(), processors, available);
    assertSettingDeprecationsAndWarnings(deprecatedSettings, expectedWarning);
}
Also used : Setting(org.opensearch.common.settings.Setting) Matchers.containsString(org.hamcrest.Matchers.containsString) Settings(org.opensearch.common.settings.Settings)

Example 4 with Setting

use of org.opensearch.common.settings.Setting in project OpenSearch by opensearch-project.

the class SettingsUpdaterTests method testDeprecationLogging.

public void testDeprecationLogging() {
    Setting<String> deprecatedSetting = Setting.simpleString("deprecated.setting", Property.Dynamic, Property.NodeScope, Property.Deprecated);
    final Settings settings = Settings.builder().put("deprecated.setting", "foo").build();
    final Set<Setting<?>> settingsSet = Stream.concat(ClusterSettings.BUILT_IN_CLUSTER_SETTINGS.stream(), Stream.of(deprecatedSetting)).collect(Collectors.toSet());
    final ClusterSettings clusterSettings = new ClusterSettings(settings, settingsSet);
    clusterSettings.addSettingsUpdateConsumer(deprecatedSetting, s -> {
    });
    final SettingsUpdater settingsUpdater = new SettingsUpdater(clusterSettings);
    final ClusterState clusterState = ClusterState.builder(new ClusterName("foo")).metadata(Metadata.builder().persistentSettings(settings).build()).build();
    final Settings toApplyDebug = Settings.builder().put("logger.org.opensearch", "debug").build();
    final ClusterState afterDebug = settingsUpdater.updateSettings(clusterState, toApplyDebug, Settings.EMPTY, logger);
    assertSettingDeprecationsAndWarnings(new Setting<?>[] { deprecatedSetting });
    final Settings toApplyUnset = Settings.builder().putNull("logger.org.opensearch").build();
    final ClusterState afterUnset = settingsUpdater.updateSettings(afterDebug, toApplyUnset, Settings.EMPTY, logger);
    assertNoDeprecationWarnings();
    // we also check that if no settings are changed, deprecation logging still occurs
    settingsUpdater.updateSettings(afterUnset, toApplyUnset, Settings.EMPTY, logger);
    assertNoDeprecationWarnings();
}
Also used : ClusterState(org.opensearch.cluster.ClusterState) ClusterSettings(org.opensearch.common.settings.ClusterSettings) Setting(org.opensearch.common.settings.Setting) ClusterName(org.opensearch.cluster.ClusterName) Settings(org.opensearch.common.settings.Settings) ClusterSettings(org.opensearch.common.settings.ClusterSettings)

Example 5 with Setting

use of org.opensearch.common.settings.Setting in project OpenSearch by opensearch-project.

the class ClusterStateUpdatersTests method runUpgradeSettings.

private void runUpgradeSettings(final BiConsumer<Metadata.Builder, Settings> applySettingsToBuilder, final Function<Metadata, Settings> metadataSettings) {
    final Setting<String> oldSetting = Setting.simpleString("foo.old", Setting.Property.Dynamic, Setting.Property.NodeScope);
    final Setting<String> newSetting = Setting.simpleString("foo.new", Setting.Property.Dynamic, Setting.Property.NodeScope);
    final Set<Setting<?>> settingsSet = Stream.concat(ClusterSettings.BUILT_IN_CLUSTER_SETTINGS.stream(), Stream.of(oldSetting, newSetting)).collect(Collectors.toSet());
    final ClusterSettings clusterSettings = new ClusterSettings(Settings.EMPTY, settingsSet, Collections.singleton(new SettingUpgrader<String>() {

        @Override
        public Setting<String> getSetting() {
            return oldSetting;
        }

        @Override
        public String getKey(final String key) {
            return "foo.new";
        }

        @Override
        public String getValue(final String value) {
            return "new." + value;
        }
    }));
    final ClusterService clusterService = new ClusterService(Settings.EMPTY, clusterSettings, null);
    final Metadata.Builder builder = Metadata.builder();
    final Settings settings = Settings.builder().put("foo.old", randomAlphaOfLength(8)).build();
    applySettingsToBuilder.accept(builder, settings);
    final ClusterState initialState = ClusterState.builder(clusterService.getClusterName()).metadata(builder.build()).build();
    final ClusterState state = upgradeAndArchiveUnknownOrInvalidSettings(initialState, clusterService.getClusterSettings());
    assertFalse(oldSetting.exists(metadataSettings.apply(state.metadata())));
    assertTrue(newSetting.exists(metadataSettings.apply(state.metadata())));
    assertThat(newSetting.get(metadataSettings.apply(state.metadata())), equalTo("new." + oldSetting.get(settings)));
}
Also used : ClusterState(org.opensearch.cluster.ClusterState) ClusterSettings(org.opensearch.common.settings.ClusterSettings) ClusterService(org.opensearch.cluster.service.ClusterService) Setting(org.opensearch.common.settings.Setting) Metadata(org.opensearch.cluster.metadata.Metadata) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) CoordinationMetadata(org.opensearch.cluster.coordination.CoordinationMetadata) SettingUpgrader(org.opensearch.common.settings.SettingUpgrader) ClusterSettings(org.opensearch.common.settings.ClusterSettings) Settings(org.opensearch.common.settings.Settings) ClusterStateUpdaters.upgradeAndArchiveUnknownOrInvalidSettings(org.opensearch.gateway.ClusterStateUpdaters.upgradeAndArchiveUnknownOrInvalidSettings)

Aggregations

Setting (org.opensearch.common.settings.Setting)19 Settings (org.opensearch.common.settings.Settings)16 ClusterSettings (org.opensearch.common.settings.ClusterSettings)10 ClusterState (org.opensearch.cluster.ClusterState)9 HashSet (java.util.HashSet)7 Metadata (org.opensearch.cluster.metadata.Metadata)6 Version (org.opensearch.Version)5 ClusterName (org.opensearch.cluster.ClusterName)5 AbstractScopedSettings (org.opensearch.common.settings.AbstractScopedSettings)5 IndexScopedSettings (org.opensearch.common.settings.IndexScopedSettings)5 ArrayList (java.util.ArrayList)4 Arrays (java.util.Arrays)4 Set (java.util.Set)4 IndexMetadata (org.opensearch.cluster.metadata.IndexMetadata)4 ClusterService (org.opensearch.cluster.service.ClusterService)4 IOException (java.io.IOException)3 Collections (java.util.Collections)3 TimeUnit (java.util.concurrent.TimeUnit)3 Tuple (org.opensearch.common.collect.Tuple)3 HashMap (java.util.HashMap)2