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 support for deep copying SearchRequest #12295

Merged

Conversation

ansjcy
Copy link
Member

@ansjcy ansjcy commented Feb 12, 2024

Description

Add support for deep copying a SearchRequest with roundtriping the request to a stream.

Related Issues

Resolves #869

Check List

  • New functionality includes testing.
    • All tests pass
  • New functionality has been documented.
    • New functionality has javadoc added
  • Failing checks are inspected and point to the corresponding known issue(s) (See: Troubleshooting Failing Builds)
  • Commits are signed per the DCO using --signoff
  • Commit changes are listed out in CHANGELOG.md file (See: Changelog)
  • Public documentation issue/PR created

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.

Copy link

codecov bot commented Feb 13, 2024

Codecov Report

Attention: Patch coverage is 55.55556% with 4 lines in your changes are missing coverage. Please review.

Project coverage is 71.42%. Comparing base (b15cb0c) to head (18ae823).
Report is 255 commits behind head on main.

❗ Current head 18ae823 differs from pull request most recent head 0750906. Consider uploading reports for the commit 0750906 to get more accurate results

Files Patch % Lines
...va/org/opensearch/action/search/SearchRequest.java 55.55% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##               main   #12295     +/-   ##
===========================================
  Coverage     71.42%   71.42%             
+ Complexity    59978    59841    -137     
===========================================
  Files          4985     4959     -26     
  Lines        282275   281135   -1140     
  Branches      40946    40857     -89     
===========================================
- Hits         201603   200792    -811     
+ Misses        63999    63694    -305     
+ Partials      16673    16649     -24     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@opensearch-trigger-bot
Copy link
Contributor

This PR is stalled because it has been open for 30 days with no activity.

@opensearch-trigger-bot opensearch-trigger-bot bot added stalled Issues that have stalled and removed stalled Issues that have stalled labels Mar 15, 2024
@ansjcy
Copy link
Member Author

ansjcy commented Mar 26, 2024

@peternied I added a bunch of use cases that can be replaced by this deep clone method in the original issue: #869 (comment)

Let me know what you think! thanks!

Copy link
Member

@peternied peternied 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 references. I suppose the utility of the deep copy could be useful as deep copies are happening in plugins, however, there is a performance trade-off to perform this copy.

For those case that you've reference why is a deep copy needed instead of a 'slim' copy?

@github-actions github-actions bot added the Search Search query, autocomplete ...etc label Apr 10, 2024
@ansjcy
Copy link
Member Author

ansjcy commented Apr 10, 2024

Hi @peternied !

For those case that you've reference why is a deep copy needed instead of a 'slim' copy?

For the first use cases I identified (https://github.com/opensearch-project/search-processor/blob/c31475e5465fdce80c7c9b86519a4d8d0141c06b/amazon-kendra-intelligent-ranking/src/main/java/org/opensearch/search/relevance/actionfilter/SearchActionFilter.java#L91), I think we want to rewrite the originalSearchSource and don't want to change the previous request. For the second use case (https://github.com/opensearch-project/alerting/blob/719db46c7312edc265952c3ffe9c5233eb9dfe1f/alerting/src/main/kotlin/org/opensearch/alerting/InputService.kt#L199) , The developer mentioned there's a bug if we don't use deep copy, as mentioned in the comment.

Deep copying query before passing it to rewriteQuery since otherwise, the monitor.input is modified directly, which causes a strange bug where the rewritten query persists on the Monitor across executions

I think the use cases are all related to query rewrite/transform. We need to clone a new search query without impacting the original query. But based on the discussions of the original issue, I think we have already validated why this function is much needed.

Copy link
Contributor

❌ Gradle check result for a23b9c2: 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?

@ansjcy ansjcy force-pushed the support-deep-copy-in-searchrequest branch from a23b9c2 to d77f578 Compare April 23, 2024 23:28
@ansjcy
Copy link
Member Author

ansjcy commented Apr 23, 2024

Hi @peternied! I just updated the PR based on your comments. Let me know it make sense to you. Thank you!

@ansjcy ansjcy force-pushed the support-deep-copy-in-searchrequest branch from d77f578 to 4793280 Compare April 23, 2024 23:31
Copy link
Contributor

❌ Gradle check result for d77f578: 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?

Copy link
Contributor

❌ Gradle check result for 4793280: 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?

@peternied
Copy link
Member

@ansjcy Please continue iterating to green on the pull request check failures & root cause the test failures (troubleshooting-failing-builds)

@ansjcy ansjcy force-pushed the support-deep-copy-in-searchrequest branch from 4793280 to 0750906 Compare May 2, 2024 20:38
@ansjcy ansjcy added the backport 2.x Backport to 2.x branch label May 2, 2024
Copy link
Contributor

github-actions bot commented May 2, 2024

❕ Gradle check result for 0750906: UNSTABLE

  • TEST FAILURES:
      1 org.opensearch.http.SearchRestCancellationIT.testAutomaticCancellationMultiSearchDuringFetchPhase

Please review all flaky tests that succeeded after retry and create an issue if one does not already exist to track the flaky failure.

@peternied peternied merged commit 79957eb into opensearch-project:main May 2, 2024
28 of 29 checks passed
@opensearch-trigger-bot
Copy link
Contributor

The backport to 2.x failed:

The process '/usr/bin/git' failed with exit code 128

To backport manually, run these commands in your terminal:

# Navigate to the root of your repository
cd $(git rev-parse --show-toplevel)
# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add ../.worktrees/OpenSearch/backport-2.x 2.x
# Navigate to the new working tree
pushd ../.worktrees/OpenSearch/backport-2.x
# Create a new branch
git switch --create backport/backport-12295-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 79957ebc03c4af746a31cdeb47158bad96553505
# Push it to GitHub
git push --set-upstream origin backport/backport-12295-to-2.x
# Go back to the original working tree
popd
# Delete the working tree
git worktree remove ../.worktrees/OpenSearch/backport-2.x

Then, create a pull request where the base branch is 2.x and the compare/head branch is backport/backport-12295-to-2.x.

@peternied
Copy link
Member

@ansjcy Could you please manually backport the change to 2.x?

finnegancarroll pushed a commit to finnegancarroll/OpenSearch that referenced this pull request May 10, 2024
deshsidd pushed a commit to deshsidd/OpenSearch that referenced this pull request May 17, 2024
parv0201 pushed a commit to parv0201/OpenSearch that referenced this pull request Jun 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x Backport to 2.x branch backport-failed enhancement Enhancement or improvement to existing feature or request good first issue Good for newcomers Indexing & Search Search Search query, autocomplete ...etc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deep copy for QueryBuilder/SearchRequest
2 participants