Skip to content
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

VTAdmin: Support for VDiff create and show last #16943

Merged
merged 3 commits into from
Oct 15, 2024
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
16 changes: 8 additions & 8 deletions go/cmd/vtctldclient/command/vreplication/vdiff/vdiff.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import (
)

var (
tabletTypesDefault = []topodatapb.TabletType{
TabletTypesDefault = []topodatapb.TabletType{
topodatapb.TabletType_RDONLY,
topodatapb.TabletType_REPLICA,
topodatapb.TabletType_PRIMARY,
Expand Down Expand Up @@ -102,7 +102,7 @@ var (
createOptions.UUID = uuid.New()
}
if !cmd.Flags().Lookup("tablet-types").Changed {
createOptions.TabletTypes = tabletTypesDefault
createOptions.TabletTypes = TabletTypesDefault
}
if cmd.Flags().Lookup("source-cells").Changed {
for i, cell := range createOptions.SourceCells {
Expand Down Expand Up @@ -790,7 +790,7 @@ func buildSingleSummary(keyspace, workflow, uuid string, resp *vtctldatapb.VDiff

// If the vdiff has been started then we can calculate the progress.
if summary.State == vdiff.StartedState {
buildProgressReport(summary, totalRowsToCompare)
summary.Progress = BuildProgressReport(summary.RowsCompared, totalRowsToCompare, summary.StartedAt)
}

sort.Strings(shards) // Sort for predictable output
Expand All @@ -809,17 +809,17 @@ func buildSingleSummary(keyspace, workflow, uuid string, resp *vtctldatapb.VDiff
return summary, nil
}

func buildProgressReport(summary *summary, rowsToCompare int64) {
func BuildProgressReport(rowsCompared int64, rowsToCompare int64, startedAt string) *vdiff.ProgressReport {
report := &vdiff.ProgressReport{}
if summary.RowsCompared >= 1 {
if rowsCompared >= 1 {
// Round to 2 decimal points.
report.Percentage = math.Round(math.Min((float64(summary.RowsCompared)/float64(rowsToCompare))*100, 100.00)*100) / 100
report.Percentage = math.Round(math.Min((float64(rowsCompared)/float64(rowsToCompare))*100, 100.00)*100) / 100
}
if math.IsNaN(report.Percentage) {
report.Percentage = 0
}
pctToGo := math.Abs(report.Percentage - 100.00)
startTime, _ := time.Parse(vdiff.TimestampFormat, summary.StartedAt)
startTime, _ := time.Parse(vdiff.TimestampFormat, startedAt)
curTime := time.Now().UTC()
runTime := curTime.Unix() - startTime.Unix()
if report.Percentage >= 1 {
Expand All @@ -830,7 +830,7 @@ func buildProgressReport(summary *summary, rowsToCompare int64) {
report.ETA = eta.Format(vdiff.TimestampFormat)
}
}
summary.Progress = report
return report
}

func commandShow(cmd *cobra.Command, args []string) error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ func TestBuildProgressReport(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
buildProgressReport(tt.args.summary, tt.args.rowsToCompare)
tt.args.summary.Progress = BuildProgressReport(tt.args.summary.RowsCompared, tt.args.rowsToCompare, tt.args.summary.StartedAt)
// We always check the percentage
require.Equal(t, int(tt.want.Percentage), int(tt.args.summary.Progress.Percentage))

Expand Down
Loading
Loading