Skip to content

Commit c2df1ab

Browse files
Improve code and reduce indexing
Index less docs to reduce runtime of test and improve code checking for partial shard failures to only check flag/successful ops once.
1 parent 5e35690 commit c2df1ab

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

server/src/main/java/org/elasticsearch/action/search/AbstractSearchAsyncAction.java

+10-11
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public final void executeNextPhase(SearchPhase currentPhase, SearchPhase nextPha
140140
} else {
141141
Boolean allowPartialResults = request.allowPartialSearchResults();
142142
assert allowPartialResults != null : "SearchRequest missing setting for allowPartialSearchResults";
143-
if (allowPartialResults == false && shardFailures.get() != null) {
143+
if (allowPartialResults == false && successfulOps.get() != getNumShards()) {
144144
// check if there are actual failures in the atomic array since
145145
// successful retries can reset the failures to null
146146
ShardOperationFailedException[] shardSearchFailures = buildShardFailures();
@@ -154,18 +154,17 @@ public final void executeNextPhase(SearchPhase currentPhase, SearchPhase nextPha
154154
}
155155
onPhaseFailure(currentPhase, "Partial shards failure", null);
156156
return;
157+
} else {
158+
int discrepancy = getNumShards() - successfulOps.get();
159+
assert discrepancy > 0 : "discrepancy: " + discrepancy;
160+
if (logger.isDebugEnabled()) {
161+
logger.debug("Partial shards failure (unavailable: {}, successful: {}, skipped: {}, num-shards: {}, phase: {})",
162+
discrepancy, successfulOps.get(), skippedOps.get(), getNumShards(), currentPhase.getName());
163+
}
164+
onPhaseFailure(currentPhase, "Partial shards failure (" + discrepancy + " shards unavailable)", null);
165+
return;
157166
}
158167
}
159-
if (allowPartialResults == false && successfulOps.get() != getNumShards()) {
160-
int discrepancy = getNumShards() - successfulOps.get();
161-
assert discrepancy > 0 : "discrepancy: " + discrepancy;
162-
if (logger.isDebugEnabled()) {
163-
logger.debug("Partial shards failure (unavailable: {}, successful: {}, skipped: {}, num-shards: {}, phase: {})",
164-
discrepancy, successfulOps.get(), skippedOps.get(), getNumShards(), currentPhase.getName());
165-
}
166-
onPhaseFailure(currentPhase, "Partial shards failure (" + discrepancy + " shards unavailable)", null);
167-
return;
168-
}
169168
if (logger.isTraceEnabled()) {
170169
final String resultsFrom = results.getSuccessfulResults()
171170
.map(r -> r.getSearchShardTarget().toString()).collect(Collectors.joining(","));

server/src/test/java/org/elasticsearch/search/basic/SearchRedStateIndexIT.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ public void testClusterDisallowPartialsWithRedState() throws Exception {
100100
}
101101

102102
public void testDisallowPartialsWithRedStateRecovering() throws Exception {
103-
int docCount = scaledRandomIntBetween(1000, 10000);
103+
int docCount = scaledRandomIntBetween(10, 1000);
104104
logger.info("Using docCount [{}]", docCount);
105-
buildIndex(cluster().numDataNodes(), 1, docCount);
105+
buildIndex(cluster().numDataNodes() + 2, 1, docCount);
106106

107107
AtomicBoolean stop = new AtomicBoolean();
108108
List<Thread> searchThreads = new ArrayList<>();
@@ -128,7 +128,7 @@ public void run() {
128128
void verify(Supplier<SearchResponse> call) {
129129
try {
130130
SearchResponse response = call.get();
131-
assertThat(response.getHits().getHits().length, equalTo(100));
131+
assertThat(response.getHits().getHits().length, equalTo(Math.min(100, docCount)));
132132
assertThat(response.getHits().getTotalHits().value, equalTo((long) docCount));
133133
} catch (Exception e) {
134134
// this is OK.

0 commit comments

Comments
 (0)