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

refactor: use rwlock for modifiable session data #4232

Merged

Conversation

sunng87
Copy link
Member

@sunng87 sunng87 commented Jun 29, 2024

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?

Follow up for #4218 . Need a rebase after #4218 merged.

Some of the properties, like schema and timezone, are modifiable within a session.

Our original design is to generate a read-only QueryContext, then pass it with all the execution process path. This works well before we have statements that modify some of the session data, like SET time_zone and USE.

After that, we introduce a new method called update_session to give back modified properties to session, after query execution. See

query_ctx.update_session(&self.session);
. The implementation of update_session has to check each modifiable field and update the session. This is because ArcSwap data structure is not clonable. So we cannot share reference between the parent Session and the child QueryContext.

This main point of this patch is to change those modifiable fields from ArcSwap to Arc<RwLock> so that we can share it between parent and child. Note that because Session is associated with a signle connection, so actually there is no race condition with reading and updating those modifiable fields.

This patch also include a feature flag fix for orc-rust to exclude it datafusion dependency.

Checklist

  • I have written the necessary rustdoc comments.
  • I have added the necessary unit tests and integration tests.
  • This PR requires documentation updates.

Summary by CodeRabbit

  • Refactor

    • Improved thread safety by replacing ArcSwap with Arc<RwLock> for fields in Session struct, enhancing concurrent access management.
  • Bug Fixes

    • Simplified user handling by removing unnecessary wrappers, improving code clarity and conciseness.
    • Adjusted method calls to improve timezone and schema handling in query contexts.
  • Chores

    • Updated dependencies to include async feature for orc-rust, enhancing asynchronous capabilities.

Copy link
Contributor

coderabbitai bot commented Jun 29, 2024

Walkthrough

The recent changes involve refining the PermissionChecker trait and numerous other components by requiring direct UserInfoRef instead of Option<UserInfoRef>. This update streamlines user handling across various modules. Additionally, the change introduces RwLock for managing concurrent mutable access to session fields like catalog, schema, user_info, and timezone. These alterations aim to improve code clarity, concurrency, and overall performance.

Changes

Files/Groups Change Summaries
src/auth/src/permission.rs Modified PermissionChecker trait to require UserInfoRef instead of Option<UserInfoRef>.
src/auth/tests/mod.rs Updated check_permission in DummyPermissionChecker to accept UserInfoRef.
src/common/datasource/Cargo.toml Added async feature to the orc-rust dependency.
src/common/function/src/.../database.rs Changed current_schema to current_schema_raw in QueryContextBuilder instantiation.
src/operator/src/expr_factory.rs and src/operator/src/... Replaced timezone with timezone_raw in QueryContextBuilder instantiation.
src/pipeline/src/manager/table.rs, src/query/src/plan.rs Modified query_ctx and test_extract_full_table_names to use current_schema_raw in QueryContextBuilder.
src/query/src/optimizer/type_conversion.rs Updated parameter in string_to_timestamp_ms function call to reference self.query_ctx.timezone().
src/query/src/sql.rs, src/servers/src/http/authorize.rs Changed timezone to timezone_raw and updated method calls and user handling logic.
src/servers/src/export_metrics.rs, src/servers/src/... Modified current_schema to current_schema_raw.
src/session/src/context.rs and src/session/src/lib.rs Introduced RwLock to manage session fields like current_schema, current_user, and timezone, replacing ArcSwap usage for better concurrency handling.

Sequence Diagram(s)

Changes don't include a new feature or modifications to the control flow that necessitate a sequence diagram.

Poem

In the realm of rust and code,
UserInfoRef now we hold,
With the RwLock dance in place,
Schemas and timezones join the race.
A smoother flow, concurrency bright,
Our sessions now dance with delight! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the docs-not-required This change does not impact docs. label Jun 29, 2024
@sunng87 sunng87 force-pushed the refactor/session-query-context-update branch from 8cec5ac to 6eba6f6 Compare July 3, 2024 03:34
@sunng87 sunng87 marked this pull request as ready for review July 3, 2024 03:35
@sunng87 sunng87 requested review from evenyag and a team as code owners July 3, 2024 03:35
@sunng87 sunng87 requested a review from shuiyisong July 3, 2024 03:35
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c4db9e8 and 6eba6f6.

Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
Files selected for processing (24)
  • src/auth/src/permission.rs (1 hunks)
  • src/auth/tests/mod.rs (2 hunks)
  • src/common/datasource/Cargo.toml (1 hunks)
  • src/common/function/src/system/database.rs (1 hunks)
  • src/operator/src/expr_factory.rs (2 hunks)
  • src/operator/src/statement.rs (2 hunks)
  • src/pipeline/src/manager/table.rs (1 hunks)
  • src/query/src/optimizer/type_conversion.rs (1 hunks)
  • src/query/src/plan.rs (1 hunks)
  • src/query/src/range_select/plan_rewrite.rs (1 hunks)
  • src/query/src/sql.rs (1 hunks)
  • src/script/src/table.rs (1 hunks)
  • src/servers/src/export_metrics.rs (1 hunks)
  • src/servers/src/grpc/authorize.rs (3 hunks)
  • src/servers/src/grpc/greptime_handler.rs (3 hunks)
  • src/servers/src/http/authorize.rs (3 hunks)
  • src/servers/src/http/prometheus.rs (1 hunks)
  • src/servers/src/mysql/handler.rs (1 hunks)
  • src/servers/src/postgres/handler.rs (1 hunks)
  • src/servers/tests/http/authorize.rs (3 hunks)
  • src/servers/tests/http/http_handler_test.rs (4 hunks)
  • src/servers/tests/py_script/mod.rs (1 hunks)
  • src/session/src/context.rs (14 hunks)
  • src/session/src/lib.rs (3 hunks)
Files skipped from review due to trivial changes (5)
  • src/operator/src/statement.rs
  • src/query/src/range_select/plan_rewrite.rs
  • src/servers/src/grpc/authorize.rs
  • src/servers/src/mysql/handler.rs
  • src/servers/tests/http/http_handler_test.rs
Additional comments not posted (57)
src/common/datasource/Cargo.toml (1)

34-36: Addition of "async" feature to orc-rust dependency.

The addition of the "async" feature to the orc-rust dependency seems appropriate given the context of the PR. This change aligns with the need for asynchronous capabilities in the codebase.

src/auth/src/permission.rs (2)

45-47: Simplified method signature by requiring UserInfoRef.

The change from Option<UserInfoRef> to UserInfoRef simplifies the method signature and eliminates the need for handling None cases. This improves code readability and reduces potential errors.


53-55: Updated implementation to match the new PermissionChecker trait signature.

The implementation of PermissionChecker for Option<&PermissionCheckerRef> has been updated to match the new trait signature. This change ensures consistency and correctness.

src/auth/tests/mod.rs (4)

30-32: Updated test implementation to match the new PermissionChecker trait signature.

The test implementation has been updated to match the new PermissionChecker trait signature. This ensures that the tests are consistent with the updated code.


48-50: Updated test cases to use UserInfoRef directly.

The test cases have been updated to use UserInfoRef directly instead of Option<UserInfoRef>. This change ensures that the tests accurately reflect the new method signature and simplifies the test logic.


54-56: Updated SQL statement test case to use UserInfoRef directly.

The SQL statement test case has been updated to use UserInfoRef directly. This change ensures that the tests are consistent with the updated code and simplifies the test logic.


62-63: Updated error handling test case to use UserInfoRef directly.

The error handling test case has been updated to use UserInfoRef directly. This change ensures that the tests are consistent with the updated code and simplifies the test logic.

src/common/function/src/system/database.rs (1)

81-81: Updated current_schema method call to current_schema_raw.

The method call has been updated to current_schema_raw to align with the changes in the QueryContext struct. This change ensures consistency and correctness in the codebase.

src/servers/tests/py_script/mod.rs (1)

63-63: Updated current_schema method call to current_schema_raw.

The method call has been updated to current_schema_raw to align with the changes in the QueryContext struct. This change ensures consistency and correctness in the codebase.

src/session/src/lib.rs (13)

20-20: Ensure correct usage of RwLock.

The RwLock is used correctly here to wrap the String type, allowing for concurrent read and write access.


34-38: Ensure correct usage of RwLock in struct fields.

The RwLock is used correctly to wrap String, UserInfoRef, and Timezone types, allowing for concurrent read and write access.


51-55: Ensure correct initialization of RwLock fields.

The RwLock fields are correctly initialized with Arc::new(RwLock::new(...)) to ensure thread-safe access.


62-69: Ensure correct cloning of RwLock fields.

The RwLock fields are correctly cloned for use in the QueryContextBuilder.


82-83: Ensure correct implementation of timezone getter.

The timezone method correctly reads the RwLock and clones the Timezone value.


87-87: Ensure correct implementation of set_timezone method.

The set_timezone method correctly writes to the RwLock.


91-91: Ensure correct implementation of user_info getter.

The user_info method correctly reads the RwLock and clones the UserInfoRef value.


95-95: Ensure correct implementation of set_user_info method.

The set_user_info method correctly writes to the RwLock.


99-99: Ensure correct implementation of set_catalog method.

The set_catalog method correctly writes to the RwLock.


103-103: Ensure correct implementation of catalog getter.

The catalog method correctly reads the RwLock and clones the String value.


107-107: Ensure correct implementation of schema getter.

The schema method correctly reads the RwLock and clones the String value.


111-111: Ensure correct implementation of set_schema method.

The set_schema method correctly writes to the RwLock.


115-115: Ensure correct usage of catalog and schema methods in get_db_string.

The get_db_string method correctly uses the catalog and schema methods to build the database string.

src/servers/tests/http/authorize.rs (3)

31-31: Ensure correct handling of user information in test.

The ctx.current_user() method is correctly used to retrieve the current user information.


42-42: Ensure correct handling of user information in test.

The ctx.current_user() method is correctly used to retrieve the current user information.


83-83: Ensure correct handling of user information in test.

The ctx.current_user() method is correctly used to retrieve the current user information.

src/servers/src/grpc/greptime_handler.rs (3)

131-131: Ensure correct handling of user information in auth function.

The auth function now directly returns auth::userinfo_by_name(None) when user_provider is None.


133-133: Ensure correct handling of user information in auth function.

The auth function now directly returns auth::userinfo_by_name(None) when user_provider is None.


198-199: Ensure correct usage of current_schema_raw and timezone_raw in create_query_context.

The create_query_context function correctly uses current_schema_raw and timezone_raw to set the schema and timezone in the query context.

src/query/src/plan.rs (1)

251-251: Ensure correct usage of current_schema_raw in test.

The current_schema_raw method is correctly used to set the schema in the query context.

src/servers/src/export_metrics.rs (1)

250-252: Update usage of current_schema_raw

The change from current_schema to current_schema_raw is consistent with the PR objectives. This ensures that the schema is wrapped in Arc<RwLock>, allowing for modifiable session data.

src/session/src/context.rs (17)

18-18: Import RwLock

The import of RwLock is necessary for the changes made to the QueryContext struct.


40-43: Replace ArcSwap with Arc<RwLock> in QueryContext

The change from ArcSwap to Arc<RwLock> for current_schema, current_user, and timezone aligns with the PR objectives to allow modifiable session data. This is a crucial change for handling concurrent access safely.


63-73: Add current_schema_raw and timezone_raw methods

The addition of current_schema_raw and timezone_raw methods in the QueryContextBuilder is consistent with the changes to use Arc<RwLock>. These methods ensure that the schema and timezone are wrapped in Arc<RwLock>.


79-81: Clone Arc<RwLock> fields in QueryContext

The clone implementation for QueryContext correctly clones the Arc<RwLock> fields, ensuring that the cloned context maintains the same references.


95-96: Update current_schema and timezone in From<RegionRequestHeader> for QueryContext

The updates to use Arc<RwLock> for current_schema and timezone in the From<RegionRequestHeader> for QueryContext implementation are consistent with the overall changes.


107-108: Update current_schema and timezone in From<api::v1::QueryContext> for QueryContext

The updates to use Arc<RwLock> for current_schema and timezone in the From<api::v1::QueryContext> for QueryContext implementation are consistent with the overall changes.


126-127: Read Arc<RwLock> fields in From<QueryContext> for api::v1::QueryContext

The changes to read from Arc<RwLock> for current_schema and timezone in the From<QueryContext> for api::v1::QueryContext implementation are necessary to obtain the values correctly.


141-141: Use Arc<RwLock> for current_schema in QueryContext::with

The change to use Arc<RwLock> for current_schema in the QueryContext::with method is consistent with the overall changes to the QueryContext struct.


159-159: Use Arc<RwLock> for current_schema in QueryContext::with_db_name

The change to use Arc<RwLock> for current_schema in the QueryContext::with_db_name method is consistent with the overall changes to the QueryContext struct.


164-164: Read current_schema from Arc<RwLock>

The change to read current_schema from Arc<RwLock> in the current_schema method of QueryContext is necessary to obtain the value correctly.


168-168: Write current_schema to Arc<RwLock>

The change to write current_schema to Arc<RwLock> in the set_current_schema method of QueryContext is necessary to update the value correctly.


185-186: Read timezone from Arc<RwLock>

The change to read timezone from Arc<RwLock> in the timezone method of QueryContext is necessary to obtain the value correctly.


189-190: Write timezone to Arc<RwLock>

The change to write timezone to Arc<RwLock> in the set_timezone method of QueryContext is necessary to update the value correctly.


193-194: Read current_user from Arc<RwLock>

The change to read current_user from Arc<RwLock> in the current_user method of QueryContext is necessary to obtain the value correctly.


197-199: Write current_user to Arc<RwLock>

The change to write current_user to Arc<RwLock> in the set_current_user method of QueryContext is necessary to update the value correctly.


238-244: Use Arc<RwLock> in QueryContextBuilder::build

The change to use Arc<RwLock> for current_schema, current_user, and timezone in the QueryContextBuilder::build method is necessary to construct the QueryContext correctly.


263-265: Clone Arc<RwLock> fields in QueryContextBuilder::from_existing

The change to clone Arc<RwLock> fields in the QueryContextBuilder::from_existing method is consistent with the overall changes to the QueryContext struct.

src/script/src/table.rs (1)

340-340: Update usage of current_schema_raw

The change from current_schema to current_schema_raw is consistent with the PR objectives. This ensures that the schema is wrapped in Arc<RwLock>, allowing for modifiable session data.

src/servers/src/http/authorize.rs (4)

65-65: Update usage of current_schema_raw

The change from current_schema to current_schema_raw in the inner_auth function is consistent with the PR objectives. This ensures that the schema is wrapped in Arc<RwLock>, allowing for modifiable session data.


68-69: Update usage of timezone_raw

The change from timezone to timezone_raw in the inner_auth function is consistent with the PR objectives. This ensures that the timezone is wrapped in Arc<RwLock>, allowing for modifiable session data.


78-78: Set current user directly

The change to set the current user directly without wrapping in Some is consistent with the updated function signature of set_current_user.


106-106: Set authenticated user

The change to set the authenticated user directly in the inner_auth function is consistent with the updated function signature of set_current_user.

src/pipeline/src/manager/table.rs (1)

207-207: Update usage of current_schema_raw

The change from current_schema to current_schema_raw is consistent with the PR objectives. This ensures that the schema is wrapped in Arc<RwLock>, allowing for modifiable session data.

src/query/src/optimizer/type_conversion.rs (1)

148-148: Verify the correctness of direct reference to timezone.

The change from self.query_ctx.timezone().as_ref() to &self.query_ctx.timezone() should be verified to ensure it correctly refers to the timezone field.

src/operator/src/expr_factory.rs (1)

683-683: Verify the correctness of direct reference to timezone.

The change from QueryContextBuilder::default().timezone(Timezone::from_tz_string("+08:00").unwrap()) to QueryContextBuilder::default().timezone_raw(Timezone::from_tz_string("+08:00").unwrap()) should be verified to ensure it correctly refers to the timezone field.

Verification successful

The timezone_raw method in QueryContextBuilder is correctly implemented. The change to use .timezone_raw(Timezone::from_tz_string("+08:00").unwrap()) is valid.

  • src/session/src/context.rs: Method timezone_raw is correctly defined and implemented.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the usage of `timezone` field in `QueryContextBuilder`.

# Test: Search for the method definition and its usage. Expect: Correct references to the `timezone` field.
rg --type rust $'QueryContextBuilder'

Length of output: 4487



Script:

#!/bin/bash
# Description: Verify the implementation of `timezone_raw` method in `QueryContextBuilder`.

# Search for the method definition within the `QueryContextBuilder` implementation
ast-grep --lang rust --pattern 'impl QueryContextBuilder {
  $$$
  pub fn timezone_raw(&self, $_: Timezone) -> &Self {
    $$$
  }
  $$$
}'

Length of output: 141



Script:

#!/bin/bash
# Description: Verify the existence of any method related to `timezone` in `QueryContextBuilder`.

# Search for any method related to `timezone` in the `QueryContextBuilder` implementation
rg --type rust 'impl QueryContextBuilder' -A 20 | rg 'timezone'

Length of output: 529

src/servers/src/http/prometheus.rs (1)

625-625: Verify the correctness of direct reference to schema.

The change from current_schema(schema.to_string()) to current_schema_raw(schema.to_string()) should be verified to ensure it correctly refers to the schema field.

Verification successful

Verified the correctness of direct reference to schema.

The change from current_schema(schema.to_string()) to current_schema_raw(schema.to_string()) correctly uses the current_schema_raw method to set the current_schema field in the QueryContextBuilder.

  • src/servers/src/http/prometheus.rs, line 625
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the usage of `schema` field in `QueryContextBuilder`.

# Test: Search for the method definition and its usage. Expect: Correct references to the `schema` field.
rg --type rust $'QueryContextBuilder'

Length of output: 4487



Script:

#!/bin/bash
# Description: Locate the definition of the `current_schema_raw` method in the `QueryContextBuilder` implementation and verify its usage.

# Search for the `current_schema_raw` method definition in the `QueryContextBuilder` implementation.
rg --type rust 'fn current_schema_raw' --context 5

Length of output: 612



Script:

#!/bin/bash
# Description: Verify the usage of the `current_schema` field within the `QueryContextBuilder` implementation.

# Search for the `current_schema` field definition and its usage within the `QueryContextBuilder` implementation.
rg --type rust 'current_schema' --context 5

Length of output: 53321

src/query/src/sql.rs (1)

1024-1024: Ensure timezone_raw method usage is appropriate.

The method timezone_raw is used here. Verify that it correctly replaces the previous timezone method and that it aligns with the new RwLock structure for timezone.

Verification successful

Verification successful for timezone_raw method usage.

The timezone_raw method correctly replaces the previous timezone method and aligns with the RwLock structure for timezone. The usage in src/query/src/sql.rs is appropriate and consistent with the changes.

  • timezone_raw method implementation: src/session/src/context.rs
  • RwLock<Timezone> structure: src/session/src/lib.rs, src/session/src/context.rs
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that `timezone_raw` method is correctly implemented and used in the codebase.

# Test: Search for the `timezone_raw` method implementation. Expect: Find the correct implementation.
rg --type rust $'fn timezone_raw'

# Test: Search for all usages of `timezone_raw`. Expect: Verify all usages are appropriate.
rg --type rust $'timezone_raw'

Length of output: 792



Script:

#!/bin/bash
# Description: Verify that the previous `timezone` method's implementation and usage.

# Test: Search for the `timezone` method implementation. Expect: Find the correct implementation.
rg --type rust $'fn timezone'

# Test: Search for all usages of `timezone`. Expect: Verify all usages are appropriate.
rg --type rust $'timezone'

Length of output: 34797


Script:

#!/bin/bash
# Description: Verify the `RwLock` structure for `timezone`.

# Test: Search for `RwLock` usage with `timezone`. Expect: Verify the structure.
rg --type rust 'RwLock<Timezone>'

Length of output: 159

Copy link

codecov bot commented Jul 3, 2024

Codecov Report

Attention: Patch coverage is 89.74359% with 8 lines in your changes missing coverage. Please review.

Project coverage is 84.65%. Comparing base (11cf9c8) to head (841842a).
Report is 9 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4232      +/-   ##
==========================================
- Coverage   84.97%   84.65%   -0.32%     
==========================================
  Files        1054     1057       +3     
  Lines      187154   187495     +341     
==========================================
- Hits       159037   158732     -305     
- Misses      28117    28763     +646     

src/session/src/context.rs Outdated Show resolved Hide resolved
src/auth/src/permission.rs Show resolved Hide resolved
src/session/src/lib.rs Outdated Show resolved Hide resolved
src/session/src/lib.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6eba6f6 and 4c9932a.

Files selected for processing (7)
  • src/operator/src/expr_factory.rs (2 hunks)
  • src/operator/src/statement.rs (2 hunks)
  • src/query/src/sql.rs (1 hunks)
  • src/servers/src/grpc/greptime_handler.rs (3 hunks)
  • src/servers/src/http/authorize.rs (3 hunks)
  • src/session/src/context.rs (11 hunks)
  • src/session/src/lib.rs (2 hunks)
Files skipped from review as they are similar to previous changes (5)
  • src/operator/src/expr_factory.rs
  • src/operator/src/statement.rs
  • src/query/src/sql.rs
  • src/servers/src/http/authorize.rs
  • src/session/src/context.rs
Additional comments not posted (18)
src/session/src/lib.rs (15)

20-20: Ensure correct usage of RwLock.

The import of RwLock is necessary for the changes. Ensure that RwLock is used correctly throughout the codebase.


34-35: Consider the necessity of Arc.

The Session struct uses Arc for RwLock fields. Evaluate if Arc is necessary, given that Session is not Clone.

Would you like to explore alternatives for managing shared mutable state without Arc?


42-48: Encapsulation of mutable fields.

The introduction of MutableInner to encapsulate mutable fields is a good practice for better organization and potential future extensions.


50-58: Default implementation for MutableInner.

The default implementation of MutableInner initializes fields with default values. Ensure these defaults are appropriate for all use cases.


67-70: Initialization of Session with RwLock.

The Session struct is correctly initialized with RwLock for catalog and mutable_inner. Ensure that all necessary initializations are covered.


76-79: Thread-safe access to catalog.

The new_query_context method provides thread-safe access to catalog using RwLock. Ensure similar patterns are followed for other mutable fields.


94-95: Thread-safe access to timezone.

The timezone method provides thread-safe read access to timezone using RwLock.


99-100: Thread-safe modification of timezone.

The set_timezone method provides thread-safe write access to timezone using RwLock.


104-104: Thread-safe access to user_info.

The user_info method provides thread-safe read access to user_info using RwLock.


108-108: Thread-safe modification of user_info.

The set_user_info method provides thread-safe write access to user_info using RwLock.


112-112: Thread-safe modification of catalog.

The set_catalog method provides thread-safe write access to catalog using RwLock.


116-116: Thread-safe access to catalog.

The catalog method provides thread-safe read access to catalog using RwLock.


120-120: Thread-safe access to schema.

The schema method provides thread-safe read access to schema using RwLock.


124-124: Thread-safe modification of schema.

The set_schema method provides thread-safe write access to schema using RwLock.


128-128: Thread-safe access to database string.

The get_db_string method provides thread-safe read access to catalog and schema using RwLock.

src/servers/src/grpc/greptime_handler.rs (3)

131-131: Ensure correct handling of UserInfoRef.

The auth function now directly handles UserInfoRef. Ensure that this change is consistent across the codebase.


133-133: Simplified handling of None case for user_provider.

The early return for the None case of user_provider simplifies the logic.


199-199: Thread-safe access to timezone.

The create_query_context function correctly sets the timezone using the new RwLock based implementation.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4c9932a and 841842a.

Files selected for processing (1)
  • src/session/src/lib.rs (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/session/src/lib.rs

Copy link
Contributor

@shuiyisong shuiyisong left a comment

Choose a reason for hiding this comment

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

LGTM

@shuiyisong shuiyisong enabled auto-merge July 4, 2024 11:14
@shuiyisong shuiyisong added this pull request to the merge queue Jul 4, 2024
Merged via the queue into GreptimeTeam:main with commit 8399dca Jul 4, 2024
53 checks passed
@shuiyisong shuiyisong deleted the refactor/session-query-context-update branch July 4, 2024 13:11
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants