|
31 | 31 | import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse; |
32 | 32 | import org.elasticsearch.action.admin.indices.flush.FlushRequest; |
33 | 33 | import org.elasticsearch.action.admin.indices.recovery.RecoveryResponse; |
| 34 | +import org.elasticsearch.action.admin.indices.stats.ShardStats; |
34 | 35 | import org.elasticsearch.action.index.IndexRequestBuilder; |
35 | 36 | import org.elasticsearch.action.search.SearchPhaseExecutionException; |
36 | 37 | import org.elasticsearch.action.search.SearchRequestBuilder; |
|
48 | 49 | import org.elasticsearch.index.Index; |
49 | 50 | import org.elasticsearch.index.IndexSettings; |
50 | 51 | import org.elasticsearch.index.MockEngineFactoryPlugin; |
| 52 | +import org.elasticsearch.index.seqno.SeqNoStats; |
51 | 53 | import org.elasticsearch.index.shard.IndexShard; |
52 | 54 | import org.elasticsearch.index.shard.ShardId; |
53 | 55 | import org.elasticsearch.indices.IndicesService; |
|
74 | 76 | import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; |
75 | 77 | import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount; |
76 | 78 | import static org.hamcrest.Matchers.containsString; |
| 79 | +import static org.hamcrest.Matchers.equalTo; |
77 | 80 | import static org.hamcrest.Matchers.greaterThan; |
78 | 81 |
|
79 | 82 | @ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.SUITE, numDataNodes = 0) |
@@ -214,6 +217,10 @@ public void testCorruptTranslogTruncation() throws Exception { |
214 | 217 | final RecoveryState replicaRecoveryState = recoveryResponse.shardRecoveryStates().get("test").stream() |
215 | 218 | .filter(recoveryState -> recoveryState.getPrimary() == false).findFirst().get(); |
216 | 219 | assertThat(replicaRecoveryState.getIndex().toString(), replicaRecoveryState.getIndex().recoveredFileCount(), greaterThan(0)); |
| 220 | + // Ensure that the global checkpoint and local checkpoint are restored from the max seqno of the last commit. |
| 221 | + final SeqNoStats seqNoStats = getSeqNoStats("test", 0); |
| 222 | + assertThat(seqNoStats.getGlobalCheckpoint(), equalTo(seqNoStats.getMaxSeqNo())); |
| 223 | + assertThat(seqNoStats.getLocalCheckpoint(), equalTo(seqNoStats.getMaxSeqNo())); |
217 | 224 | } |
218 | 225 |
|
219 | 226 | public void testCorruptTranslogTruncationOfReplica() throws Exception { |
@@ -316,6 +323,10 @@ public void testCorruptTranslogTruncationOfReplica() throws Exception { |
316 | 323 | .filter(recoveryState -> recoveryState.getPrimary() == false).findFirst().get(); |
317 | 324 | // the replica translog was disabled so it doesn't know what hte global checkpoint is and thus can't do ops based recovery |
318 | 325 | assertThat(replicaRecoveryState.getIndex().toString(), replicaRecoveryState.getIndex().recoveredFileCount(), greaterThan(0)); |
| 326 | + // Ensure that the global checkpoint and local checkpoint are restored from the max seqno of the last commit. |
| 327 | + final SeqNoStats seqNoStats = getSeqNoStats("test", 0); |
| 328 | + assertThat(seqNoStats.getGlobalCheckpoint(), equalTo(seqNoStats.getMaxSeqNo())); |
| 329 | + assertThat(seqNoStats.getLocalCheckpoint(), equalTo(seqNoStats.getMaxSeqNo())); |
319 | 330 | } |
320 | 331 |
|
321 | 332 | private Set<Path> getTranslogDirs(String indexName) throws IOException { |
@@ -360,4 +371,10 @@ private static void disableTranslogFlush(String index) { |
360 | 371 | client().admin().indices().prepareUpdateSettings(index).setSettings(settings).get(); |
361 | 372 | } |
362 | 373 |
|
| 374 | + private SeqNoStats getSeqNoStats(String index, int shardId) { |
| 375 | + final ShardStats[] shardStats = client().admin().indices() |
| 376 | + .prepareStats(index).get() |
| 377 | + .getIndices().get(index).getShards(); |
| 378 | + return shardStats[shardId].getSeqNoStats(); |
| 379 | + } |
363 | 380 | } |
0 commit comments