opensearch-project/OpenSearch

[BUG] Resize request should throw 4xx as part of validation failure for write block

Open

#19,026 创建于 2025年8月11日

在 GitHub 查看
 (1 评论) (0 反应) (1 负责人)Java (1,505 fork)batch import
Cluster Managerbuggood first issue

仓库指标

Star
 (8,123 star)
PR 合并指标
 (平均合并 5天 9小时) (30 天内合并 266 个 PR)

描述

Describe the bug

Currently as part of the resize request validation while creating a target index using MetadataCreateIndexService, it throws IllegalStateException that gets translated to 5xx. Here it should instead throw IllegalArgumentException which will be translated to 4xx. 5xx is usually treated as server side failure/error whereas 4xx will be wrong user input which fits well in this case.

Ref: https://github.com/opensearch-project/OpenSearch/blame/1a5331727b8037b4bcaf3e7c2a46dfb467259d13/server/src/main/java/org/opensearch/cluster/metadata/MetadataCreateIndexService.java#L1655

Response:

HTTP/2 500 Internal Server Error
Date: Mon, 07 Jul 2025 15:48:17 GMT
Content-Type: application/json; charset=UTF-8
Content-Length: 315
Access-Control-Allow-Origin: *

{"error":{"root_cause":[{"type":"illegal_state_exception","reason":"index test-01 must block write operations to resize index. use \"index.blocks.write=true\""}],"type":"illegal_state_exception","reason":"index test-01 must block write operations to resize index. use \"index.blocks.write=true\""},"status":500}

Related component

No response

To Reproduce

  • Submit request to shrink an existing index (test-01) without write block on it.
curl localhost:9200/test-01/_shrink/test-shrink-01

Expected behavior

OpenSearch should throw 4xx error instead of 5xx

Additional Details

N/A

贡献者指南