Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Order of atomic alias operations seems inconsistent #27689

Closed
mayya-sharipova opened this issue Dec 6, 2017 · 8 comments
Closed

Order of atomic alias operations seems inconsistent #27689

mayya-sharipova opened this issue Dec 6, 2017 · 8 comments
Assignees
Labels
>bug :Data Management/Indices APIs APIs to create and manage indices and templates help wanted adoptme

Comments

@mayya-sharipova
Copy link
Contributor

Executing an atomic alias operations on the same index and same alias returns inconsistent results:

# 1) Put an index
PUT some-concrete-index

# 2) no alias exists yet
GET some-concrete-index/_alias

# 3) add an alias, then remove it
POST /_aliases
{
  "actions": [
    {
      "add": {
        "index": "some-concrete-index",
        "alias": "oci-cmdb_service_members"
      }
    },
    {
      "remove": {
        "index": "some-concrete-index",
        "alias": "oci-cmdb_service_members"
      }
    }
  ]
}

# 4) Order shouldn't matter, and it does not seem to, as the alias now exists
GET some-concrete-index/_alias

#5) Execute the same operation again:
POST /_aliases
{
  "actions": [
    {
      "add": {
        "index": "some-concrete-index",
        "alias": "oci-cmdb_service_members"
      }
    },
    {
      "remove": {
        "index": "some-concrete-index",
        "alias": "oci-cmdb_service_members"
      }
    }
  ]
}

#6) The alias is removed now
GET some-concrete-index/_alias

To sum up:
The same request will produce different result:

  1. If the alias doesn’t exist before the request, it will be created
  2. If the alias doest exists, it will be removed
@bleskes
Copy link
Contributor

bleskes commented Dec 7, 2017

I did some digging and this has to do with the fact that we treat aliases in the remove command as wild card expressions and resolve them in advance against the cluster state before we run the command. This means that if the alias was not there when we started, the remove command will never be executed when the cluster state update. I think this is trappy as there is no correlation between the cluster state that this pre filtering is run on and the cluster state which actually serves as base for the commands execution. On top of it it doesn't account for relationship between commands. I think we should not prefilter and resolve wild cards when we execute the commands on the cluster state thread.

@mayya-sharipova mayya-sharipova self-assigned this Jan 12, 2018
mayya-sharipova added a commit to mayya-sharipova/elasticsearch that referenced this issue Jan 15, 2018
Currently aliases' names are resolved in advance against the cluster state
at the point of time before executing an alias update command command.
This means that if an alias was not there when we started this command,
but created as a part of this command, the subsequent remove operation within
the same command on the same alias will not be able to find this alias,
and will not be executed.

This is not correct as there is no correlation between the cluster state
that the alias resolution is run on and the cluster state which actually serves
as base for the commands execution.
On top of this, the current situation doesn't account
for relationship between commands.

This commit postpones aliases' wild card resolution
until we execute the commands on the cluster state thread,
so the resolution is run on the cluster state
we are modifying.

Closes elastic#27689
@clintongormley clintongormley added :Data Management/Indices APIs APIs to create and manage indices and templates and removed :Aliases labels Feb 13, 2018
@colings86 colings86 added the >bug label Apr 24, 2018
@talevy talevy added the discuss label Apr 27, 2018
@talevy
Copy link
Contributor

talevy commented Apr 27, 2018

I added the [discuss] label because I would like to discuss this in the context of eagerness to validate. This issue comes up with regards to #28231, and #30195. This also influences whether certain data-structures that are useful for early validation have value in being created as metadata is being changed and built by alias actions, rather than being re-created and validated all at once after all actions (whether legal or not, depending on the order) when the final MetaData is being built and validated (re: #29575).

to highlight some examples that all behave differently:

PUT foo

# add alias, then remove alias
# 1st call: alias created. 2nd call: alias removed
POST _aliases
{
  "actions": [
    { "add": { "index": "foo", "alias": "logs" } },
    { "remove": {"index": "foo", "alias": "logs" } }
  ]
}

# remove alias, then add alias
# after all calls: alias created
POST _aliases
{
  "actions": [
    { "remove": {"index": "foo", "alias": "logs" } },
    { "add": { "index": "foo", "alias": "logs" } }
  ]
}

# remove_index, then add alias
# after all calls: exception thrown when trying to add alias, index remains.
POST _aliases
{
  "actions": [
    { "remove_index": {"index": "foo"} },
    { "add": { "index": "foo", "alias": "logs" } }
  ]
}

# add alias, twice, updated
# after all calls: last alias metadata definition wins
POST _aliases
{
  "actions": [
    { "add": { "index": "foo","alias": "logs", "filter": { "exists": { "field": "FIELD_NAME" } }}},
    { "add": { "index": "foo","alias": "logs" }}
  ]
}

@tomcallahan
Copy link
Contributor

@bleskes what would you like to do on this issue?

@bleskes
Copy link
Contributor

bleskes commented Jul 31, 2018

@tomcallahan we discussed it in the core infra sync a while ago and agree that the actions should be applied one by one, modifying things as they go, based on the output of the previous command. If I recall correctly, the conversation went with validating correctness on every step. That said, is write index validation ended being done once in the end, so we might need to revisit it.

Bottom line - it's a valid issue and someone needs to pick it up. I expect more work here as the alias code needs some cleanup IMO. I believe that is also what made @mayya-sharipova fight an up hill battle with her PR.

@tomcallahan tomcallahan added help wanted adoptme and removed discuss labels Jul 31, 2018
@mayya-sharipova
Copy link
Contributor Author

@bleskes To confirm, you were saying that we need to take another approach for this. So, I am going to close my previous PR on this, and somebody else can work on it.

@bleskes
Copy link
Contributor

bleskes commented Aug 5, 2018

@mayya-sharipova I think your PR is an improvement but indeed, this should be picked up in a more structural way. I'm OK with you just closing it, if you're not going to spend more time in that area (and otherwise we need to finish that discussion we started)

@ddreonomy
Copy link

Does that mean that renaming an alias is not working properly?

https://www.elastic.co/guide/en/elasticsearch/reference/6.2/indices-aliases.html

POST /_aliases
{
    "actions" : [
        { "remove" : { "index" : "test1", "alias" : "alias1" } },
        { "add" : { "index" : "test2", "alias" : "alias1" } }
    ]
}

@mayya-sharipova
Copy link
Contributor Author

@ddreonomy The renaming of alias should work well. If you experience any problem, please create a separate issue.
This PR is about adding/removing alias for the same index.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Data Management/Indices APIs APIs to create and manage indices and templates help wanted adoptme
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants