mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-17 10:25:15 +00:00
* Normalized prefix for rollover API (#57271) Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Lee Hinman <lee@writequit.org> It fixes the issue #53388 by normalizing prefix at index creation request itself * Fix compilation for backport Co-authored-by: Gaurav Chandani <chngau@amazon.com>
This commit is contained in:
parent
7079a3b09f
commit
03ce0f8a4d
@ -188,6 +188,41 @@ public class RolloverIT extends ESIntegTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public void testRolloverWithIndexSettingsWithoutPrefix() throws Exception {
|
||||
Alias testAlias = new Alias("test_alias");
|
||||
boolean explicitWriteIndex = randomBoolean();
|
||||
if (explicitWriteIndex) {
|
||||
testAlias.writeIndex(true);
|
||||
}
|
||||
assertAcked(prepareCreate("test_index-2").addAlias(testAlias).get());
|
||||
index("test_index-2", "_doc", "1", "field", "value");
|
||||
flush("test_index-2");
|
||||
final Settings settings = Settings.builder()
|
||||
.put("number_of_shards", 1)
|
||||
.put("number_of_replicas", 0)
|
||||
.build();
|
||||
final RolloverResponse response = client().admin().indices().prepareRolloverIndex("test_alias")
|
||||
.settings(settings).alias(new Alias("extra_alias")).get();
|
||||
assertThat(response.getOldIndex(), equalTo("test_index-2"));
|
||||
assertThat(response.getNewIndex(), equalTo("test_index-000003"));
|
||||
assertThat(response.isDryRun(), equalTo(false));
|
||||
assertThat(response.isRolledOver(), equalTo(true));
|
||||
assertThat(response.getConditionStatus().size(), equalTo(0));
|
||||
final ClusterState state = client().admin().cluster().prepareState().get().getState();
|
||||
final IndexMetadata oldIndex = state.metadata().index("test_index-2");
|
||||
final IndexMetadata newIndex = state.metadata().index("test_index-000003");
|
||||
assertThat(newIndex.getNumberOfShards(), equalTo(1));
|
||||
assertThat(newIndex.getNumberOfReplicas(), equalTo(0));
|
||||
assertTrue(newIndex.getAliases().containsKey("test_alias"));
|
||||
assertTrue(newIndex.getAliases().containsKey("extra_alias"));
|
||||
if (explicitWriteIndex) {
|
||||
assertFalse(oldIndex.getAliases().get("test_alias").writeIndex());
|
||||
assertTrue(newIndex.getAliases().get("test_alias").writeIndex());
|
||||
} else {
|
||||
assertFalse(oldIndex.getAliases().containsKey("test_alias"));
|
||||
}
|
||||
}
|
||||
|
||||
public void testRolloverDryRun() throws Exception {
|
||||
if (randomBoolean()) {
|
||||
PutIndexTemplateRequestBuilder putTemplate = client().admin().indices()
|
||||
|
@ -65,7 +65,6 @@ public class MetadataRolloverService {
|
||||
private final MetadataCreateIndexService createIndexService;
|
||||
private final MetadataIndexAliasesService indexAliasesService;
|
||||
private final IndexNameExpressionResolver indexNameExpressionResolver;
|
||||
|
||||
@Inject
|
||||
public MetadataRolloverService(ThreadPool threadPool,
|
||||
MetadataCreateIndexService createIndexService, MetadataIndexAliasesService indexAliasesService,
|
||||
|
@ -276,10 +276,7 @@ public class MetadataCreateIndexService {
|
||||
|
||||
private void onlyCreateIndex(final CreateIndexClusterStateUpdateRequest request,
|
||||
final ActionListener<ClusterStateUpdateResponse> listener) {
|
||||
Settings.Builder updatedSettingsBuilder = Settings.builder();
|
||||
Settings build = updatedSettingsBuilder.put(request.settings()).normalizePrefix(IndexMetadata.INDEX_SETTING_PREFIX).build();
|
||||
indexScopedSettings.validate(build, true); // we do validate here - index setting must be consistent
|
||||
request.settings(build);
|
||||
normalizeRequestSetting(request);
|
||||
clusterService.submitStateUpdateTask(
|
||||
"create-index [" + request.index() + "], cause [" + request.cause() + "]",
|
||||
new AckedClusterStateUpdateTask<ClusterStateUpdateResponse>(Priority.URGENT, request, listener) {
|
||||
@ -305,12 +302,21 @@ public class MetadataCreateIndexService {
|
||||
});
|
||||
}
|
||||
|
||||
private void normalizeRequestSetting(CreateIndexClusterStateUpdateRequest createIndexClusterStateRequest) {
|
||||
Settings.Builder updatedSettingsBuilder = Settings.builder();
|
||||
Settings build = updatedSettingsBuilder.put(createIndexClusterStateRequest.settings())
|
||||
.normalizePrefix(IndexMetadata.INDEX_SETTING_PREFIX).build();
|
||||
indexScopedSettings.validate(build, true);
|
||||
createIndexClusterStateRequest.settings(build);
|
||||
}
|
||||
/**
|
||||
* Handles the cluster state transition to a version that reflects the {@link CreateIndexClusterStateUpdateRequest}.
|
||||
* All the requested changes are firstly validated before mutating the {@link ClusterState}.
|
||||
*/
|
||||
public ClusterState applyCreateIndexRequest(ClusterState currentState, CreateIndexClusterStateUpdateRequest request, boolean silent,
|
||||
BiConsumer<Metadata.Builder, IndexMetadata> metadataTransformer) throws Exception {
|
||||
|
||||
normalizeRequestSetting(request);
|
||||
logger.trace("executing IndexCreationTask for [{}] against cluster state version [{}]", request, currentState.version());
|
||||
|
||||
validate(request, currentState);
|
||||
|
@ -47,6 +47,7 @@ import org.elasticsearch.cluster.service.ClusterService;
|
||||
import org.elasticsearch.common.CheckedFunction;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.UUIDs;
|
||||
import org.elasticsearch.common.settings.IndexScopedSettings;
|
||||
import org.elasticsearch.common.compress.CompressedXContent;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
@ -483,8 +484,8 @@ public class MetadataRolloverServiceTests extends ESTestCase {
|
||||
|
||||
ShardLimitValidator shardLimitValidator = new ShardLimitValidator(Settings.EMPTY, clusterService);
|
||||
MetadataCreateIndexService createIndexService = new MetadataCreateIndexService(Settings.EMPTY,
|
||||
clusterService, indicesService, allocationService, null, shardLimitValidator, env, null,
|
||||
testThreadPool, null, Collections.emptyList(), false);
|
||||
clusterService, indicesService, allocationService, null, shardLimitValidator, env,
|
||||
IndexScopedSettings.DEFAULT_SCOPED_SETTINGS, testThreadPool, null, Collections.emptyList(), false);
|
||||
MetadataIndexAliasesService indexAliasesService = new MetadataIndexAliasesService(clusterService, indicesService,
|
||||
new AliasValidator(), null, xContentRegistry());
|
||||
MetadataRolloverService rolloverService = new MetadataRolloverService(testThreadPool, createIndexService, indexAliasesService,
|
||||
@ -560,8 +561,8 @@ public class MetadataRolloverServiceTests extends ESTestCase {
|
||||
|
||||
ShardLimitValidator shardLimitValidator = new ShardLimitValidator(Settings.EMPTY, clusterService);
|
||||
MetadataCreateIndexService createIndexService = new MetadataCreateIndexService(Settings.EMPTY,
|
||||
clusterService, indicesService, allocationService, null, shardLimitValidator, env, null,
|
||||
testThreadPool, null, Collections.emptyList(), false);
|
||||
clusterService, indicesService, allocationService, null, shardLimitValidator, env,
|
||||
IndexScopedSettings.DEFAULT_SCOPED_SETTINGS, testThreadPool, null, Collections.emptyList(), false);
|
||||
MetadataIndexAliasesService indexAliasesService = new MetadataIndexAliasesService(clusterService, indicesService,
|
||||
new AliasValidator(), null, xContentRegistry());
|
||||
MetadataRolloverService rolloverService = new MetadataRolloverService(testThreadPool, createIndexService, indexAliasesService,
|
||||
|
Loading…
x
Reference in New Issue
Block a user