From c5ad5640e38b0f2e0b5fd7f55f898aeb5c2957da Mon Sep 17 00:00:00 2001 From: "vitess-bot[bot]" <108069721+vitess-bot[bot]@users.noreply.github.com> Date: Wed, 3 Dec 2025 01:19:04 -0500 Subject: [PATCH] vdiff: do not sort by table name in summary, it is not necessary (#18972) Signed-off-by: Nick Van Wiggeren --- .../command/vreplication/vdiff/vdiff.go | 2 +- go/vt/vtctl/workflow/vdiff.go | 16 +++++++++++ go/vt/vtctl/workflow/vdiff_test.go | 27 +++++++++++++++++++ go/vt/vttablet/tabletmanager/vdiff/schema.go | 2 +- 4 files changed, 45 insertions(+), 2 deletions(-) diff --git a/go/cmd/vtctldclient/command/vreplication/vdiff/vdiff.go b/go/cmd/vtctldclient/command/vreplication/vdiff/vdiff.go index 94147fd3550..f980dcf699e 100644 --- a/go/cmd/vtctldclient/command/vreplication/vdiff/vdiff.go +++ b/go/cmd/vtctldclient/command/vreplication/vdiff/vdiff.go @@ -438,7 +438,7 @@ HasMismatch: {{.HasMismatch}} StartedAt: {{.StartedAt}} {{if (eq .State "started")}}Progress: {{printf "%.2f" .Progress.Percentage}}%{{if .Progress.ETA}}, ETA: {{.Progress.ETA}}{{end}}{{end}} {{if .CompletedAt}}CompletedAt: {{.CompletedAt}}{{end}} -{{range $table := .TableSummaryMap}} +{{range $table := .SortedTableSummaries}} Table {{$table.TableName}}: State: {{$table.State}} ProcessedRows: {{$table.RowsCompared}} diff --git a/go/vt/vtctl/workflow/vdiff.go b/go/vt/vtctl/workflow/vdiff.go index 30953868b0b..ab5d50c1489 100644 --- a/go/vt/vtctl/workflow/vdiff.go +++ b/go/vt/vtctl/workflow/vdiff.go @@ -69,6 +69,22 @@ type Summary struct { Progress *vdiff.ProgressReport `json:"Progress,omitempty"` } +// SortedTableSummaries returns the table summaries sorted alphabetically by table name. +// This is used by text templates to display tables in a consistent order. +func (s *Summary) SortedTableSummaries() []TableSummary { + names := make([]string, 0, len(s.TableSummaryMap)) + for name := range s.TableSummaryMap { + names = append(names, name) + } + sort.Strings(names) + + result := make([]TableSummary, 0, len(names)) + for _, name := range names { + result = append(result, s.TableSummaryMap[name]) + } + return result +} + // BuildSummary generates a summary from a vdiff show response. func BuildSummary(keyspace, workflow, uuid string, resp *vtctldatapb.VDiffShowResponse, verbose bool) (*Summary, error) { summary := &Summary{ diff --git a/go/vt/vtctl/workflow/vdiff_test.go b/go/vt/vtctl/workflow/vdiff_test.go index 0da4a3ef480..9c2c5cca77a 100644 --- a/go/vt/vtctl/workflow/vdiff_test.go +++ b/go/vt/vtctl/workflow/vdiff_test.go @@ -34,6 +34,33 @@ import ( vtctldatapb "vitess.io/vitess/go/vt/proto/vtctldata" ) +func TestSortedTableSummaries(t *testing.T) { + summary := &Summary{ + TableSummaryMap: map[string]TableSummary{ + "zebra": {TableName: "zebra"}, + "apple": {TableName: "apple"}, + "mango": {TableName: "mango"}, + }, + } + + sorted := summary.SortedTableSummaries() + + require.Len(t, sorted, 3) + require.Equal(t, "apple", sorted[0].TableName) + require.Equal(t, "mango", sorted[1].TableName) + require.Equal(t, "zebra", sorted[2].TableName) +} + +func TestSortedTableSummariesEmpty(t *testing.T) { + summary := &Summary{ + TableSummaryMap: map[string]TableSummary{}, + } + + sorted := summary.SortedTableSummaries() + + require.Len(t, sorted, 0) +} + func TestBuildProgressReport(t *testing.T) { now := time.Now() type args struct { diff --git a/go/vt/vttablet/tabletmanager/vdiff/schema.go b/go/vt/vttablet/tabletmanager/vdiff/schema.go index 9fef975e1e0..bb238cb8a7a 100644 --- a/go/vt/vttablet/tabletmanager/vdiff/schema.go +++ b/go/vt/vttablet/tabletmanager/vdiff/schema.go @@ -40,7 +40,7 @@ const ( vd.started_at as started_at, vdt.rows_compared as rows_compared, vd.completed_at as completed_at, IF(vdt.mismatch = 1, 1, 0) as has_mismatch, vdt.report as report from _vt.vdiff as vd left join _vt.vdiff_table as vdt on (vd.id = vdt.vdiff_id) - where vd.id = %a order by table_name` + where vd.id = %a` // sqlUpdateVDiffState has a penultimate placeholder for any additional columns you want to update, e.g. `, foo = 1`. // It also truncates the error if needed to ensure that we can save the state when the error text is very long. sqlUpdateVDiffState = "update _vt.vdiff set state = %s, last_error = left(%s, 1024) %s where id = %d"