Skip to content

Commit e04474b

Browse files
committed
Allow to disable sending a refresh-mapping to master node
When a node processed an index request, which caused it to update its own mapping, then it sends that mapping to the master. While the master process it, that node receives a state that includes an older version of the mapping. Now, there is a conflict, its not bad (i.e. the cluster state will eventually have the correct mapping), but we send for a refresh just in case form that node to the master. With a system that has extreme cases of updates and frequent mapping changes, it might make sense to disable this feature. The indices.cluster.send_refresh_mapping setting can be introduced to support that (note, this setting need to be set on the data nodes) Note, sending refresh mapping is more important when the reverse happens, and for some reason, the mapping in the master is ahead, or in conflict, with the actual parsing of it in the actual node the index exists on. In this case, the refresh mapping will result in warning being logged on the master node. closes elastic#4342
1 parent df4ffbe commit e04474b

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,10 @@ static class FailedShard {
109109
}
110110

111111
private final Object mutex = new Object();
112-
113112
private final FailedEngineHandler failedEngineHandler = new FailedEngineHandler();
114113

114+
private final boolean sendRefreshMapping;
115+
115116
@Inject
116117
public IndicesClusterStateService(Settings settings, IndicesService indicesService, ClusterService clusterService,
117118
ThreadPool threadPool, RecoveryTarget recoveryTarget,
@@ -127,6 +128,8 @@ public IndicesClusterStateService(Settings settings, IndicesService indicesServi
127128
this.nodeIndexCreatedAction = nodeIndexCreatedAction;
128129
this.nodeIndexDeletedAction = nodeIndexDeletedAction;
129130
this.nodeMappingRefreshAction = nodeMappingRefreshAction;
131+
132+
this.sendRefreshMapping = componentSettings.getAsBoolean("send_refresh_mapping", true);
130133
}
131134

132135
@Override
@@ -374,9 +377,11 @@ private void applyMappings(ClusterChangedEvent event) {
374377
}
375378
}
376379
if (typesToRefresh != null) {
377-
nodeMappingRefreshAction.nodeMappingRefresh(event.state(),
378-
new NodeMappingRefreshAction.NodeMappingRefreshRequest(index, indexMetaData.uuid(),
379-
typesToRefresh.toArray(new String[typesToRefresh.size()]), event.state().nodes().localNodeId()));
380+
if (sendRefreshMapping) {
381+
nodeMappingRefreshAction.nodeMappingRefresh(event.state(),
382+
new NodeMappingRefreshAction.NodeMappingRefreshRequest(index, indexMetaData.uuid(),
383+
typesToRefresh.toArray(new String[typesToRefresh.size()]), event.state().nodes().localNodeId()));
384+
}
380385
}
381386
// go over and remove mappings
382387
for (DocumentMapper documentMapper : mapperService) {
@@ -394,6 +399,13 @@ private boolean processMapping(String index, MapperService mapperService, String
394399
seenMappings.put(new Tuple<String, String>(index, mappingType), true);
395400
}
396401

402+
// refresh mapping can happen for 2 reasons. The first is less urgent, and happens when the mapping on this
403+
// node is ahead of what there is in the cluster state (yet an update-mapping has been sent to it already,
404+
// it just hasn't been processed yet and published). Eventually, the mappings will converge, and the refresh
405+
// mapping sent is more of a safe keeping (assuming the update mapping failed to reach the master, ...)
406+
// the second case is where the parsing/merging of the mapping from the metadata doesn't result in the same
407+
// mapping, in this case, we send to the master to refresh its own version of the mappings (to conform with the
408+
// merge version of it, which it does when refreshing the mappings), and warn log it.
397409
boolean requiresRefresh = false;
398410
try {
399411
if (!mapperService.hasMapping(mappingType)) {
@@ -403,7 +415,6 @@ private boolean processMapping(String index, MapperService mapperService, String
403415
// we don't apply default, since it has been applied when the mappings were parsed initially
404416
mapperService.merge(mappingType, mappingSource, false);
405417
if (!mapperService.documentMapper(mappingType).mappingSource().equals(mappingSource)) {
406-
// this might happen when upgrading from 0.15 to 0.16
407418
logger.debug("[{}] parsed mapping [{}], and got different sources\noriginal:\n{}\nparsed:\n{}", index, mappingType, mappingSource, mapperService.documentMapper(mappingType).mappingSource());
408419
requiresRefresh = true;
409420
}
@@ -418,7 +429,6 @@ private boolean processMapping(String index, MapperService mapperService, String
418429
mapperService.merge(mappingType, mappingSource, false);
419430
if (!mapperService.documentMapper(mappingType).mappingSource().equals(mappingSource)) {
420431
requiresRefresh = true;
421-
// this might happen when upgrading from 0.15 to 0.16
422432
logger.debug("[{}] parsed mapping [{}], and got different sources\noriginal:\n{}\nparsed:\n{}", index, mappingType, mappingSource, mapperService.documentMapper(mappingType).mappingSource());
423433
}
424434
}

0 commit comments

Comments
 (0)