Skip to content

Single mapping name for system indices #86373

@ywangd

Description

@ywangd

Context

In 7.17, we assert that the incoming mappings for index creation has a single out key of _doc (the default single mapping name):

assert mapping.size() == 1 : mapping;
assert entry.getKey().equals(mapping.keySet().iterator().next()) : entry.getKey() + " != " + mapping;

But this is not always true when security indices are created in a mixed cluster (8.x and 7.17) because the mappings are configured without the single-mapping-name in 8.x:

while they are configured with the single-mapping-name in 7.17:

.mapping(descriptorForVersion.getIndexType(), descriptorForVersion.getMappings(), XContentType.JSON)

Therefore, if the request hits a 8.x node first, the assertion will be tripped in the 7.17 node (if 7.17 is the master node). Till today, we didn't have any tests that create a net new security index in 8.x node of a mixed cluster. So the assertions are never tripped. It does not seem to be a problem in production because: (1) assertions are not fired in production; (2) MapperService handles the mappings with or without the single-mapping-type in 7.17:

if (type == null || type.equals(rootName) || documentTypeResolver.apply(type).equals(rootName)) {
mapping = new Tuple<>(rootName, (Map<String, Object>) root.get(rootName));
} else {
mapping = new Tuple<>(type, root);
}

Though the above is for security indices, it seems that all system indices can have similar issue:


Steps to reproduce:

  1. Start a 7.17 node with -ea to enable assertions
  2. Start a 8.x node to form a cluster with the above 7.17 node. Make sure 7.17 is the master
  3. Create a user on the 8.x node to trigger creation of the security index:
PUT _security/user/foo
{"password":"password","roles":["foo-role"]}
  1. The 7.17 node crashes with AssertionError

Question

Is simply dropping the assertions in 7.17 the right fix?

It seems to be. However, I am not entirely sure whether the underlying system is fully ready for handling mappings that do not have the single-mapping-name key. It appears to be working fine. In fact, the code is out there for a while and I am not aware of any related bug report. So it most likely works. But I'd appreciate confirmation from people who are more expert for system indices and mapping services.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions