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");
}
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));
}
Aggregations