Make BulkItemRequest immutable#20831
Conversation
PR Reviewer Guide 🔍(Review updated until commit d2a6232)Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Latest suggestions up to d2a6232 Explore these optional code suggestions:
Previous suggestionsSuggestions up to commit 93814fc
Suggestions up to commit 1201d59
Suggestions up to commit 0450fb9
|
|
❌ Gradle check result for 0450fb9: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
0450fb9 to
1201d59
Compare
|
Persistent review updated to latest commit 1201d59 |
|
❌ Gradle check result for 1201d59: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
|
Persistent review updated to latest commit 93814fc |
server/src/main/java/org/opensearch/action/bulk/BulkItemRequest.java
Outdated
Show resolved
Hide resolved
|
❌ Gradle check result for 93814fc: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
|
Persistent review updated to latest commit d2a6232 |
|
❌ Gradle check result for d2a6232: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
d2a6232 to
8bde4b5
Compare
|
Failed to generate code suggestions for PR |
|
❌ Gradle check result for 8bde4b5: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
8bde4b5 to
ea74e1a
Compare
|
Failed to generate code suggestions for PR |
I was talking with @itschrispeck about some JIT optimization issues in BulkItemRequest's serialization. While looking at the code, the `volatile` keyword on the `primaryResponse` field made me cringe. Why is a `BulkItemRequest` mutable at all? It turns out that we modify the existing `BulkItemRequest` instances on the primary shard. These modified requests are send to the replicas. This change makes `BulkItemRequest` immutable. The primary execution context collects all of the primary responses, then produces a new `BulkShardRequest` that gets forwarded to replicas. Signed-off-by: Michael Froh <msfroh@apache.org>
These tests relied on the assumption that the BulkShardRequest would be mutated on the primary. In particular, there were some ridiculous tests that were verifying that the output was unchanged from the input, when the output was the same object as the input, which had been changed in place. Signed-off-by: Michael Froh <msfroh@apache.org>
Follow @andrross's suggestion of converting BulkItemRequest to a record, since it's immutable now. Also, we were seeing test failures because the cloned BulkShardRequest (that is propagated to replicas) did not copy the primary request's parent TaskId. Along with that, I made sure it copied all other properties from the primary shard request. Signed-off-by: Michael Froh <msfroh@apache.org>
ea74e1a to
3ca0f4a
Compare
|
Failed to generate code suggestions for PR |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #20831 +/- ##
============================================
+ Coverage 73.12% 73.15% +0.03%
- Complexity 72496 72522 +26
============================================
Files 5848 5848
Lines 331952 331938 -14
Branches 47948 47944 -4
============================================
+ Hits 242728 242834 +106
+ Misses 69710 69613 -97
+ Partials 19514 19491 -23 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
The comments from the PR bot (#20831 (comment)) are not bad.
|
Description
I was talking with @itschrispeck about some JIT optimization issues in BulkItemRequest's serialization. While looking at the code, the
volatilekeyword on theprimaryResponsefield made me cringe. Why is aBulkItemRequestmutable at all?It turns out that we modify the existing
BulkItemRequestinstances on the primary shard. These modified requests (as part of aBulkShardRequest) are sent to the replicas. That is, thePrimaryExecutionContextreturns the modified-in-placeBulkShardRequestthat it was created with, which is sent to the replicas.This change makes
BulkItemRequestimmutable. ThePrimaryExecutionContextcollects all of the primary responses, then produces a newBulkShardRequestthat combines the originalBulkItemRequests with the responses, which gets forwarded to replicas.Related Issues
N/A
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.