Skip to content

Commit

Permalink
VTAdmin: Support for VDiff create and show last
Browse files Browse the repository at this point in the history
Signed-off-by: Noble Mittal <[email protected]>
  • Loading branch information
beingnoble03 committed Oct 13, 2024
1 parent f0062e6 commit 0e1815b
Show file tree
Hide file tree
Showing 14 changed files with 4,845 additions and 766 deletions.
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

0 comments on commit 0e1815b

Please sign in to comment.