Search in sources :

Example 1 with DeleteIndexResponse

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;
}
Also used : DeleteIndexResponse(org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse) DeleteIndexRequest(org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest) FutureActionListener(io.crate.action.FutureActionListener)

Example 2 with DeleteIndexResponse

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);
    }
}
Also used : DeleteIndexResponse(org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse) DeleteIndexRequest(org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest)

Example 3 with DeleteIndexResponse

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());
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) RangeQueryBuilder(org.elasticsearch.index.query.RangeQueryBuilder) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) UnavailableShardsException(org.elasticsearch.action.UnavailableShardsException) SearchResponse(org.elasticsearch.action.search.SearchResponse) DeleteIndexResponse(org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse) UnavailableShardsException(org.elasticsearch.action.UnavailableShardsException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException)

Example 4 with DeleteIndexResponse

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();
}
Also used : DeleteIndexResponse(org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse) TransportClient(org.elasticsearch.client.transport.TransportClient) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress)

Example 5 with DeleteIndexResponse

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);
            }
        }
    });
}
Also used : DeleteIndexResponse(org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse) DeleteIndexRequest(org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException)

Aggregations

DeleteIndexResponse (org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse)8 DeleteIndexRequest (org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest)4 IndexNotFoundException (org.elasticsearch.index.IndexNotFoundException)2 FutureActionListener (io.crate.action.FutureActionListener)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 UnavailableShardsException (org.elasticsearch.action.UnavailableShardsException)1 ClusterHealthResponse (org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse)1 CreateIndexResponse (org.elasticsearch.action.admin.indices.create.CreateIndexResponse)1 SearchResponse (org.elasticsearch.action.search.SearchResponse)1 TransportClient (org.elasticsearch.client.transport.TransportClient)1 ClusterState (org.elasticsearch.cluster.ClusterState)1 RoutingNode (org.elasticsearch.cluster.routing.RoutingNode)1 Settings (org.elasticsearch.common.settings.Settings)1 InetSocketTransportAddress (org.elasticsearch.common.transport.InetSocketTransportAddress)1 RangeQueryBuilder (org.elasticsearch.index.query.RangeQueryBuilder)1 After (org.junit.After)1