|
6 | 6 |
|
7 | 7 | package org.elasticsearch.xpack.ilm;
|
8 | 8 |
|
| 9 | +import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainRequest; |
| 10 | +import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainResponse; |
9 | 11 | import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
|
| 12 | +import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest; |
| 13 | +import org.elasticsearch.cluster.routing.ShardRoutingState; |
10 | 14 | import org.elasticsearch.common.settings.Settings;
|
11 | 15 | import org.elasticsearch.common.unit.TimeValue;
|
12 | 16 | import org.elasticsearch.plugins.Plugin;
|
13 | 17 | import org.elasticsearch.test.ESIntegTestCase;
|
| 18 | +import org.elasticsearch.xpack.cluster.routing.allocation.DataTierAllocationDecider; |
14 | 19 | import org.elasticsearch.xpack.core.DataTier;
|
15 | 20 | import org.elasticsearch.xpack.core.LocalStateCompositeXPackPlugin;
|
16 | 21 | import org.elasticsearch.xpack.core.XPackSettings;
|
|
29 | 34 | import java.util.Collection;
|
30 | 35 | import java.util.Collections;
|
31 | 36 | import java.util.Locale;
|
| 37 | +import java.util.concurrent.TimeUnit; |
32 | 38 |
|
33 | 39 | import static org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_REPLICAS;
|
34 | 40 | import static org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_SHARDS;
|
@@ -153,4 +159,91 @@ public void testIndexDataTierMigration() throws Exception {
|
153 | 159 | assertThat(indexLifecycleExplainResponse.getStep(), is("complete"));
|
154 | 160 | });
|
155 | 161 | }
|
| 162 | + |
| 163 | + public void testUserOptsOutOfTierMigration() throws Exception { |
| 164 | + internalCluster().startMasterOnlyNodes(1, Settings.EMPTY); |
| 165 | + logger.info("starting hot data node"); |
| 166 | + internalCluster().startNode(hotNode(Settings.EMPTY)); |
| 167 | + |
| 168 | + Phase hotPhase = new Phase("hot", TimeValue.ZERO, Collections.emptyMap()); |
| 169 | + Phase warmPhase = new Phase("warm", TimeValue.ZERO, Collections.emptyMap()); |
| 170 | + Phase coldPhase = new Phase("cold", TimeValue.ZERO, Collections.emptyMap()); |
| 171 | + LifecyclePolicy lifecyclePolicy = new LifecyclePolicy( |
| 172 | + policy, org.elasticsearch.common.collect.Map.of("hot", hotPhase, "warm", warmPhase, "cold", coldPhase) |
| 173 | + ); |
| 174 | + PutLifecycleAction.Request putLifecycleRequest = new PutLifecycleAction.Request(lifecyclePolicy); |
| 175 | + PutLifecycleAction.Response putLifecycleResponse = client().execute(PutLifecycleAction.INSTANCE, putLifecycleRequest).get(); |
| 176 | + assertAcked(putLifecycleResponse); |
| 177 | + |
| 178 | + Settings settings = Settings.builder().put(indexSettings()).put(SETTING_NUMBER_OF_SHARDS, 1) |
| 179 | + .put(SETTING_NUMBER_OF_REPLICAS, 1).put(LifecycleSettings.LIFECYCLE_NAME, policy).build(); |
| 180 | + CreateIndexResponse res = client().admin().indices().prepareCreate(managedIndex).setSettings(settings).get(); |
| 181 | + assertTrue(res.isAcknowledged()); |
| 182 | + |
| 183 | + assertBusy(() -> { |
| 184 | + ExplainLifecycleRequest explainRequest = new ExplainLifecycleRequest().indices(managedIndex); |
| 185 | + ExplainLifecycleResponse explainResponse = client().execute(ExplainLifecycleAction.INSTANCE, |
| 186 | + explainRequest).get(); |
| 187 | + |
| 188 | + IndexLifecycleExplainResponse indexLifecycleExplainResponse = explainResponse.getIndexResponses().get(managedIndex); |
| 189 | + assertThat(indexLifecycleExplainResponse.getPhase(), is("warm")); |
| 190 | + assertThat(indexLifecycleExplainResponse.getStep(), is(DataTierMigrationRoutedStep.NAME)); |
| 191 | + }); |
| 192 | + |
| 193 | + Settings removeTierRoutingSetting = Settings.builder().putNull(DataTierAllocationDecider.INDEX_ROUTING_PREFER).build(); |
| 194 | + UpdateSettingsRequest updateSettingsRequest = new UpdateSettingsRequest(managedIndex).settings(removeTierRoutingSetting); |
| 195 | + assertAcked(client().admin().indices().updateSettings(updateSettingsRequest).actionGet()); |
| 196 | + |
| 197 | + assertBusy(() -> { |
| 198 | + ExplainLifecycleRequest explainRequest = new ExplainLifecycleRequest().indices(managedIndex); |
| 199 | + ExplainLifecycleResponse explainResponse = client().execute(ExplainLifecycleAction.INSTANCE, |
| 200 | + explainRequest).get(); |
| 201 | + |
| 202 | + IndexLifecycleExplainResponse indexLifecycleExplainResponse = explainResponse.getIndexResponses().get(managedIndex); |
| 203 | + assertThat(indexLifecycleExplainResponse.getPhase(), is("warm")); |
| 204 | + assertThat(indexLifecycleExplainResponse.getStep(), is(DataTierMigrationRoutedStep.NAME)); |
| 205 | + assertReplicaIsUnassigned(); |
| 206 | + }, 30, TimeUnit.SECONDS); |
| 207 | + |
| 208 | + internalCluster().startNode(coldNode(Settings.EMPTY)); |
| 209 | + |
| 210 | + // the index should successfully allocate |
| 211 | + ensureGreen(managedIndex); |
| 212 | + |
| 213 | + // the index is successfully allocated but the migrate action from the cold phase re-configured the tier migration setting to the |
| 214 | + // cold tier so ILM is stuck in `check-migration` in the cold phase this time |
| 215 | + // we have 2 options to resume the ILM execution: |
| 216 | + // 1. start another cold node so both the primary and replica can relocate to the cold nodes |
| 217 | + // 2. remove the tier routing setting from the index again (we're doing this below) |
| 218 | + assertBusy(() -> { |
| 219 | + ExplainLifecycleRequest explainRequest = new ExplainLifecycleRequest().indices(managedIndex); |
| 220 | + ExplainLifecycleResponse explainResponse = client().execute(ExplainLifecycleAction.INSTANCE, |
| 221 | + explainRequest).get(); |
| 222 | + |
| 223 | + IndexLifecycleExplainResponse indexLifecycleExplainResponse = explainResponse.getIndexResponses().get(managedIndex); |
| 224 | + assertThat(indexLifecycleExplainResponse.getPhase(), is("cold")); |
| 225 | + assertThat(indexLifecycleExplainResponse.getStep(), is(DataTierMigrationRoutedStep.NAME)); |
| 226 | + }); |
| 227 | + |
| 228 | + // remove the tier routing setting again |
| 229 | + assertAcked(client().admin().indices().updateSettings(updateSettingsRequest).actionGet()); |
| 230 | + |
| 231 | + // wait for lifecycle to complete in the cold phase |
| 232 | + assertBusy(() -> { |
| 233 | + ExplainLifecycleRequest explainRequest = new ExplainLifecycleRequest().indices(managedIndex); |
| 234 | + ExplainLifecycleResponse explainResponse = client().execute(ExplainLifecycleAction.INSTANCE, |
| 235 | + explainRequest).get(); |
| 236 | + |
| 237 | + IndexLifecycleExplainResponse indexLifecycleExplainResponse = explainResponse.getIndexResponses().get(managedIndex); |
| 238 | + assertThat(indexLifecycleExplainResponse.getPhase(), is("cold")); |
| 239 | + assertThat(indexLifecycleExplainResponse.getStep(), is("complete")); |
| 240 | + }, 30, TimeUnit.SECONDS); |
| 241 | + } |
| 242 | + |
| 243 | + private void assertReplicaIsUnassigned() { |
| 244 | + ClusterAllocationExplainRequest explainReplicaShard = |
| 245 | + new ClusterAllocationExplainRequest().setIndex(managedIndex).setPrimary(false).setShard(0); |
| 246 | + ClusterAllocationExplainResponse response = client().admin().cluster().allocationExplain(explainReplicaShard).actionGet(); |
| 247 | + assertThat(response.getExplanation().getShardState(), is(ShardRoutingState.UNASSIGNED)); |
| 248 | + } |
156 | 249 | }
|
0 commit comments