|
49 | 49 | import org.elasticsearch.common.unit.TimeValue;
|
50 | 50 | import org.elasticsearch.common.xcontent.XContentType;
|
51 | 51 | import org.elasticsearch.index.Index;
|
| 52 | +import org.elasticsearch.index.IndexService; |
52 | 53 | import org.elasticsearch.index.analysis.AbstractTokenFilterFactory;
|
53 | 54 | import org.elasticsearch.index.analysis.TokenFilterFactory;
|
54 | 55 | import org.elasticsearch.index.mapper.MapperParsingException;
|
|
70 | 71 | import org.elasticsearch.test.ESIntegTestCase;
|
71 | 72 | import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
|
72 | 73 | import org.elasticsearch.test.ESIntegTestCase.Scope;
|
| 74 | +import org.elasticsearch.test.InternalSettingsPlugin; |
73 | 75 | import org.elasticsearch.test.InternalTestCluster;
|
74 | 76 | import org.elasticsearch.test.junit.annotations.TestLogging;
|
75 | 77 | import org.elasticsearch.test.store.MockFSIndexStore;
|
@@ -127,8 +129,12 @@ public class IndexRecoveryIT extends ESIntegTestCase {
|
127 | 129 |
|
128 | 130 | @Override
|
129 | 131 | protected Collection<Class<? extends Plugin>> nodePlugins() {
|
130 |
| - return Arrays.asList(MockTransportService.TestPlugin.class, MockFSIndexStore.TestPlugin.class, |
131 |
| - RecoverySettingsChunkSizePlugin.class, TestAnalysisPlugin.class); |
| 132 | + return Arrays.asList( |
| 133 | + MockTransportService.TestPlugin.class, |
| 134 | + MockFSIndexStore.TestPlugin.class, |
| 135 | + RecoverySettingsChunkSizePlugin.class, |
| 136 | + TestAnalysisPlugin.class, |
| 137 | + InternalSettingsPlugin.class); |
132 | 138 | }
|
133 | 139 |
|
134 | 140 | @After
|
@@ -1015,4 +1021,45 @@ public TokenStream create(TokenStream tokenStream) {
|
1015 | 1021 | });
|
1016 | 1022 | }
|
1017 | 1023 | }
|
| 1024 | + |
| 1025 | + public void testRepeatedRecovery() throws Exception { |
| 1026 | + internalCluster().ensureAtLeastNumDataNodes(2); |
| 1027 | + |
| 1028 | + // Ensures that you can remove a replica and then add it back again without any ill effects, even if it's allocated back to the |
| 1029 | + // node that held it previously, in case that node hasn't completely cleared it up. |
| 1030 | + |
| 1031 | + final String indexName = "test-index"; |
| 1032 | + createIndex(indexName, Settings.builder() |
| 1033 | + .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1) |
| 1034 | + .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, randomIntBetween(1, 6)) |
| 1035 | + .put(IndexService.RETENTION_LEASE_SYNC_INTERVAL_SETTING.getKey(), "200ms") |
| 1036 | + .build()); |
| 1037 | + indexRandom(randomBoolean(), false, randomBoolean(), IntStream.range(0, randomIntBetween(0, 10)) |
| 1038 | + .mapToObj(n -> client().prepareIndex(indexName, "_doc").setSource("num", n)).collect(toList())); |
| 1039 | + |
| 1040 | + assertThat(client().admin().indices().prepareFlush(indexName).get().getFailedShards(), equalTo(0)); |
| 1041 | + |
| 1042 | + assertBusy(() -> { |
| 1043 | + final ShardStats[] shardsStats = client().admin().indices().prepareStats(indexName).get().getIndex(indexName).getShards(); |
| 1044 | + for (final ShardStats shardStats : shardsStats) { |
| 1045 | + final long maxSeqNo = shardStats.getSeqNoStats().getMaxSeqNo(); |
| 1046 | + assertTrue(shardStats.getRetentionLeaseStats().retentionLeases().leases().stream() |
| 1047 | + .allMatch(retentionLease -> retentionLease.retainingSequenceNumber() == maxSeqNo + 1)); |
| 1048 | + } |
| 1049 | + }); |
| 1050 | + |
| 1051 | + logger.info("--> remove replicas"); |
| 1052 | + assertAcked(client().admin().indices().prepareUpdateSettings(indexName) |
| 1053 | + .setSettings(Settings.builder().put("index.number_of_replicas", 0))); |
| 1054 | + ensureGreen(indexName); |
| 1055 | + |
| 1056 | + logger.info("--> index more documents"); |
| 1057 | + indexRandom(randomBoolean(), false, randomBoolean(), IntStream.range(0, randomIntBetween(0, 10)) |
| 1058 | + .mapToObj(n -> client().prepareIndex(indexName, "_doc").setSource("num", n)).collect(toList())); |
| 1059 | + |
| 1060 | + logger.info("--> add replicas again"); |
| 1061 | + assertAcked(client().admin().indices().prepareUpdateSettings(indexName) |
| 1062 | + .setSettings(Settings.builder().put("index.number_of_replicas", 1))); |
| 1063 | + ensureGreen(indexName); |
| 1064 | + } |
1018 | 1065 | }
|
0 commit comments