Skip to content

Mo inspect checkpoint command - #17795

Merged
mergify[bot] merged 6 commits into
matrixorigin:mainfrom
Wenbin1002:mo-inspect-checkpoint
Aug 1, 2024
Merged

mergify[bot] merged 6 commits into
matrixorigin:mainfrom
Wenbin1002:mo-inspect-checkpoint

Conversation

@Wenbin1002

@Wenbin1002 Wenbin1002 commented Jul 30, 2024 •

Copy link
Copy Markdown
Contributor

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 #17698

What this PR does / why we need it:

Support for online commands of Checkpoint analysis tools


PR Type

Feature, Enhancement


Description

  • Added a new CheckpointArg command to support checkpoint analysis tools.
  • Enhanced existing commands with additional flags and improved JSON output.
  • Added methods for JSON serialization and checkpoint metadata retrieval in CheckpointData.
  • Introduced a new LSN method to the CheckpointEntry struct.

Changes walkthrough 📝

Relevant files
Enhancement
entry.go
Add LSN method to CheckpointEntry struct                                 

pkg/vm/engine/tae/db/checkpoint/entry.go

  • Added LSN method to CheckpointEntry struct.
+4/-0     
utils.go
Add JSON serialization and checkpoint metadata methods     

pkg/vm/engine/tae/logtail/utils.go

  • Added multiple structs for JSON serialization.
  • Implemented GetCheckpointMetaInfo and GetTableIds methods for
    CheckpointData.
  • +172/-0 
    Feature
    tool.go
    Add checkpoint command and enhance existing commands         

    pkg/vm/engine/tae/rpc/tool.go

  • Added CheckpointArg command with subcommands.
  • Enhanced existing commands with additional flags and improved JSON
    output.
  • +459/-115

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

    * checkpoint stat
    
    * update json res
    
    * update object size
    
    * add stat col
    
    * copyright info
    
    * fix sca
    
    * checkpoint list command
    
    * checkpoint list
    
    * update usage
    
    * fix
    
    * fix
    
    * fix
    
    * fix
    
    * fix
    
    * fix sca
    
    * add limit flag
    @qodo-code-review

    Copy link
    Copy Markdown

    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: 4 🔵🔵🔵🔵⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Key issues to review

    Performance Concern
    The method GetCheckpointMetaInfo in utils.go appears to be computationally expensive and complex due to nested loops and multiple condition checks. Consider optimizing this method by reducing complexity or refactoring into smaller, more manageable functions.

    Data Integrity
    The method GetDetailedStat in tool.go does not handle cases where column data might be missing or malformed. This could lead to incorrect data representation or runtime errors. Consider adding checks and validations for data completeness and integrity.

    @qodo-code-review

    qodo-code-review Bot commented Jul 30, 2024 •

    Copy link
    Copy Markdown

    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
    Error handling
    Improve error handling by checking the return values from flag retrieval

    For better error handling, consider checking the return value of
    cmd.Flags().GetInt("col") and cmd.Flags().GetInt("id") to handle potential errors
    explicitly rather than ignoring them.

    pkg/vm/engine/tae/rpc/tool.go [258-259]

    -c.id, _ = cmd.Flags().GetInt("id")
    -c.col, _ = cmd.Flags().GetInt("col")
    +c.id, err = cmd.Flags().GetInt("id")
    +if err != nil {
    +    return fmt.Errorf("error getting id: %v", err)
    +}
    +c.col, err = cmd.Flags().GetInt("col")
    +if err != nil {
    +    return fmt.Errorf("error getting column: %v", err)
    +}
     
    • Apply this suggestion
    Suggestion importance[1-10]: 9

    Why: This suggestion addresses potential runtime errors by adding proper error handling, which is important for robustness and reliability of the code.

    9
    Possible bug
    Add nil checks for data.bats[BLKMetaInsertIDX] and data.bats[BLKCNMetaInsertIDX] to prevent nil pointer dereference

    To avoid potential nil pointer dereference, check if data.bats[BLKMetaInsertIDX] and
    data.bats[BLKCNMetaInsertIDX] are not nil before accessing their methods.

    pkg/vm/engine/tae/logtail/utils.go [2830-2847]

    -deltaLoc := objectio.Location(
    -    data.bats[BLKMetaInsertIDX].GetVectorByName(pkgcatalog.BlockMeta_DeltaLoc).Get(i).([]byte))
    -deltaLoc := objectio.Location(
    -    data.bats[BLKCNMetaInsertIDX].GetVectorByName(pkgcatalog.BlockMeta_DeltaLoc).Get(i).([]byte))
    +if data.bats[BLKMetaInsertIDX] != nil && data.bats[BLKCNMetaInsertIDX] != nil {
    +    deltaLoc := objectio.Location(
    +        data.bats[BLKMetaInsertIDX].GetVectorByName(pkgcatalog.BlockMeta_DeltaLoc).Get(i).([]byte))
    +    deltaLoc := objectio.Location(
    +        data.bats[BLKCNMetaInsertIDX].GetVectorByName(pkgcatalog.BlockMeta_DeltaLoc).Get(i).([]byte))
    +}
     
    • Apply this suggestion
    Suggestion importance[1-10]: 9

    Why: This suggestion addresses a potential runtime error by adding necessary nil checks, which is crucial for preventing crashes due to nil pointer dereference.

    9
    Add overflow checks when summing up data sizes to prevent integer overflow

    To avoid potential integer overflow when adding up dataSize and oriDataSize,
    consider using a larger integer type or adding checks to ensure values do not exceed
    the maximum size of uint32.

    pkg/vm/engine/tae/rpc/tool.go [406-407]

    -dataSize += col.Location().Length()
    -oriDataSize += col.Location().OriginSize()
    +dataSize, ok := checkedAddUint32(dataSize, col.Location().Length())
    +if !ok {
    +    return nil, fmt.Errorf("data size overflow")
    +}
    +oriDataSize, ok = checkedAddUint32(oriDataSize, col.Location().OriginSize())
    +if !ok {
    +    return nil, fmt.Errorf("original data size overflow")
    +}
     
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: The suggestion prevents potential integer overflow issues, which could lead to incorrect calculations or crashes. This is a significant improvement for ensuring data integrity.

    8
    Handle errors from vector.MustFixedCol to avoid runtime panics

    Consider handling the error returned by vector.MustFixedCol immediately to prevent
    runtime panics in case of an error.

    pkg/vm/engine/tae/logtail/utils.go [2856-2859]

    -insTableIDs := vector.MustFixedCol[uint64](
    +insTableIDs, err := vector.FixedCol[uint64](
         data.bats[ObjectInfoIDX].GetVectorByName(SnapshotAttr_TID).GetDownstreamVector())
    -insDeleteTSs := vector.MustFixedCol[types.TS](
    +if err != nil {
    +    return nil, err
    +}
    +insDeleteTSs, err := vector.FixedCol[types.TS](
         data.bats[ObjectInfoIDX].GetVectorByName(catalog.EntryNode_DeleteAt).GetDownstreamVector())
    +if err != nil {
    +    return nil, err
    +}
     
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: Handling errors immediately after calling vector.MustFixedCol is important for robustness, as it prevents potential runtime panics and ensures proper error propagation.

    8
    Best practice
    Rename constants to follow Go's naming conventions and improve readability

    It's recommended to use a more descriptive name for the constant invalidId and
    invalidLimit to reflect their purpose clearly. For example, InvalidID and
    InvalidLimit can be used to follow Go's naming conventions for constants.

    pkg/vm/engine/tae/rpc/tool.go [38-39]

    -invalidId    = 0x3f3f3f3f
    -invalidLimit = 0x3f3f3f3f
    +InvalidID    = 0x3f3f3f3f
    +InvalidLimit = 0x3f3f3f3f
     
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    Why: The suggestion improves code readability and follows Go's naming conventions for constants, which is a good practice. However, it is not crucial for functionality.

    7
    Enhancement
    Improve the error message to include specific context

    Use a more descriptive error message that includes the context of the error for
    better debugging.

    pkg/vm/engine/tae/logtail/utils.go [2849]

    -return nil, moerr.NewInfoNoCtx("failed to get checkpoint data, deltaLoc in empty")
    +return nil, moerr.NewInfoNoCtx("failed to get checkpoint data, deltaLoc is empty in BLKCNMetaInsertIDX")
     
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    Why: Enhancing the error message with specific context improves debugging and maintenance, making it easier to identify the source of the error.

    7
    Maintainability
    Refactor code to use a loop for appending ColumnJson objects to the cols slice

    Consider using a loop to append ColumnJson objects to cols instead of repeating the
    append operation. This will make the code cleaner and easier to maintain.

    pkg/vm/engine/tae/rpc/tool.go [466-470]

    -cols = append(cols, ColumnJson{
    -    Index:       idx,
    -    DataSize:    formatBytes(col.Location().Length()),
    -    OriDataSize: formatBytes(col.Location().OriginSize()),
    -    Zonemap:     col.ZoneMap().String(),
    -})
    +for _, col := range data.Columns {
    +    cols = append(cols, ColumnJson{
    +        Index:       col.Index,
    +        DataSize:    formatBytes(col.Location().Length()),
    +        OriDataSize: formatBytes(col.Location().OriginSize()),
    +        Zonemap:     col.ZoneMap().String(),
    +    })
    +}
     
    • Apply this suggestion
    Suggestion importance[1-10]: 6

    Why: The suggestion improves code maintainability and readability by reducing redundancy. However, it does not address a critical issue.

    6
    Performance
    Optimize map access and modification for better performance

    Use a more efficient method for checking if a key exists in a map before
    incrementing a counter to improve performance.

    pkg/vm/engine/tae/logtail/utils.go [2839-2841]

     if _, ok := tombstone[deltaLoc.Name().String()]; !ok {
         tombstone[deltaLoc.Name().String()] = struct{}{}
    -    tombstoneInfo[tid].delete++
     }
    +tombstoneInfo[tid].delete++
     
    • Apply this suggestion
    Suggestion importance[1-10]: 6

    Why: While the performance improvement is minor, optimizing map access and modification can be beneficial in performance-critical sections of the code.

    6

    @matrix-meow matrix-meow added the size/L Denotes a PR that changes [500,999] lines label Jul 30, 2024
    @mergify mergify Bot added the kind/feature label Jul 30, 2024
    @mergify
    mergify Bot merged commit 029a4f0 into matrixorigin:main Aug 1, 2024
    triump2020 added a commit to triump2020/matrixone that referenced this pull request Aug 1, 2024
    * support restore pitr phase2 (matrixorigin#17772)
    
    support restore pitr phase2
    
    Approved by: @iamlinjunhong, @daviszhen
    
    * split merge receivers from join operators  (matrixorigin#17759)
    
    从channel里收数据的任务应该只由merge算子来完成,join算子只负责call子节点,而不是直接访问channel
    
    Approved by: @aunjgr, @m-schen
    
    * fix unnecessary pipeline broken (matrixorigin#17777)
    
    以前的pipeline会在阻塞算子处断开。现在不需要这个逻辑了。避免pipeline在不必要的地方断开。
    
    Approved by: @ouyuanning, @XuPeng-SH
    
    * fix unnecessary merge scope in broadcast join (matrixorigin#17778)
    
    减少broadcast join中不必要的merge scope,减少pipeline的打断
    
    Approved by: @ouyuanning
    
    * [bug] stats: fix nil pointer (matrixorigin#17767)
    
    fix nil pointer in Merge function of stats info
    
    Approved by: @zhangxu19830126
    
    * Implement MySQL Encode()/Decode() function by AES (matrixorigin#17568)
    
    Implement Encode() and Decode() functions by AES
    
    Approved by: @fengttt, @heni02, @m-schen
    
    * Revert "fix unnecessary merge scope in broadcast join (matrixorigin#17778)" (matrixorigin#17787)
    
    先revert引入问题的pr,再继续调查
    
    Approved by: @ouyuanning
    
    * container/types: make empty Packer valid for use (matrixorigin#17780)
    
    Some packers may be used after Close. Make them work.
    
    Approved by: @XuPeng-SH
    
    * add sql length metric (matrixorigin#17792)
    
    增加sql 长度监控项。用于定位问题。
    
    Approved by: @qingxinhome
    
    * reduce flush&merge memory usage (matrixorigin#17768)
    
    1. reduce `TransferDestPos` size from 12B to 8B, which can reduce ~25%(16B -> 12B) memory usage for transfer map.
    2. During a merge commit, avoid creating a map with rowid as values to save memory. Only generate the corresponding rowid when needed for transfer, using the TransferMap produced by the merge and createObjs.
    
    Result:
    Before:
    ![tmp k3FnO9DlPr](https://github.com/user-attachments/assets/b40ba6f0-f6d5-4d2c-9aad-191ae47f2280)
    
    
    After:
    ![tmp sbw8STJdBx](https://github.com/user-attachments/assets/29abd2a3-0346-409e-858b-664bfa8d0033)
    
    Diff:
    ![image](https://github.com/user-attachments/assets/cf16f961-1df4-4b24-bb75-686a1b16753d)
    
    Approved by: @LeftHandCold, @zhangxu19830126, @XuPeng-SH
    
    * refactor the three tables (matrixorigin#17721)
    
    * Revert "Small reader update (#75)"
    
    This reverts commit f39edde.
    
    * Revert "Revert "Small reader update (#75)""
    
    This reverts commit a414863.
    
    * support restore cluster by pitr (matrixorigin#17796)
    
    support restore cluster by pitr
    
    Approved by: @iamlinjunhong, @daviszhen
    
    * fix bug: panic when get vector (type.Oid is T_any) from pool (matrixorigin#17801)
    
    fix bug: panic when get vector (type.Oid is T_any) from pool
    
    Approved by: @m-schen, @XuPeng-SH, @aunjgr
    
    * remove unnecessary merge scope in broadcast join (matrixorigin#17808)
    
    在某些场景下,broadcast join的probe端会merge不止一次。 这个pr的目标是保证一定只merge一次。
    之前测试场景覆盖不够充分,现在已经重新跑了多个测试场景。
    
    Approved by: @m-schen, @ouyuanning, @aunjgr
    
    * refactor message framework (matrixorigin#17786)
    
    该pr本身没有实质性逻辑改动,将message从process包中独立出来,并修改message的api接口,为后续重构做准备
    
    Approved by: @qingxinhome, @triump2020, @m-schen, @ouyuanning, @fengttt, @aunjgr, @XuPeng-SH
    
    * Handle data race when get table def (matrixorigin#17774)
    
    * Session disable agg stmt (matrixorigin#17802)
    
    change
    1. support session variable `disable_agg_statement`
    - default: off
    - if set on, this session will do NO statement aggregation.
    2. base on `disable_agg_statement`, fix 2 bvt case
    - case: result_count.sql
    - case: statement_query_type_1.sql
    
    Approved by: @heni02, @daviszhen
    
    * fileservice: add active reader metrics to object storage (matrixorigin#17799)
    
    more metrics for active object storage readers.
    
    Approved by: @zhangxu19830126, @fengttt
    
    * More constant fold for expression executor (matrixorigin#17779)
    
    More constant fold for expression executor
    
    Approved by: @m-schen, @heni02
    
    * Mo inspect checkpoint command (matrixorigin#17795)
    
    Support for online commands of Checkpoint analysis tools
    
    Approved by: @aptend, @LeftHandCold, @XuPeng-SH
    
    * merge main
    
    * make pb
    
    ---------
    
    Co-authored-by: YANGGMM <[email protected]>
    Co-authored-by: nitao <[email protected]>
    Co-authored-by: LiuBo <[email protected]>
    Co-authored-by: Charles Chi Le <[email protected]>
    Co-authored-by: reusee <[email protected]>
    Co-authored-by: davis zhen <[email protected]>
    Co-authored-by: Wei Ziran <[email protected]>
    Co-authored-by: aptend <[email protected]>
    Co-authored-by: ou yuanning <[email protected]>
    Co-authored-by: qingxinhome <[email protected]>
    Co-authored-by: Jackson <[email protected]>
    Co-authored-by: Wenbin <[email protected]>
    fengttt pushed a commit to fengttt/matrixone that referenced this pull request May 7, 2026
    Support for online commands of Checkpoint analysis tools
    
    Approved by: @aptend, @LeftHandCold, @XuPeng-SH
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Labels

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    5 participants