summaryrefslogtreecommitdiff
path: root/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexService.java
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexService.java')
-rw-r--r--core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexService.java430
1 files changed, 215 insertions, 215 deletions
diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexService.java b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexService.java
index 2344e9af77..fbf3446b2d 100644
--- a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexService.java
+++ b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexService.java
@@ -137,22 +137,22 @@ public class MetaDataCreateIndexService extends AbstractComponent {
public void validateIndexName(String index, ClusterState state) {
if (state.routingTable().hasIndex(index)) {
- throw new IndexAlreadyExistsException(new Index(index));
+ throw new IndexAlreadyExistsException(state.routingTable().index(index).getIndex());
}
if (state.metaData().hasIndex(index)) {
- throw new IndexAlreadyExistsException(new Index(index));
+ throw new IndexAlreadyExistsException(state.metaData().index(index).getIndex());
}
if (!Strings.validFileName(index)) {
- throw new InvalidIndexNameException(new Index(index), index, "must not contain the following characters " + Strings.INVALID_FILENAME_CHARS);
+ throw new InvalidIndexNameException(index, "must not contain the following characters " + Strings.INVALID_FILENAME_CHARS);
}
if (index.contains("#")) {
- throw new InvalidIndexNameException(new Index(index), index, "must not contain '#'");
+ throw new InvalidIndexNameException(index, "must not contain '#'");
}
if (index.charAt(0) == '_') {
- throw new InvalidIndexNameException(new Index(index), index, "must not start with '_'");
+ throw new InvalidIndexNameException(index, "must not start with '_'");
}
if (!index.toLowerCase(Locale.ROOT).equals(index)) {
- throw new InvalidIndexNameException(new Index(index), index, "must be lowercase");
+ throw new InvalidIndexNameException(index, "must be lowercase");
}
int byteCount = 0;
try {
@@ -162,15 +162,15 @@ public class MetaDataCreateIndexService extends AbstractComponent {
throw new ElasticsearchException("Unable to determine length of index name", e);
}
if (byteCount > MAX_INDEX_NAME_BYTES) {
- throw new InvalidIndexNameException(new Index(index), index,
+ throw new InvalidIndexNameException(index,
"index name is too long, (" + byteCount +
- " > " + MAX_INDEX_NAME_BYTES + ")");
+ " > " + MAX_INDEX_NAME_BYTES + ")");
}
if (state.metaData().hasAlias(index)) {
- throw new InvalidIndexNameException(new Index(index), index, "already exists as alias");
+ throw new InvalidIndexNameException(index, "already exists as alias");
}
if (index.equals(".") || index.equals("..")) {
- throw new InvalidIndexNameException(new Index(index), index, "must not be '.' or '..'");
+ throw new InvalidIndexNameException(index, "must not be '.' or '..'");
}
}
@@ -187,242 +187,242 @@ public class MetaDataCreateIndexService extends AbstractComponent {
return new ClusterStateUpdateResponse(acknowledged);
}
- @Override
- public ClusterState execute(ClusterState currentState) throws Exception {
- boolean indexCreated = false;
- String removalReason = null;
- try {
- validate(request, currentState);
-
- for (Alias alias : request.aliases()) {
- aliasValidator.validateAlias(alias, request.index(), currentState.metaData());
- }
+ @Override
+ public ClusterState execute(ClusterState currentState) throws Exception {
+ boolean indexCreated = false;
+ String removalReason = null;
+ try {
+ validate(request, currentState);
- // we only find a template when its an API call (a new index)
- // find templates, highest order are better matching
- List<IndexTemplateMetaData> templates = findTemplates(request, currentState, indexTemplateFilter);
+ for (Alias alias : request.aliases()) {
+ aliasValidator.validateAlias(alias, request.index(), currentState.metaData());
+ }
- Map<String, Custom> customs = new HashMap<>();
+ // we only find a template when its an API call (a new index)
+ // find templates, highest order are better matching
+ List<IndexTemplateMetaData> templates = findTemplates(request, currentState, indexTemplateFilter);
- // add the request mapping
- Map<String, Map<String, Object>> mappings = new HashMap<>();
+ Map<String, Custom> customs = new HashMap<>();
- Map<String, AliasMetaData> templatesAliases = new HashMap<>();
+ // add the request mapping
+ Map<String, Map<String, Object>> mappings = new HashMap<>();
- List<String> templateNames = new ArrayList<>();
+ Map<String, AliasMetaData> templatesAliases = new HashMap<>();
- for (Map.Entry<String, String> entry : request.mappings().entrySet()) {
- mappings.put(entry.getKey(), parseMapping(entry.getValue()));
- }
+ List<String> templateNames = new ArrayList<>();
- for (Map.Entry<String, Custom> entry : request.customs().entrySet()) {
- customs.put(entry.getKey(), entry.getValue());
- }
+ for (Map.Entry<String, String> entry : request.mappings().entrySet()) {
+ mappings.put(entry.getKey(), parseMapping(entry.getValue()));
+ }
- // apply templates, merging the mappings into the request mapping if exists
- for (IndexTemplateMetaData template : templates) {
- templateNames.add(template.getName());
- for (ObjectObjectCursor<String, CompressedXContent> cursor : template.mappings()) {
- if (mappings.containsKey(cursor.key)) {
- XContentHelper.mergeDefaults(mappings.get(cursor.key), parseMapping(cursor.value.string()));
- } else {
- mappings.put(cursor.key, parseMapping(cursor.value.string()));
+ for (Map.Entry<String, Custom> entry : request.customs().entrySet()) {
+ customs.put(entry.getKey(), entry.getValue());
}
- }
- // handle custom
- for (ObjectObjectCursor<String, Custom> cursor : template.customs()) {
- String type = cursor.key;
- IndexMetaData.Custom custom = cursor.value;
- IndexMetaData.Custom existing = customs.get(type);
- if (existing == null) {
- customs.put(type, custom);
- } else {
- IndexMetaData.Custom merged = existing.mergeWith(custom);
- customs.put(type, merged);
+
+ // apply templates, merging the mappings into the request mapping if exists
+ for (IndexTemplateMetaData template : templates) {
+ templateNames.add(template.getName());
+ for (ObjectObjectCursor<String, CompressedXContent> cursor : template.mappings()) {
+ if (mappings.containsKey(cursor.key)) {
+ XContentHelper.mergeDefaults(mappings.get(cursor.key), parseMapping(cursor.value.string()));
+ } else {
+ mappings.put(cursor.key, parseMapping(cursor.value.string()));
+ }
+ }
+ // handle custom
+ for (ObjectObjectCursor<String, Custom> cursor : template.customs()) {
+ String type = cursor.key;
+ IndexMetaData.Custom custom = cursor.value;
+ IndexMetaData.Custom existing = customs.get(type);
+ if (existing == null) {
+ customs.put(type, custom);
+ } else {
+ IndexMetaData.Custom merged = existing.mergeWith(custom);
+ customs.put(type, merged);
+ }
+ }
+ //handle aliases
+ for (ObjectObjectCursor<String, AliasMetaData> cursor : template.aliases()) {
+ AliasMetaData aliasMetaData = cursor.value;
+ //if an alias with same name came with the create index request itself,
+ // ignore this one taken from the index template
+ if (request.aliases().contains(new Alias(aliasMetaData.alias()))) {
+ continue;
+ }
+ //if an alias with same name was already processed, ignore this one
+ if (templatesAliases.containsKey(cursor.key)) {
+ continue;
+ }
+
+ //Allow templatesAliases to be templated by replacing a token with the name of the index that we are applying it to
+ if (aliasMetaData.alias().contains("{index}")) {
+ String templatedAlias = aliasMetaData.alias().replace("{index}", request.index());
+ aliasMetaData = AliasMetaData.newAliasMetaData(aliasMetaData, templatedAlias);
+ }
+
+ aliasValidator.validateAliasMetaData(aliasMetaData, request.index(), currentState.metaData());
+ templatesAliases.put(aliasMetaData.alias(), aliasMetaData);
+ }
}
- }
- //handle aliases
- for (ObjectObjectCursor<String, AliasMetaData> cursor : template.aliases()) {
- AliasMetaData aliasMetaData = cursor.value;
- //if an alias with same name came with the create index request itself,
- // ignore this one taken from the index template
- if (request.aliases().contains(new Alias(aliasMetaData.alias()))) {
- continue;
+
+ Settings.Builder indexSettingsBuilder = settingsBuilder();
+ // apply templates, here, in reverse order, since first ones are better matching
+ for (int i = templates.size() - 1; i >= 0; i--) {
+ indexSettingsBuilder.put(templates.get(i).settings());
}
- //if an alias with same name was already processed, ignore this one
- if (templatesAliases.containsKey(cursor.key)) {
- continue;
+ // now, put the request settings, so they override templates
+ indexSettingsBuilder.put(request.settings());
+ if (request.index().equals(ScriptService.SCRIPT_INDEX)) {
+ indexSettingsBuilder.put(SETTING_NUMBER_OF_SHARDS, settings.getAsInt(SETTING_NUMBER_OF_SHARDS, 1));
+ } else {
+ if (indexSettingsBuilder.get(SETTING_NUMBER_OF_SHARDS) == null) {
+ indexSettingsBuilder.put(SETTING_NUMBER_OF_SHARDS, settings.getAsInt(SETTING_NUMBER_OF_SHARDS, 5));
+ }
}
-
- //Allow templatesAliases to be templated by replacing a token with the name of the index that we are applying it to
- if (aliasMetaData.alias().contains("{index}")) {
- String templatedAlias = aliasMetaData.alias().replace("{index}", request.index());
- aliasMetaData = AliasMetaData.newAliasMetaData(aliasMetaData, templatedAlias);
+ if (request.index().equals(ScriptService.SCRIPT_INDEX)) {
+ indexSettingsBuilder.put(SETTING_NUMBER_OF_REPLICAS, settings.getAsInt(SETTING_NUMBER_OF_REPLICAS, 0));
+ indexSettingsBuilder.put(SETTING_AUTO_EXPAND_REPLICAS, "0-all");
+ } else {
+ if (indexSettingsBuilder.get(SETTING_NUMBER_OF_REPLICAS) == null) {
+ indexSettingsBuilder.put(SETTING_NUMBER_OF_REPLICAS, settings.getAsInt(SETTING_NUMBER_OF_REPLICAS, 1));
+ }
}
- aliasValidator.validateAliasMetaData(aliasMetaData, request.index(), currentState.metaData());
- templatesAliases.put(aliasMetaData.alias(), aliasMetaData);
- }
- }
-
- Settings.Builder indexSettingsBuilder = settingsBuilder();
- // apply templates, here, in reverse order, since first ones are better matching
- for (int i = templates.size() - 1; i >= 0; i--) {
- indexSettingsBuilder.put(templates.get(i).settings());
- }
- // now, put the request settings, so they override templates
- indexSettingsBuilder.put(request.settings());
- if (request.index().equals(ScriptService.SCRIPT_INDEX)) {
- indexSettingsBuilder.put(SETTING_NUMBER_OF_SHARDS, settings.getAsInt(SETTING_NUMBER_OF_SHARDS, 1));
- } else {
- if (indexSettingsBuilder.get(SETTING_NUMBER_OF_SHARDS) == null) {
- indexSettingsBuilder.put(SETTING_NUMBER_OF_SHARDS, settings.getAsInt(SETTING_NUMBER_OF_SHARDS, 5));
- }
- }
- if (request.index().equals(ScriptService.SCRIPT_INDEX)) {
- indexSettingsBuilder.put(SETTING_NUMBER_OF_REPLICAS, settings.getAsInt(SETTING_NUMBER_OF_REPLICAS, 0));
- indexSettingsBuilder.put(SETTING_AUTO_EXPAND_REPLICAS, "0-all");
- } else {
- if (indexSettingsBuilder.get(SETTING_NUMBER_OF_REPLICAS) == null) {
- indexSettingsBuilder.put(SETTING_NUMBER_OF_REPLICAS, settings.getAsInt(SETTING_NUMBER_OF_REPLICAS, 1));
- }
- }
-
- if (settings.get(SETTING_AUTO_EXPAND_REPLICAS) != null && indexSettingsBuilder.get(SETTING_AUTO_EXPAND_REPLICAS) == null) {
- indexSettingsBuilder.put(SETTING_AUTO_EXPAND_REPLICAS, settings.get(SETTING_AUTO_EXPAND_REPLICAS));
- }
+ if (settings.get(SETTING_AUTO_EXPAND_REPLICAS) != null && indexSettingsBuilder.get(SETTING_AUTO_EXPAND_REPLICAS) == null) {
+ indexSettingsBuilder.put(SETTING_AUTO_EXPAND_REPLICAS, settings.get(SETTING_AUTO_EXPAND_REPLICAS));
+ }
- if (indexSettingsBuilder.get(SETTING_VERSION_CREATED) == null) {
- DiscoveryNodes nodes = currentState.nodes();
- final Version createdVersion = Version.smallest(version, nodes.smallestNonClientNodeVersion());
- indexSettingsBuilder.put(SETTING_VERSION_CREATED, createdVersion);
- }
+ if (indexSettingsBuilder.get(SETTING_VERSION_CREATED) == null) {
+ DiscoveryNodes nodes = currentState.nodes();
+ final Version createdVersion = Version.smallest(version, nodes.smallestNonClientNodeVersion());
+ indexSettingsBuilder.put(SETTING_VERSION_CREATED, createdVersion);
+ }
- if (indexSettingsBuilder.get(SETTING_CREATION_DATE) == null) {
- indexSettingsBuilder.put(SETTING_CREATION_DATE, new DateTime(DateTimeZone.UTC).getMillis());
- }
+ if (indexSettingsBuilder.get(SETTING_CREATION_DATE) == null) {
+ indexSettingsBuilder.put(SETTING_CREATION_DATE, new DateTime(DateTimeZone.UTC).getMillis());
+ }
- indexSettingsBuilder.put(SETTING_INDEX_UUID, Strings.randomBase64UUID());
+ indexSettingsBuilder.put(SETTING_INDEX_UUID, Strings.randomBase64UUID());
+
+ Settings actualIndexSettings = indexSettingsBuilder.build();
+
+ // Set up everything, now locally create the index to see that things are ok, and apply
+ final IndexMetaData tmpImd = IndexMetaData.builder(request.index()).settings(actualIndexSettings).build();
+ // create the index here (on the master) to validate it can be created, as well as adding the mapping
+ indicesService.createIndex(nodeServicesProvider, tmpImd, Collections.emptyList());
+ indexCreated = true;
+ // now add the mappings
+ IndexService indexService = indicesService.indexServiceSafe(request.index());
+ MapperService mapperService = indexService.mapperService();
+ // first, add the default mapping
+ if (mappings.containsKey(MapperService.DEFAULT_MAPPING)) {
+ try {
+ mapperService.merge(MapperService.DEFAULT_MAPPING, new CompressedXContent(XContentFactory.jsonBuilder().map(mappings.get(MapperService.DEFAULT_MAPPING)).string()), MapperService.MergeReason.MAPPING_UPDATE, request.updateAllTypes());
+ } catch (Exception e) {
+ removalReason = "failed on parsing default mapping on index creation";
+ throw new MapperParsingException("Failed to parse mapping [{}]: {}", e, MapperService.DEFAULT_MAPPING, e.getMessage());
+ }
+ }
+ for (Map.Entry<String, Map<String, Object>> entry : mappings.entrySet()) {
+ if (entry.getKey().equals(MapperService.DEFAULT_MAPPING)) {
+ continue;
+ }
+ try {
+ // apply the default here, its the first time we parse it
+ mapperService.merge(entry.getKey(), new CompressedXContent(XContentFactory.jsonBuilder().map(entry.getValue()).string()), MapperService.MergeReason.MAPPING_UPDATE, request.updateAllTypes());
+ } catch (Exception e) {
+ removalReason = "failed on parsing mappings on index creation";
+ throw new MapperParsingException("Failed to parse mapping [{}]: {}", e, entry.getKey(), e.getMessage());
+ }
+ }
- Settings actualIndexSettings = indexSettingsBuilder.build();
+ QueryShardContext queryShardContext = indexService.getQueryShardContext();
+ for (Alias alias : request.aliases()) {
+ if (Strings.hasLength(alias.filter())) {
+ aliasValidator.validateAliasFilter(alias.name(), alias.filter(), queryShardContext);
+ }
+ }
+ for (AliasMetaData aliasMetaData : templatesAliases.values()) {
+ if (aliasMetaData.filter() != null) {
+ aliasValidator.validateAliasFilter(aliasMetaData.alias(), aliasMetaData.filter().uncompressed(), queryShardContext);
+ }
+ }
- // Set up everything, now locally create the index to see that things are ok, and apply
- final IndexMetaData tmpImd = IndexMetaData.builder(request.index()).settings(actualIndexSettings).build();
- // create the index here (on the master) to validate it can be created, as well as adding the mapping
- indicesService.createIndex(nodeServicesProvider, tmpImd, Collections.emptyList());
- indexCreated = true;
- // now add the mappings
- IndexService indexService = indicesService.indexServiceSafe(request.index());
- MapperService mapperService = indexService.mapperService();
- // first, add the default mapping
- if (mappings.containsKey(MapperService.DEFAULT_MAPPING)) {
- try {
- mapperService.merge(MapperService.DEFAULT_MAPPING, new CompressedXContent(XContentFactory.jsonBuilder().map(mappings.get(MapperService.DEFAULT_MAPPING)).string()), MapperService.MergeReason.MAPPING_UPDATE, request.updateAllTypes());
- } catch (Exception e) {
- removalReason = "failed on parsing default mapping on index creation";
- throw new MapperParsingException("Failed to parse mapping [{}]: {}", e, MapperService.DEFAULT_MAPPING, e.getMessage());
- }
- }
- for (Map.Entry<String, Map<String, Object>> entry : mappings.entrySet()) {
- if (entry.getKey().equals(MapperService.DEFAULT_MAPPING)) {
- continue;
- }
- try {
- // apply the default here, its the first time we parse it
- mapperService.merge(entry.getKey(), new CompressedXContent(XContentFactory.jsonBuilder().map(entry.getValue()).string()), MapperService.MergeReason.MAPPING_UPDATE, request.updateAllTypes());
- } catch (Exception e) {
- removalReason = "failed on parsing mappings on index creation";
- throw new MapperParsingException("Failed to parse mapping [{}]: {}", e, entry.getKey(), e.getMessage());
- }
- }
+ // now, update the mappings with the actual source
+ Map<String, MappingMetaData> mappingsMetaData = new HashMap<>();
+ for (DocumentMapper mapper : mapperService.docMappers(true)) {
+ MappingMetaData mappingMd = new MappingMetaData(mapper);
+ mappingsMetaData.put(mapper.type(), mappingMd);
+ }
- QueryShardContext queryShardContext = indexService.getQueryShardContext();
- for (Alias alias : request.aliases()) {
- if (Strings.hasLength(alias.filter())) {
- aliasValidator.validateAliasFilter(alias.name(), alias.filter(), queryShardContext);
- }
- }
- for (AliasMetaData aliasMetaData : templatesAliases.values()) {
- if (aliasMetaData.filter() != null) {
- aliasValidator.validateAliasFilter(aliasMetaData.alias(), aliasMetaData.filter().uncompressed(), queryShardContext);
- }
- }
+ final IndexMetaData.Builder indexMetaDataBuilder = IndexMetaData.builder(request.index()).settings(actualIndexSettings);
+ for (MappingMetaData mappingMd : mappingsMetaData.values()) {
+ indexMetaDataBuilder.putMapping(mappingMd);
+ }
- // now, update the mappings with the actual source
- Map<String, MappingMetaData> mappingsMetaData = new HashMap<>();
- for (DocumentMapper mapper : mapperService.docMappers(true)) {
- MappingMetaData mappingMd = new MappingMetaData(mapper);
- mappingsMetaData.put(mapper.type(), mappingMd);
- }
+ for (AliasMetaData aliasMetaData : templatesAliases.values()) {
+ indexMetaDataBuilder.putAlias(aliasMetaData);
+ }
+ for (Alias alias : request.aliases()) {
+ AliasMetaData aliasMetaData = AliasMetaData.builder(alias.name()).filter(alias.filter())
+ .indexRouting(alias.indexRouting()).searchRouting(alias.searchRouting()).build();
+ indexMetaDataBuilder.putAlias(aliasMetaData);
+ }
- final IndexMetaData.Builder indexMetaDataBuilder = IndexMetaData.builder(request.index()).settings(actualIndexSettings);
- for (MappingMetaData mappingMd : mappingsMetaData.values()) {
- indexMetaDataBuilder.putMapping(mappingMd);
- }
+ for (Map.Entry<String, Custom> customEntry : customs.entrySet()) {
+ indexMetaDataBuilder.putCustom(customEntry.getKey(), customEntry.getValue());
+ }
- for (AliasMetaData aliasMetaData : templatesAliases.values()) {
- indexMetaDataBuilder.putAlias(aliasMetaData);
- }
- for (Alias alias : request.aliases()) {
- AliasMetaData aliasMetaData = AliasMetaData.builder(alias.name()).filter(alias.filter())
- .indexRouting(alias.indexRouting()).searchRouting(alias.searchRouting()).build();
- indexMetaDataBuilder.putAlias(aliasMetaData);
- }
+ indexMetaDataBuilder.state(request.state());
- for (Map.Entry<String, Custom> customEntry : customs.entrySet()) {
- indexMetaDataBuilder.putCustom(customEntry.getKey(), customEntry.getValue());
- }
+ final IndexMetaData indexMetaData;
+ try {
+ indexMetaData = indexMetaDataBuilder.build();
+ } catch (Exception e) {
+ removalReason = "failed to build index metadata";
+ throw e;
+ }
- indexMetaDataBuilder.state(request.state());
+ indexService.getIndexEventListener().beforeIndexAddedToCluster(indexMetaData.getIndex(),
+ indexMetaData.getSettings());
- final IndexMetaData indexMetaData;
- try {
- indexMetaData = indexMetaDataBuilder.build();
- } catch (Exception e) {
- removalReason = "failed to build index metadata";
- throw e;
- }
+ MetaData newMetaData = MetaData.builder(currentState.metaData())
+ .put(indexMetaData, false)
+ .build();
- indexService.getIndexEventListener().beforeIndexAddedToCluster(new Index(request.index()),
- indexMetaData.getSettings());
+ String maybeShadowIndicator = IndexMetaData.isIndexUsingShadowReplicas(indexMetaData.getSettings()) ? "s" : "";
+ logger.info("[{}] creating index, cause [{}], templates {}, shards [{}]/[{}{}], mappings {}",
+ request.index(), request.cause(), templateNames, indexMetaData.getNumberOfShards(),
+ indexMetaData.getNumberOfReplicas(), maybeShadowIndicator, mappings.keySet());
- MetaData newMetaData = MetaData.builder(currentState.metaData())
- .put(indexMetaData, false)
- .build();
+ ClusterBlocks.Builder blocks = ClusterBlocks.builder().blocks(currentState.blocks());
+ if (!request.blocks().isEmpty()) {
+ for (ClusterBlock block : request.blocks()) {
+ blocks.addIndexBlock(request.index(), block);
+ }
+ }
+ blocks.updateBlocks(indexMetaData);
- String maybeShadowIndicator = IndexMetaData.isIndexUsingShadowReplicas(indexMetaData.getSettings()) ? "s" : "";
- logger.info("[{}] creating index, cause [{}], templates {}, shards [{}]/[{}{}], mappings {}",
- request.index(), request.cause(), templateNames, indexMetaData.getNumberOfShards(),
- indexMetaData.getNumberOfReplicas(), maybeShadowIndicator, mappings.keySet());
+ ClusterState updatedState = ClusterState.builder(currentState).blocks(blocks).metaData(newMetaData).build();
- ClusterBlocks.Builder blocks = ClusterBlocks.builder().blocks(currentState.blocks());
- if (!request.blocks().isEmpty()) {
- for (ClusterBlock block : request.blocks()) {
- blocks.addIndexBlock(request.index(), block);
+ if (request.state() == State.OPEN) {
+ RoutingTable.Builder routingTableBuilder = RoutingTable.builder(updatedState.routingTable())
+ .addAsNew(updatedState.metaData().index(request.index()));
+ RoutingAllocation.Result routingResult = allocationService.reroute(
+ ClusterState.builder(updatedState).routingTable(routingTableBuilder.build()).build(),
+ "index [" + request.index() + "] created");
+ updatedState = ClusterState.builder(updatedState).routingResult(routingResult).build();
+ }
+ removalReason = "cleaning up after validating index on master";
+ return updatedState;
+ } finally {
+ if (indexCreated) {
+ // Index was already partially created - need to clean up
+ indicesService.removeIndex(request.index(), removalReason != null ? removalReason : "failed to create index");
+ }
}
}
- blocks.updateBlocks(indexMetaData);
-
- ClusterState updatedState = ClusterState.builder(currentState).blocks(blocks).metaData(newMetaData).build();
-
- if (request.state() == State.OPEN) {
- RoutingTable.Builder routingTableBuilder = RoutingTable.builder(updatedState.routingTable())
- .addAsNew(updatedState.metaData().index(request.index()));
- RoutingAllocation.Result routingResult = allocationService.reroute(
- ClusterState.builder(updatedState).routingTable(routingTableBuilder.build()).build(),
- "index [" + request.index() + "] created");
- updatedState = ClusterState.builder(updatedState).routingResult(routingResult).build();
- }
- removalReason = "cleaning up after validating index on master";
- return updatedState;
- } finally {
- if (indexCreated) {
- // Index was already partially created - need to clean up
- indicesService.removeIndex(request.index(), removalReason != null ? removalReason : "failed to create index");
- }
- }
- }
- });
+ });
}
private Map<String, Object> parseMapping(String mappingSource) throws Exception {
@@ -459,7 +459,7 @@ public class MetaDataCreateIndexService extends AbstractComponent {
if (validationErrors.isEmpty() == false) {
ValidationException validationException = new ValidationException();
validationException.addValidationErrors(validationErrors);
- throw new IndexCreationException(new Index(indexName), validationException);
+ throw new IndexCreationException(indexName, validationException);
}
}