Fixing bug with bedrock client caching#118177
Merged
ymao1 merged 6 commits intoelastic:mainfrom Dec 10, 2024
Merged
Conversation
Collaborator
|
Hi @ymao1, I've created a changelog YAML for you. |
Collaborator
|
Pinging @elastic/ml-core (Team:ML) |
jonathan-buttner
approved these changes
Dec 9, 2024
docs/changelog/118177.yaml
Outdated
| @@ -0,0 +1,6 @@ | |||
| pr: 118177 | |||
| summary: Fixing bug with bedrock client caching | |||
Contributor
There was a problem hiding this comment.
Maybe something like: Fixing bedrock event executor terminated cache issue
| builtClient.resetExpiration(); | ||
| return builtClient; | ||
| return clientsCache.compute(modelHash, (hashKey, client) -> { | ||
| if (client == null) { |
Contributor
There was a problem hiding this comment.
nit: I think we could collapse this to something like:
AmazonBedrockBaseClient clientToUse = client;
if (clientToUse == null) {
clientToUse = creator.apply(model, timeout);
}
clientToUse.setClock(clock);
clientToUse.resetExpiration();
return clientToUse;
| return builtClient; | ||
| } else { | ||
| // for testing | ||
| client.setClock(clock); |
Contributor
There was a problem hiding this comment.
nit: This is completely unrelated to your PR but I wonder if we could refactor the client class' creator function to take the clock as a parameter so we can avoid the setClock() class here 🤔
Contributor
Author
There was a problem hiding this comment.
I did not tackle this comment in this PR but I left a code comment. Would you like me to open an issue?
Collaborator
💚 Backport successful
|
ymao1
added a commit
to ymao1/elasticsearch
that referenced
this pull request
Dec 10, 2024
* Fixing bug with bedrock client caching * Update docs/changelog/118177.yaml * PR feedback
elasticsearchmachine
pushed a commit
that referenced
this pull request
Dec 10, 2024
prwhelan
pushed a commit
to prwhelan/elasticsearch
that referenced
this pull request
Mar 28, 2025
* Fixing bug with bedrock client caching * Update docs/changelog/118177.yaml * PR feedback
prwhelan
added a commit
that referenced
this pull request
Mar 28, 2025
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #117916
Summary
Fixes an order of operations bug with flushing the client cache and retrieving the client. Previously, we look in the cache for a client and return it, regardless of whether it is expired or not, and then we flush the cache of expired clients. This was causing the
event executor terminatederror. This PR changes the order so that we flush the cache of expired clients first and then we try to retrieve the client (creating a new one if the expired one was flushed).Updates the expiration date of the client if the client is used. This allows an actively used client to continue being cached. Previously, the client would be flushed every 5 minutes regardless of whether it's in use or not. If this is not the desired behavior, I can revert this change.