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 global system variable and session variable account isolation cases #16695

Merged
merged 6 commits into from
Jun 7, 2024

Conversation

heni02
Copy link
Contributor

@heni02 heni02 commented Jun 5, 2024

User description

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #16047

What this PR does / why we need it:

add global system variable and session variable account isolation cases


PR Type

Tests


Description

  • Added new test cases to verify the setting and isolation of global system variables.
  • Added new test cases to verify the setting and isolation of session variables.
  • Created SQL scripts to automate the testing of these variables across different accounts.

Changes walkthrough 📝

Relevant files
Tests
system_variables_new.result
Add test cases for global and session system variables     

test/distributed/cases/database/system_variables_new.result

  • Added test cases for setting and verifying global system variables.
  • Added test cases for setting and verifying session variables.
  • Included checks for variable isolation across different accounts.
  • +352/-0 
    system_variables_new.sql
    Add SQL scripts for testing system variable isolation       

    test/distributed/cases/database/system_variables_new.sql

  • Created accounts for testing variable settings.
  • Added SQL commands to set and verify global system variables.
  • Added SQL commands to set and verify session variables.
  • Included SQL commands to confirm variable isolation across different
    accounts.
  • +161/-0 

    💡 PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    Copy link

    PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here.

    PR Review 🔍

    ⏱️ Estimated effort to review [1-5]

    4, because the PR involves a significant number of new test cases and SQL commands that need to be thoroughly reviewed for syntax, logic, and potential side effects in different session and global settings. The complexity of the variable settings and their interactions across different accounts increases the review effort.

    🧪 Relevant tests

    Yes

    ⚡ Possible issues

    Possible Bug: The test cases show some internal errors when setting session variables that are actually global. This might be intentional to test error handling, but it should be clearly documented to avoid confusion.

    Inconsistency: There are discrepancies in the expected values of some variables (e.g., max_connections, lower_case_table_names) after setting them, which might indicate either an issue with the test setup or the database system's variable handling.

    🔒 Security concerns

    No

    @matrix-meow matrix-meow added the size/L Denotes a PR that changes [500,999] lines label Jun 5, 2024
    @mergify mergify bot requested a review from sukki37 June 5, 2024 11:16
    @mergify mergify bot added the kind/feature label Jun 5, 2024
    Copy link

    PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here.

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Possible issue
    Add checks to ensure accounts do not already exist before creating them

    Consider adding a check to ensure that the accounts acc1, acc2, and acc3 do not already
    exist before attempting to create them. This will prevent potential errors if the accounts
    already exist.

    test/distributed/cases/database/system_variables_new.sql [2-4]

    +drop account if exists acc1;
    +drop account if exists acc2;
    +drop account if exists acc3;
     create account acc1 ADMIN_NAME 'admin' IDENTIFIED BY '111';
     create account acc2 ADMIN_NAME 'admin' IDENTIFIED BY '111';
     create account acc3 ADMIN_NAME 'admin' IDENTIFIED BY '111';
     
    Suggestion importance[1-10]: 8

    Why: Adding checks for the existence of accounts before creating them is crucial to prevent errors and ensure the script's robustness.

    8
    Add a check to ensure max_connections is set correctly after attempting to change it

    Add a check to ensure that the global variable max_connections is set correctly after
    attempting to set it to 65536, as the subsequent select shows it remains 151.

    test/distributed/cases/database/system_variables_new.sql [19-20]

     set global max_connections=65536;
     select @@max_connections;
    +-- Check if the value is set correctly
    +if @@max_connections != 65536 then
    +    signal sqlstate '45000' set message_text = 'Failed to set max_connections to 65536';
    +end if;
     
    Suggestion importance[1-10]: 6

    Why: Adding a check for the correct setting of max_connections is important for validating the expected behavior of the system configuration.

    6
    Best practice
    Reset global variables to their default values at the end of the test

    To ensure consistency and avoid potential conflicts, consider resetting the global
    variables to their default values at the end of the test.

    test/distributed/cases/database/system_variables_new.sql [159-161]

    +set global sql_mode = "DEFAULT";
    +set global TIME_ZONE = "SYSTEM";
    +set global autocommit = on;
    +set global enable_privilege_cache = on;
    +set global save_query_result = off;
    +set global max_connections = 151;
    +set global lower_case_table_names = 1;
    +set global keep_user_target_list_in_result = 1;
    +set global interactive_timeout = 28800;
    +set global net_write_timeout = 60;
    +set global wait_timeout = 28800;
    +set global sql_select_limit = 18446744073709551615;
    +set global max_allowed_packet = 67108864;
    +set global tx_isolation = "REPEATABLE-READ";
     drop account acc1;
     drop account acc2;
     drop account acc3;
     
    Suggestion importance[1-10]: 7

    Why: Resetting global variables to their default values at the end of the test is a best practice to avoid side effects on other tests or systems.

    7
    Robustness
    Add error handling for setting session variables that are actually global

    Consider adding error handling for setting session variables that are actually global, to
    make the test more robust and informative.

    test/distributed/cases/database/system_variables_new.sql [80-81]

     set max_connections=1000;
    +if @@error then
    +    signal sqlstate '45000' set message_text = 'Failed to set max_connections as it is a global variable';
    +end if;
     select @@max_connections;
     
    Suggestion importance[1-10]: 6

    Why: Adding error handling for incorrect scope variable settings increases the robustness and clarity of the test script.

    6

    @mergify mergify bot merged commit cda2347 into matrixorigin:1.2-dev Jun 7, 2024
    17 of 18 checks passed
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    kind/feature Review effort [1-5]: 4 size/L Denotes a PR that changes [500,999] lines Tests
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    4 participants