Skip to content

Commit ae73b87

Browse files
committed
tweak counts
1 parent 8f95ff6 commit ae73b87

File tree

3 files changed

+39
-16
lines changed

3 files changed

+39
-16
lines changed

internal/verifier/mismatches.go

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"encoding/binary"
66
"fmt"
77

8-
"github.com/10gen/migration-verifier/mbson"
98
"github.com/10gen/migration-verifier/option"
109
"github.com/pkg/errors"
1110
"github.com/samber/lo"
@@ -140,11 +139,11 @@ func countMismatchesForTasks(
140139
return matched, totalRV.AsInt64() - matched, nil
141140
}
142141

143-
func countMismatchesForGeneration(
142+
func countRechecksForGeneration(
144143
ctx context.Context,
145144
metaDB *mongo.Database,
146145
generation int,
147-
) (int64, error) {
146+
) (int64, int64, error) {
148147
cursor, err := metaDB.Collection(verificationTasksCollection).Aggregate(
149148
ctx,
150149
mongo.Pipeline{
@@ -157,35 +156,51 @@ func countMismatchesForGeneration(
157156
{"foreignField", "task"},
158157
{"as", "mismatches"},
159158
}}},
159+
{{"$addFields", bson.D{
160+
{"mismatches", bson.D{{"$size", "$mismatches"}}},
161+
}}},
160162
{{"$group", bson.D{
161163
{"_id", nil},
164+
{"changes", bson.D{
165+
{"$sum", bson.D{
166+
{"$subtract", bson.A{
167+
bson.D{{"$size", "$_ids"}},
168+
"$mismatches",
169+
}},
170+
}},
171+
}},
162172
{"mismatches", bson.D{
163-
{"$sum", bson.D{{"$size", "$mismatches"}}},
173+
{"$sum", "$mismatches"},
164174
}},
165175
}}},
166176
},
167177
)
168178
if err != nil {
169-
return 0, errors.Wrap(err, "sending query to count last generation’s found mismatches")
179+
return 0, 0, errors.Wrap(err, "sending query to count last generation’s found mismatches")
170180
}
171181

172182
defer cursor.Close(ctx)
173183

174184
if !cursor.Next(ctx) {
175185
if cursor.Err() != nil {
176-
return 0, errors.Wrap(err, "reading count of last generation’s found mismatches")
186+
return 0, 0, errors.Wrap(err, "reading count of last generation’s found mismatches")
177187
}
178188

179189
// This happens if there were no tasks in the queried generation.
180-
return 0, nil
190+
return 0, 0, nil
181191
}
182192

183-
mmRV, err := cursor.Current.LookupErr("mismatches")
193+
result := struct {
194+
Mismatches int64
195+
Changes int64
196+
}{}
197+
198+
err = cursor.Decode(&result)
184199
if err != nil {
185-
return 0, errors.Wrapf(err, "reading mismatches from result (%v)", cursor.Current)
200+
return 0, 0, errors.Wrapf(err, "reading mismatches from result (%v)", cursor.Current)
186201
}
187202

188-
return mbson.ToInt64(mmRV)
203+
return result.Mismatches, result.Changes, nil
189204
}
190205

191206
func getMismatchesForTasks(

internal/verifier/progress.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func (verifier *Verifier) GetProgress(ctx context.Context) (Progress, error) {
2626
progressTime := time.Now()
2727
genElapsed := progressTime.Sub(verifier.generationStartTime)
2828

29-
genStats.TimeElapsed = option.Some(genElapsed.Round(10 * time.Millisecond).String())
29+
genStats.TimeElapsed = option.Some(genElapsed.Round(time.Millisecond).String())
3030
}
3131

3232
eg, egCtx := contextplus.ErrGroup(ctx)
@@ -42,7 +42,7 @@ func (verifier *Verifier) GetProgress(ctx context.Context) (Progress, error) {
4242
if generation > 0 {
4343
eg.Go(
4444
func() error {
45-
count, err := countMismatchesForGeneration(
45+
mismatches, changes, err := countRechecksForGeneration(
4646
egCtx,
4747
verifier.metaClient.Database(verifier.metaDBName),
4848
generation-1,
@@ -52,7 +52,10 @@ func (verifier *Verifier) GetProgress(ctx context.Context) (Progress, error) {
5252
return errors.Wrapf(err, "counting mismatches seen during generation %d", generation-1)
5353
}
5454

55-
genStats.PriorMismatches = option.Some(count)
55+
genStats.PriorRechecks = option.Some(ProgressRechecks{
56+
Changes: changes,
57+
Mismatches: mismatches,
58+
})
5659

5760
return nil
5861
},

internal/verifier/webserver.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,11 @@ func (server *WebServer) writesOffEndpoint(c *gin.Context) {
242242
successResponse(c)
243243
}
244244

245+
type ProgressRechecks struct {
246+
Mismatches int64 `json:"mismatches"`
247+
Changes int64 `json:"changes"`
248+
}
249+
245250
type ProgressGenerationStats struct {
246251
TimeElapsed option.Option[string] `json:"timeElapsed"`
247252
ActiveWorkers int `json:"activeWorkers"`
@@ -252,9 +257,9 @@ type ProgressGenerationStats struct {
252257
SrcBytesCompared types.ByteCount `json:"srcBytesCompared"`
253258
TotalSrcBytes types.ByteCount `json:"totalSrcBytes,omitempty"`
254259

255-
PriorMismatches option.Option[int64] `json:"priorMismatches"`
256-
MismatchesFound int64 `json:"mismatchesFound"`
257-
RechecksEnqueued int64 `json:"rechecksEnqueued"`
260+
PriorRechecks option.Option[ProgressRechecks] `json:"priorRechecks"`
261+
MismatchesFound int64 `json:"mismatchesFound"`
262+
RechecksEnqueued int64 `json:"rechecksEnqueued"`
258263
}
259264

260265
type ProgressChangeStats struct {

0 commit comments

Comments
 (0)