Skip to content

Load FieldInfos from store if not yet initialised through a refresh on IndexShard #125650

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

Merged
merged 6 commits into from
Mar 26, 2025

Conversation

original-brownbear
Copy link
Contributor

Load field caps from store if they haven't been initialised through a refresh yet.
Keep the plain reads to not mess with performance characteristics too much on the good path but protect against confusing races when loading field infos now (that probably should have been ordered stores in the first place but this was safe due to other locks/volatiles on the refresh path).

Closes #125483

If we don't yet have a cached value ready to go for the field infos,
lets load it from the directory.

Fixes elastic#125383
@original-brownbear original-brownbear added >bug auto-backport Automatically create backport pull requests when merged :Search Foundations/Search Catch all for Search Foundations v9.0.0 v8.19.0 v9.1.0 labels Mar 26, 2025
@elasticsearchmachine elasticsearchmachine added the Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch label Mar 26, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-search-foundations (Team:Search Foundations)

@elasticsearchmachine
Copy link
Collaborator

Hi @original-brownbear, I've created a changelog YAML for you.

Copy link
Member

@piergm piergm 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 @original-brownbear for working on this :D

try (Engine.Searcher hasValueSearcher = getEngine().acquireSearcher("field_has_value")) {
return FieldInfos.getMergedFieldInfos(hasValueSearcher.getIndexReader());
} catch (AlreadyClosedException ignore) {
// engine is closed - no update to3 FieldInfos is fine
Copy link
Member

Choose a reason for hiding this comment

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

typo?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

lol right and in the process of fixing grammar/typo no less 🤣 thanks!

Copy link
Contributor

@andreidan andreidan left a comment

Choose a reason for hiding this comment

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

LGTM too :) Thanks for fixing this Armin


static {
try {
FIELD_INFOS = MethodHandles.lookup().findVarHandle(IndexShard.class, "fieldInfos", FieldInfos.class);
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah this is a bit I don't like about VarHandle, and I'd normally prefer an Atomic... for the CAS operation for readability.

However, the tradeoff here is pretty sweet as we avoid creating (a potential alternative) one Atomic... instance for every IndexShard in order to wrap the fieldInfos giving us a sweet memory saving.

Nicely done ! :)

@original-brownbear
Copy link
Contributor Author

Thanks you two!

@original-brownbear original-brownbear merged commit 632b9e7 into elastic:main Mar 26, 2025
17 checks passed
@original-brownbear original-brownbear deleted the 125483 branch March 26, 2025 17:54
original-brownbear added a commit to original-brownbear/elasticsearch that referenced this pull request Mar 26, 2025
…n IndexShard (elastic#125650)

Load field caps from store if they haven't been initialised through a refresh yet.
Keep the plain reads to not mess with performance characteristics too much on the good path but protect against confusing races when loading field infos now (that probably should have been ordered stores in the first place but this was safe due to other locks/volatiles on the refresh path).

Closes elastic#125483
original-brownbear added a commit to original-brownbear/elasticsearch that referenced this pull request Mar 26, 2025
…n IndexShard (elastic#125650)

Load field caps from store if they haven't been initialised through a refresh yet.
Keep the plain reads to not mess with performance characteristics too much on the good path but protect against confusing races when loading field infos now (that probably should have been ordered stores in the first place but this was safe due to other locks/volatiles on the refresh path).

Closes elastic#125483
@elasticsearchmachine
Copy link
Collaborator

💚 Backport successful

Status Branch Result
9.0
8.x

elasticsearchmachine pushed a commit that referenced this pull request Mar 26, 2025
…n IndexShard (#125650) (#125703)

Load field caps from store if they haven't been initialised through a refresh yet.
Keep the plain reads to not mess with performance characteristics too much on the good path but protect against confusing races when loading field infos now (that probably should have been ordered stores in the first place but this was safe due to other locks/volatiles on the refresh path).

Closes #125483
elasticsearchmachine pushed a commit that referenced this pull request Mar 26, 2025
…n IndexShard (#125650) (#125704)

Load field caps from store if they haven't been initialised through a refresh yet.
Keep the plain reads to not mess with performance characteristics too much on the good path but protect against confusing races when loading field infos now (that probably should have been ordered stores in the first place but this was safe due to other locks/volatiles on the refresh path).

Closes #125483
@javanna
Copy link
Member

javanna commented Mar 27, 2025

Thanks for fixing @original-brownbear I believe it makes sense to backport this to 8.18 as well.

original-brownbear added a commit to original-brownbear/elasticsearch that referenced this pull request Mar 27, 2025
…n IndexShard (elastic#125650)

Load field caps from store if they haven't been initialised through a refresh yet.
Keep the plain reads to not mess with performance characteristics too much on the good path but protect against confusing races when loading field infos now (that probably should have been ordered stores in the first place but this was safe due to other locks/volatiles on the refresh path).

Closes elastic#125483
@original-brownbear
Copy link
Contributor Author

incoming in #125762 :)

original-brownbear added a commit that referenced this pull request Mar 27, 2025
…n IndexShard (#125650) (#125762)

Load field caps from store if they haven't been initialised through a refresh yet.
Keep the plain reads to not mess with performance characteristics too much on the good path but protect against confusing races when loading field infos now (that probably should have been ordered stores in the first place but this was safe due to other locks/volatiles on the refresh path).

Closes #125483

// check that field_caps empty field filtering works as well
FieldCapabilitiesResponse response = client().prepareFieldCaps(mountedIndices).setFields("*").setincludeEmptyFields(false).get();
assertNotNull(response.getField("keyword"));
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if it makes sense to add the same test to the N-2 indices related tests for indices that are imported as verified read-only. We know the fix addresses the same issue for them too, but it'd be safer to have a specific test for them? These tests are under qa/lucene-index-compatibility .

Copy link
Contributor Author

Choose a reason for hiding this comment

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

++ definitely. Let me try something, maybe I can get the full field caps suite running for searchable snapshots and there somehow, would be really nice to have coverage across all the implementations that play tricks on the engine :)

omricohenn pushed a commit to omricohenn/elasticsearch that referenced this pull request Mar 28, 2025
…n IndexShard (elastic#125650)

Load field caps from store if they haven't been initialised through a refresh yet.
Keep the plain reads to not mess with performance characteristics too much on the good path but protect against confusing races when loading field infos now (that probably should have been ordered stores in the first place but this was safe due to other locks/volatiles on the refresh path).

Closes elastic#125483
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Automatically create backport pull requests when merged >bug :Search Foundations/Search Catch all for Search Foundations Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch v8.18.1 v8.19.0 v9.0.0 v9.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Field_caps] field_caps request don't return fields for indices with readonly_state when include_empty_fields=false
5 participants