opensearch-project / OpenSearch

🔎 Open source distributed and RESTful search engine.
https://opensearch.org/docs/latest/opensearch/index/
Apache License 2.0
9.61k stars 1.76k forks source link

[BUG] Set `index.number_of_replicas` to null through `index/_settings` API doesn't honor cluster setting #14810

Open chishui opened 2 months ago

chishui commented 2 months ago

Describe the bug

I tried to set index.number_of_replicas to null so that it will pick up default replica number configured for cluster.

PUT index/_settings
{
  "index": {
    "number_of_replicas": null
  }
}

It always sets index.number_of_replicas to 1. However, I configured cluster.default_number_of_replicas to 3, and when I create the index and not specify index.number_of_replicas, it will use 3 as default replica number.

Related component

Indexing

To Reproduce

  1. configure cluster replica number
    PUT _cluster/settings
    {
    "persistent" : {
    "cluster.default_number_of_replicas": 3
    }
    }
  2. Create index
    PUT index
    {
    "settings": {
     "index": {
       "refresh_interval": "30s",
       "default_pipeline": "pipeline"
      },
      "number_of_shards": 1
    }
    }
  3. Check index settings
    
    GET index/_settings

it returns: { ... "number_of_replicas": 3 }

4. Update settings

PUT index/_settings { "index": { "number_of_replicas": null } }

5. Check settings again, `number_of_replicas` becomes 1

GET index/_settings

it returns: { ... "number_of_replicas": 1 }



### Expected behavior

The default value of `index.number_of_replicas` should honor value of cluster setting `cluster.default_number_of_replicas`

### Additional Details

**Plugins**
Please list all plugins currently enabled.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Host/Environment (please complete the following information):**
 - OS: all
 - Version 2.15

**Additional context**
Add any other context about the problem here.
mgodwan commented 2 months ago

Duplicate of https://github.com/opensearch-project/OpenSearch/issues/14783

chishui commented 2 months ago

@mgodwan this bug is different from #14783. #14783 is about create index API with replica parameter set to null and caused NPE, this is about update setting API with null and it doesn't honor the cluster replica configuration

chishui commented 2 months ago

Fixed in #14948

sandeshkr419 commented 1 month ago

@chishui Thanks for reporting and raising a fix for this.

I have my concern on what should be the number of replicas when null is supplied. Should null translate to default count of 3 or it should translate to no replica at all, that is 0.

I suggest that null should translate to 0 - implying that the user does not actually wants to set any replicas. User not supplying anything should only translate to default replica count.

What are your thoughts @mgodwan?

chishui commented 1 month ago

@sandeshkr419 thanks for the comment. If cluster setting is not configured, then 1 is the default replica number. The default number of 1 has been there and acknowledged by users for really long time. Setting it to 0 means user has no backup for their data and can potentially lose data if they don't explicitly configure the replica number.