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

Update txn print #16894

Merged
merged 4 commits into from
Jun 14, 2024
Merged

Update txn print #16894

merged 4 commits into from
Jun 14, 2024

Conversation

XuPeng-SH
Copy link
Contributor

@XuPeng-SH XuPeng-SH commented Jun 14, 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 #16883

What this PR does / why we need it:

print more detailed info


PR Type

Enhancement, Bug fix


Description

  • Enhanced NewTxnStaleNoCtx function to accept a message string for better error context.
  • Added makeCompactTxnInfo function to format transaction info and updated related transaction ID handling.
  • Replaced SetStaticTxnId and GetStaticTxnId with SetStaticTxnInfo and GetStaticTxnInfo in session handling.
  • Improved error logging to use transaction info instead of transaction ID.
  • Added TxnInfoField for logging transaction info.
  • Enhanced NewObjectsIter to include detailed error message.
  • Added error logging with transaction details in Ranges and MergeObjects functions in transaction table.

Changes walkthrough 📝

Relevant files
Enhancement
error_no_ctx.go
Enhance `NewTxnStaleNoCtx` with message parameter               

pkg/common/moerr/error_no_ctx.go

  • Modified NewTxnStaleNoCtx function to accept a message string.
  • Enhanced error handling with additional context.
  • +2/-2     
    mysql_cmd_executor.go
    Add compact transaction info formatting                                   

    pkg/frontend/mysql_cmd_executor.go

  • Added makeCompactTxnInfo function to format transaction info.
  • Updated transaction ID handling to use compact transaction info.
  • +7/-1     
    types.go
    Update session transaction info handling                                 

    pkg/frontend/types.go

  • Replaced SetStaticTxnId and GetStaticTxnId with SetStaticTxnInfo and
    GetStaticTxnInfo.
  • Updated session implementation to handle transaction info as string.
  • +7/-7     
    util.go
    Improve error logging with transaction info                           

    pkg/frontend/util.go

  • Updated error logging to use transaction info instead of transaction
    ID.
  • +8/-3     
    fields.go
    Add logging field for transaction info                                     

    pkg/logutil/fields.go

    • Added TxnInfoField for logging transaction info.
    +1/-0     
    blocks_iter.go
    Improve error message in `NewObjectsIter`                               

    pkg/vm/engine/disttae/logtailreplay/blocks_iter.go

    • Enhanced NewObjectsIter to include detailed error message.
    +3/-1     
    Bug fix
    txn_table.go
    Enhance error logging in transaction table operations       

    pkg/vm/engine/disttae/txn_table.go

  • Added error logging with transaction details in Ranges and
    MergeObjects.
  • +4/-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 Reviewer Guide 🔍

    ⏱️ Estimated effort to review [1-5]

    3

    🧪 Relevant tests

    No

    🔒 Security concerns

    No

    ⚡ Key issues to review

    Possible Bug:
    The NewTxnStaleNoCtx function now requires a message string, but existing calls to this function may not have been updated to include this parameter, leading to compilation errors.

    Refactoring Impact:
    The change from SetStaticTxnId and GetStaticTxnId to SetStaticTxnInfo and GetStaticTxnInfo might affect other parts of the system that depend on the transaction ID directly. It's important to ensure all relevant parts of the codebase are updated to handle this new method of transaction info management.

    @matrix-meow matrix-meow added the size/S Denotes a PR that changes [10,99] lines label Jun 14, 2024
    @mergify mergify bot requested a review from sukki37 June 14, 2024 06:11
    @mergify mergify bot added the kind/refactor Code refactor label Jun 14, 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 bug
    Add nil checks before logging transaction information to prevent nil pointer dereference

    To avoid potential nil pointer dereference, add a check to ensure tbl.db.op and
    tbl.db.op.Txn() are not nil before logging the error in the Ranges and MergeObjects
    methods.

    pkg/vm/engine/disttae/txn_table.go [662]

    -logutil.Errorf("txn: %s, error: %v", tbl.db.op.Txn().DebugString(), err)
    +if tbl.db.op != nil && tbl.db.op.Txn() != nil {
    +    logutil.Errorf("txn: %s, error: %v", tbl.db.op.Txn().DebugString(), err)
    +} else {
    +    logutil.Errorf("txn: nil, error: %v", err)
    +}
     
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: Adding nil checks is crucial to prevent runtime errors due to nil pointer dereference, which is a significant concern in Go.

    8
    Best practice
    Add synchronization to ensure thread safety when accessing shared data

    To ensure thread safety, consider adding synchronization mechanisms such as mutexes when
    accessing and modifying the staticTxnInfo field in the feSessionImpl struct.

    pkg/frontend/types.go [857]

    +ses.mu.Lock()
    +defer ses.mu.Unlock()
     ses.staticTxnInfo = info
     
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    Why: The suggestion to add synchronization mechanisms like mutexes is valid and important for ensuring thread safety in concurrent environments.

    7
    Maintainability
    Break down a long function call into multiple lines for better readability

    To improve readability and maintainability, consider breaking down the ses.Error call into
    multiple lines, each for a different field, in the logStatementStringStatus function.

    pkg/frontend/util.go [504-511]

    +ses.Error(
    +    ctx,
    +    "query trace status",
    +    logutil.StatementField(str),
    +    logutil.StatusField(status.String()),
    +    logutil.ErrorField(err),
    +    logutil.TxnInfoField(ses.GetStaticTxnInfo()),
    +)
     
    -
    • Apply this suggestion
    Suggestion importance[1-10]: 6

    Why: The suggestion correctly identifies a readability improvement by breaking down a long function call into multiple lines, enhancing maintainability.

    6

    @mergify mergify bot merged commit 6071110 into matrixorigin:1.2-dev Jun 14, 2024
    17 of 18 checks passed
    XuPeng-SH added a commit to XuPeng-SH/matrixone that referenced this pull request Jun 18, 2024
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    Bug fix Enhancement kind/refactor Code refactor Review effort [1-5]: 3 size/S Denotes a PR that changes [10,99] lines
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    7 participants