Skip to content

Revert "[Fix] : replace point locks with table lock in some cases (#1… - #15710

Merged
sukki37 merged 2 commits into
matrixorigin:mainfrom
jensenojs:revert
Apr 25, 2024
Merged

sukki37 merged 2 commits into
matrixorigin:mainfrom
jensenojs:revert

Conversation

@jensenojs

Copy link
Copy Markdown
Contributor

…5578)"

This reverts commit 57def8e.

What type of PR is this?

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

Which issue(s) this PR fixes:

issue https://github.com/matrixorigin/MO-Cloud/issues/3039

What this PR does / why we need it:

fix tpcc hung

@matrix-meow matrix-meow added the size/S Denotes a PR that changes [10,99] lines label Apr 25, 2024
@mergify mergify Bot added the kind/bug Something isn't working label Apr 25, 2024
@matrix-meow

Copy link
Copy Markdown
Contributor

@jensenojs Thanks for your contributions!

Here are review comments for file pkg/cnservice/types.go:

Pull Request Review:

Title and Body:

The title and body of the pull request indicate that the changes are a revert of a previous commit that attempted to fix an issue related to TPCC hanging. The PR is associated with fixing a bug mentioned in issue #3039. The revert is necessary due to potential issues introduced by the previous fix.

Changes in pkg/cnservice/types.go:

  1. Problem - Incorrect Package Import:

    • The addition of import "github.com/matrixorigin/matrixone/pkg/sql/plan" seems unrelated to the purpose of the PR, which is to revert a previous fix.
    • Suggestion: Remove the added import statement as it is not relevant to the current changes being made.
  2. Potential Issue - Incorrect Assignment:

    • In the Validate function, the assignment plan.CNPrimaryCheck = true and plan.CNPrimaryCheck = false seems incorrect as it is modifying a field directly on the plan package, which might not be the intended behavior.
    • Suggestion: Verify if the assignment should be made to config.CNPrimaryCheck instead of plan.CNPrimaryCheck to ensure the correct field is being updated.
  3. Optimization - Code Consistency:

    • The assignment statements config.CNPrimaryCheck = true and config.CNPrimaryCheck = false could be improved for consistency and clarity.
    • Suggestion: Use a ternary conditional assignment to make the code more concise and readable. For example:
      config.CNPrimaryCheck = txn.GetTxnMode(c.Txn.Mode) == txn.TxnMode_Pessimistic || c.PrimaryKeyCheck

Security Concern:

No specific security concerns were identified in the provided changes.

Overall Suggestions:

  • Ensure that the changes made align with the purpose of the revert and do not introduce unrelated modifications.
  • Verify the correctness of assignments and make sure they are updating the intended variables.
  • Consider using ternary conditional assignments for improved code readability and consistency.

By addressing the mentioned issues and suggestions, the code quality and clarity can be enhanced, ensuring that the changes align with the intended purpose of the pull request.

Here are review comments for file pkg/config/configuration.go:

Pull Request Review:

Title:

The title of the pull request indicates a revert of a previous fix related to replacing point locks with table locks in some cases.

Body:

The body of the pull request specifies that this revert is related to fixing an issue with TPCC hanging. It also references the specific issue on GitHub that this PR fixes.

Changes in pkg/config/configuration.go:

  1. Typo in Variable Name:

    • Issue: There is a typo in the variable name dafaultSqlMode, it should be defaultSqlMode.
    • Recommendation: Correct the variable name to defaultSqlMode for consistency and clarity.
  2. Uninitialized Variable:

    • Issue: The defaultSqlMode variable is declared but not used anywhere in the code.
    • Recommendation: If this variable is not needed, it should be removed to avoid clutter in the codebase.
  3. Incorrect Default SQL Mode Value:

    • Issue: The value assigned to defaultSqlMode seems to be a list of SQL modes, but it is misspelled and not in the correct format.
    • Recommendation: If this list of SQL modes is required, ensure it is correctly spelled and formatted according to the SQL mode requirements.
  4. Comment Clarification:

    • Issue: The comment for defaultSqlMode mentions SQL modes, but it does not provide clear information on why these specific modes are set as defaults.
    • Recommendation: Update the comment to explain the rationale behind setting these SQL modes as defaults for better understanding.

Security Concerns:

  • Sensitive Data Exposure:
    • Ensure that no sensitive information such as passwords, keys, or tokens are hardcoded in the codebase, especially in configuration files. If the SQL modes contain sensitive information, consider using environment variables or a secure configuration management solution.

Optimization Suggestions:

  • Code Cleanup:
    • Remove any unused variables or unnecessary comments to keep the codebase clean and maintainable.

General Recommendations:

  • Testing:
    • Ensure that the changes are tested thoroughly to prevent any regressions, especially after reverting a previous fix.

Conclusion:

Overall, the changes in the pull request need some adjustments to address the issues mentioned above. It is essential to review the code carefully, correct any typos, remove unused variables, and provide clear comments for better code readability and maintainability. Additionally, consider the security implications of the changes made and follow best practices to avoid exposing sensitive data.

Here are review comments for file pkg/lockservice/cfg.go:

Pull Request Review:

Title:

The title indicates a revert of a specific commit related to fixing an issue. It is clear and concise.

Body:

The body provides information about the type of PR, the issue it fixes, and the reason for the revert. It mentions fixing an issue related to tpcc hung.

Changes in pkg/lockservice/cfg.go:

  1. Removed Code:
    • The code related to checking if MaxLockRowCount is greater than MaxFixedSliceSize has been removed.
    • The removed code had a panic statement which would trigger an error if the condition was met.

Feedback and Suggestions:

  1. Reverting Commit:

    • Ensure that reverting the commit is necessary and does not reintroduce any issues that were previously fixed. Verify that the issue related to tpcc hung is resolved without the changes from the reverted commit causing any new problems.
  2. Removed Code:

    • The removed code had a validation check that prevented a specific scenario. It is essential to understand why this check was initially added and if there are alternative ways to handle the scenario without causing issues.
    • Consider if there is a different approach to address the potential problem that was being checked by the removed code. If necessary, refactor the validation logic to ensure the system's stability.
  3. Error Handling:

    • Instead of using a panic statement for validation, consider using error handling mechanisms like returning an error or logging the issue. This can help in gracefully handling invalid configurations without abruptly terminating the program.
  4. Testing:

    • After making changes, ensure thorough testing to validate that the system behaves as expected and that the removal of the validation check does not introduce any vulnerabilities or unexpected behavior.
  5. Documentation:

    • Update relevant documentation or comments to reflect the changes made in the code. This will help other developers understand the reasoning behind the modifications and how to maintain the code in the future.

By addressing the points mentioned above, you can ensure that the codebase remains stable, secure, and maintainable. Remember to communicate any significant changes clearly with the team to maintain transparency and collaboration.

Here are review comments for file pkg/sql/plan/build_constraint_util.go:

Pull Request Review:

Title:

The title indicates that the pull request is reverting a previous fix related to replacing point locks with table locks in some cases.

Body:

The body of the pull request specifies that it fixes an issue related to TPCC hanging and references the corresponding GitHub issue.

Changes in pkg/sql/plan/build_constraint_util.go:

  1. Removed Import Statement:

    • The import statement for github.com/matrixorigin/matrixone/pkg/config has been removed.
    • Issue: This removal might cause a problem if the config package was being used in the file.
    • Suggestion: If the config package is still required in the file, the import statement should be added back. If not, ensure that there are no references to config left in the file.
  2. Variable Reference Change:

    • The reference to config.CNPrimaryCheck has been changed to CNPrimaryCheck.
    • Issue: This change might lead to a compilation error if CNPrimaryCheck is not defined in the current scope.
    • Suggestion: Ensure that CNPrimaryCheck is defined in the current scope or import the necessary package if CNPrimaryCheck is defined there.
  3. Code Comment:

    • There is a comment mentioning a refactor that has not been completed yet.
    • Issue: The comment suggests that there is unfinished work that might need attention.
    • Suggestion: Review the code to determine if the unfinished refactor needs to be completed or if any redundant code can be removed.

Overall Suggestions for Optimization:

  • Code Consistency: Ensure that all necessary import statements are present and that variables are referenced correctly to avoid compilation errors.
  • Code Cleanup: Review and remove any redundant comments or code that is no longer needed to improve code readability and maintainability.

Security Concerns:

  • There are no apparent security concerns based on the changes in the provided diff.

By addressing the issues mentioned above and considering the suggestions for optimization, the codebase can be improved in terms of correctness and maintainability.

Here are review comments for file pkg/sql/plan/build_delete.go:

Pull Request Review:

Problem:

  1. The pull request title and body indicate a revert of a previous fix without a clear explanation of why the revert is necessary. Reverting a fix without proper justification can lead to reintroducing bugs or issues that were previously resolved.

Suggestions:

  1. Provide a detailed explanation in the pull request body regarding why the revert is necessary. Include information on the specific issue or reason that prompted the revert to ensure transparency and clarity for other team members.

Optimization Suggestions:

  1. If the revert is deemed necessary due to unforeseen consequences or new insights, consider providing a brief summary of the issues encountered after the original fix was implemented. This can help in understanding the context behind the decision to revert the changes.

Security Concerns:

No security concerns were identified in the provided diff.


Overall Comments:

  • It is crucial to maintain clear communication and documentation when reverting changes to ensure that the development process remains transparent and efficient.
  • When reverting a previous fix, it is beneficial to provide context on the reasons for the reversion to facilitate understanding and collaboration within the team.

By addressing the lack of detailed explanation for the revert and providing context for the decision, the team can maintain a more organized and informed development process.

Here are review comments for file pkg/sql/plan/build_dml_util.go:

Pull Request Review:

Title:

The title of the pull request indicates a revert action of a previous fix.

Body:

The body of the pull request provides information about the type of PR, the issue it fixes, and the reason for the PR - fixing "tpcc hung".

Changes:

  1. Variable CNPrimaryCheck:

    • Issue: The addition of this variable CNPrimaryCheck without any usage or explanation in the code can lead to confusion and potential dead code.
    • Suggestion: Remove the CNPrimaryCheck variable if it is not being used or provide a clear purpose and usage for it.
  2. Removal of lockTable assignments:

    • Issue: The removal of upPlanCtx.lockTable and similar assignments in multiple places without a clear reason can introduce unexpected behavior or bugs.
    • Suggestion: If the intention is to remove locking behavior, ensure it is safe to do so and document the reason for removing these assignments.
  3. Changes in appendLockNode function:

    • Issue: The changes in the appendLockNode function, specifically the condition builder.qry.LoadTag && !lockTable, might introduce a potential security issue by bypassing table locks.
    • Security Concern: By bypassing table locks based on the condition, it could lead to data inconsistency or unauthorized access.
    • Suggestion: Review the logic in the appendLockNode function carefully to ensure that table locks are applied correctly based on the requirements. Avoid bypassing locks based on conditions that could compromise data integrity.
  4. LockTable usage in makePreUpdateDeletePlan:

    • Issue: Setting LockTable: false in makePreUpdateDeletePlan without proper justification can impact the intended locking behavior.
    • Suggestion: If the locking behavior is necessary for data consistency or integrity, ensure that LockTable is set appropriately based on the requirements.

Overall Suggestions:

  • Clearly document the purpose and usage of any new variables introduced.
  • Ensure that changes related to locking mechanisms are reviewed thoroughly to maintain data consistency and security.
  • Provide comments or documentation explaining the rationale behind changes that alter locking behavior to prevent unintended consequences.

By addressing the issues mentioned above and following the suggestions provided, the codebase can be improved in terms of clarity, maintainability, and security.

Here are review comments for file pkg/sql/plan/build_insert.go:

Pull Request Review:

Title and Body:

The title and body of the pull request indicate that the commit being reverted is related to fixing an issue with TPCC hanging. The PR is reverting a previous fix that replaced point locks with table locks in some cases. The issue being addressed is linked to a specific problem in the project's issue tracker.

Changes in pkg/sql/plan/build_insert.go:

  1. Removal of config Import:

    • The commit removes the import statement for github.com/matrixorigin/matrixone/pkg/config.
    • Issue: Removing this import may cause issues if the config package was being used in the file.
    • Suggestion: Ensure that any functionality or variables from the config package that were being used in the file are either replaced or refactored appropriately.
  2. Condition Check Change:

    • The commit changes the condition check from !config.CNPrimaryCheck to !CNPrimaryCheck.
    • Issue: The change in the condition check may lead to a reference error if CNPrimaryCheck is not defined or imported correctly.
    • Suggestion: Verify that CNPrimaryCheck is defined or imported correctly in the file. If it is a global variable, ensure it is accessible in the context where it is being used.

Security Concerns:

  • Security: While the changes in the file do not directly introduce security vulnerabilities, the removal of imports and changes in condition checks can potentially lead to runtime errors or unexpected behavior if not handled correctly.
  • Suggestion: Conduct thorough testing after making these changes to ensure that the functionality of the code is not compromised and that there are no security vulnerabilities introduced.

Optimization Suggestions:

  • Code Cleanup: Consider cleaning up any unused variables or functions in the file to improve code readability and maintainability.
  • Consistency: Ensure consistency in variable naming and coding style throughout the file for better code maintenance.

Overall Recommendations:

  • Testing: After addressing the issues mentioned above, thoroughly test the code to validate its correctness and ensure that the changes do not introduce new bugs or regressions.
  • Documentation: Update any relevant documentation or comments to reflect the changes made in the codebase for better understanding by other developers.

By addressing the issues mentioned above and following the suggestions provided, the codebase can be improved in terms of functionality, maintainability, and security.

Here are review comments for file pkg/sql/plan/build_update.go:

Pull Request Review:

Title and Body:

The title and body of the pull request indicate that the commit being reverted is related to fixing an issue with TPCC hanging. The PR is reverting a specific commit that replaced point locks with table locks in some cases. The PR is marked as a bug fix and references the related issue on GitHub. The reason provided for the revert is to fix the TPCC hang issue.

Changes in pkg/sql/plan/build_update.go:

  1. Problem:

    • The removal of the line upPlanCtx.lockTable = ifNeedLockWholeTable(builder, lastNodeId) can potentially reintroduce the issue of TPCC hanging that was previously addressed by replacing point locks with table locks.
  2. Suggestion:

    • Instead of reverting the entire commit, consider revisiting the changes made in the original commit that replaced point locks with table locks. Analyze why the change was made and whether there is a better way to address the TPCC hang issue without reverting the entire commit.
    • If the original change was necessary for performance or correctness reasons, find a way to retain the improvements while addressing the TPCC hang issue in a different manner.

Overall Suggestions:

  1. Investigate the Root Cause:

    • Before reverting changes, ensure that the root cause of the TPCC hang issue is thoroughly investigated. Reverting changes without understanding the underlying problem may not be the most effective solution.
  2. Partial Revert or Alternative Solution:

    • Consider partial reverting the commit or finding an alternative solution that addresses the TPCC hang issue without undoing the improvements made in the original commit.
  3. Testing:

    • After making any changes, ensure thorough testing, especially related to TPCC scenarios, to validate that the issue is resolved without introducing new problems.
  4. Documentation:

    • Update the documentation or comments to reflect the reason for the revert and any new changes made to address the TPCC hang issue.

By carefully analyzing the impact of the revert and considering alternative solutions, you can ensure that the codebase remains stable and the TPCC hang issue is effectively resolved.

Here are review comments for file pkg/sql/plan/build_util.go:

Pull Request Review:

Title and Body:

The title and body of the pull request indicate that it is reverting a previous commit that attempted to fix an issue related to TPCC hanging. The PR is marked as a bug fix and references the specific issue it addresses. The reason for the revert is not explicitly mentioned in the body, but it seems to be related to the fix causing unexpected behavior or issues.

Changes in pkg/sql/plan/build_util.go:

  1. Removed Function ifNeedLockWholeTable:

    • The function ifNeedLockWholeTable has been completely removed from the codebase.
    • This function was responsible for checking if the whole table needed to be locked based on certain conditions.
    • Problem: Removing this function without a clear explanation or replacement could potentially lead to unintended consequences or missing functionality.
    • Suggestion: If the function is no longer needed, ensure that its functionality is no longer required in the codebase. If it is still necessary, consider refactoring it rather than outright removal.
  2. Commented Out Code:

    • Several lines of code related to the removed function have been commented out.
    • Problem: Commented out code can clutter the codebase and make it harder to understand the purpose of the code.
    • Suggestion: Remove the commented-out code entirely to maintain code cleanliness and improve readability.

Security Implications:

  • The removal of the ifNeedLockWholeTable function could potentially introduce security vulnerabilities if table locking logic was crucial for ensuring data integrity or preventing race conditions.
  • It is important to ensure that any changes related to locking mechanisms are thoroughly reviewed to prevent unauthorized access or data corruption.

Optimization Suggestions:

  • Consider providing a more detailed explanation in the pull request body regarding the reason for reverting the commit. This will help other team members understand the decision and prevent confusion.
  • If the functionality provided by ifNeedLockWholeTable is still required but needed modifications, consider refactoring the function instead of removing it entirely to maintain the code's integrity and functionality.

Overall:

The pull request effectively reverts a previous commit, but the removal of the ifNeedLockWholeTable function without clear justification raises concerns about potential impacts on the codebase. It is essential to ensure that such changes are thoroughly reviewed and tested to maintain the stability and security of the application. Additionally, providing more detailed explanations in the pull request body can help improve transparency and collaboration within the development team.

Here are review comments for file pkg/sql/plan/query_builder.go:

Pull Request Review:

Title:

The title of the pull request indicates a revert action for a specific fix related to replacing point locks with table locks in some cases.

Body:

The body of the pull request provides information about the type of PR (Bug fix), the issue it fixes (issue #3039), and the reason for the PR (fixing tpcc hung).

Changes in pkg/sql/plan/query_builder.go:

  1. Removed Code:
    • The code related to ifLockTable variable and its usage has been removed.
    • The condition ifNeedLockWholeTable(builder, nodeID) and the associated logic have been removed.

Feedback and Suggestions:

  1. Reverting Changes:

    • Reverting a commit should be done with caution, especially if it was intended to fix a specific issue. Ensure that the reason for the revert is well-understood and justified.
    • It's important to investigate why the original fix was implemented and whether reverting it will reintroduce the issue or create new problems.
  2. Code Removal:

    • Removing code without a clear explanation in the pull request can be confusing. It's essential to provide a detailed reason for the removal of specific logic or variables to help reviewers understand the intention behind the change.
    • If the ifLockTable variable and related logic were crucial for the functionality or performance, consider revisiting the decision to remove them.
  3. Optimization and Clarity:

    • When making changes to code, ensure that the modifications improve clarity, maintainability, or performance.
    • If the removal of ifLockTable was necessary, consider updating comments or documentation to explain why it was no longer needed.
  4. Security Considerations:

    • When handling locks in a database system, it's crucial to ensure that the locking mechanisms are correctly implemented to prevent data inconsistencies or concurrency issues.
    • Verify that the removal of ifLockTable does not compromise the integrity or security of the system, especially in a multi-user or concurrent environment.
  5. Testing:

    • After reverting the changes, thorough testing should be conducted to validate that the issue reported (tpcc hung) is resolved without introducing regressions or new bugs.
    • Consider adding test cases or scenarios that cover the problematic behavior to prevent similar issues in the future.

In conclusion, while the revert action has been taken to address the reported issue, it is essential to review the impact of the reverted changes and ensure that the codebase remains stable and secure. Communication and documentation regarding the reasons for the revert can help maintain transparency and facilitate collaboration among team members.

@sukki37
sukki37 merged commit cd1ac40 into matrixorigin:main Apr 25, 2024
@jensenojs
jensenojs deleted the revert branch April 25, 2024 07:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/S Denotes a PR that changes [10,99] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants