Skip to content

Commit

Permalink
[reindex] Don't attempt to refresh on noop
Browse files Browse the repository at this point in the history
If the user asks for a refresh but their reindex or update-by-query
operation touched no indexes we should just skip the resfresh call
entirely. Without this commit we refresh *all* indexes which is totally
wrong.

Closes #17296
  • Loading branch information
nik9000 committed Mar 24, 2016
1 parent eb0714c commit 95de616
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,12 @@ private void recordFailure(Failure failure, List<Failure> failures) {
failures.add(failure);
}

/**
* Start terminating a request that finished non-catastrophically.
*/
void startNormalTermination(final List<Failure> indexingFailures, final List<ShardSearchFailure> searchFailures,
final boolean timedOut) {
if (task.isCancelled() || false == mainRequest.isRefresh()) {
if (task.isCancelled() || false == mainRequest.isRefresh() || destinationIndices.isEmpty()) {
finishHim(null, indexingFailures, searchFailures, timedOut);
return;
}
Expand Down Expand Up @@ -432,4 +435,4 @@ public void remove() {
}
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -415,23 +415,29 @@ public void testDefaultRetryTimes() {
}

public void testRefreshIsFalseByDefault() throws Exception {
refreshTestCase(null, false);
refreshTestCase(null, true, false);
}

public void testRefreshFalseDoesntMakeVisible() throws Exception {
refreshTestCase(false, false);
public void testRefreshFalseDoesntExecuteRefresh() throws Exception {
refreshTestCase(false, true, false);
}

public void testRefreshTrueMakesVisible() throws Exception {
refreshTestCase(true, true);
public void testRefreshTrueExecutesRefresh() throws Exception {
refreshTestCase(true, true, true);
}

private void refreshTestCase(Boolean refresh, boolean shouldRefresh) {
public void testRefreshTrueSkipsRefreshIfNoDestinationIndexes() throws Exception {
refreshTestCase(true, false, false);
}

private void refreshTestCase(Boolean refresh, boolean addDestinationIndexes, boolean shouldRefresh) {
if (refresh != null) {
mainRequest.setRefresh(refresh);
}
DummyAbstractAsyncBulkByScrollAction action = new DummyAbstractAsyncBulkByScrollAction();
action.addDestinationIndices(singleton("foo"));
if (addDestinationIndexes) {
action.addDestinationIndices(singleton("foo"));
}
action.startNormalTermination(Collections.<Failure>emptyList(), Collections.<ShardSearchFailure>emptyList(), false);
if (shouldRefresh) {
assertArrayEquals(new String[] {"foo"}, client.lastRefreshRequest.get().indices());
Expand Down Expand Up @@ -657,4 +663,4 @@ > void doExecute(Action<Request, Response, RequestBuilder> action, Request reque
super.doExecute(action, request, listener);
}
}
}
}

0 comments on commit 95de616

Please sign in to comment.