Search in sources :

Example 6 with RefreshRequest

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.refresh.RefreshRequest in project elasticsearch by elastic.

the class BulkProcessorRetryIT method executeBulkRejectionLoad.

private void executeBulkRejectionLoad(BackoffPolicy backoffPolicy, boolean rejectedExecutionExpected) throws Throwable {
    final CorrelatingBackoffPolicy internalPolicy = new CorrelatingBackoffPolicy(backoffPolicy);
    int numberOfAsyncOps = randomIntBetween(600, 700);
    final CountDownLatch latch = new CountDownLatch(numberOfAsyncOps);
    final Set<Object> responses = Collections.newSetFromMap(new ConcurrentHashMap<>());
    assertAcked(prepareCreate(INDEX_NAME));
    ensureGreen();
    BulkProcessor bulkProcessor = BulkProcessor.builder(client(), new BulkProcessor.Listener() {

        @Override
        public void beforeBulk(long executionId, BulkRequest request) {
        // no op
        }

        @Override
        public void afterBulk(long executionId, BulkRequest request, BulkResponse response) {
            internalPolicy.logResponse(response);
            responses.add(response);
            latch.countDown();
        }

        @Override
        public void afterBulk(long executionId, BulkRequest request, Throwable failure) {
            responses.add(failure);
            latch.countDown();
        }
    }).setBulkActions(1).setConcurrentRequests(randomIntBetween(0, 100)).setBackoffPolicy(internalPolicy).build();
    indexDocs(bulkProcessor, numberOfAsyncOps);
    latch.await(10, TimeUnit.SECONDS);
    bulkProcessor.close();
    assertThat(responses.size(), equalTo(numberOfAsyncOps));
    // validate all responses
    for (Object response : responses) {
        if (response instanceof BulkResponse) {
            BulkResponse bulkResponse = (BulkResponse) response;
            for (BulkItemResponse bulkItemResponse : bulkResponse.getItems()) {
                if (bulkItemResponse.isFailed()) {
                    BulkItemResponse.Failure failure = bulkItemResponse.getFailure();
                    Throwable rootCause = ExceptionsHelper.unwrapCause(failure.getCause());
                    if (rootCause instanceof EsRejectedExecutionException) {
                        if (rejectedExecutionExpected == false) {
                            Iterator<TimeValue> backoffState = internalPolicy.backoffStateFor(bulkResponse);
                            assertNotNull("backoffState is null (indicates a bulk request got rejected without retry)", backoffState);
                            if (backoffState.hasNext()) {
                                // we're not expecting that we overwhelmed it even once when we maxed out the number of retries
                                throw new AssertionError("Got rejected although backoff policy would allow more retries", rootCause);
                            } else {
                                logger.debug("We maxed out the number of bulk retries and got rejected (this is ok).");
                            }
                        }
                    } else {
                        throw new AssertionError("Unexpected failure", rootCause);
                    }
                }
            }
        } else {
            Throwable t = (Throwable) response;
            // we're not expecting any other errors
            throw new AssertionError("Unexpected failure", t);
        }
    }
    client().admin().indices().refresh(new RefreshRequest()).get();
    // validate we did not create any duplicates due to retries
    Matcher<Long> searchResultCount;
    // it is ok if we lost some index operations to rejected executions (which is possible even when backing off (although less likely)
    searchResultCount = lessThanOrEqualTo((long) numberOfAsyncOps);
    SearchResponse results = client().prepareSearch(INDEX_NAME).setTypes(TYPE_NAME).setQuery(QueryBuilders.matchAllQuery()).setSize(0).get();
    assertThat(results.getHits().getTotalHits(), searchResultCount);
}
Also used : RefreshRequest(org.elasticsearch.action.admin.indices.refresh.RefreshRequest) CountDownLatch(java.util.concurrent.CountDownLatch) SearchResponse(org.elasticsearch.action.search.SearchResponse) TimeValue(org.elasticsearch.common.unit.TimeValue) EsRejectedExecutionException(org.elasticsearch.common.util.concurrent.EsRejectedExecutionException)

Example 7 with RefreshRequest

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.refresh.RefreshRequest in project elasticsearch by elastic.

the class IndicesRequestIT method testRefresh.

public void testRefresh() {
    String[] indexShardActions = new String[] { TransportShardRefreshAction.NAME, TransportShardRefreshAction.NAME + "[r]", TransportShardRefreshAction.NAME + "[p]" };
    interceptTransportActions(indexShardActions);
    RefreshRequest refreshRequest = new RefreshRequest(randomIndicesOrAliases());
    internalCluster().coordOnlyNodeClient().admin().indices().refresh(refreshRequest).actionGet();
    clearInterceptedActions();
    String[] indices = new IndexNameExpressionResolver(Settings.EMPTY).concreteIndexNames(client().admin().cluster().prepareState().get().getState(), refreshRequest);
    assertIndicesSubset(Arrays.asList(indices), indexShardActions);
}
Also used : RefreshRequest(org.elasticsearch.action.admin.indices.refresh.RefreshRequest) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver)

Example 8 with RefreshRequest

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.refresh.RefreshRequest in project chili-core by codingchili.

the class ElasticMap method clear.

@Override
public void clear(Handler<AsyncResult<Void>> handler) {
    DeleteIndexResponse response = client.admin().indices().delete(new DeleteIndexRequest(context.database())).actionGet();
    if (response.isAcknowledged()) {
        client.admin().indices().refresh(new RefreshRequest(context.database()));
        handler.handle(result());
        context.onCollectionDropped();
    } else {
        handler.handle(error(new StorageFailureException()));
    }
}
Also used : RefreshRequest(org.elasticsearch.action.admin.indices.refresh.RefreshRequest) DeleteIndexResponse(org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse) DeleteIndexRequest(org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest)

Example 9 with RefreshRequest

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.refresh.RefreshRequest in project sonarqube by SonarSource.

the class EsRequestDetailsTest method should_format_RefreshRequest.

@Test
public void should_format_RefreshRequest() {
    RefreshRequest deleteRequest = new RefreshRequest().indices("index-1", "index-2");
    assertThat(EsRequestDetails.computeDetailsAsString(deleteRequest)).isEqualTo("ES refresh request on indices 'index-1,index-2'");
}
Also used : RefreshRequest(org.elasticsearch.action.admin.indices.refresh.RefreshRequest) Test(org.junit.Test)

Example 10 with RefreshRequest

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.refresh.RefreshRequest in project metron by apache.

the class ElasticSearchComponent method getAllIndexedDocs.

public List<Map<String, Object>> getAllIndexedDocs(String index, String sourceType, String subMessage) throws IOException {
    getClient().admin().indices().refresh(new RefreshRequest());
    SearchResponse response = getClient().prepareSearch(index).setTypes(sourceType).setFrom(0).setSize(1000).execute().actionGet();
    List<Map<String, Object>> ret = new ArrayList<Map<String, Object>>();
    for (SearchHit hit : response.getHits()) {
        Object o = null;
        if (subMessage == null) {
            o = hit.getSource();
        } else {
            o = hit.getSource().get(subMessage);
        }
        ret.add((Map<String, Object>) (o));
    }
    return ret;
}
Also used : RefreshRequest(org.elasticsearch.action.admin.indices.refresh.RefreshRequest) SearchHit(org.elasticsearch.search.SearchHit) ArrayList(java.util.ArrayList) JSONObject(org.json.simple.JSONObject) HashMap(java.util.HashMap) Map(java.util.Map) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Aggregations

RefreshRequest (org.elasticsearch.action.admin.indices.refresh.RefreshRequest)15 DeleteIndexRequest (org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest)6 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)5 IndexRequest (org.elasticsearch.action.index.IndexRequest)4 RestHighLevelClient (org.elasticsearch.client.RestHighLevelClient)4 CreateIndexRequest (org.elasticsearch.client.indices.CreateIndexRequest)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 RefreshResponse (org.elasticsearch.action.admin.indices.refresh.RefreshResponse)3 Map (java.util.Map)2 FlushRequest (org.elasticsearch.action.admin.indices.flush.FlushRequest)2 SearchResponse (org.elasticsearch.action.search.SearchResponse)2 IndicesOptions (org.elasticsearch.action.support.IndicesOptions)2 EsRejectedExecutionException (org.elasticsearch.common.util.concurrent.EsRejectedExecutionException)2 RefreshRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.refresh.RefreshRequest)2 AnalyzedRefreshTable (io.crate.analyze.AnalyzedRefreshTable)1 PartitionPropertiesAnalyzer.toPartitionName (io.crate.analyze.PartitionPropertiesAnalyzer.toPartitionName)1 SymbolEvaluator (io.crate.analyze.SymbolEvaluator)1 Lists2 (io.crate.common.collections.Lists2)1 InMemoryBatchIterator (io.crate.data.InMemoryBatchIterator)1