|
84 | 84 | import org.elasticsearch.index.IndexService;
|
85 | 85 | import org.elasticsearch.index.IndexSettings;
|
86 | 86 | import org.elasticsearch.index.IndexVersion;
|
| 87 | +import org.elasticsearch.index.IndexVersions; |
87 | 88 | import org.elasticsearch.index.analysis.AbstractTokenFilterFactory;
|
88 | 89 | import org.elasticsearch.index.analysis.TokenFilterFactory;
|
89 | 90 | import org.elasticsearch.index.engine.Engine;
|
|
120 | 121 | import org.elasticsearch.test.ESIntegTestCase.Scope;
|
121 | 122 | import org.elasticsearch.test.InternalTestCluster;
|
122 | 123 | import org.elasticsearch.test.engine.MockEngineSupport;
|
| 124 | +import org.elasticsearch.test.index.IndexVersionUtils; |
123 | 125 | import org.elasticsearch.test.junit.annotations.TestLogging;
|
124 | 126 | import org.elasticsearch.test.transport.MockTransportService;
|
125 | 127 | import org.elasticsearch.transport.TestTransportChannel;
|
@@ -2036,6 +2038,69 @@ public Settings onNodeStopped(String nodeName) {
|
2036 | 2038 | assertBusy(() -> assertThat(searchableSegmentCountSupplier.getAsLong(), lessThan((long) initialSegmentCount)));
|
2037 | 2039 | }
|
2038 | 2040 |
|
| 2041 | + @Override |
| 2042 | + protected boolean forbidPrivateIndexSettings() { |
| 2043 | + return false; // need to set index.version.created to test difference in behaviour on older indices |
| 2044 | + } |
| 2045 | + |
| 2046 | + public void testPostRecoveryMergeDisabledOnOlderIndices() throws Exception { |
| 2047 | + internalCluster().startMasterOnlyNode(); |
| 2048 | + final var dataNode = internalCluster().startDataOnlyNode(); |
| 2049 | + final var indexName = randomIdentifier(); |
| 2050 | + createIndex( |
| 2051 | + indexName, |
| 2052 | + indexSettings(1, 0).put(INDEX_MERGE_ENABLED, false) |
| 2053 | + .put( |
| 2054 | + IndexMetadata.SETTING_VERSION_CREATED, |
| 2055 | + IndexVersionUtils.randomVersionBetween( |
| 2056 | + random(), |
| 2057 | + IndexVersionUtils.getFirstVersion(), |
| 2058 | + IndexVersionUtils.getPreviousVersion(IndexVersions.MERGE_ON_RECOVERY_VERSION) |
| 2059 | + ) |
| 2060 | + ) |
| 2061 | + .build() |
| 2062 | + ); |
| 2063 | + |
| 2064 | + final var initialSegmentCount = 20; |
| 2065 | + for (int i = 0; i < initialSegmentCount; i++) { |
| 2066 | + indexDoc(indexName, Integer.toString(i), "f", randomAlphaOfLength(10)); |
| 2067 | + refresh(indexName); // force a one-doc segment |
| 2068 | + } |
| 2069 | + flush(indexName); // commit all the one-doc segments |
| 2070 | + |
| 2071 | + final LongSupplier searchableSegmentCountSupplier = () -> indicesAdmin().prepareSegments(indexName) |
| 2072 | + .get(SAFE_AWAIT_TIMEOUT) |
| 2073 | + .getIndices() |
| 2074 | + .get(indexName) |
| 2075 | + .getShards() |
| 2076 | + .get(0) |
| 2077 | + .shards()[0].getSegments() |
| 2078 | + .stream() |
| 2079 | + .filter(Segment::isSearch) |
| 2080 | + .count(); |
| 2081 | + |
| 2082 | + assertEquals(initialSegmentCount, searchableSegmentCountSupplier.getAsLong()); |
| 2083 | + |
| 2084 | + // force a recovery by restarting the node, re-enabling merges while the node is down |
| 2085 | + internalCluster().restartNode(dataNode, new InternalTestCluster.RestartCallback() { |
| 2086 | + @Override |
| 2087 | + public Settings onNodeStopped(String nodeName) { |
| 2088 | + final var request = new UpdateSettingsRequest(Settings.builder().putNull(INDEX_MERGE_ENABLED).build(), indexName); |
| 2089 | + request.reopen(true); |
| 2090 | + safeGet(indicesAdmin().updateSettings(request)); |
| 2091 | + return Settings.EMPTY; |
| 2092 | + } |
| 2093 | + }); |
| 2094 | + |
| 2095 | + ensureGreen(indexName); |
| 2096 | + final var mergeStats = indicesAdmin().prepareStats(indexName).clear().setMerge(true).get().getIndex(indexName).getShards()[0] |
| 2097 | + .getStats() |
| 2098 | + .getMerge(); |
| 2099 | + assertEquals(0, mergeStats.getCurrent()); |
| 2100 | + assertEquals(0, mergeStats.getTotal()); |
| 2101 | + assertEquals(initialSegmentCount, searchableSegmentCountSupplier.getAsLong()); |
| 2102 | + } |
| 2103 | + |
2039 | 2104 | private void assertGlobalCheckpointIsStableAndSyncedInAllNodes(String indexName, List<String> nodes, int shard) throws Exception {
|
2040 | 2105 | assertThat(nodes, is(not(empty())));
|
2041 | 2106 |
|
|
0 commit comments