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

Add more index blocks check for resize APIs (#4845) #6774

Merged
merged 6 commits into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Added equals/hashcode for named DocValueFormat.DateTime inner class ([#6357](https://github.com/opensearch-project/OpenSearch/pull/6357))
- Fixed bug for searchable snapshot to take 'base_path' of blob into account ([#6558](https://github.com/opensearch-project/OpenSearch/pull/6558))
- Fix fuzziness validation ([#5805](https://github.com/opensearch-project/OpenSearch/pull/5805))
- Add more index blocks check for resize APIs ([#6774](https://github.com/opensearch-project/OpenSearch/pull/6774))

### Security

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,99 @@ setup:
settings:
index.number_of_replicas: 0
index.number_of_shards: 6

---
"Returns error if target index's metadata write is blocked":

- skip:
version: " - 2.9.99"
reason: "only available in 3.0+"

# block source index's write operations
- do:
indices.put_settings:
index: source
body:
index.blocks.write: true
index.number_of_replicas: 0

- do:
cluster.health:
wait_for_status: green
index: source

# set `index.blocks.read_only` to `true` for target index
- do:
catch: /action_request_validation_exception/
indices.clone:
index: "source"
target: "new_cloned_index"
wait_for_active_shards: 1
cluster_manager_timeout: 10s
body:
settings:
index.number_of_replicas: 0
index.blocks.read_only: true

# set `index.blocks.metadata` to `true` for target index
- do:
catch: /action_request_validation_exception/
indices.clone:
index: "source"
target: "new_cloned_index"
wait_for_active_shards: 1
cluster_manager_timeout: 10s
body:
settings:
index.number_of_replicas: 0
index.blocks.metadata: true

# set source index's setting `index.blocks.read_only` to `true`
- do:
indices.put_settings:
index: source
body:
index.blocks.read_only: true

- do:
catch: /illegal_argument_exception/
indices.clone:
index: "source"
target: "new_cloned_index"
wait_for_active_shards: 1
cluster_manager_timeout: 10s
body:
settings:
index.number_of_replicas: 0

# overwrite the source index's setting, everything is fine
- do:
indices.clone:
index: "source"
target: "new_cloned_index"
wait_for_active_shards: 1
cluster_manager_timeout: 10s
body:
settings:
index.number_of_replicas: 0
index.blocks.read_only: null

- do:
cluster.health:
wait_for_status: green

- do:
get:
index: new_cloned_index
id: "1"

- match: { _index: new_cloned_index }
- match: { _id: "1" }
- match: { _source: { foo: "hello world" } }

# clear the source index's read_only blocks because it will block deleting index
- do:
indices.put_settings:
index: source
body:
index.blocks.read_only: null
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
---
"Shrink index via API":
setup:
# creates an index with one document solely allocated on a particular data node
# and shrinks it into a new index with a single shard
# we don't do the relocation to a single node after the index is created
# here since in a mixed version cluster we can't identify
# which node is the one with the highest version and that is the only one that can safely
# be used to shrink the index.

- skip:
features: allowed_warnings

- do:
nodes.info:
node_id: data:true
Expand All @@ -32,14 +28,10 @@
id: "1"
body: { "foo": "hello world" }

- do:
get:
index: source
id: "1"

- match: { _index: source }
- match: { _id: "1" }
- match: { _source: { foo: "hello world" } }
---
"Shrink index via API":
- skip:
features: allowed_warnings

# make it read-only
- do:
Expand Down Expand Up @@ -79,3 +71,103 @@
- match: { _index: target }
- match: { _id: "1" }
- match: { _source: { foo: "hello world" } }

---
"Returns error if target index's metadata write is blocked":

- skip:
version: " - 2.9.99"
reason: "only available in 3.0+"

# block source index's write operations
- do:
indices.put_settings:
index: source
body:
index.blocks.write: true
index.number_of_replicas: 0

- do:
cluster.health:
wait_for_status: green
index: source

# set `index.blocks.read_only` to `true` for target index
- do:
catch: /action_request_validation_exception/
indices.shrink:
index: "source"
target: "new_shrunken_index"
wait_for_active_shards: 1
cluster_manager_timeout: 10s
body:
settings:
index.number_of_replicas: 0
index.number_of_shards: 1
index.blocks.read_only: true

# set `index.blocks.metadata` to `true` for target index
- do:
catch: /action_request_validation_exception/
indices.shrink:
index: "source"
target: "new_shrunken_index"
wait_for_active_shards: 1
cluster_manager_timeout: 10s
body:
settings:
index.number_of_replicas: 0
index.number_of_shards: 1
index.blocks.metadata: true

# set source index's setting `index.blocks.read_only` to `true`
- do:
indices.put_settings:
index: source
body:
index.blocks.read_only: true

- do:
catch: /illegal_argument_exception/
indices.shrink:
index: "source"
target: "new_shrunken_index"
wait_for_active_shards: 1
cluster_manager_timeout: 10s
body:
settings:
index.number_of_replicas: 0
index.number_of_shards: 1

# overwrite the source index's setting, everything is fine
- do:
indices.shrink:
index: "source"
target: "new_shrunken_index"
wait_for_active_shards: 1
cluster_manager_timeout: 10s
body:
settings:
index.number_of_replicas: 0
index.number_of_shards: 1
index.blocks.read_only: null

- do:
cluster.health:
wait_for_status: green

- do:
get:
index: new_shrunken_index
id: "1"

- match: { _index: new_shrunken_index }
- match: { _id: "1" }
- match: { _source: { foo: "hello world" } }

# clear the source index's read_only blocks because it will block deleting index
- do:
indices.put_settings:
index: source
body:
index.blocks.read_only: null
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,103 @@ setup:
settings:
index.number_of_replicas: 0
index.number_of_shards: 6

---
"Returns error if target index's metadata write is blocked":

- skip:
version: " - 2.9.99"
reason: "only available in 3.0+"

# block source index's write operations
- do:
indices.put_settings:
index: source
body:
index.blocks.write: true
index.number_of_replicas: 0

- do:
cluster.health:
wait_for_status: green
index: source

# set `index.blocks.read_only` to `true` for target index
- do:
catch: /action_request_validation_exception/
indices.split:
index: "source"
target: "new_split_index"
wait_for_active_shards: 1
cluster_manager_timeout: 10s
body:
settings:
index.number_of_replicas: 0
index.number_of_shards: 4
index.blocks.read_only: true

# set `index.blocks.metadata` to `true` for target index
- do:
catch: /action_request_validation_exception/
indices.split:
index: "source"
target: "new_split_index"
wait_for_active_shards: 1
cluster_manager_timeout: 10s
body:
settings:
index.number_of_replicas: 0
index.number_of_shards: 4
index.blocks.metadata: true

# set source index's setting `index.blocks.read_only` to `true`
- do:
indices.put_settings:
index: source
body:
index.blocks.read_only: true

- do:
catch: /illegal_argument_exception/
indices.split:
index: "source"
target: "new_split_index"
wait_for_active_shards: 1
cluster_manager_timeout: 10s
body:
settings:
index.number_of_replicas: 0
index.number_of_shards: 4

# overwrite the source index's setting, everything is fine
- do:
indices.split:
index: "source"
target: "new_split_index"
wait_for_active_shards: 1
cluster_manager_timeout: 10s
body:
settings:
index.number_of_replicas: 0
index.number_of_shards: 4
index.blocks.read_only: null

- do:
cluster.health:
wait_for_status: green

- do:
get:
index: new_split_index
id: "1"

- match: { _index: new_split_index }
- match: { _id: "1" }
- match: { _source: { foo: "hello world" } }

# clear the source index's read_only blocks because it will block deleting index
- do:
indices.put_settings:
index: source
body:
index.blocks.read_only: null
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,29 @@ public ActionRequestValidationException validate() {
if (maxShardSize != null && maxShardSize.getBytes() <= 0) {
validationException = addValidationError("max_shard_size must be greater than 0", validationException);
}
// Check target index's settings, if `index.blocks.read_only` is `true`, the target index's metadata writes will be disabled
gaobinlong marked this conversation as resolved.
Show resolved Hide resolved
// and then cause the new shards to be unassigned.
if (IndexMetadata.INDEX_READ_ONLY_SETTING.get(targetIndexRequest.settings()) == true) {
validationException = addValidationError(
"target index ["
+ targetIndexRequest.index()
+ "] will be blocked by [index.blocks.read_only=true], this will disable metadata writes and cause the shards to be unassigned,"
+ " please set \"index.blocks.read_only=false\" or \"index.blocks.read_only=null\"",
validationException
);
}

// Check target index's settings, if `index.blocks.metadata` is `true`, the target index's metadata writes will be disabled
// and then cause the new shards to be unassigned.
if (IndexMetadata.INDEX_BLOCKS_METADATA_SETTING.get(targetIndexRequest.settings()) == true) {
validationException = addValidationError(
"target index ["
+ targetIndexRequest.index()
+ "] will be blocked by [index.blocks.metadata=true], this will disable metadata writes and cause the shards to be unassigned,"
+ " please set \"index.blocks.metadata=false\" or \"index.blocks.metadata=null\"",
validationException
);
}
assert copySettings == null || copySettings;
return validationException;
}
Expand Down
Loading