-
Notifications
You must be signed in to change notification settings - Fork 25.7k
Fix mapping conflicts in clone/split/shrink APIs #137096
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5ec65b4
Fix mapping conflicts in clone/split/shrink APIs
nielsbauman 5d459f6
Update docs/changelog/137096.yaml
nielsbauman 42c211d
Fix comment
nielsbauman 2f8f0ad
Merge branch 'main' into fix-clone
nielsbauman da0c541
Also `ensureGreen` at the end of tests
nielsbauman 5278988
Merge branch 'main' into fix-clone
nielsbauman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| pr: 137096 | ||
| summary: Fix mapping conflicts in clone/split/shrink APIs | ||
| area: Indices APIs | ||
| type: bug | ||
| issues: [] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ | |
| import org.elasticsearch.index.seqno.SeqNoStats; | ||
| import org.elasticsearch.test.ESIntegTestCase; | ||
| import org.elasticsearch.test.index.IndexVersionUtils; | ||
| import org.elasticsearch.xcontent.ObjectPath; | ||
| import org.elasticsearch.xcontent.XContentType; | ||
|
|
||
| import java.util.List; | ||
|
|
@@ -203,4 +204,49 @@ public void testResizeChangeIndexSorts() { | |
| }); | ||
| assertThat(error.getMessage(), containsString("can't override index sort when resizing an index")); | ||
| } | ||
|
|
||
| /** | ||
| * Test that cloning a logsdb index with a non-default timestamp mapping doesn't result in any mapping conflicts. | ||
| */ | ||
| public void testCloneLogsdbIndexWithNonDefaultTimestamp() { | ||
| // Create a logsdb index with a date_nanos @timestamp field | ||
| final var settings = indexSettings(1, randomInt(internalCluster().numDataNodes() - 1)).put("index.mode", "logsdb") | ||
| .put("index.blocks.write", true); | ||
| prepareCreate("source").setSettings(settings).setMapping("@timestamp", "type=date_nanos").get(); | ||
| ensureGreen(); | ||
|
|
||
| // Clone the index | ||
| indicesAdmin().prepareResizeIndex("source", "target").setResizeType(ResizeType.CLONE).get(); | ||
|
|
||
| // Verify that the target index has the correct @timestamp mapping | ||
| final var targetMappings = indicesAdmin().prepareGetMappings(TEST_REQUEST_TIMEOUT, "target").get(); | ||
nielsbauman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| assertThat( | ||
| ObjectPath.eval("[email protected]", targetMappings.mappings().get("target").getSourceAsMap()), | ||
| equalTo("date_nanos") | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Test that cloning a time series index with a non-default timestamp mapping doesn't result in any mapping conflicts. | ||
| */ | ||
| public void testCloneTimeSeriesIndexWithNonDefaultTimestamp() { | ||
| // Create a time series index with a date_nanos @timestamp field | ||
| final var settings = indexSettings(1, randomInt(internalCluster().numDataNodes() - 1)).put("index.mode", "time_series") | ||
| .put("index.routing_path", "sensor_id") | ||
| .put("index.blocks.write", true); | ||
| prepareCreate("source").setSettings(settings) | ||
| .setMapping("@timestamp", "type=date_nanos", "sensor_id", "type=keyword,time_series_dimension=true") | ||
| .get(); | ||
| ensureGreen(); | ||
|
|
||
| // Clone the index | ||
| indicesAdmin().prepareResizeIndex("source", "target").setResizeType(ResizeType.CLONE).get(); | ||
|
|
||
| // Verify that the target index has the correct @timestamp mapping | ||
| final var targetMappings = indicesAdmin().prepareGetMappings(TEST_REQUEST_TIMEOUT, "target").get(); | ||
| assertThat( | ||
nielsbauman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ObjectPath.eval("[email protected]", targetMappings.mappings().get("target").getSourceAsMap()), | ||
| equalTo("date_nanos") | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,6 +51,7 @@ | |
| import org.elasticsearch.indices.IndicesService; | ||
| import org.elasticsearch.test.ESIntegTestCase; | ||
| import org.elasticsearch.test.index.IndexVersionUtils; | ||
| import org.elasticsearch.xcontent.ObjectPath; | ||
| import org.elasticsearch.xcontent.XContentType; | ||
|
|
||
| import java.util.Arrays; | ||
|
|
@@ -614,6 +615,59 @@ public void testShrinkThenSplitWithFailedNode() throws Exception { | |
| assertNoResizeSourceIndexSettings("splitagain"); | ||
| } | ||
|
|
||
| /** | ||
| * Tests that shrinking a logsdb index with a non-default timestamp mapping doesn't result in any mapping conflicts. | ||
| */ | ||
| public void testShrinkLogsdbIndexWithNonDefaultTimestamp() { | ||
| // Create a logsdb index with a date_nanos @timestamp field | ||
| final var settings = indexSettings(2, 0).put("index.mode", "logsdb") | ||
| .put("index.blocks.write", true) | ||
| .put("index.routing.allocation.require._name", internalCluster().getRandomDataNodeName()); | ||
| prepareCreate("source").setSettings(settings).setMapping("@timestamp", "type=date_nanos").get(); | ||
| ensureGreen(); | ||
|
|
||
| // Shrink the index | ||
| indicesAdmin().prepareResizeIndex("source", "target") | ||
| .setResizeType(ResizeType.SHRINK) | ||
| .setSettings(Settings.builder().put("index.number_of_shards", 1).build()) | ||
| .get(); | ||
|
|
||
| // Verify that the target index has the correct @timestamp mapping | ||
| final var targetMappings = indicesAdmin().prepareGetMappings(TEST_REQUEST_TIMEOUT, "target").get(); | ||
| assertThat( | ||
| ObjectPath.eval("[email protected]", targetMappings.mappings().get("target").getSourceAsMap()), | ||
| equalTo("date_nanos") | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Tests that shrinking a time series index with a non-default timestamp mapping doesn't result in any mapping conflicts. | ||
| */ | ||
| public void testShrinkTimeSeriesIndexWithNonDefaultTimestamp() { | ||
| // Create a time series index with a date_nanos @timestamp field | ||
| final var settings = indexSettings(2, 0).put("index.mode", "time_series") | ||
| .put("index.routing_path", "sensor_id") | ||
| .put("index.routing.allocation.require._name", internalCluster().getRandomDataNodeName()) | ||
| .put("index.blocks.write", true); | ||
| prepareCreate("source").setSettings(settings) | ||
| .setMapping("@timestamp", "type=date_nanos", "sensor_id", "type=keyword,time_series_dimension=true") | ||
| .get(); | ||
| ensureGreen(); | ||
|
|
||
| // Shrink the index | ||
| indicesAdmin().prepareResizeIndex("source", "target") | ||
| .setResizeType(ResizeType.SHRINK) | ||
| .setSettings(Settings.builder().put("index.number_of_shards", 1).build()) | ||
| .get(); | ||
|
|
||
| // Verify that the target index has the correct @timestamp mapping | ||
| final var targetMappings = indicesAdmin().prepareGetMappings(TEST_REQUEST_TIMEOUT, "target").get(); | ||
| assertThat( | ||
| ObjectPath.eval("[email protected]", targetMappings.mappings().get("target").getSourceAsMap()), | ||
| equalTo("date_nanos") | ||
| ); | ||
| } | ||
|
|
||
| static void assertNoResizeSourceIndexSettings(final String index) { | ||
| ClusterStateResponse clusterStateResponse = clusterAdmin().prepareState(TEST_REQUEST_TIMEOUT) | ||
| .clear() | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,6 +46,7 @@ | |
| import org.elasticsearch.indices.IndicesService; | ||
| import org.elasticsearch.test.ESIntegTestCase; | ||
| import org.elasticsearch.test.index.IndexVersionUtils; | ||
| import org.elasticsearch.xcontent.ObjectPath; | ||
| import org.elasticsearch.xcontent.XContentType; | ||
|
|
||
| import java.io.IOException; | ||
|
|
@@ -496,4 +497,29 @@ public void testCreateSplitWithIndexSort() throws Exception { | |
| assertSortedSegments("target", expectedIndexSort); | ||
| assertNoResizeSourceIndexSettings("target"); | ||
| } | ||
|
|
||
| /** | ||
| * Tests that splitting a logsdb index with a non-default timestamp mapping doesn't result in any mapping conflicts. | ||
| * N.B.: we don't test time_series indices as split is not supported for them. | ||
| */ | ||
| public void testSplitLogsdbIndexWithNonDefaultTimestamp() { | ||
| // Create a logsdb index with a date_nanos @timestamp field | ||
| final var settings = indexSettings(1, randomInt(internalCluster().numDataNodes() - 1)).put("index.mode", "logsdb") | ||
| .put("index.blocks.write", true); | ||
| prepareCreate("source").setSettings(settings).setMapping("@timestamp", "type=date_nanos").get(); | ||
| ensureGreen(); | ||
|
|
||
| // Split the index | ||
| indicesAdmin().prepareResizeIndex("source", "target") | ||
| .setResizeType(ResizeType.SPLIT) | ||
| .setSettings(Settings.builder().put("index.number_of_shards", 2).build()) | ||
| .get(); | ||
|
|
||
| // Verify that the target index has the correct @timestamp mapping | ||
| final var targetMappings = indicesAdmin().prepareGetMappings(TEST_REQUEST_TIMEOUT, "target").get(); | ||
| assertThat( | ||
| ObjectPath.eval("[email protected]", targetMappings.mappings().get("target").getSourceAsMap()), | ||
| equalTo("date_nanos") | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we make changelog more elaborate/descriptive? cc @mattc58
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, and probably needs to be a release highlight since this might warrant a special release. But that can wait until we determine the impact and precise triggering conditions of this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, then I'm merging this as-is. We can come back and update the changelog later if we want to.