|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the Elastic License |
| 4 | + * 2.0; you may not use this file except in compliance with the Elastic License |
| 5 | + * 2.0. |
| 6 | + */ |
| 7 | + |
| 8 | +package org.elasticsearch.xpack.ilm; |
| 9 | + |
| 10 | +import org.elasticsearch.action.admin.indices.template.put.PutComposableIndexTemplateAction; |
| 11 | +import org.elasticsearch.cluster.metadata.ComposableIndexTemplate; |
| 12 | +import org.elasticsearch.cluster.metadata.DataStream; |
| 13 | +import org.elasticsearch.cluster.metadata.IndexMetadata; |
| 14 | +import org.elasticsearch.cluster.metadata.Template; |
| 15 | +import org.elasticsearch.common.Strings; |
| 16 | +import org.elasticsearch.common.settings.Settings; |
| 17 | +import org.elasticsearch.core.TimeValue; |
| 18 | +import org.elasticsearch.datastreams.DataStreamsPlugin; |
| 19 | +import org.elasticsearch.plugins.Plugin; |
| 20 | +import org.elasticsearch.test.ESIntegTestCase; |
| 21 | +import org.elasticsearch.xpack.ccr.Ccr; |
| 22 | +import org.elasticsearch.xpack.core.LocalStateCompositeXPackPlugin; |
| 23 | +import org.elasticsearch.xpack.core.XPackSettings; |
| 24 | +import org.elasticsearch.xpack.core.ilm.ExplainLifecycleRequest; |
| 25 | +import org.elasticsearch.xpack.core.ilm.ExplainLifecycleResponse; |
| 26 | +import org.elasticsearch.xpack.core.ilm.IndexLifecycleExplainResponse; |
| 27 | +import org.elasticsearch.xpack.core.ilm.LifecyclePolicy; |
| 28 | +import org.elasticsearch.xpack.core.ilm.LifecycleSettings; |
| 29 | +import org.elasticsearch.xpack.core.ilm.Phase; |
| 30 | +import org.elasticsearch.xpack.core.ilm.RolloverAction; |
| 31 | +import org.elasticsearch.xpack.core.ilm.ShrinkAction; |
| 32 | +import org.elasticsearch.xpack.core.ilm.action.ExplainLifecycleAction; |
| 33 | +import org.elasticsearch.xpack.core.ilm.action.PutLifecycleAction; |
| 34 | + |
| 35 | +import java.util.Arrays; |
| 36 | +import java.util.Collection; |
| 37 | +import java.util.Collections; |
| 38 | +import java.util.HashMap; |
| 39 | +import java.util.Map; |
| 40 | +import java.util.concurrent.TimeUnit; |
| 41 | + |
| 42 | +import static org.elasticsearch.xpack.core.ilm.ShrinkIndexNameSupplier.SHRUNKEN_INDEX_PREFIX; |
| 43 | +import static org.hamcrest.Matchers.equalTo; |
| 44 | + |
| 45 | +@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 0, numClientNodes = 0) |
| 46 | +public class ILMMultiNodeWithCCRDisabledIT extends ESIntegTestCase { |
| 47 | + private static final String index = "myindex"; |
| 48 | + |
| 49 | + @Override |
| 50 | + protected Collection<Class<? extends Plugin>> nodePlugins() { |
| 51 | + return Arrays.asList(LocalStateCompositeXPackPlugin.class, DataStreamsPlugin.class, IndexLifecycle.class, Ccr.class); |
| 52 | + } |
| 53 | + |
| 54 | + @Override |
| 55 | + protected Settings nodeSettings(int nodeOrdinal, Settings otherSettings) { |
| 56 | + return Settings.builder() |
| 57 | + .put(super.nodeSettings(nodeOrdinal, otherSettings)) |
| 58 | + .put(LifecycleSettings.LIFECYCLE_POLL_INTERVAL, "1s") |
| 59 | + // This just generates less churn and makes it easier to read the log file if needed |
| 60 | + .put(LifecycleSettings.LIFECYCLE_HISTORY_INDEX_ENABLED, false) |
| 61 | + .put(XPackSettings.CCR_ENABLED_SETTING.getKey(), false) |
| 62 | + .build(); |
| 63 | + } |
| 64 | + |
| 65 | + public void testShrinkOnTiers() throws Exception { |
| 66 | + startHotOnlyNode(); |
| 67 | + startWarmOnlyNode(); |
| 68 | + ensureGreen(); |
| 69 | + |
| 70 | + RolloverAction rolloverAction = new RolloverAction(null, null, null, 1L, null, null, null, null, null, null); |
| 71 | + Phase hotPhase = new Phase("hot", TimeValue.ZERO, Collections.singletonMap(rolloverAction.getWriteableName(), rolloverAction)); |
| 72 | + ShrinkAction shrinkAction = new ShrinkAction(1, null); |
| 73 | + Phase warmPhase = new Phase("warm", TimeValue.ZERO, Collections.singletonMap(shrinkAction.getWriteableName(), shrinkAction)); |
| 74 | + Map<String, Phase> phases = new HashMap<>(); |
| 75 | + phases.put(hotPhase.getName(), hotPhase); |
| 76 | + phases.put(warmPhase.getName(), warmPhase); |
| 77 | + LifecyclePolicy lifecyclePolicy = new LifecyclePolicy("shrink-policy", phases); |
| 78 | + client().execute(PutLifecycleAction.INSTANCE, new PutLifecycleAction.Request(lifecyclePolicy)).get(); |
| 79 | + |
| 80 | + Template t = new Template( |
| 81 | + Settings.builder() |
| 82 | + .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 2) |
| 83 | + .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) |
| 84 | + .put(LifecycleSettings.LIFECYCLE_NAME, "shrink-policy") |
| 85 | + .build(), |
| 86 | + null, |
| 87 | + null |
| 88 | + ); |
| 89 | + |
| 90 | + ComposableIndexTemplate template = new ComposableIndexTemplate( |
| 91 | + Collections.singletonList(index), |
| 92 | + t, |
| 93 | + null, |
| 94 | + null, |
| 95 | + null, |
| 96 | + null, |
| 97 | + new ComposableIndexTemplate.DataStreamTemplate(), |
| 98 | + null |
| 99 | + ); |
| 100 | + client().execute( |
| 101 | + PutComposableIndexTemplateAction.INSTANCE, |
| 102 | + new PutComposableIndexTemplateAction.Request("template").indexTemplate(template) |
| 103 | + ).actionGet(); |
| 104 | + client().prepareIndex(index).setCreate(true).setId("1").setSource("@timestamp", "2020-09-09").get(); |
| 105 | + |
| 106 | + assertBusy(() -> { |
| 107 | + ExplainLifecycleResponse explain = client().execute(ExplainLifecycleAction.INSTANCE, new ExplainLifecycleRequest().indices("*")) |
| 108 | + .get(); |
| 109 | + logger.info("--> explain: {}", Strings.toString(explain)); |
| 110 | + |
| 111 | + String backingIndexName = DataStream.getDefaultBackingIndexName(index, 1); |
| 112 | + IndexLifecycleExplainResponse indexResp = null; |
| 113 | + for (Map.Entry<String, IndexLifecycleExplainResponse> indexNameAndResp : explain.getIndexResponses().entrySet()) { |
| 114 | + if (indexNameAndResp.getKey().startsWith(SHRUNKEN_INDEX_PREFIX) && indexNameAndResp.getKey().contains(backingIndexName)) { |
| 115 | + indexResp = indexNameAndResp.getValue(); |
| 116 | + assertNotNull(indexResp); |
| 117 | + assertThat(indexResp.getPhase(), equalTo("warm")); |
| 118 | + assertThat(indexResp.getStep(), equalTo("complete")); |
| 119 | + break; |
| 120 | + } |
| 121 | + } |
| 122 | + |
| 123 | + assertNotNull("Unable to find an ilm explain output for the shrunk index of " + index, indexResp); |
| 124 | + }, 30, TimeUnit.SECONDS); |
| 125 | + } |
| 126 | + |
| 127 | + public void startHotOnlyNode() { |
| 128 | + Settings nodeSettings = Settings.builder().putList("node.roles", Arrays.asList("master", "data_hot", "ingest")).build(); |
| 129 | + internalCluster().startNode(nodeSettings); |
| 130 | + } |
| 131 | + |
| 132 | + public void startWarmOnlyNode() { |
| 133 | + Settings nodeSettings = Settings.builder().putList("node.roles", Arrays.asList("master", "data_warm", "ingest")).build(); |
| 134 | + internalCluster().startNode(nodeSettings); |
| 135 | + } |
| 136 | +} |
0 commit comments