Skip to content

refactor: make extension mutable in query context#8088

Closed
sunng87 wants to merge 3 commits into
GreptimeTeam:mainfrom
sunng87:feat/mutable-extensions
Closed

refactor: make extension mutable in query context#8088
sunng87 wants to merge 3 commits into
GreptimeTeam:mainfrom
sunng87:feat/mutable-extensions

Conversation

@sunng87
Copy link
Copy Markdown
Member

@sunng87 sunng87 commented May 8, 2026

I hereby agree to the terms of the GreptimeDB CLA.

Refer to a related PR or issue link (optional)

What's changed and what's your intention?

In order to store some information with QueryContext, I will need to make extension mutable. This patch moves all mutable items into QueryContextMutableFields.

It also changes it's clone to deep copy to match original behaviour.

PR Checklist

Please convert it to a draft if some of the following conditions are not met.

  • I have written the necessary rustdoc comments.
  • I have added the necessary unit tests and integration tests.
  • This PR requires documentation updates.
  • API changes are backward compatible.
  • Schema or data changes are backward compatible.

@sunng87 sunng87 requested review from a team, discord9, evenyag and waynexia as code owners May 8, 2026 13:58
@github-actions github-actions Bot added size/S docs-not-required This change does not impact docs. labels May 8, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors QueryContext to consolidate mutable fields into a RwLock-protected structure and optimizes string handling across the codebase. Review feedback points out that the manual Clone implementation for QueryContext now performs a deep copy, breaking the shared mutable state for snapshot tracking which could cause consistency issues. Additionally, it is suggested to update set_extension to take &self to facilitate mutation via shared references and to optimize the extension method to avoid unnecessary String allocations.

mutable_session_data: Arc<RwLock<MutableInner>>,
#[builder(default)]
mutable_query_context_data: Arc<RwLock<QueryContextMutableFields>>,
mutable_query_context_data: RwLock<QueryContextMutableFields>,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The change from Arc<RwLock> to RwLock combined with the manual Clone implementation (lines 95-97) breaks the sharing of snapshot_seqs and sst_min_sequences across QueryContext clones. In the original implementation, these fields were wrapped in an Arc, ensuring that all clones of a context shared the same mutable state for snapshot tracking. The current implementation performs a deep copy, making these fields independent. This could lead to consistency issues if different parts of a query execution expect to share or collectively update snapshot information through cloned contexts.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed deep copy will work for existing cases.

Comment thread src/session/src/context.rs Outdated
Comment thread src/session/src/context.rs
@waynexia
Copy link
Copy Markdown
Member

what kind of usage is needed from this change? can once cell suit it?

@sunng87
Copy link
Copy Markdown
Member Author

sunng87 commented May 15, 2026

This is for storing some context information through the execution path.

@killme2008
Copy link
Copy Markdown
Member

@sunng87 Need to fix the conflict.

@sunng87
Copy link
Copy Markdown
Member Author

sunng87 commented May 21, 2026

This is no longer required after a few refactor. Will close this and reopen when needed again.

@sunng87 sunng87 closed this May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs-not-required This change does not impact docs. size/S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants