Commit 8c39fff
authored
* Fix NPE caused by race condition in async search when minimise round trips is true
Previously, the `notifyListShards()` initialised and updated the
required pre-requisites (`searchResponse` being amongst them) when a
search op began. This function takes in arguments that contain
shard-specific details amongst others. Because this information is not
immediately available when the search begins, it is not immediately
called. In some specific cases, there can be a race condition that can
cause the pre-requisities (such as `searchResponse`) to be accessed
before they're initialised, causing an NPE.
This fix addresses the race condition by splitting the initialisation
and subsequent updation amongst 2 different methods. This way, the
pre-requisities are always initialised and do not lead to an NPE.
* Try: call `notifyListShards()` after `notifySearchStart()` when minimize round trips is true
* Add removed code comment
* Pass `Clusters` to `SearchTask` rather than using progress listener to
signify search start.
To prevent polluting the progress listener with unnecessary search
specific details, we now pass the `Clusters` object to `SearchTask` when
a search op begins. This lets `AsyncSearchTask` access it and use it to
initialise `MutableSearchResponse` appropriately.
* Use appropriate `clusters` object rather than re-building it
* Do not double set `mutableSearchResponse`
* Move mutable entities such as shard counts out of `MutableSearchResponse`
* Address PR review: revert moving out mutable entities from
`MutableSearchResponse`
* Update docs/changelog/117504.yaml
* Get rid of `SetOnce` for `searchResponse`
* Drop redundant check around shards count
* Add a test that calls `onListShards()` at last and clarify `updateShardsAndClusters()`'s comment
* Fix test: ref count
* Address review comment: rewrite comment and test
1 parent 1bd85f3 commit 8c39fff
File tree
4 files changed
+87
-38
lines changed- docs/changelog
- x-pack/plugin/async-search/src
- main/java/org/elasticsearch/xpack/search
- test/java/org/elasticsearch/xpack/search
4 files changed
+87
-38
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
Lines changed: 18 additions & 25 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | 10 | | |
12 | 11 | | |
13 | 12 | | |
| |||
73 | 72 | | |
74 | 73 | | |
75 | 74 | | |
76 | | - | |
| 75 | + | |
77 | 76 | | |
78 | 77 | | |
79 | 78 | | |
| |||
112 | 111 | | |
113 | 112 | | |
114 | 113 | | |
| 114 | + | |
115 | 115 | | |
116 | 116 | | |
117 | 117 | | |
| |||
340 | 340 | | |
341 | 341 | | |
342 | 342 | | |
343 | | - | |
| 343 | + | |
344 | 344 | | |
345 | 345 | | |
346 | 346 | | |
| |||
370 | 370 | | |
371 | 371 | | |
372 | 372 | | |
373 | | - | |
| 373 | + | |
374 | 374 | | |
375 | 375 | | |
376 | 376 | | |
| |||
381 | 381 | | |
382 | 382 | | |
383 | 383 | | |
384 | | - | |
| 384 | + | |
385 | 385 | | |
386 | 386 | | |
387 | 387 | | |
| |||
420 | 420 | | |
421 | 421 | | |
422 | 422 | | |
423 | | - | |
424 | | - | |
425 | | - | |
426 | | - | |
427 | | - | |
428 | | - | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
429 | 428 | | |
430 | 429 | | |
431 | 430 | | |
| |||
467 | 466 | | |
468 | 467 | | |
469 | 468 | | |
470 | | - | |
471 | | - | |
472 | | - | |
| 469 | + | |
473 | 470 | | |
474 | 471 | | |
475 | 472 | | |
| |||
496 | 493 | | |
497 | 494 | | |
498 | 495 | | |
499 | | - | |
| 496 | + | |
500 | 497 | | |
501 | 498 | | |
502 | 499 | | |
| |||
510 | 507 | | |
511 | 508 | | |
512 | 509 | | |
513 | | - | |
| 510 | + | |
514 | 511 | | |
515 | 512 | | |
516 | 513 | | |
| |||
523 | 520 | | |
524 | 521 | | |
525 | 522 | | |
526 | | - | |
| 523 | + | |
527 | 524 | | |
528 | 525 | | |
529 | 526 | | |
530 | 527 | | |
531 | | - | |
| 528 | + | |
532 | 529 | | |
533 | 530 | | |
534 | 531 | | |
535 | 532 | | |
536 | 533 | | |
537 | | - | |
538 | | - | |
539 | | - | |
540 | | - | |
541 | | - | |
542 | | - | |
543 | | - | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
544 | 537 | | |
545 | 538 | | |
546 | 539 | | |
| |||
x-pack/plugin/async-search/src/main/java/org/elasticsearch/xpack/search/MutableSearchResponse.java
Lines changed: 21 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| |||
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | 85 | | |
89 | 86 | | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
| 87 | + | |
96 | 88 | | |
97 | 89 | | |
98 | 90 | | |
99 | 91 | | |
100 | 92 | | |
101 | 93 | | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
102 | 110 | | |
103 | 111 | | |
104 | 112 | | |
| |||
Lines changed: 42 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
| |||
424 | 425 | | |
425 | 426 | | |
426 | 427 | | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
427 | 469 | | |
428 | 470 | | |
429 | 471 | | |
| |||
0 commit comments