Skip to content

Commit 35c527b

Browse files
committed
strengthen operation-based condition
1 parent 042ceb4 commit 35c527b

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

server/src/main/java/org/elasticsearch/index/engine/ReadOnlyEngine.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,8 @@ public int estimateNumberOfHistoryOperations(String source, MapperService mapper
300300

301301
@Override
302302
public boolean hasCompleteOperationHistory(String source, MapperService mapperService, long startingSeqNo) throws IOException {
303-
return startingSeqNo > seqNoStats.getLocalCheckpoint();
303+
// we can do operation-based recovery if we don't have to replay any operation.
304+
return startingSeqNo > seqNoStats.getMaxSeqNo();
304305
}
305306

306307
@Override

server/src/test/java/org/elasticsearch/indices/state/CloseIndexIT.java

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -349,22 +349,26 @@ public void testNoopPeerRecoveriesWhenIndexClosed() throws Exception {
349349
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, numberOfReplicas)
350350
.put("index.routing.rebalance.enable", "none")
351351
.build());
352-
indexRandom(randomBoolean(), false, randomBoolean(), IntStream.range(0, randomIntBetween(0, 50))
353-
.mapToObj(i -> client().prepareIndex(indexName, "_doc").setSource("num", i)).collect(toList()));
354-
ensureGreen(indexName);
355-
356-
// Closing an index should execute noop peer recovery
357-
assertAcked(client().admin().indices().prepareClose(indexName).get());
358-
assertIndexIsClosed(indexName);
359-
ensureGreen(indexName);
360-
assertNoFileBasedRecovery(indexName);
361-
362-
// Open a closed index should execute noop recovery
363-
assertAcked(client().admin().indices().prepareOpen(indexName).get());
364-
assertIndexIsOpened(indexName);
365-
ensureGreen(indexName);
366-
assertNoFileBasedRecovery(indexName);
367-
internalCluster().assertSameDocIdsOnShards();
352+
int iterations = between(1, 3);
353+
for (int iter = 0; iter < iterations; iter++) {
354+
indexRandom(randomBoolean(), randomBoolean(), randomBoolean(), IntStream.range(0, randomIntBetween(0, 50))
355+
.mapToObj(n -> client().prepareIndex(indexName, "_doc").setSource("num", n)).collect(toList()));
356+
ensureGreen(indexName);
357+
358+
// Closing an index should execute noop peer recovery
359+
assertAcked(client().admin().indices().prepareClose(indexName).get());
360+
assertIndexIsClosed(indexName);
361+
ensureGreen(indexName);
362+
assertNoFileBasedRecovery(indexName);
363+
internalCluster().assertSameDocIdsOnShards();
364+
365+
// Open a closed index should execute noop recovery
366+
assertAcked(client().admin().indices().prepareOpen(indexName).get());
367+
assertIndexIsOpened(indexName);
368+
ensureGreen(indexName);
369+
assertNoFileBasedRecovery(indexName);
370+
internalCluster().assertSameDocIdsOnShards();
371+
}
368372
}
369373

370374
static void assertIndexIsClosed(final String... indices) {

0 commit comments

Comments
 (0)