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
191206func getMismatchesForTasks (
0 commit comments