@Override public void clearScroll(String scrollId, Runnable onCompletion) { ClearScrollRequest clearScrollRequest = new ClearScrollRequest(); clearScrollRequest.addScrollId(scrollId); /* * Unwrap the client so we don't set our task as the parent. If we *did* set our ID then the clear scroll would be cancelled as * if this task is cancelled. But we want to clear the scroll regardless of whether or not the main request was cancelled. */ client.unwrap().clearScroll(clearScrollRequest, new ActionListener<ClearScrollResponse>() { @Override public void onResponse(ClearScrollResponse response) { logger.debug("Freed [{}] contexts", response.getNumFreed()); onCompletion.run(); } @Override public void onFailure(Exception e) { logger.warn((Supplier<?>) () -> new ParameterizedMessage("Failed to clear scroll [{}]", scrollId), e); onCompletion.run(); } }); }
@Override public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) { String scrollIds = request.param("scroll_id"); ClearScrollRequest clearRequest = new ClearScrollRequest(); clearRequest.setScrollIds(Arrays.asList(splitScrollIds(scrollIds))); if (RestActions.hasBodyContent(request)) { XContentType type = RestActions.guessBodyContentType(request); if (type == null) { scrollIds = RestActions.getRestContent(request).toUtf8(); clearRequest.setScrollIds(Arrays.asList(splitScrollIds(scrollIds))); } else { // NOTE: if rest request with xcontent body has request parameters, these parameters does not override xcontent value clearRequest.setScrollIds(null); buildFromContent(RestActions.getRestContent(request), clearRequest); } } client.clearScroll(clearRequest, new RestStatusToXContentListener<ClearScrollResponse>(channel)); }
public void interrupt() { interrupted.set(true); if (scrollId != null) { client.prepareClearScroll().addScrollId(scrollId) .execute(new ActionListener<ClearScrollResponse>() { @Override public void onResponse(ClearScrollResponse response) { // nothing } @Override public void onFailure(Throwable e) { if (logger.isDebugEnabled()) { logger.debug( "Failed to stop reindexing for " + toIndex + ".", e); } } }); } }
public void testClearNonExistentScrollId() throws Exception { createIndex("idx"); ClearScrollResponse response = client().prepareClearScroll() .addScrollId("DnF1ZXJ5VGhlbkZldGNoAwAAAAAAAAABFnRtLWMyRzBqUUQyNk1uM0xDTjJ4S0EAAAAAAAAAARYzNkhxbWFTYVFVNmgxTGQyYUZVYV9nAAAAAAAAAAEWdVcxNWZmRGZSVFN2V0xMUGF2NGx1Zw==") .get(); // Whether we actually clear a scroll, we can't know, since that information isn't serialized in the // free search context response, which is returned from each node we want to clear a particular scroll. assertThat(response.isSucceeded(), is(true)); assertThat(response.getNumFreed(), equalTo(0)); assertThat(response.status(), equalTo(RestStatus.NOT_FOUND)); assertToXContentResponse(response, true, response.getNumFreed()); }
public void testThatNonExistingScrollIdReturnsCorrectException() throws Exception { client().prepareIndex("index", "type", "1").setSource("field", "value").execute().get(); refresh(); SearchResponse searchResponse = client().prepareSearch("index").setSize(1).setScroll("1m").get(); assertThat(searchResponse.getScrollId(), is(notNullValue())); ClearScrollResponse clearScrollResponse = client().prepareClearScroll().addScrollId(searchResponse.getScrollId()).get(); assertThat(clearScrollResponse.isSucceeded(), is(true)); assertThrows(internalCluster().transportClient().prepareSearchScroll(searchResponse.getScrollId()), RestStatus.NOT_FOUND); }
private void assertToXContentResponse(ClearScrollResponse response, boolean succeed, int numFreed) throws IOException { XContentBuilder builder = XContentFactory.jsonBuilder(); response.toXContent(builder, ToXContent.EMPTY_PARAMS); Map<String, Object> map = XContentHelper.convertToMap(builder.bytes(), false, builder.contentType()).v2(); assertThat(map.get("succeeded"), is(succeed)); assertThat(map.get("num_freed"), equalTo(numFreed)); }
@Override public void close() throws IOException { if (response != null) { ClearScrollResponse clearScrollResponse = client.prepareClearScroll() .addScrollId(response.getScrollId()) .execute() .actionGet(); if (!clearScrollResponse.isSucceeded()) { LOGGER.debug("Failed to clear scroll: {}", clearScrollResponse.status()); } } }
/** * Clears the given scroll Ids */ public void clearScroll(String... scrollIds) { ClearScrollResponse clearResponse = client().prepareClearScroll() .setScrollIds(Arrays.asList(scrollIds)).get(); assertThat(clearResponse.isSucceeded(), equalTo(true)); }
@Override public void clearScroll(ClearScrollRequest request, ActionListener<ClearScrollResponse> listener) { execute(ClearScrollAction.INSTANCE, request, listener); }
@Override public ActionFuture<ClearScrollResponse> clearScroll(ClearScrollRequest request) { return execute(ClearScrollAction.INSTANCE, request); }
@Override public void clearScroll(ClearScrollRequest request, ActionListener<ClearScrollResponse> listener) { // TODO Auto-generated method stub }
@Override public ActionFuture<ClearScrollResponse> clearScroll(ClearScrollRequest request) { // TODO Auto-generated method stub return null; }
/** * Clears the given scroll Ids */ public void clearScroll(final String... scrollIds) { final ClearScrollResponse clearResponse = client().prepareClearScroll().setScrollIds(Arrays.asList(scrollIds)).get(); assertThat(clearResponse.isSucceeded(), equalTo(true)); }
/** * Clears the search contexts associated with specified scroll ids. */ ActionFuture<ClearScrollResponse> clearScroll(ClearScrollRequest request);
/** * Clears the search contexts associated with specified scroll ids. */ void clearScroll(ClearScrollRequest request, ActionListener<ClearScrollResponse> listener);