-
Notifications
You must be signed in to change notification settings - Fork 306
sync-diff-inspector: calculate checksum only with export-fix-sql = false
#12531
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
Changes from all commits
15e04f8
38de6f3
5af0c21
bfa8476
eb6a537
9b5e979
34008c5
0cb0681
bd1b8a7
f90ee22
d4aa85a
3ca1ccf
09d0ec9
ca3f527
3317a75
da208b7
7724757
5ac196d
397398f
d3c496e
81e9fe7
3a196ed
94e0276
2f87d92
0981412
c1a8edc
5b21f12
e4e249e
f029a3d
e5193b9
41ead0e
196acc9
c65078b
0592329
9052fd3
aa19e10
a698a49
6a9564b
db7859b
e2d447d
95f6c0e
faf8fd2
b9366ab
8ed8109
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -150,11 +150,46 @@ type Checkpoint struct { | |
| hp *nodeHeap | ||
| } | ||
|
|
||
| // SavedState contains the information of the latest checked chunk and state of `report` | ||
| // When sync-diff start from the checkpoint, it will load this information and continue running | ||
| // ChecksumSourceState stores one source's checksum progress in global-checksum mode. | ||
| type ChecksumSourceState struct { | ||
| LastRange *chunk.Range `json:"last-range,omitempty"` | ||
| Checksum uint64 `json:"checksum"` | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we add omitempty for other fields too
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in joechenrh@faf8fd2 . Added |
||
| Count int64 `json:"count"` | ||
| Done bool `json:"done"` | ||
|
D3Hunter marked this conversation as resolved.
|
||
| } | ||
|
|
||
| // ChecksumState stores checkpoint progress for global-checksum mode. | ||
| type ChecksumState struct { | ||
| TableIndex int `json:"table-index"` | ||
| Upstream *ChecksumSourceState `json:"upstream,omitempty"` | ||
| Downstream *ChecksumSourceState `json:"downstream,omitempty"` | ||
| } | ||
|
|
||
| // NewChecksumState returns an initialized checksum state for one table index. | ||
| func NewChecksumState(tableIndex int) *ChecksumState { | ||
| return &ChecksumState{ | ||
| TableIndex: tableIndex, | ||
| Upstream: &ChecksumSourceState{}, | ||
| Downstream: &ChecksumSourceState{}, | ||
| } | ||
| } | ||
|
|
||
| func (s *ChecksumState) init() { | ||
| if s.Upstream == nil { | ||
| s.Upstream = &ChecksumSourceState{} | ||
| } | ||
| if s.Downstream == nil { | ||
| s.Downstream = &ChecksumSourceState{} | ||
| } | ||
| } | ||
|
|
||
| // SavedState stores mode-dependent checkpoint state plus report state for resume. | ||
| // Depending on the execution mode, it contains either Chunk (chunk diff mode) | ||
| // or Checksum (global-checksum mode). | ||
| type SavedState struct { | ||
|
D3Hunter marked this conversation as resolved.
joechenrh marked this conversation as resolved.
|
||
| Chunk *Node `json:"chunk-info"` | ||
| Report *report.Report `json:"report-info"` | ||
| Chunk *Node `json:"chunk-info,omitempty"` | ||
| Checksum *ChecksumState `json:"checksum-info,omitempty"` | ||
| Report *report.Report `json:"report-info"` | ||
| } | ||
|
|
||
| // InitCurrentSavedID the method is only used in initialization without lock, be cautious | ||
|
|
@@ -258,16 +293,56 @@ func (cp *Checkpoint) SaveChunk(ctx context.Context, fileName string, cur *Node, | |
| return cur.GetID(), nil | ||
| } | ||
|
|
||
| // LoadChunk loads chunk info from file `chunk` | ||
| func (cp *Checkpoint) LoadChunk(fileName string) (*Node, *report.Report, error) { | ||
| // SaveChecksumState saves global-checksum checkpoint state to file. | ||
| func (cp *Checkpoint) SaveChecksumState( | ||
| ctx context.Context, | ||
| fileName string, | ||
| state *ChecksumState, | ||
| reportInfo *report.Report, | ||
| ) error { | ||
| savedState := &SavedState{ | ||
| Checksum: state, | ||
| Report: reportInfo, | ||
| } | ||
| checkpointData, err := json.Marshal(savedState) | ||
| if err != nil { | ||
| log.Warn("fail to save checksum checkpoint", zap.Error(err)) | ||
| return errors.Trace(err) | ||
| } | ||
|
|
||
| return writeFileAtomic(fileName, checkpointData, config.LocalFilePerm) | ||
| } | ||
|
|
||
| func loadSavedState(fileName string) (*SavedState, error) { | ||
| bytes, err := os.ReadFile(fileName) | ||
| if err != nil { | ||
| return nil, nil, errors.Trace(err) | ||
| return nil, errors.Trace(err) | ||
| } | ||
| n := &SavedState{} | ||
| err = json.Unmarshal(bytes, n) | ||
| if err != nil { | ||
| return nil, errors.Trace(err) | ||
| } | ||
| if n.Checksum != nil { | ||
| n.Checksum.init() | ||
| } | ||
| return n, nil | ||
| } | ||
|
|
||
| // LoadChunk loads chunk info from file `chunk` | ||
| func (cp *Checkpoint) LoadChunk(fileName string) (*Node, *report.Report, error) { | ||
| n, err := loadSavedState(fileName) | ||
| if err != nil { | ||
| return nil, nil, errors.Trace(err) | ||
| } | ||
| return n.Chunk, n.Report, nil | ||
| } | ||
|
|
||
| // LoadChecksumState loads checksum checkpoint state from file. | ||
| func (cp *Checkpoint) LoadChecksumState(fileName string) (*ChecksumState, *report.Report, error) { | ||
| n, err := loadSavedState(fileName) | ||
| if err != nil { | ||
| return nil, nil, errors.Trace(err) | ||
| } | ||
| return n.Checksum, n.Report, nil | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does checksum-only mode the
global checksum?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep — when
export-fix-sql=falseand both sources implementChecksumCapableSource, the tool routes intoequalByGlobalChecksumwhich computes a single aggregated checksum per table (XOR of per-chunk CRC32), comparing the final value between upstream and downstream. Unified the terminology to "global checksum" throughout the codebase in joechenrh@faf8fd2 👍