use of org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse in project crate by crate.
the class BlobAdminClient method dropBlobTable.
public CompletableFuture<Void> dropBlobTable(final String tableName) {
FutureActionListener<DeleteIndexResponse, Void> listener = new FutureActionListener<>(Functions.<Void>constant(null));
deleteIndexAction.execute(new DeleteIndexRequest(fullIndexName(tableName)), listener);
return listener;
}
use of org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse in project crate by crate.
the class TableCreator method deleteOrphanedPartitions.
/**
* if some orphaned partition with the same table name still exist,
* delete them beforehand as they would create unwanted and maybe invalid
* initial data.
* <p>
* should never delete partitions of existing partitioned tables
*/
private void deleteOrphanedPartitions(final CreateTableResponseListener listener, TableIdent tableIdent) {
String partitionWildCard = PartitionName.templateName(tableIdent.schema(), tableIdent.name()) + "*";
String[] orphans = indexNameExpressionResolver.concreteIndices(clusterService.state(), IndicesOptions.strictExpand(), partitionWildCard);
if (orphans.length > 0) {
if (logger.isDebugEnabled()) {
logger.debug("Deleting orphaned partitions: {}", Joiner.on(", ").join(orphans));
}
transportActionProvider.transportDeleteIndexAction().execute(new DeleteIndexRequest(orphans), new ActionListener<DeleteIndexResponse>() {
@Override
public void onResponse(DeleteIndexResponse response) {
if (!response.isAcknowledged()) {
warnNotAcknowledged("deleting orphans");
}
listener.onResponse(SUCCESS_RESULT);
}
@Override
public void onFailure(Throwable e) {
listener.onFailure(e);
}
});
} else {
listener.onResponse(SUCCESS_RESULT);
}
}
use of org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse in project elasticsearch by elastic.
the class CreateIndexIT method testCreateAndDeleteIndexConcurrently.
public void testCreateAndDeleteIndexConcurrently() throws InterruptedException {
createIndex("test");
final AtomicInteger indexVersion = new AtomicInteger(0);
final Object indexVersionLock = new Object();
final CountDownLatch latch = new CountDownLatch(1);
int numDocs = randomIntBetween(1, 10);
for (int i = 0; i < numDocs; i++) {
client().prepareIndex("test", "test").setSource("index_version", indexVersion.get()).get();
}
synchronized (indexVersionLock) {
// not necessarily needed here but for completeness we lock here too
indexVersion.incrementAndGet();
}
client().admin().indices().prepareDelete("test").execute(new // this happens async!!!
ActionListener<DeleteIndexResponse>() {
@Override
public void onResponse(DeleteIndexResponse deleteIndexResponse) {
Thread thread = new Thread() {
@Override
public void run() {
try {
// recreate that index
client().prepareIndex("test", "test").setSource("index_version", indexVersion.get()).get();
synchronized (indexVersionLock) {
// we sync here since we have to ensure that all indexing operations below for a given ID are done before
// we increment the index version otherwise a doc that is in-flight could make it into an index that it
// was supposed to be deleted for and our assertion fail...
indexVersion.incrementAndGet();
}
// from here on all docs with index_version == 0|1 must be gone!!!! only 2 are ok;
assertAcked(client().admin().indices().prepareDelete("test").get());
} finally {
latch.countDown();
}
}
};
thread.start();
}
@Override
public void onFailure(Exception e) {
throw new RuntimeException(e);
}
});
numDocs = randomIntBetween(100, 200);
for (int i = 0; i < numDocs; i++) {
try {
synchronized (indexVersionLock) {
client().prepareIndex("test", "test").setSource("index_version", indexVersion.get()).setTimeout(TimeValue.timeValueSeconds(10)).get();
}
} catch (IndexNotFoundException inf) {
// fine
} catch (UnavailableShardsException ex) {
assertEquals(ex.getCause().getClass(), IndexNotFoundException.class);
// fine we run into a delete index while retrying
}
}
latch.await();
refresh();
// we only really assert that we never reuse segments of old indices or anything like this here and that nothing fails with
// crazy exceptions
SearchResponse expected = client().prepareSearch("test").setIndicesOptions(IndicesOptions.lenientExpandOpen()).setQuery(new RangeQueryBuilder("index_version").from(indexVersion.get(), true)).get();
SearchResponse all = client().prepareSearch("test").setIndicesOptions(IndicesOptions.lenientExpandOpen()).get();
assertEquals(expected + " vs. " + all, expected.getHits().getTotalHits(), all.getHits().getTotalHits());
logger.info("total: {}", expected.getHits().getTotalHits());
}
use of org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse in project sonarqube by SonarSource.
the class EsServerHolder method reset.
private void reset() {
TransportClient client = TransportClient.builder().settings(Settings.builder().put("network.bind_host", "localhost").put("cluster.name", clusterName).build()).build();
client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getLoopbackAddress(), port));
// wait for node to be ready
client.admin().cluster().prepareHealth().setWaitForGreenStatus().get();
// delete the indices created by previous tests
DeleteIndexResponse response = client.admin().indices().prepareDelete("_all").get();
if (!response.isAcknowledged()) {
throw new IllegalStateException("Fail to delete all indices");
}
client.close();
}
use of org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse in project crate by crate.
the class DropTableTask method deleteESIndex.
private void deleteESIndex(String indexOrAlias, final BatchConsumer consumer) {
DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(indexOrAlias);
if (tableInfo.isPartitioned()) {
deleteIndexRequest.indicesOptions(IndicesOptions.lenientExpandOpen());
}
deleteIndexAction.execute(deleteIndexRequest, new ActionListener<DeleteIndexResponse>() {
@Override
public void onResponse(DeleteIndexResponse response) {
if (!response.isAcknowledged()) {
warnNotAcknowledged();
}
consumer.accept(RowsBatchIterator.newInstance(ROW_ONE), null);
}
@Override
public void onFailure(Throwable e) {
if (tableInfo.isPartitioned()) {
logger.warn("Could not (fully) delete all partitions of {}. " + "Some orphaned partitions might still exist, " + "but are not accessible.", e, tableInfo.ident().fqn());
}
if (ifExists && e instanceof IndexNotFoundException) {
consumer.accept(RowsBatchIterator.newInstance(ROW_ZERO), null);
} else {
consumer.accept(null, e);
}
}
});
}
Aggregations