Skip to content

Metadata cannot reject aliases pointing to multiple indices when resolving routing #31936

@talevy

Description

@talevy

With #30942 (add is-write-index to aliases) and #31520, we allow an alias to point to multiple indices when
writing/deleting documents. This means that we will resolve the alias to the "write index" specified in alias metadata.

This presents a problem when requests resolve routing values against aliases. Historically, it was clear
that if an alias specified routing values, those would be used, instead of the index's. With, potentially, different aliases having different routing values, it isn't clear which routing value an index request should use.

The code in Metadata that needs modifying:
https://github.com/elastic/elasticsearch/blob/4761a1f/server/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java#L479-L491

    public String resolveIndexRouting(@Nullable String routing, String aliasOrIndex) {
        if (aliasOrIndex == null) {
            return routing;
        }

        AliasOrIndex result = getAliasAndIndexLookup().get(aliasOrIndex);
        if (result == null || result.isAlias() == false) {
            return routing;
        }
        AliasOrIndex.Alias alias = (AliasOrIndex.Alias) result;
        if (result.getIndices().size() > 1) {
            rejectSingleIndexOperation(aliasOrIndex, result);
        }

There are a few solutions

  1. when resolving routing within write operations (ones that require a write index), aliases matching multiple indices can have their routing values ignored. This means the default routing value is used, and no exception is thrown.
  2. We can throw an exception if an alias points to multiple indices and any one of the aliases specifies their own routing values. Otherwise, we have nothing to look for, so it is safe to have an alias point to multiple indices, and simply return the default routing value passed into the method.
  3. others?

cc/ @bleskes

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions