Skip to content

Remove list checkpoint meta file (#16723) - #16918

Merged
mergify[bot] merged 3 commits into
matrixorigin:1.2-devfrom
LeftHandCold:debug_1.2.4
Jun 15, 2024
Merged

mergify[bot] merged 3 commits into
matrixorigin:1.2-devfrom
LeftHandCold:debug_1.2.4

Conversation

@LeftHandCold

@LeftHandCold LeftHandCold commented Jun 15, 2024 •

Copy link
Copy Markdown
Collaborator

User description

Remove list checkpoint meta file

Approved by: @XuPeng-SH

What type of PR is this?

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

Which issue(s) this PR fixes:

issue #16043

What this PR does / why we need it:

Remove list checkpoint meta file


PR Type

Enhancement, Bug fix


Description

  • Added EncodeCheckpointMetadataFileNameWithoutDir function to generate checkpoint metadata filenames without directory paths.
  • Extended RunnerReader interface with methods for managing checkpoint metadata files.
  • Introduced a new structure in runner to manage checkpoint metadata files, with methods to add, remove, and get these files.
  • Added ListSnapshotMetaWithDiskCleaner function to list snapshot metadata with disk cleaner.
  • Updated GC check logic to use new checkpoint metadata management.
  • Enhanced checkpointCleaner with a method to get checkpoints and updated merge logic to handle checkpoint metadata files.
  • Fixed batch closing logic in SaveFullTable method.

Changes walkthrough 📝

Relevant files
Enhancement
types.go
Add function to encode checkpoint metadata filename without directory

pkg/vm/engine/tae/blockio/types.go

  • Added EncodeCheckpointMetadataFileNameWithoutDir function to generate
    checkpoint metadata filenames without directory paths.
  • +4/-0     
    info.go
    Extend RunnerReader interface with checkpoint metadata management

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

  • Added methods to RunnerReader interface for managing checkpoint
    metadata files.
  • +2/-0     
    replay.go
    Add locking for checkpoint metadata files in replay           

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

  • Added locking mechanism to manage checkpoint metadata files during
    replay.
  • +3/-0     
    runner.go
    Manage checkpoint metadata files in runner                             

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

  • Introduced a new structure to manage checkpoint metadata files.
  • Added methods to add, remove, and get checkpoint metadata files.
  • +33/-0   
    snapshot.go
    Add function to list snapshot metadata with disk cleaner 

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

  • Added ListSnapshotMetaWithDiskCleaner function to list snapshot
    metadata with disk cleaner.
  • +35/-0   
    check.go
    Update GC check logic for checkpoint metadata management 

    pkg/vm/engine/tae/db/gc/check.go

    • Updated GC check logic to use new checkpoint metadata management.
    +17/-2   
    checkpoint.go
    Enhance checkpoint cleaner with metadata management           

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

  • Added method to get checkpoints in checkpointCleaner.
  • Updated merge logic to handle checkpoint metadata files.
  • +17/-4   
    Bug fix
    table.go
    Fix batch closing logic in SaveFullTable                                 

    pkg/vm/engine/tae/db/gc/table.go

    • Fixed batch closing logic in SaveFullTable method.
    +1/-1     

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

    Remove list checkpoint meta file
    
    Approved by: @XuPeng-SH
    @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 [1-5]

    4

    🧪 Relevant tests

    No

    🔒 Security concerns

    No

    ⚡ Key issues to review

    Thread Safety:
    The implementation of locking mechanism around the checkpoint metadata files management should be reviewed to ensure thread safety. The use of sync.RWMutex is appropriate, but the actual locking and unlocking operations should be carefully checked to prevent potential deadlocks or race conditions.

    Error Handling:
    There are several places in the code where errors are either logged or ignored but not handled properly. For example, in the saveCheckpoint function, the error from writer.WriteEnd is checked but not returned, which could lead to silent failures.

    Resource Management:
    The closeBatch method is now called conditionally within SaveFullTable, which might lead to resource leaks if not all paths that allocate resources are properly managed.

    @mergify
    mergify Bot requested a review from sukki37 June 15, 2024 01:59
    @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 Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Best practice
    Defer the unlock operation immediately after acquiring the lock to avoid potential deadlocks

    To avoid potential deadlocks, it's better to defer the unlock operation immediately after
    acquiring the lock.

    pkg/vm/engine/tae/db/checkpoint/replay.go [65-75]

     r.checkpointMetaFiles.Lock()
    +defer r.checkpointMetaFiles.Unlock()
     for i, dir := range dirs {
         r.checkpointMetaFiles.files[dir.Name] = struct{}{}
         start, end := blockio.DecodeCheckpointMetadataFileName(dir.Name)
         metaFiles = append(metaFiles, &MetaFile{
             start: start,
             end:   end,
             index: i,
         })
     }
    -r.checkpointMetaFiles.Unlock()
     
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: The suggestion correctly identifies a best practice in Go for managing mutex locks, which can prevent potential deadlocks by ensuring the lock is always unlocked even if a panic occurs between the lock and unlock calls.

    8
    Use a constructor function to initialize the checkpointMetaFiles struct to avoid potential race conditions

    To avoid potential race conditions, consider initializing the checkpointMetaFiles struct
    with a constructor function instead of directly in the NewRunner function.

    pkg/vm/engine/tae/db/checkpoint/runner.go [281]

    -r.checkpointMetaFiles.files = make(map[string]struct{})
    +r.checkpointMetaFiles = newCheckpointMetaFiles()
     
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    Why: This suggestion promotes a safer initialization pattern that can help avoid race conditions, especially in a multi-threaded environment. It's a good practice to encapsulate initialization logic within a constructor.

    7
    Performance
    Use a buffered channel for logging errors to improve performance

    To improve performance, consider using a buffered channel for logging errors in the Check
    function.

    pkg/vm/engine/tae/db/gc/check.go [131-136]

    -logutil.Errorf("[Check GC]lost checkpoint file %s", ckp.GetName())
    +errCh := make(chan string, len(checkFiles))
    +for _, ckp := range checkFiles {
    +    if _, ok := ckpfiles[ckp.GetName()]; !ok {
    +        errCh <- fmt.Sprintf("[Check GC]lost checkpoint file %s", ckp.GetName())
    +        continue
    +    }
    +    delete(ckpfiles, ckp.GetName())
    +}
    +close(errCh)
    +for err := range errCh {
    +    logutil.Errorf(err)
    +}
     
    • Apply this suggestion
    Suggestion importance[1-10]: 6

    Why: Using a buffered channel for error logging can indeed improve performance by reducing blocking on error logging. However, the impact might be limited depending on the frequency and volume of errors, thus the moderate score.

    6
    Enhancement
    Rename the listFunc parameter to checkpointRangeFunc for better readability and clarity

    To improve readability and avoid potential issues, consider renaming the listFunc
    parameter to checkpointRangeFunc to better reflect its purpose.

    pkg/vm/engine/tae/db/checkpoint/snapshot.go [109]

    -listFunc GetCheckpointRange,
    +checkpointRangeFunc GetCheckpointRange,
     
    • Apply this suggestion
    Suggestion importance[1-10]: 5

    Why: The suggestion is valid and improves code readability by making the parameter name more descriptive, although it's a minor enhancement and doesn't impact functionality.

    5

    @matrix-meow matrix-meow added the size/M Denotes a PR that changes [100,499] lines label Jun 15, 2024
    @mergify
    mergify Bot merged commit 7ec65cf into matrixorigin:1.2-dev Jun 15, 2024
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    4 participants