@@ -7,12 +7,14 @@ package verifier
77// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
88
99import (
10+ "context"
1011 "fmt"
1112 "strings"
1213 "time"
1314
1415 "github.com/10gen/migration-verifier/internal/partitions"
1516 "github.com/10gen/migration-verifier/internal/types"
17+ "github.com/pkg/errors"
1618 "go.mongodb.org/mongo-driver/bson"
1719 "go.mongodb.org/mongo-driver/bson/primitive"
1820 "go.mongodb.org/mongo-driver/mongo"
@@ -44,8 +46,9 @@ const (
4446 // The “workhorse” task type: verify a partition of documents.
4547 verificationTaskVerifyDocuments verificationTaskType = "verify"
4648
47- // A verifyCollection task verifies collection metadata
48- // and inserts verify-documents tasks to verify data ranges.
49+ // A verifyCollection task verifies one collection's metadata
50+ // and inserts verify-documents tasks to verify its data ranges.
51+ // This includes sampling & partitioning the collection.
4952 verificationTaskVerifyCollection verificationTaskType = "verifyCollection"
5053
5154 // The primary task creates a verifyCollection task for each
@@ -186,7 +189,43 @@ func (verifier *Verifier) InsertFailedIdsVerificationTask(ctx mongo.SessionConte
186189 return err
187190}
188191
189- func (verifier * Verifier ) FindNextVerifyTaskAndUpdate (ctx mongo.SessionContext ) (* VerificationTask , error ) {
192+ func (v * Verifier ) resetProcessingTasks (ctx context.Context ) error {
193+ coll := v .verificationTaskCollection ()
194+
195+ result , err := coll .UpdateMany (
196+ ctx ,
197+ bson.M {
198+ "generation" : v .generation ,
199+ "status" : verificationTaskProcessing ,
200+ },
201+ bson.M {
202+ "$set" : bson.M {
203+ "status" : verificationTaskAdded ,
204+ },
205+ "$unset" : bson.M {
206+ "begin_time" : 1 ,
207+ },
208+ },
209+ )
210+
211+ if err != nil {
212+ return errors .Wrap (err , "failed to reset in-progress tasks" )
213+ }
214+
215+ if result .ModifiedCount > 0 {
216+ v .logger .Info ().
217+ Int64 ("count" , result .ModifiedCount ).
218+ Msg ("Formerly in-progress task(s) found and reset." )
219+ }
220+
221+ return nil
222+ }
223+
224+ func (verifier * Verifier ) FindNextVerifyTaskAndUpdate (ctx context.Context ) (* VerificationTask , error ) {
225+ if mongo .SessionFromContext (ctx ) != nil {
226+ panic ("should be called from outside transaction" )
227+ }
228+
190229 var verificationTask = VerificationTask {}
191230 filter := bson.M {
192231 "$and" : bson.A {
0 commit comments