fix(sessions): skip unnecessary FOR UPDATE lock on app/user state rows#4730
fix(sessions): skip unnecessary FOR UPDATE lock on app/user state rows#4730giulio-leone wants to merge 3 commits intogoogle:mainfrom
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the concurrency and performance of the database session service by optimizing the acquisition of Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
Response from ADK Triaging Agent Hello @giulio-leone, thank you for your contribution! Could you please add a You can find more information about the contribution guidelines here: https://github.com/google/adk-python/blob/main/CONTRIBUTING.md#requirement-for-prs Thanks! |
There was a problem hiding this comment.
Code Review
This pull request introduces a valuable performance optimization by skipping unnecessary FOR UPDATE locks on app and user state rows during event appends when there are no state deltas. The approach of pre-analyzing state deltas to conditionally acquire locks is sound and well-implemented. The accompanying changes and tests are appropriate. I have one minor suggestion to improve code clarity by removing a redundant check.
91f19fd to
1ef2fcd
Compare
DatabaseSessionService.append_event() unconditionally acquires SELECT ... FOR UPDATE on both app_states and user_states tables, even when the event carries no state delta for those scopes. Since app_states is keyed by app_name alone, all concurrent append_event calls within the same app serialize on this single row lock, even when they only carry session-scoped state (the vast majority of events). Fix: pre-analyze the event's state_delta before acquiring locks and only use FOR UPDATE when the corresponding scope actually has changes. This also avoids a redundant call to extract_state_delta later in the method. Fixes google#4655
Addresses review feedback: use a single conditional expression instead of separate variable initializations and if block.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1ef2fcd to
8db8a51
Compare
The database session service currently takes
FOR UPDATElocks on app and user state rows even when there are no deltas to write. This causes unnecessary lock contention under concurrent requests.This PR skips the lock acquisition when there are no state deltas to persist.
Supersedes #4656 (closed due to CLA issue, now resolved).
Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com