Search in sources :

Example 6 with Settings

use of org.elasticsearch.common.settings.Settings in project crate by crate.

the class PartitionedTableIntegrationTest method testAlterNumberOfReplicas.

@Test
public void testAlterNumberOfReplicas() throws Exception {
    execute("create table quotes (id integer, quote string, date timestamp) " + "partitioned by(date) clustered into 3 shards with (number_of_replicas='0-all')");
    ensureYellow();
    String templateName = PartitionName.templateName(null, "quotes");
    GetIndexTemplatesResponse templatesResponse = client().admin().indices().prepareGetTemplates(templateName).execute().actionGet();
    Settings templateSettings = templatesResponse.getIndexTemplates().get(0).getSettings();
    assertThat(templateSettings.get(IndexMetaData.SETTING_AUTO_EXPAND_REPLICAS), is("0-all"));
    execute("alter table quotes set (number_of_replicas=0)");
    ensureYellow();
    templatesResponse = client().admin().indices().prepareGetTemplates(templateName).execute().actionGet();
    templateSettings = templatesResponse.getIndexTemplates().get(0).getSettings();
    assertThat(templateSettings.getAsInt(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1), is(0));
    assertThat(templateSettings.getAsBoolean(IndexMetaData.SETTING_AUTO_EXPAND_REPLICAS, true), is(false));
    execute("insert into quotes (id, quote, date) values (?, ?, ?), (?, ?, ?)", new Object[] { 1, "Don't panic", 1395874800000L, 2, "Now panic", 1395961200000L });
    assertThat(response.rowCount(), is(2L));
    ensureYellow();
    refresh();
    assertTrue(clusterService().state().metaData().hasAlias("quotes"));
    List<String> partitions = ImmutableList.of(new PartitionName("quotes", Collections.singletonList(new BytesRef("1395874800000"))).asIndexName(), new PartitionName("quotes", Collections.singletonList(new BytesRef("1395961200000"))).asIndexName());
    GetSettingsResponse settingsResponse = client().admin().indices().prepareGetSettings(partitions.get(0), partitions.get(1)).execute().get();
    for (String index : partitions) {
        Settings partitionSetting = settingsResponse.getIndexToSettings().get(index);
        assertThat(partitionSetting.getAsInt(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1), is(0));
        assertThat(partitionSetting.getAsBoolean(IndexMetaData.SETTING_AUTO_EXPAND_REPLICAS, true), is(false));
    }
    execute("select number_of_replicas, number_of_shards from information_schema.tables where table_name = 'quotes'");
    assertEquals("0", response.rows()[0][0]);
    assertEquals(3, response.rows()[0][1]);
    execute("alter table quotes set (number_of_replicas='1-all')");
    ensureYellow();
    execute("select number_of_replicas from information_schema.tables where table_name = 'quotes'");
    assertEquals("1-all", response.rows()[0][0]);
    templatesResponse = client().admin().indices().prepareGetTemplates(templateName).execute().actionGet();
    templateSettings = templatesResponse.getIndexTemplates().get(0).getSettings();
    assertThat(templateSettings.get(IndexMetaData.SETTING_AUTO_EXPAND_REPLICAS), is("1-all"));
    settingsResponse = client().admin().indices().prepareGetSettings(partitions.get(0), partitions.get(1)).execute().get();
    for (String index : partitions) {
        assertThat(settingsResponse.getSetting(index, IndexMetaData.SETTING_AUTO_EXPAND_REPLICAS), is("1-all"));
    }
}
Also used : PartitionName(io.crate.metadata.PartitionName) GetSettingsResponse(org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse) GetIndexTemplatesResponse(org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse) Settings(org.elasticsearch.common.settings.Settings) BytesRef(org.apache.lucene.util.BytesRef) Test(org.junit.Test)

Example 7 with Settings

use of org.elasticsearch.common.settings.Settings in project crate by crate.

the class PartitionedTableIntegrationTest method testAlterTableResetEmptyPartitionedTable.

@Test
public void testAlterTableResetEmptyPartitionedTable() throws Exception {
    execute("create table quotes (id integer, quote string, date timestamp) " + "partitioned by(date) clustered into 3 shards with (number_of_replicas='1-all')");
    ensureYellow();
    String templateName = PartitionName.templateName(null, "quotes");
    GetIndexTemplatesResponse templatesResponse = client().admin().indices().prepareGetTemplates(templateName).execute().actionGet();
    Settings templateSettings = templatesResponse.getIndexTemplates().get(0).getSettings();
    assertThat(templateSettings.getAsInt(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0), is(1));
    assertThat(templateSettings.get(IndexMetaData.SETTING_AUTO_EXPAND_REPLICAS), is("1-all"));
    execute("alter table quotes reset (number_of_replicas)");
    ensureYellow();
    templatesResponse = client().admin().indices().prepareGetTemplates(templateName).execute().actionGet();
    templateSettings = templatesResponse.getIndexTemplates().get(0).getSettings();
    assertThat(templateSettings.getAsInt(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0), is(1));
    assertThat(templateSettings.get(IndexMetaData.SETTING_AUTO_EXPAND_REPLICAS), is("false"));
}
Also used : GetIndexTemplatesResponse(org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse) Settings(org.elasticsearch.common.settings.Settings) Test(org.junit.Test)

Example 8 with Settings

use of org.elasticsearch.common.settings.Settings in project crate by crate.

the class PartitionedTableIntegrationTest method testAlterTableResetPartitionedTable.

@Test
public void testAlterTableResetPartitionedTable() throws Exception {
    execute("create table quotes (id integer, quote string, date timestamp) " + "partitioned by(date) clustered into 3 shards with (number_of_replicas='1-all')");
    ensureYellow();
    execute("insert into quotes (id, quote, date) values (?, ?, ?), (?, ?, ?)", new Object[] { 1, "Don't panic", 1395874800000L, 2, "Now panic", 1395961200000L });
    assertThat(response.rowCount(), is(2L));
    ensureYellow();
    refresh();
    execute("alter table quotes reset (number_of_replicas)");
    ensureYellow();
    String templateName = PartitionName.templateName(null, "quotes");
    GetIndexTemplatesResponse templatesResponse = client().admin().indices().prepareGetTemplates(templateName).execute().actionGet();
    Settings templateSettings = templatesResponse.getIndexTemplates().get(0).getSettings();
    assertThat(templateSettings.getAsInt(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0), is(1));
    assertThat(templateSettings.get(IndexMetaData.SETTING_AUTO_EXPAND_REPLICAS), is("false"));
    List<String> partitions = ImmutableList.of(new PartitionName("quotes", Collections.singletonList(new BytesRef("1395874800000"))).asIndexName(), new PartitionName("quotes", Collections.singletonList(new BytesRef("1395961200000"))).asIndexName());
    Thread.sleep(1000);
    GetSettingsResponse settingsResponse = client().admin().indices().prepareGetSettings(partitions.get(0), partitions.get(1)).execute().get();
    for (String index : partitions) {
        assertThat(settingsResponse.getSetting(index, IndexMetaData.SETTING_NUMBER_OF_REPLICAS), is("1"));
        assertThat(settingsResponse.getSetting(index, IndexMetaData.SETTING_AUTO_EXPAND_REPLICAS), is("false"));
    }
}
Also used : PartitionName(io.crate.metadata.PartitionName) GetSettingsResponse(org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse) GetIndexTemplatesResponse(org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse) Settings(org.elasticsearch.common.settings.Settings) BytesRef(org.apache.lucene.util.BytesRef) Test(org.junit.Test)

Example 9 with Settings

use of org.elasticsearch.common.settings.Settings in project crate by crate.

the class SysClusterSettingsTest method testDynamicPersistentSettings.

@Test
public void testDynamicPersistentSettings() throws Exception {
    Settings.Builder builder = Settings.builder().put(CrateSettings.STATS_OPERATIONS_LOG_SIZE.settingName(), 100);
    client().admin().cluster().prepareUpdateSettings().setPersistentSettings(builder.build()).execute().actionGet();
    execute("select settings from sys.cluster");
    assertEquals(1L, response.rowCount());
    Map<String, Map> settings = (Map<String, Map>) response.rows()[0][0];
    Map bulk = settings.get(CrateSettings.STATS.name());
    assertEquals(100, bulk.get(CrateSettings.STATS_OPERATIONS_LOG_SIZE.name()));
    internalCluster().fullRestart();
    // the gateway recovery is async and
    // it might take a bit until it reads the persisted cluster state and updates the settings expression
    assertBusy(new Runnable() {

        @Override
        public void run() {
            execute("select settings from sys.cluster");
            assertEquals(1L, response.rowCount());
            Map<String, Map> settings = (Map<String, Map>) response.rows()[0][0];
            Map bulk = settings.get(CrateSettings.STATS.name());
            assertEquals(100, bulk.get(CrateSettings.STATS_OPERATIONS_LOG_SIZE.name()));
        }
    });
}
Also used : Map(java.util.Map) CrateSettings(io.crate.metadata.settings.CrateSettings) Settings(org.elasticsearch.common.settings.Settings) Test(org.junit.Test)

Example 10 with Settings

use of org.elasticsearch.common.settings.Settings in project crate by crate.

the class SysClusterSettingsTest method testDynamicTransientSettings.

@Test
public void testDynamicTransientSettings() throws Exception {
    Settings.Builder builder = Settings.builder().put(CrateSettings.STATS_JOBS_LOG_SIZE.settingName(), 1).put(CrateSettings.STATS_OPERATIONS_LOG_SIZE.settingName(), 2).put(CrateSettings.STATS_ENABLED.settingName(), false);
    client().admin().cluster().prepareUpdateSettings().setTransientSettings(builder.build()).execute().actionGet();
    execute("select settings from sys.cluster");
    assertEquals(1L, response.rowCount());
    Map<String, Map> settings = (Map<String, Map>) response.rows()[0][0];
    Map stats = settings.get(CrateSettings.STATS.name());
    assertEquals(1, stats.get(CrateSettings.STATS_JOBS_LOG_SIZE.name()));
    assertEquals(2, stats.get(CrateSettings.STATS_OPERATIONS_LOG_SIZE.name()));
    assertEquals(false, stats.get(CrateSettings.STATS_ENABLED.name()));
    internalCluster().fullRestart();
    execute("select settings from sys.cluster");
    assertEquals(1L, response.rowCount());
    settings = (Map<String, Map>) response.rows()[0][0];
    stats = settings.get(CrateSettings.STATS.name());
    assertEquals(CrateSettings.STATS_JOBS_LOG_SIZE.defaultValue(), stats.get(CrateSettings.STATS_JOBS_LOG_SIZE.name()));
    assertEquals(CrateSettings.STATS_OPERATIONS_LOG_SIZE.defaultValue(), stats.get(CrateSettings.STATS_OPERATIONS_LOG_SIZE.name()));
    assertEquals(CrateSettings.STATS_ENABLED.defaultValue(), stats.get(CrateSettings.STATS_ENABLED.name()));
}
Also used : Map(java.util.Map) CrateSettings(io.crate.metadata.settings.CrateSettings) Settings(org.elasticsearch.common.settings.Settings) Test(org.junit.Test)

Aggregations

Settings (org.elasticsearch.common.settings.Settings)866 IndexSettings (org.elasticsearch.index.IndexSettings)112 Path (java.nio.file.Path)91 IOException (java.io.IOException)83 ClusterState (org.elasticsearch.cluster.ClusterState)76 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)72 ClusterSettings (org.elasticsearch.common.settings.ClusterSettings)68 HashMap (java.util.HashMap)66 ArrayList (java.util.ArrayList)64 Version (org.elasticsearch.Version)63 Environment (org.elasticsearch.env.Environment)63 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)61 Test (org.junit.Test)60 Map (java.util.Map)55 Index (org.elasticsearch.index.Index)55 Matchers.containsString (org.hamcrest.Matchers.containsString)54 List (java.util.List)45 ThreadPool (org.elasticsearch.threadpool.ThreadPool)40 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)37 MetaData (org.elasticsearch.cluster.metadata.MetaData)36