-
Notifications
You must be signed in to change notification settings - Fork 2.4k
[release-24.0] VDiff: save a sample for every drained extra row so reconciliation can match them (#20855) #20943
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
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 |
|---|---|---|
|
|
@@ -581,7 +581,14 @@ func (td *tableDiffer) diff(ctx context.Context, coreOpts *tabletmanagerdatapb.V | |
| maxReportSampleRows := reportOpts.GetMaxSampleRows() | ||
|
|
||
| for { | ||
| lastProcessedRow = sourceRow | ||
| // Only advance the persisted position when the previous iteration | ||
| // consumed the held source row (advanceSource still holds that | ||
| // iteration's decision here). After an extra-target-row iteration the | ||
| // held source row has not been processed yet, and recording it as | ||
| // lastpk would make a resumed diff skip it permanently. | ||
| if advanceSource { | ||
| lastProcessedRow = sourceRow | ||
|
Comment on lines
+589
to
+590
|
||
| } | ||
|
|
||
| select { | ||
| case <-ctx.Done(): | ||
|
|
@@ -629,35 +636,60 @@ func (td *tableDiffer) diff(ctx context.Context, coreOpts *tabletmanagerdatapb.V | |
| advanceSource = true | ||
| advanceTarget = true | ||
| if sourceRow == nil { | ||
| diffRow, err := td.genRowDiff(td.tablePlan.sourceQuery, targetRow, reportOpts) | ||
| if err != nil { | ||
| return nil, vterrors.Wrap(err, "unexpected error generating diff") | ||
| } | ||
| dr.ExtraRowsTargetDiffs = append(dr.ExtraRowsTargetDiffs, diffRow) | ||
|
|
||
| // Drain target, update count. | ||
| count, err := targetExecutor.drain(ctx) | ||
| if err != nil { | ||
| return nil, err | ||
| // No more rows from the source; drain the remaining target rows, | ||
| // saving a sample for each one (up to maxExtraRowsToCompare) so that | ||
| // reconcileExtraRows can match them against any extra source rows. | ||
| // Counting drained rows without saving a sample makes them impossible | ||
| // to reconcile, producing false positive extra rows in the report. | ||
| // The drained rows are merged into the report only after the full | ||
| // drain succeeds: they are beyond the persisted lastpk, so partially | ||
| // counted rows would be counted again when a failed diff is resumed. | ||
| drainedRows := int64(0) | ||
| var drainedDiffs []*RowDiff | ||
| for targetRow != nil { | ||
| if dr.ExtraRowsTarget+drainedRows < maxExtraRowsToCompare { | ||
| diffRow, err := td.genRowDiff(td.tablePlan.targetQuery, targetRow, reportOpts) | ||
|
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.
When a workflow projection transforms or renames columns, such as Useful? React with 👍 / 👎. |
||
| if err != nil { | ||
| return nil, vterrors.Wrap(err, "unexpected error generating diff") | ||
| } | ||
| drainedDiffs = append(drainedDiffs, diffRow) | ||
| } | ||
| drainedRows++ | ||
| targetRow, err = targetExecutor.next() | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| } | ||
| dr.ExtraRowsTarget += 1 + count | ||
| dr.ProcessedRows += 1 + count | ||
| dr.ExtraRowsTarget += drainedRows | ||
| dr.ProcessedRows += drainedRows | ||
| dr.ExtraRowsTargetDiffs = append(dr.ExtraRowsTargetDiffs, drainedDiffs...) | ||
| return dr, nil | ||
| } | ||
| if targetRow == nil { | ||
| // No more rows from the target but we know we have more rows from | ||
| // source, so drain them and update the counts. | ||
| diffRow, err := td.genRowDiff(td.tablePlan.sourceQuery, sourceRow, reportOpts) | ||
| if err != nil { | ||
| return nil, vterrors.Wrap(err, "unexpected error generating diff") | ||
| } | ||
| dr.ExtraRowsSourceDiffs = append(dr.ExtraRowsSourceDiffs, diffRow) | ||
| count, err := sourceExecutor.drain(ctx) | ||
| if err != nil { | ||
| return nil, err | ||
| // No more rows from the target; drain the remaining source rows, | ||
| // saving a sample for each one (up to maxExtraRowsToCompare) so that | ||
| // reconcileExtraRows can match them against any extra target rows. | ||
| // As above, the drained rows are merged into the report only after | ||
| // the full drain succeeds. | ||
| drainedRows := int64(0) | ||
| var drainedDiffs []*RowDiff | ||
| for sourceRow != nil { | ||
| if dr.ExtraRowsSource+drainedRows < maxExtraRowsToCompare { | ||
| diffRow, err := td.genRowDiff(td.tablePlan.sourceQuery, sourceRow, reportOpts) | ||
| if err != nil { | ||
| return nil, vterrors.Wrap(err, "unexpected error generating diff") | ||
| } | ||
| drainedDiffs = append(drainedDiffs, diffRow) | ||
| } | ||
| drainedRows++ | ||
| sourceRow, err = sourceExecutor.next() | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| } | ||
| dr.ExtraRowsSource += 1 + count | ||
| dr.ProcessedRows += 1 + count | ||
| dr.ExtraRowsSource += drainedRows | ||
| dr.ProcessedRows += drainedRows | ||
| dr.ExtraRowsSourceDiffs = append(dr.ExtraRowsSourceDiffs, drainedDiffs...) | ||
|
Comment on lines
+690
to
+692
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.
When the target is exhausted immediately after an extra-target comparison, AGENTS.md reference: AGENTS.md:L119-L124 Useful? React with 👍 / 👎. |
||
| return dr, 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.
This changes user-visible VDiff reconciliation results and also adds
LosslessValuesto serialized row samples, but the commit contains no release/deployment-note update. Add the required callout so operators and report consumers are informed of the changed behavior and JSON output.AGENTS.md reference: AGENTS.md:L232-L234
Useful? React with 👍 / 👎.