use of io.crate.protocols.postgres.PostgresNetty in project crate by crate.
the class GatewayIndexStateIT method testIndexDeletionWhenNodeRejoins.
/**
* This test ensures that when an index deletion takes place while a node is offline, when that
* node rejoins the cluster, it deletes the index locally instead of importing it as a dangling index.
*/
@Test
public void testIndexDeletionWhenNodeRejoins() throws Exception {
final int numNodes = 2;
final List<String> nodes;
logger.info("--> starting a cluster with " + numNodes + " nodes");
nodes = internalCluster().startNodes(numNodes, Settings.builder().put(IndexGraveyard.SETTING_MAX_TOMBSTONES.getKey(), randomIntBetween(10, 100)).build());
logger.info("--> create an index");
// createIndex(indexName);
execute("create table my_schema.test (id int) with (number_of_replicas = 0)");
var tableName = "my_schema.test";
logger.info("--> waiting for green status");
ensureGreen();
final String indexUUID = resolveIndex(tableName).getUUID();
logger.info("--> restart a random date node, deleting the index in between stopping and restarting");
internalCluster().restartRandomDataNode(new RestartCallback() {
@Override
public Settings onNodeStopped(final String nodeName) throws Exception {
nodes.remove(nodeName);
logger.info("--> stopped node[{}], remaining nodes {}", nodeName, nodes);
assert nodes.size() > 0;
final String otherNode = nodes.get(0);
logger.info("--> delete index and verify it is deleted");
var clientProvider = new SQLTransportExecutor.ClientProvider() {
@Override
public Client client() {
return ESIntegTestCase.client(otherNode);
}
@Override
public String pgUrl() {
PostgresNetty postgresNetty = internalCluster().getInstance(PostgresNetty.class, otherNode);
BoundTransportAddress boundTransportAddress = postgresNetty.boundAddress();
if (boundTransportAddress != null) {
InetSocketAddress address = boundTransportAddress.publishAddress().address();
return String.format(Locale.ENGLISH, "jdbc:postgresql://%s:%d/?ssl=%s&sslmode=%s", address.getHostName(), address.getPort(), false, "disable");
}
return null;
}
@Override
public SQLOperations sqlOperations() {
return internalCluster().getInstance(SQLOperations.class, otherNode);
}
};
var sqlExecutor = new SQLTransportExecutor(clientProvider);
// client.admin().indices().prepareDelete(indexName).execute().actionGet();
sqlExecutor.exec("drop table my_schema.test");
assertThat(response.rowCount(), is(1L));
// assertFalse(indexExists(indexName, client));
try {
sqlExecutor.exec("select * from my_schema.test");
fail("expecting index to be deleted");
} catch (Exception e) {
// pass
}
logger.info("--> index deleted");
return super.onNodeStopped(nodeName);
}
});
logger.info("--> wait until all nodes are back online");
client().admin().cluster().health(Requests.clusterHealthRequest().waitForEvents(Priority.LANGUID).waitForNodes(Integer.toString(numNodes))).actionGet(REQUEST_TIMEOUT);
logger.info("--> waiting for green status");
ensureGreen();
logger.info("--> verify that the deleted index is removed from the cluster and not reimported as dangling by the restarted node");
// assertFalse(indexExists(indexName));
try {
execute("select * from my_schema.test");
fail("expecting index to be deleted");
} catch (Exception e) {
// pass
}
assertBusy(() -> {
final NodeEnvironment nodeEnv = internalCluster().getInstance(NodeEnvironment.class);
try {
assertFalse("index folder " + indexUUID + " should be deleted", nodeEnv.availableIndexFolders().contains(indexUUID));
} catch (IOException e) {
logger.error("Unable to retrieve available index folders from the node", e);
fail("Unable to retrieve available index folders from the node");
}
});
}
Aggregations