Simplify MetaDataMappingService.

Now that we create all types on indices that receive a mapping update, creation
of temporary indices could get simpler.
This commit is contained in:
Adrien Grand 2015-12-03 16:06:51 +01:00
parent c5301e853a
commit 3ff91baedf
1 changed files with 7 additions and 14 deletions

View File

@ -212,22 +212,15 @@ public class MetaDataMappingService extends AbstractComponent {
for (PutMappingClusterStateUpdateRequest request : tasks) { for (PutMappingClusterStateUpdateRequest request : tasks) {
// failures here mean something is broken with our cluster state - fail all tasks by letting exceptions bubble up // failures here mean something is broken with our cluster state - fail all tasks by letting exceptions bubble up
for (String index : request.indices()) { for (String index : request.indices()) {
if (currentState.metaData().hasIndex(index)) {
// if we don't have the index, we will throw exceptions later;
if (indicesService.hasIndex(index) == false || indicesToClose.contains(index)) {
final IndexMetaData indexMetaData = currentState.metaData().index(index); final IndexMetaData indexMetaData = currentState.metaData().index(index);
IndexService indexService; if (indexMetaData != null && indicesService.hasIndex(index) == false) {
if (indicesService.hasIndex(index) == false) { // if we don't have the index, we will throw exceptions later;
indicesToClose.add(index); indicesToClose.add(index);
indexService = indicesService.createIndex(nodeServicesProvider, indexMetaData, Collections.emptyList()); IndexService indexService = indicesService.createIndex(nodeServicesProvider, indexMetaData, Collections.emptyList());
// add mappings for all types, we need them for cross-type validation // add mappings for all types, we need them for cross-type validation
for (ObjectCursor<MappingMetaData> mapping : indexMetaData.getMappings().values()) { for (ObjectCursor<MappingMetaData> mapping : indexMetaData.getMappings().values()) {
indexService.mapperService().merge(mapping.value.type(), mapping.value.source(), false, request.updateAllTypes()); indexService.mapperService().merge(mapping.value.type(), mapping.value.source(), false, request.updateAllTypes());
} }
} else {
indexService = indicesService.indexService(index);
}
}
} }
} }
} }