-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Fields API Caching Regression (#90017)
This fixes both a bug and a performance regression. After adding the text mappings family to the scripting fields API, field-style access uses source to generate values while doc-style access uses doc values. This means that a script accessing the same text field using both apis may see incorrect results. There is also a performance regression where previously we checked a single cache to try to ensure that doc-style access only used doc values, but this was done on a per-document basis. This change adds separate caches for field-style access and doc-style access in LeafDocLookup where all the work to cache field data is done per-segment, and the parallel caches allow no additional checks to be made when accessing the values per-document. The caches still share field data when possible for non-text based fields, so we don't double load.
- Loading branch information
Showing
4 changed files
with
607 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pr: 90017 | ||
summary: Fix Fields API Caching Regression | ||
area: Infra/Scripting | ||
type: regression | ||
issues: [] |
191 changes: 191 additions & 0 deletions
191
...ess/src/yamlRestTest/resources/rest-api-spec/test/painless/45_script_doc_values_cache.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
setup: | ||
- do: | ||
indices.create: | ||
index: test0 | ||
body: | ||
settings: | ||
number_of_shards: 1 | ||
mappings: | ||
properties: | ||
text: | ||
type: text | ||
fielddata: true | ||
long: | ||
type: long | ||
|
||
- do: | ||
index: | ||
index: test0 | ||
id: "1" | ||
body: | ||
text: "Lots of text." | ||
long: 1 | ||
|
||
- do: | ||
indices.create: | ||
index: test1 | ||
body: | ||
settings: | ||
number_of_shards: 1 | ||
mappings: | ||
properties: | ||
text: | ||
type: text | ||
fielddata: true | ||
long: | ||
type: long | ||
|
||
- do: | ||
index: | ||
index: test1 | ||
id: "1" | ||
body: | ||
text: "Lots of text." | ||
long: 1 | ||
|
||
- do: | ||
indices.refresh: {} | ||
|
||
--- | ||
"test_leaf_cache_text_field_first": | ||
- do: | ||
search: | ||
rest_total_hits_as_int: true | ||
index: test0 | ||
body: | ||
script_fields: | ||
field_0: | ||
script: | ||
source: "/* avoid stash */ $('text', '') + ' ' + doc['text'].value" | ||
- match: { hits.hits.0.fields.field_0.0: 'Lots of text. lots' } | ||
|
||
- do: | ||
search: | ||
rest_total_hits_as_int: true | ||
index: test0 | ||
body: | ||
script_fields: | ||
field_0: | ||
script: | ||
source: "/* avoid stash */ $('text', '') + ' ' + doc['text'].value" | ||
field_1: | ||
script: | ||
source: "doc['text'].value + ' ' + $('text', '')" | ||
field_2: | ||
script: | ||
source: "/* avoid stash */ $('text', '') + ' ' + doc['text'].value" | ||
field_3: | ||
script: | ||
source: "doc['text'].value + ' ' + $('text', '')" | ||
- match: { hits.hits.0.fields.field_0.0: 'Lots of text. lots' } | ||
- match: { hits.hits.0.fields.field_1.0: 'lots Lots of text.' } | ||
- match: { hits.hits.0.fields.field_2.0: 'Lots of text. lots' } | ||
- match: { hits.hits.0.fields.field_3.0: 'lots Lots of text.' } | ||
|
||
--- | ||
"test_leaf_cache_text_doc_first": | ||
- do: | ||
search: | ||
rest_total_hits_as_int: true | ||
index: test1 | ||
body: | ||
script_fields: | ||
field_0: | ||
script: | ||
source: "doc['text'].value + ' ' + $('text', '')" | ||
- match: { hits.hits.0.fields.field_0.0: 'lots Lots of text.' } | ||
|
||
- do: | ||
search: | ||
rest_total_hits_as_int: true | ||
index: test1 | ||
body: | ||
script_fields: | ||
field_0: | ||
script: | ||
source: "doc['text'].value + ' ' + $('text', '')" | ||
field_1: | ||
script: | ||
source: "/* avoid stash */ $('text', '') + ' ' + doc['text'].value" | ||
field_2: | ||
script: | ||
source: "doc['text'].value + ' ' + $('text', '')" | ||
field_3: | ||
script: | ||
source: "/* avoid stash */ $('text', '') + ' ' + doc['text'].value" | ||
- match: { hits.hits.0.fields.field_0.0: 'lots Lots of text.' } | ||
- match: { hits.hits.0.fields.field_1.0: 'Lots of text. lots' } | ||
- match: { hits.hits.0.fields.field_2.0: 'lots Lots of text.' } | ||
- match: { hits.hits.0.fields.field_3.0: 'Lots of text. lots' } | ||
|
||
--- | ||
"test_leaf_cache_long_field_first": | ||
- do: | ||
search: | ||
rest_total_hits_as_int: true | ||
index: test0 | ||
body: | ||
script_fields: | ||
field_0: | ||
script: | ||
source: "/* avoid stash */ $('long', 0) + ' ' + doc['long'].value" | ||
- match: { hits.hits.0.fields.field_0.0: '1 1' } | ||
|
||
- do: | ||
search: | ||
rest_total_hits_as_int: true | ||
index: test0 | ||
body: | ||
script_fields: | ||
field_0: | ||
script: | ||
source: "/* avoid stash */ $('long', 0) + ' ' + doc['long'].value" | ||
field_1: | ||
script: | ||
source: "doc['long'].value + ' ' + $('long', 0)" | ||
field_2: | ||
script: | ||
source: "/* avoid stash */ $('long', 0) + ' ' + doc['long'].value" | ||
field_3: | ||
script: | ||
source: "doc['long'].value + ' ' + $('long', 0)" | ||
- match: { hits.hits.0.fields.field_0.0: '1 1' } | ||
- match: { hits.hits.0.fields.field_1.0: '1 1' } | ||
- match: { hits.hits.0.fields.field_2.0: '1 1' } | ||
- match: { hits.hits.0.fields.field_3.0: '1 1' } | ||
|
||
--- | ||
"test_leaf_cache_long_doc_first": | ||
- do: | ||
search: | ||
rest_total_hits_as_int: true | ||
index: test1 | ||
body: | ||
script_fields: | ||
field_0: | ||
script: | ||
source: "doc['long'].value + ' ' + $('long', 0)" | ||
- match: { hits.hits.0.fields.field_0.0: '1 1' } | ||
|
||
- do: | ||
search: | ||
rest_total_hits_as_int: true | ||
index: test1 | ||
body: | ||
script_fields: | ||
field_0: | ||
script: | ||
source: "doc['long'].value + ' ' + $('long', 0)" | ||
field_1: | ||
script: | ||
source: "/* avoid stash */ $('long', 0) + ' ' + doc['long'].value" | ||
field_2: | ||
script: | ||
source: "doc['long'].value + ' ' + $('long', 0)" | ||
field_3: | ||
script: | ||
source: "/* avoid stash */ $('long', 0) + ' ' + doc['long'].value" | ||
- match: { hits.hits.0.fields.field_0.0: '1 1' } | ||
- match: { hits.hits.0.fields.field_1.0: '1 1' } | ||
- match: { hits.hits.0.fields.field_2.0: '1 1' } | ||
- match: { hits.hits.0.fields.field_3.0: '1 1' } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.