Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go/cmd/vtctldclient/command/vreplication/vdiff/vdiff.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down
16 changes: 16 additions & 0 deletions go/vt/vtctl/workflow/vdiff.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
27 changes: 27 additions & 0 deletions go/vt/vtctl/workflow/vdiff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vttablet/tabletmanager/vdiff/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading