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 index block api #58094

Merged
merged 26 commits into from
Jun 30, 2020
Merged

Add index block api #58094

merged 26 commits into from
Jun 30, 2020

Conversation

ywelsch
Copy link
Contributor

@ywelsch ywelsch commented Jun 15, 2020

Adds an API for putting an index block in place, which also ensures for write blocks that, once successfully returning to the user, all shards of the index are properly accounting for the block, for example that all in-flight writes to an index have been completed after adding the write block.

This API allows coordinating more complex workflows, where it is crucial that an index is no longer receiving writes after the API completes, useful for example when marking an index as read-only during an upgrade in order to reindex its documents.

Note to reviewers: I will fix the docs in a later revision once we're all good on naming etc.
Also, HLRC support will only come later.

@ywelsch ywelsch added v7.9.0 v8.0.0 :Data Management/Indices APIs APIs to create and manage indices and templates >enhancement labels Jun 17, 2020
@ywelsch ywelsch marked this pull request as ready for review June 17, 2020 08:26
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-features (:Core/Features/Indices APIs)

@elasticmachine elasticmachine added the Team:Data Management Meta label for data/management team label Jun 17, 2020
@dakrone dakrone self-requested a review June 17, 2020 14:25
Copy link
Member

@dakrone dakrone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this Yannick, I think this will be a neat API and it'll be nice to be able to use this from ILM. I left some comments for you. I have two additional thoughts:

  • I think we should change /{index}/_blocks/{block} to /{index}/_block/{block}. By and large the bulk of our APIs use singular verbs/nouns, and it reads better mentally (/foo/_blocks/read can be thought of as "foo blocks reads", but /foo/_blocks/read_only is awkward thought of as "foo blocks read onlys", it's nicer to think of /foo/_block/read_only as "add the read_only block to foo"). It's also useful because we only support a single block, not a comma-separated or wildcard of blocks to add to the index.
  • How do these blocks work for a searchable snapshot index? Should we add a test for that? (the write block is pretty obviously not needed, but a read block may still be desired)

@ywelsch
Copy link
Contributor Author

ywelsch commented Jun 24, 2020

@dakrone I've adapted /{index}/_blocks/{block} to /{index}/_block/{block} according to your suggestion. Regarding the interoperability with searchable snapshots: The API and verify action here is completely agnostic to the underlying engine being used, so will just work with frozen / searchable snapshots / whatever other flavor we have there. I will comment in-line on the other stuff.

@ywelsch
Copy link
Contributor Author

ywelsch commented Jun 24, 2020

@jrodewig can you help out with the docs here? (Feel free to directly push changes to this PR)

@ywelsch ywelsch requested a review from dakrone June 24, 2020 10:08
Copy link
Contributor

@jrodewig jrodewig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ywelsch I made some changes to fix the docs CI test. However, I left some other feedback that should be addressed.

docs/reference/index-modules/blocks.asciidoc Outdated Show resolved Hide resolved
docs/reference/index-modules/blocks.asciidoc Outdated Show resolved Hide resolved
docs/reference/index-modules/blocks.asciidoc Outdated Show resolved Hide resolved
docs/reference/index-modules/blocks.asciidoc Outdated Show resolved Hide resolved
docs/reference/index-modules/blocks.asciidoc Outdated Show resolved Hide resolved
docs/reference/index-modules/blocks.asciidoc Outdated Show resolved Hide resolved
Copy link
Contributor

@jrodewig jrodewig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:doh: Forgot you gave me permission to push the changes. I went ahead and added my suggestions. 😄

Copy link
Member

@dakrone dakrone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update Yannick, I made some more comments.

As an aside, it doesn't appear to me (though I am certainly not an expert in shard operation permits!) that this allows adding a read block and waiting for all query operations to finish before returning. Is that correct? Out of curiosity, how hard would that be to add? (It wouldn't have to be in this PR) It would be very useful for ILM operations if we had that ability


@Override
public XContentBuilder toXContent(final XContentBuilder builder, final Params params) throws IOException {
builder.startObject(index.getName());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't agree, I think if we go with consistency with our earlier APIs, then we would never eventually transition to the change. Since this is introducing a new API if we make the change now it's one less that we have to change in the future when we eventually have REST versioning.

We've discussed this a lot on the core/features team and always ended up with newly introduced APIs using the newer format, rather than matching the existing dynamically keyed format.

Comment on lines 7 to 10
index settings, or can be added using a dedicated API, which also ensures
that, once successfully returning to the user, all shards of the index are
properly accounting for the block, for example that all in-flight writes to
an index have been completed after adding the write block.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we call out that this only applies to write operations, not read operations?

@ywelsch
Copy link
Contributor Author

ywelsch commented Jun 29, 2020

As an aside, it doesn't appear to me (though I am certainly not an expert in shard operation permits!) that this allows adding a read block and waiting for all query operations to finish before returning. Is that correct?

You're absolutely right here. The PR was overpromising in this regard (I initially started with a dedicated API to just allow adding a write block, which eventually got turned into this more general one here). I've adapted the docs to point out that we only guarantee this for write operations.

Out of curiosity, how hard would that be to add? (It wouldn't have to be in this PR) It would be very useful for ILM operations if we had that ability

We could do something similar for reads as we do for writes, but there are a bigger number of cases / scenarios to consider and to handle accordingly. For example, how should his affect scrolls that have been opened before the block has been put in place (AFAICS we don't directly close the scroll context today). Similarly how should this handle long-running searches, or a fetch phase (where the query phase successfully executed)...

Copy link
Member

@dakrone dakrone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for iterating on it Yannick!

For example, how should his affect scrolls that have been opened before the block has been put in place (AFAICS we don't directly close the scroll context today). Similarly how should this handle long-running searches, or a fetch phase (where the query phase successfully executed)...

This is the exact scenario I was thinking about, in some places in ILM (like after a shrink) we do a swap-and-delete from the alias, but we have some unavoidable issues where the query may be in the middle of execution during the delete, we unfortunately don't have a way to wait until they are all done. Maybe in the future though?

@ywelsch
Copy link
Contributor Author

ywelsch commented Jun 29, 2020

in some places in ILM (like after a shrink) we do a swap-and-delete from the alias, but we have some unavoidable issues where the query may be in the middle of execution during the delete, we unfortunately don't have a way to wait until they are all done.

I'm wondering if that's a situation which should rather be covered by a more resilient _search API, where it would retry searching on the new shards (after alias been swapped), similar to what's discussed in #56236

@ywelsch ywelsch merged commit 5e345e1 into elastic:master Jun 30, 2020
@ywelsch
Copy link
Contributor Author

ywelsch commented Jun 30, 2020

Thanks @dakrone and @jrodewig

ywelsch added a commit to ywelsch/elasticsearch that referenced this pull request Jun 30, 2020
Adds an API for putting an index block in place, which also ensures for write blocks that, once successfully returning to
the user, all shards of the index are properly accounting for the block, for example that all in-flight writes to an index have
been completed after adding the write block.

This API allows coordinating more complex workflows, where it is crucial that an index is no longer receiving writes after
the API completes, useful for example when marking an index as read-only during an upgrade in order to reindex its
documents.
@ywelsch ywelsch mentioned this pull request Jun 30, 2020
DaveCTurner added a commit to DaveCTurner/elasticsearch that referenced this pull request Jun 30, 2020
The read-only-allow-delete block is not really under the user's control
since Elasticsearch adds/removes it automatically. This commit removes
support for it from the new API for adding blocks to indices that was
introduced in elastic#58094.
ywelsch added a commit that referenced this pull request Jun 30, 2020
DaveCTurner added a commit that referenced this pull request Jul 1, 2020
* Forbid read-only-allow-delete block in blocks API

The read-only-allow-delete block is not really under the user's control
since Elasticsearch adds/removes it automatically. This commit removes
support for it from the new API for adding blocks to indices that was
introduced in #58094.

* Missing xref

* Reword paragraph on read-only-allow-delete block
DaveCTurner added a commit that referenced this pull request Jul 1, 2020
The read-only-allow-delete block is not really under the user's control
since Elasticsearch adds/removes it automatically. This commit removes
support for it from the new API for adding blocks to indices that was
introduced in #58094.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Data Management/Indices APIs APIs to create and manage indices and templates >enhancement Team:Data Management Meta label for data/management team v7.9.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants