Search in sources :

Example 56 with IndicesService

use of org.elasticsearch.indices.IndicesService in project crate by crate.

the class DanglingIndicesIT method testDanglingIndicesAreRecoveredWhenSettingIsEnabled.

/**
 * Check that when dangling indices are discovered, then they are recovered into
 * the cluster, so long as the recovery setting is enabled.
 */
public void testDanglingIndicesAreRecoveredWhenSettingIsEnabled() throws Exception {
    final Settings settings = buildSettings(true, true);
    internalCluster().startNodes(3, settings);
    execute("create table doc.test(id integer) clustered into 2 shards with(number_of_replicas = 2)");
    ensureGreen("test");
    assertBusy(() -> internalCluster().getInstances(IndicesService.class).forEach(indicesService -> assertTrue(indicesService.allPendingDanglingIndicesWritten())));
    boolean refreshIntervalChanged = randomBoolean();
    if (refreshIntervalChanged) {
        client().admin().indices().prepareUpdateSettings("test").setSettings(Settings.builder().put("index.refresh_interval", "42s").build()).get();
        assertBusy(() -> internalCluster().getInstances(IndicesService.class).forEach(indicesService -> assertTrue(indicesService.allPendingDanglingIndicesWritten())));
    }
    // Restart node, deleting the index in its absence, so that there is a dangling index to recover
    internalCluster().restartRandomDataNode(new InternalTestCluster.RestartCallback() {

        @Override
        public Settings onNodeStopped(String nodeName) throws Exception {
            ensureClusterSizeConsistency();
            execute("drop table doc.test");
            return super.onNodeStopped(nodeName);
        }
    });
    assertBusy(() -> assertThat("Expected dangling index test to be recovered", execute("select 1 from information_schema.tables where table_name='test'").rowCount(), is((1L))));
    ensureGreen("test");
}
Also used : InternalTestCluster(org.elasticsearch.test.InternalTestCluster) TimeUnit(java.util.concurrent.TimeUnit) SETTING_MAX_TOMBSTONES(org.elasticsearch.cluster.metadata.IndexGraveyard.SETTING_MAX_TOMBSTONES) ClusterScope(org.elasticsearch.test.ESIntegTestCase.ClusterScope) Settings(org.elasticsearch.common.settings.Settings) ESIntegTestCase(org.elasticsearch.test.ESIntegTestCase) AUTO_IMPORT_DANGLING_INDICES_SETTING(org.elasticsearch.gateway.DanglingIndicesState.AUTO_IMPORT_DANGLING_INDICES_SETTING) SQLIntegrationTestCase(io.crate.integrationtests.SQLIntegrationTestCase) Matchers.is(org.hamcrest.Matchers.is) IndicesService(org.elasticsearch.indices.IndicesService) InternalTestCluster(org.elasticsearch.test.InternalTestCluster) Settings(org.elasticsearch.common.settings.Settings)

Example 57 with IndicesService

use of org.elasticsearch.indices.IndicesService in project crate by crate.

the class UnsafeBootstrapAndDetachCommandIT method testAllMasterEligibleNodesFailedDanglingIndexImport.

public void testAllMasterEligibleNodesFailedDanglingIndexImport() throws Exception {
    internalCluster().setBootstrapMasterNodeIndex(0);
    logger.info("--> start mixed data and master-eligible node and bootstrap cluster");
    // node ordinal 0
    String masterNode = internalCluster().startNode();
    logger.info("--> start data-only node and ensure 2 nodes stable cluster");
    // node ordinal 1
    String dataNode = internalCluster().startDataOnlyNode();
    ensureStableCluster(2);
    execute("create table doc.test(x int)");
    logger.info("--> index 1 doc and ensure index is green");
    execute("insert into doc.test values(1)");
    execute("refresh table doc.test");
    ensureGreen("test");
    assertBusy(() -> internalCluster().getInstances(IndicesService.class).forEach(indicesService -> assertTrue(indicesService.allPendingDanglingIndicesWritten())));
    logger.info("--> verify 1 doc in the index");
    execute("select count(*) from doc.test");
    assertThat(response.rows()[0][0], is(1L));
    logger.info("--> stop data-only node and detach it from the old cluster");
    Settings dataNodeDataPathSettings = internalCluster().dataPathSettings(dataNode);
    internalCluster().stopRandomNode(InternalTestCluster.nameFilter(dataNode));
    final Environment environment = TestEnvironment.newEnvironment(Settings.builder().put(internalCluster().getDefaultSettings()).put(dataNodeDataPathSettings).build());
    detachCluster(environment, false);
    logger.info("--> stop master-eligible node, clear its data and start it again - new cluster should form");
    internalCluster().restartNode(masterNode, new InternalTestCluster.RestartCallback() {

        @Override
        public boolean clearData(String nodeName) {
            return true;
        }
    });
    logger.info("--> start data-only only node and ensure 2 nodes stable cluster");
    internalCluster().startDataOnlyNode(dataNodeDataPathSettings);
    ensureStableCluster(2);
    logger.info("--> verify that the dangling index exists and has green status");
    assertBusy(() -> {
        execute("select 1 from information_schema.tables where table_name='test'");
        if (response.rowCount() == 1) {
            assertThat(response.rows()[0][0], is(1));
        } else {
            fail();
        }
    });
    ensureGreen("test");
    logger.info("--> verify the doc is there");
    execute("select count(*) from doc.test");
    assertThat(response.rows()[0][0], is(1L));
}
Also used : ElasticsearchException(org.elasticsearch.ElasticsearchException) InternalTestCluster(org.elasticsearch.test.InternalTestCluster) Environment(org.elasticsearch.env.Environment) SQLIntegrationTestCase(io.crate.integrationtests.SQLIntegrationTestCase) INDICES_RECOVERY_MAX_BYTES_PER_SEC_SETTING(org.elasticsearch.indices.recovery.RecoverySettings.INDICES_RECOVERY_MAX_BYTES_PER_SEC_SETTING) ArrayList(java.util.ArrayList) ClusterState(org.elasticsearch.cluster.ClusterState) Metadata(org.elasticsearch.cluster.metadata.Metadata) Settings(org.elasticsearch.common.settings.Settings) Locale(java.util.Locale) Node(org.elasticsearch.node.Node) IndicesService(org.elasticsearch.indices.IndicesService) MockTerminal(org.elasticsearch.cli.MockTerminal) OptionSet(joptsimple.OptionSet) NodeMetadata(org.elasticsearch.env.NodeMetadata) Test(org.junit.Test) IOException(java.io.IOException) List(java.util.List) NodeEnvironment(org.elasticsearch.env.NodeEnvironment) TestEnvironment(org.elasticsearch.env.TestEnvironment) ESIntegTestCase(org.elasticsearch.test.ESIntegTestCase) Matchers.equalTo(org.hamcrest.Matchers.equalTo) LuceneTestCase(org.apache.lucene.util.LuceneTestCase) Matchers.is(org.hamcrest.Matchers.is) PersistedClusterStateService(org.elasticsearch.gateway.PersistedClusterStateService) UseJdbc(io.crate.testing.UseJdbc) Matchers.containsString(org.hamcrest.Matchers.containsString) Environment(org.elasticsearch.env.Environment) NodeEnvironment(org.elasticsearch.env.NodeEnvironment) TestEnvironment(org.elasticsearch.env.TestEnvironment) InternalTestCluster(org.elasticsearch.test.InternalTestCluster) Matchers.containsString(org.hamcrest.Matchers.containsString) Settings(org.elasticsearch.common.settings.Settings)

Aggregations

IndicesService (org.elasticsearch.indices.IndicesService)57 IndexService (org.elasticsearch.index.IndexService)41 IndexShard (org.elasticsearch.index.shard.IndexShard)29 Index (org.elasticsearch.index.Index)21 ClusterState (org.elasticsearch.cluster.ClusterState)12 Settings (org.elasticsearch.common.settings.Settings)12 ClusterService (org.elasticsearch.cluster.service.ClusterService)11 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)10 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)9 ShardId (org.elasticsearch.index.shard.ShardId)9 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)7 ByteSizeValue (org.elasticsearch.common.unit.ByteSizeValue)7 Test (org.junit.Test)7 List (java.util.List)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)6 HashMap (java.util.HashMap)5 Set (java.util.Set)5 ActionListener (org.elasticsearch.action.ActionListener)5