use of org.elasticsearch.action.admin.cluster.state.ClusterStateResponse in project crate by crate.
the class GatewayIndexStateIT method testJustMasterNode.
/**
* Creating a table without any data node will take very long as internally at CrateDB, a table creation
* is waiting for all shards to acknowledge until it times out if no data node is available.
* So this will run under the @Slow annotation.
*/
@Slow
@Test
public void testJustMasterNode() throws Exception {
logger.info("--> cleaning nodes");
logger.info("--> starting 1 master node non data");
internalCluster().startNode(Settings.builder().put(Node.NODE_DATA_SETTING.getKey(), false).build());
logger.info("--> create an index");
execute("create table test (id int) with (number_of_replicas = 0, \"write.wait_for_active_shards\" = 0)", null, new TimeValue(90, TimeUnit.SECONDS));
var tableName = getFqn("test");
logger.info("--> restarting master node");
internalCluster().fullRestart(new RestartCallback() {
@Override
public Settings onNodeStopped(String nodeName) {
return Settings.builder().put(Node.NODE_DATA_SETTING.getKey(), false).build();
}
});
logger.info("--> waiting for test index to be created");
ClusterHealthResponse health = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setIndices(tableName).execute().actionGet(REQUEST_TIMEOUT);
assertThat(health.isTimedOut(), equalTo(false));
logger.info("--> verify we have an index");
ClusterStateResponse clusterStateResponse = client().admin().cluster().prepareState().setIndices(tableName).execute().actionGet(REQUEST_TIMEOUT);
assertThat(clusterStateResponse.getState().metadata().hasIndex(tableName), equalTo(true));
}
use of org.elasticsearch.action.admin.cluster.state.ClusterStateResponse in project crate by crate.
the class IndexRecoveryIT method testDisconnectsWhileRecovering.
@Test
public void testDisconnectsWhileRecovering() throws Exception {
final String indexName = "test";
final Settings nodeSettings = Settings.builder().put(RecoverySettings.INDICES_RECOVERY_RETRY_DELAY_NETWORK_SETTING.getKey(), "100ms").put(RecoverySettings.INDICES_RECOVERY_INTERNAL_ACTION_TIMEOUT_SETTING.getKey(), "1s").put(NodeConnectionsService.CLUSTER_NODE_RECONNECT_INTERVAL_SETTING.getKey(), "1s").build();
// start a master node
internalCluster().startNode(nodeSettings);
final String blueNodeName = internalCluster().startNode(Settings.builder().put("node.attr.color", "blue").put(nodeSettings).build());
final String redNodeName = internalCluster().startNode(Settings.builder().put("node.attr.color", "red").put(nodeSettings).build());
ClusterHealthResponse response = client().admin().cluster().prepareHealth().setWaitForNodes(">=3").get();
assertThat(response.isTimedOut(), is(false));
execute("CREATE TABLE doc." + indexName + " (id int) CLUSTERED INTO 1 SHARDS " + "WITH (" + " number_of_replicas=0," + " \"routing.allocation.include.color\" = 'blue'" + ")");
int numDocs = scaledRandomIntBetween(25, 250);
var args = new Object[numDocs][];
for (int i = 0; i < numDocs; i++) {
args[i] = new Object[] { i };
}
execute("INSERT INTO doc." + indexName + " (id) VALUES (?)", args);
ensureGreen();
ClusterStateResponse stateResponse = client().admin().cluster().prepareState().get();
final String blueNodeId = internalCluster().getInstance(ClusterService.class, blueNodeName).localNode().getId();
assertFalse(stateResponse.getState().getRoutingNodes().node(blueNodeId).isEmpty());
refresh();
var searchResponse = execute("SELECT COUNT(*) FROM doc." + indexName);
assertThat((long) searchResponse.rows()[0][0], is((long) numDocs));
String[] recoveryActions = new String[] { PeerRecoverySourceService.Actions.START_RECOVERY, PeerRecoveryTargetService.Actions.FILES_INFO, PeerRecoveryTargetService.Actions.FILE_CHUNK, PeerRecoveryTargetService.Actions.CLEAN_FILES, // RecoveryTarget.Actions.TRANSLOG_OPS, <-- may not be sent if already flushed
PeerRecoveryTargetService.Actions.PREPARE_TRANSLOG, PeerRecoveryTargetService.Actions.FINALIZE };
final String recoveryActionToBlock = randomFrom(recoveryActions);
final boolean dropRequests = randomBoolean();
logger.info("--> will {} between blue & red on [{}]", dropRequests ? "drop requests" : "break connection", recoveryActionToBlock);
MockTransportService blueMockTransportService = (MockTransportService) internalCluster().getInstance(TransportService.class, blueNodeName);
MockTransportService redMockTransportService = (MockTransportService) internalCluster().getInstance(TransportService.class, redNodeName);
TransportService redTransportService = internalCluster().getInstance(TransportService.class, redNodeName);
TransportService blueTransportService = internalCluster().getInstance(TransportService.class, blueNodeName);
final CountDownLatch requestFailed = new CountDownLatch(1);
if (randomBoolean()) {
// Fail on the sending side
blueMockTransportService.addSendBehavior(redTransportService, new RecoveryActionBlocker(dropRequests, recoveryActionToBlock, requestFailed));
redMockTransportService.addSendBehavior(blueTransportService, new RecoveryActionBlocker(dropRequests, recoveryActionToBlock, requestFailed));
} else {
// Fail on the receiving side.
blueMockTransportService.addRequestHandlingBehavior(recoveryActionToBlock, (handler, request, channel) -> {
logger.info("--> preventing {} response by closing response channel", recoveryActionToBlock);
requestFailed.countDown();
redMockTransportService.disconnectFromNode(blueMockTransportService.getLocalNode());
handler.messageReceived(request, channel);
});
redMockTransportService.addRequestHandlingBehavior(recoveryActionToBlock, (handler, request, channel) -> {
logger.info("--> preventing {} response by closing response channel", recoveryActionToBlock);
requestFailed.countDown();
blueMockTransportService.disconnectFromNode(redMockTransportService.getLocalNode());
handler.messageReceived(request, channel);
});
}
logger.info("--> starting recovery from blue to red");
execute("ALTER TABLE doc." + indexName + " SET (" + " number_of_replicas=1," + " \"routing.allocation.include.color\" = 'red,blue'" + ")");
requestFailed.await();
logger.info("--> clearing rules to allow recovery to proceed");
blueMockTransportService.clearAllRules();
redMockTransportService.clearAllRules();
ensureGreen();
// TODO: ES will use the shard routing preference here to prefer `_local` shards on that node
var nodeRedExecutor = executor(redNodeName);
searchResponse = nodeRedExecutor.exec("SELECT COUNT(*) FROM doc." + indexName);
assertThat((long) searchResponse.rows()[0][0], is((long) numDocs));
}
use of org.elasticsearch.action.admin.cluster.state.ClusterStateResponse in project crate by crate.
the class AbstractSnapshotIntegTestCase method waitForCompletion.
public SnapshotInfo waitForCompletion(String repository, String snapshotName, TimeValue timeout) throws InterruptedException {
long start = System.currentTimeMillis();
while (System.currentTimeMillis() - start < timeout.millis()) {
List<SnapshotInfo> snapshotInfos = client().admin().cluster().prepareGetSnapshots(repository).setSnapshots(snapshotName).get().getSnapshots();
assertThat(snapshotInfos.size(), equalTo(1));
if (snapshotInfos.get(0).state().completed()) {
// Make sure that snapshot clean up operations are finished
ClusterStateResponse stateResponse = client().admin().cluster().prepareState().get();
SnapshotsInProgress snapshotsInProgress = stateResponse.getState().custom(SnapshotsInProgress.TYPE);
if (snapshotsInProgress == null) {
return snapshotInfos.get(0);
} else {
boolean found = false;
for (SnapshotsInProgress.Entry entry : snapshotsInProgress.entries()) {
final Snapshot curr = entry.snapshot();
if (curr.getRepository().equals(repository) && curr.getSnapshotId().getName().equals(snapshotName)) {
found = true;
break;
}
}
if (found == false) {
return snapshotInfos.get(0);
}
}
}
Thread.sleep(100);
}
fail("Timeout!!!");
return null;
}
use of org.elasticsearch.action.admin.cluster.state.ClusterStateResponse in project crate by crate.
the class SQLIntegrationTestCase method getIndexSettings.
/**
* Get the IndexSettings as JSON String
*
* @param index the name of the index
* @return the IndexSettings as JSON String
* @throws IOException
*/
protected String getIndexSettings(String index) throws IOException {
ClusterStateRequest request = Requests.clusterStateRequest().routingTable(false).nodes(false).metadata(true).indices(index);
ClusterStateResponse response = client().admin().cluster().state(request).actionGet();
Metadata metadata = response.getState().metadata();
XContentBuilder builder = XContentFactory.jsonBuilder().startObject();
for (IndexMetadata indexMetadata : metadata) {
builder.startObject(indexMetadata.getIndex().getName());
builder.startObject("settings");
Settings settings = indexMetadata.getSettings();
for (String settingName : settings.keySet()) {
builder.field(settingName, settings.get(settingName));
}
builder.endObject();
builder.endObject();
}
builder.endObject();
return Strings.toString(builder);
}
Aggregations