Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AutoCreate should work for non-primary system indices (#77045)
Previously, we handled the case of a write request to a system index alias without a backing index by auto-creating the primary index. This had the unfortunate side-effect of making it impossible to auto-create non-primary system indices. This commit fixes the bug so that we can handle both cases. * Add internal cluster test for system index auto create * Allow auto-creation of non-primary indices for a system index pattern * Use primary index if autocreate is called with system index alias name
- Loading branch information
1 parent
c3e815c
commit 83355d3
Showing
3 changed files
with
92 additions
and
15 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
...usterTest/java/org/elasticsearch/action/admin/indices/create/AutoCreateSystemIndexIT.java
This file contains 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,54 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.action.admin.indices.create; | ||
|
||
import org.elasticsearch.action.admin.indices.get.GetIndexResponse; | ||
import org.elasticsearch.common.util.CollectionUtils; | ||
import org.elasticsearch.indices.TestSystemIndexPlugin; | ||
import org.elasticsearch.plugins.Plugin; | ||
import org.elasticsearch.test.ESIntegTestCase; | ||
|
||
import java.util.Collection; | ||
|
||
import static org.elasticsearch.indices.TestSystemIndexDescriptor.INDEX_NAME; | ||
import static org.elasticsearch.indices.TestSystemIndexDescriptor.PRIMARY_INDEX_NAME; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 0) | ||
public class AutoCreateSystemIndexIT extends ESIntegTestCase { | ||
|
||
@Override | ||
protected Collection<Class<? extends Plugin>> nodePlugins() { | ||
return CollectionUtils.appendToCopy(super.nodePlugins(), TestSystemIndexPlugin.class); | ||
} | ||
|
||
public void testAutoCreatePrimaryIndex() throws Exception { | ||
CreateIndexRequest request = new CreateIndexRequest(PRIMARY_INDEX_NAME); | ||
client().execute(AutoCreateAction.INSTANCE, request).get(); | ||
|
||
GetIndexResponse response = client().admin().indices().prepareGetIndex().addIndices(PRIMARY_INDEX_NAME).get(); | ||
assertThat(response.indices().length, is(1)); | ||
} | ||
|
||
public void testAutoCreatePrimaryIndexFromAlias() throws Exception { | ||
CreateIndexRequest request = new CreateIndexRequest(INDEX_NAME); | ||
client().execute(AutoCreateAction.INSTANCE, request).get(); | ||
|
||
GetIndexResponse response = client().admin().indices().prepareGetIndex().addIndices(PRIMARY_INDEX_NAME).get(); | ||
assertThat(response.indices().length, is(1)); | ||
} | ||
|
||
public void testAutoCreateNonPrimaryIndex() throws Exception { | ||
CreateIndexRequest request = new CreateIndexRequest(INDEX_NAME + "-2"); | ||
client().execute(AutoCreateAction.INSTANCE, request).get(); | ||
|
||
GetIndexResponse response = client().admin().indices().prepareGetIndex().addIndices(INDEX_NAME + "-2").get(); | ||
assertThat(response.indices().length, is(1)); | ||
} | ||
} |
This file contains 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 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