Skip to content

Commit 4b4ff40

Browse files
[release-22.0] vdiff: do not sort by table name in summary, it is not necessary (#18972) (#18977)
Signed-off-by: Nick Van Wiggeren <[email protected]> Co-authored-by: vitess-bot[bot] <108069721+vitess-bot[bot]@users.noreply.github.com>
1 parent d634143 commit 4b4ff40

File tree

4 files changed

+45
-2
lines changed

4 files changed

+45
-2
lines changed

go/cmd/vtctldclient/command/vreplication/vdiff/vdiff.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ HasMismatch: {{.HasMismatch}}
438438
StartedAt: {{.StartedAt}}
439439
{{if (eq .State "started")}}Progress: {{printf "%.2f" .Progress.Percentage}}%{{if .Progress.ETA}}, ETA: {{.Progress.ETA}}{{end}}{{end}}
440440
{{if .CompletedAt}}CompletedAt: {{.CompletedAt}}{{end}}
441-
{{range $table := .TableSummaryMap}}
441+
{{range $table := .SortedTableSummaries}}
442442
Table {{$table.TableName}}:
443443
State: {{$table.State}}
444444
ProcessedRows: {{$table.RowsCompared}}

go/vt/vtctl/workflow/vdiff.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,22 @@ type Summary struct {
6969
Progress *vdiff.ProgressReport `json:"Progress,omitempty"`
7070
}
7171

72+
// SortedTableSummaries returns the table summaries sorted alphabetically by table name.
73+
// This is used by text templates to display tables in a consistent order.
74+
func (s *Summary) SortedTableSummaries() []TableSummary {
75+
names := make([]string, 0, len(s.TableSummaryMap))
76+
for name := range s.TableSummaryMap {
77+
names = append(names, name)
78+
}
79+
sort.Strings(names)
80+
81+
result := make([]TableSummary, 0, len(names))
82+
for _, name := range names {
83+
result = append(result, s.TableSummaryMap[name])
84+
}
85+
return result
86+
}
87+
7288
// BuildSummary generates a summary from a vdiff show response.
7389
func BuildSummary(keyspace, workflow, uuid string, resp *vtctldatapb.VDiffShowResponse, verbose bool) (*Summary, error) {
7490
summary := &Summary{

go/vt/vtctl/workflow/vdiff_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,33 @@ import (
3434
vtctldatapb "vitess.io/vitess/go/vt/proto/vtctldata"
3535
)
3636

37+
func TestSortedTableSummaries(t *testing.T) {
38+
summary := &Summary{
39+
TableSummaryMap: map[string]TableSummary{
40+
"zebra": {TableName: "zebra"},
41+
"apple": {TableName: "apple"},
42+
"mango": {TableName: "mango"},
43+
},
44+
}
45+
46+
sorted := summary.SortedTableSummaries()
47+
48+
require.Len(t, sorted, 3)
49+
require.Equal(t, "apple", sorted[0].TableName)
50+
require.Equal(t, "mango", sorted[1].TableName)
51+
require.Equal(t, "zebra", sorted[2].TableName)
52+
}
53+
54+
func TestSortedTableSummariesEmpty(t *testing.T) {
55+
summary := &Summary{
56+
TableSummaryMap: map[string]TableSummary{},
57+
}
58+
59+
sorted := summary.SortedTableSummaries()
60+
61+
require.Len(t, sorted, 0)
62+
}
63+
3764
func TestBuildProgressReport(t *testing.T) {
3865
now := time.Now()
3966
type args struct {

go/vt/vttablet/tabletmanager/vdiff/schema.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const (
4040
vd.started_at as started_at, vdt.rows_compared as rows_compared, vd.completed_at as completed_at,
4141
IF(vdt.mismatch = 1, 1, 0) as has_mismatch, vdt.report as report
4242
from _vt.vdiff as vd left join _vt.vdiff_table as vdt on (vd.id = vdt.vdiff_id)
43-
where vd.id = %a order by table_name`
43+
where vd.id = %a`
4444
// sqlUpdateVDiffState has a penultimate placeholder for any additional columns you want to update, e.g. `, foo = 1`.
4545
// It also truncates the error if needed to ensure that we can save the state when the error text is very long.
4646
sqlUpdateVDiffState = "update _vt.vdiff set state = %s, last_error = left(%s, 1024) %s where id = %d"

0 commit comments

Comments
 (0)