Skip to content

Conversation

@huanghaoyuanhhy
Copy link
Collaborator

No description provided.

@sre-ci-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: huanghaoyuanhhy

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@huanghaoyuanhhy
Copy link
Collaborator Author

/kind improvement

@sre-ci-robot sre-ci-robot added size/M kind/improvement Changes related to something improve, likes ut and code refactor labels Nov 27, 2025
@mergify mergify bot added the dco-passed label Nov 27, 2025
@mergify mergify bot added the ci-passed label Nov 27, 2025
@mergify mergify bot added ci-passed and removed ci-passed labels Nov 27, 2025
Copy link

@santiago-wjq santiago-wjq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Review: backup: improve write meta logic

Summary

This PR refactors the writeMeta function in core/backup/task.go, replacing repetitive meta build/write code blocks with a loop-based approach.

Changes Analysis

Before (~47 lines): 5 nearly identical code blocks for each meta type
After (~20 lines): Single loop iterating over a slice of meta entries

Pros ✅

  1. Reduces code duplication - Eliminates 5 repetitive code blocks
  2. Easier to maintain - Adding a new meta type only requires adding one line to the slice
  3. Consistent error handling - All meta types use the same error format pattern

Suggestions ⚠️

  1. Naming: The struct name metaTypes is slightly misleading since it represents a single meta entry, not multiple types. Consider renaming to metaEntry or metaWriter:

    type metaEntry struct {
        Type mpath.MetaType
        Fn   func() ([]byte, error)
    }
  2. Logger inconsistency: The function starts with t.logger.Info("start write meta") but ends with log.Info("finish write meta"). Consider using t.logger consistently for both.

Overall

Good refactoring that follows the DRY principle. The logic is correct and functionality remains unchanged. 👍

Signed-off-by: huanghaoyuanhhy <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved ci-passed dco-passed kind/improvement Changes related to something improve, likes ut and code refactor size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants