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

[BUG] Inconsistent behavior on POST _aliases when two opposing actions are operating on the same index/alias pair #14503

Open
theahura opened this issue Jun 21, 2024 · 7 comments
Labels
bug Something isn't working Indexing Indexing, Bulk Indexing and anything related to indexing Other

Comments

@theahura
Copy link

theahura commented Jun 21, 2024

Describe the bug

I basically ran into elastic/elasticsearch#27689 almost exactly.

# 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

Related component

Other

To Reproduce

See above.

Expected behavior

I expected the actions to resolve in order.

Additional Details

This is running on aws opensearch serverless.

@theahura theahura added bug Something isn't working untriaged labels Jun 21, 2024
@github-actions github-actions bot added the Other label Jun 21, 2024
@theahura
Copy link
Author

To be more explicit, I got logs from my own system. Here are the actions:

Making the following alias modifications: [
  {
    remove: { index: 'indexedinstance', alias: 'current-published-instance' }
  },
  {
    add: {
      index: 'indexedinstance',
      alias: 'current-published-instance',
      filter: undefined,
      is_write_index: true
    }
  }
]

and then when I run

 30   // Get the mappings.                                                           
 31   const mappings = await client.cat.aliases();                                   
 32   console.log(JSON.stringify(mappings, null, 2));  

I get

{                                                                                                                                                                                      
 "body": "",                                                                                                                                                                          
 "statusCode": 200,                         
 "headers": {                               
   "content-type": "text/plain; charset=UTF-8",                                           
   "content-length": "0",                   
   "x-envoy-upstream-service-time": "17",                                                 
   "date": "Sat, 22 Jun 2024 03:05:22 GMT",                                               
   "server": "aoss-amazon-m",                                                             
   "x-request-id": "865cd86d-77ce-9a30-a215-3fbbc77d49d2"                                 
 },                                         
 "meta": {                                  
   "context": null,                         
   "request": {                             
     "params": {                            
       "method": "GET",                     
       "path": "/_cat/aliases",             
       "body": null,                        
       "querystring": "",                   
       "headers": {                         
         "user-agent": "opensearch-js/2.3.1 (linux 5.15.0-1041-aws-x64; Node.js v17.9.1)"
       },                                                                                 
       "timeout": 30000                     
     },                                     
     "options": {},                         
     "id": 1                                
   },                                       
   "name": "opensearch-js",                 
...

@dblock
Copy link
Member

dblock commented Jun 25, 2024

Looks like a bug. @theahura Want to try and write a YAML REST test for it?
https://github.com/opensearch-project/OpenSearch/blob/main/TESTING.md#testing-the-rest-layer

@theahura
Copy link
Author

Maybe something like this?

---
setup:
  - do:
      indices.create:
        index: test_index
        body:
          settings:
            number_of_shards: 1
            number_of_replicas: 0

  - do:
      indices.update_aliases:
        body:
          actions:
            - add:
                index: test_index
                alias: alias1

---
- do:
    indices.update_aliases:
      body:
        actions:
          - remove:
              index: test_index
              alias: alias1
          - add:
              index: test_index
              alias: alias1

- do:
    indices.get_alias:
      name: alias1
  - match: { test_index.aliases.alias1: {} }

---
teardown:
  - do:
      indices.delete:
        index: test_index

Note that I didn't get around to actually testing this though, also not really sure if the syntax is correct

@peternied peternied added Indexing Indexing, Bulk Indexing and anything related to indexing and removed untriaged labels Jun 26, 2024
@peternied
Copy link
Member

[Triage - attendees 1 2 3]
@theahura Thanks for writing out that test case, could you make a pull request to add the test - maybe build off that to fix the issue?

@theahura
Copy link
Author

theahura commented Jun 28, 2024

How do I add the test? I'm not sure it's actually valid fwiw, and I don't have a ton of spare time so it may take me a bit before I am able to add the test in

@peternied
Copy link
Member

I found a PR [1] that added a feature and tests - should give you some pointers on where the code goes, good luck

@vikasvb90
Copy link
Contributor

Thanks @theahura for raising this! Can you please confirm if this has been fixed or this is still pending to be fixed? Also, if it still has a pending fix then would you be interested in raising a PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Indexing Indexing, Bulk Indexing and anything related to indexing Other
Projects
None yet
Development

No branches or pull requests

4 participants