Skip to content

Commit d0c18c5

Browse files
committed
Add test for creation date
1 parent 9a7d620 commit d0c18c5

File tree

2 files changed

+28
-60
lines changed

2 files changed

+28
-60
lines changed

x-pack/plugin/migrate/src/internalClusterTest/java/org/elasticsearch/xpack/migrate/action/CopyIndexMetadataTransportActionIT.java

Lines changed: 15 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -8,50 +8,45 @@
88
package org.elasticsearch.xpack.migrate.action;
99

1010
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
11-
import org.elasticsearch.action.admin.indices.get.GetIndexRequest;
12-
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest;
1311
import org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest;
14-
import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest;
1512
import org.elasticsearch.cluster.metadata.IndexMetadata;
16-
import org.elasticsearch.cluster.metadata.MappingMetadata;
17-
import org.elasticsearch.common.settings.Settings;
18-
import org.elasticsearch.common.xcontent.XContentHelper;
19-
import org.elasticsearch.common.xcontent.support.XContentMapValues;
2013
import org.elasticsearch.datastreams.DataStreamsPlugin;
21-
import org.elasticsearch.index.IndexNotFoundException;
14+
import org.elasticsearch.ingest.common.IngestCommonPlugin;
2215
import org.elasticsearch.plugins.Plugin;
2316
import org.elasticsearch.reindex.ReindexPlugin;
2417
import org.elasticsearch.test.ESIntegTestCase;
2518
import org.elasticsearch.test.transport.MockTransportService;
26-
import org.elasticsearch.xcontent.json.JsonXContent;
2719
import org.elasticsearch.xpack.migrate.MigratePlugin;
2820

2921
import java.util.Collection;
3022
import java.util.List;
3123
import java.util.Locale;
32-
import java.util.Map;
3324

3425
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
3526

3627
public class CopyIndexMetadataTransportActionIT extends ESIntegTestCase {
3728

3829
@Override
3930
protected Collection<Class<? extends Plugin>> nodePlugins() {
40-
// return List.of();
41-
return List.of(MigratePlugin.class, ReindexPlugin.class, MockTransportService.TestPlugin.class, DataStreamsPlugin.class);
31+
return List.of(
32+
MigratePlugin.class,
33+
ReindexPlugin.class,
34+
MockTransportService.TestPlugin.class,
35+
DataStreamsPlugin.class,
36+
IngestCommonPlugin.class
37+
);
4238
}
4339

4440
public void testCreationDate() throws Exception {
4541
var sourceIndex = randomAlphaOfLength(20).toLowerCase(Locale.ROOT);
4642
indicesAdmin().create(new CreateIndexRequest(sourceIndex)).get();
4743

4844
// so creation date is different
49-
safeSleep(3);
45+
safeSleep(2);
5046

5147
var destIndex = randomAlphaOfLength(20).toLowerCase(Locale.ROOT);
5248
indicesAdmin().create(new CreateIndexRequest(destIndex)).get();
5349

54-
5550
// verify source and dest date are actually different before copying
5651
var settingsResponse = indicesAdmin().getSettings(new GetSettingsRequest().indices(sourceIndex, destIndex)).actionGet();
5752
var indexToSettings = settingsResponse.getIndexToSettings();
@@ -64,50 +59,17 @@ public void testCreationDate() throws Exception {
6459
}
6560

6661
assertAcked(
67-
client().execute(CopyIndexMetadataAction.INSTANCE, new CopyIndexMetadataAction.Request(TEST_REQUEST_TIMEOUT, sourceIndex, destIndex))
62+
client().execute(
63+
CopyIndexMetadataAction.INSTANCE,
64+
new CopyIndexMetadataAction.Request(TEST_REQUEST_TIMEOUT, sourceIndex, destIndex)
65+
)
6866
);
6967

70-
var destDate = indicesAdmin().getSettings(new GetSettingsRequest().indices(sourceIndex, destIndex)).actionGet()
68+
var destDate = indicesAdmin().getSettings(new GetSettingsRequest().indices(sourceIndex, destIndex))
69+
.actionGet()
7170
.getIndexToSettings()
7271
.get(destIndex)
7372
.getAsLong(IndexMetadata.SETTING_CREATION_DATE, 0L);
7473
assertEquals(sourceDate, destDate);
7574
}
76-
77-
78-
79-
public void testOldSettingsManuallyFiltered() throws Exception {
80-
var numShards = randomIntBetween(1, 10);
81-
var staticSettings = Settings.builder()
82-
// setting to filter
83-
.put("index.soft_deletes.enabled", true)
84-
// good setting to keep
85-
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, numShards)
86-
.build();
87-
88-
// start with a static setting
89-
var sourceIndex = randomAlphaOfLength(20).toLowerCase(Locale.ROOT);
90-
indicesAdmin().create(new CreateIndexRequest(sourceIndex, staticSettings)).get();
91-
92-
// create from source
93-
var destIndex = randomAlphaOfLength(20).toLowerCase(Locale.ROOT);
94-
assertAcked(
95-
client().execute(CreateIndexFromSourceAction.INSTANCE, new CreateIndexFromSourceAction.Request(sourceIndex, destIndex))
96-
);
97-
98-
// assert both static and dynamic settings set on dest index
99-
var settingsResponse = indicesAdmin().getSettings(new GetSettingsRequest().indices(sourceIndex, destIndex)).actionGet();
100-
var destSettings = settingsResponse.getIndexToSettings().get(destIndex);
101-
var sourceSettings = settingsResponse.getIndexToSettings().get(sourceIndex);
102-
103-
// sanity check that source settings were added
104-
assertEquals(true, sourceSettings.getAsBoolean("index.soft_deletes.enabled", false));
105-
assertEquals(numShards, Integer.parseInt(destSettings.get(IndexMetadata.SETTING_NUMBER_OF_SHARDS)));
106-
107-
// check that old setting was not added to index
108-
assertNull(destSettings.get("index.soft_deletes.enabled"));
109-
assertEquals(numShards, Integer.parseInt(destSettings.get(IndexMetadata.SETTING_NUMBER_OF_SHARDS)));
110-
}
111-
112-
11375
}

x-pack/plugin/migrate/src/main/java/org/elasticsearch/xpack/migrate/action/CopyIndexMetadataTransportAction.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,18 +99,24 @@ private static ClusterState applyUpdate(ClusterState state, UpdateIndexMetadataT
9999
throw new IndexNotFoundException(updateTask.destIndex);
100100
}
101101

102-
IndexMetadata newDestMetadata = IndexMetadata.builder(destMetadata)
103-
.putCustom(
102+
IndexMetadata.Builder newDestMetadata = IndexMetadata.builder(destMetadata);
103+
104+
var sourceILM = sourceMetadata.getCustomData(LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY);
105+
if (sourceILM != null) {
106+
newDestMetadata.putCustom(
104107
LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY,
105108
sourceMetadata.getCustomData(LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY)
106-
)
107-
.putRolloverInfos(sourceMetadata.getRolloverInfos())
108-
// creation data is required for ILM to function
109+
);
110+
}
111+
112+
newDestMetadata.putRolloverInfos(sourceMetadata.getRolloverInfos())
113+
// creation date is required for ILM to function
109114
.creationDate(sourceMetadata.getCreationDate())
110-
.build();
115+
// creation date updates settings so must increment settings version
116+
.settingsVersion(destMetadata.getSettingsVersion() + 1);
111117

112118
var indices = new HashMap<>(state.metadata().indices());
113-
indices.put(updateTask.destIndex, newDestMetadata);
119+
indices.put(updateTask.destIndex, newDestMetadata.build());
114120

115121
Metadata newMetadata = Metadata.builder(state.metadata()).indices(indices).build();
116122
return ClusterState.builder(state).metadata(newMetadata).build();

0 commit comments

Comments
 (0)