@@ -61,6 +61,9 @@ func (verifier *Verifier) insertRecheckDocs(
6161
6262 generation , _ := verifier .getGenerationWhileLocked ()
6363
64+ // We enqueue for the generation after the current one.
65+ generation ++
66+
6467 eg , groupCtx := contextplus .ErrGroup (ctx )
6568
6669 // MongoDB’s Go driver starts failing requests if we try to exceed
@@ -233,66 +236,37 @@ func buildRequestBSON(collName string, rechecks []bson.Raw) bson.Raw {
233236 return requestBSON
234237}
235238
236- // DropOldRecheckQueueWhileLocked deletes the previous generation’s recheck
237- // documents from the verifier’s metadata.
238- //
239- // The verifier **MUST** be locked when this function is called (or panic).
240- func (verifier * Verifier ) DropOldRecheckQueueWhileLocked (ctx context.Context ) error {
241- prevGeneration := verifier .getPreviousGenerationWhileLocked ()
239+ // DropCurrentGenRecheckQueue deletes the current generation’s recheck
240+ // documents from the verifier’s metadata. This should only be called
241+ // after new recheck tasks have been created from those rechecks.
242+ func (verifier * Verifier ) DropCurrentGenRecheckQueue (ctx context.Context ) error {
243+ generation := verifier .generation
242244
243245 verifier .logger .Debug ().
244- Int ("previousGeneration " , prevGeneration ).
245- Msg ("Deleting previous generation's enqueued rechecks." )
246+ Int ("generation " , generation ).
247+ Msg ("Deleting current generation's enqueued rechecks." )
246248
247- genCollection := verifier .getRecheckQueueCollection (prevGeneration )
249+ genCollection := verifier .getRecheckQueueCollection (generation )
248250
249251 return retry .New ().WithCallback (
250252 func (ctx context.Context , i * retry.FuncInfo ) error {
251253 return genCollection .Drop (ctx )
252254 },
253255 "deleting generation %d's enqueued rechecks" ,
254- prevGeneration ,
256+ generation ,
255257 ).Run (ctx , verifier .logger )
256258}
257259
258- func (verifier * Verifier ) getPreviousGenerationWhileLocked () int {
259- generation , _ := verifier .getGenerationWhileLocked ()
260- if generation < 1 {
261- panic ("This function is forbidden before generation 1!" )
262- }
263-
264- return generation - 1
265- }
266-
267- // GenerateRecheckTasksWhileLocked fetches the previous generation’s recheck
268- // documents from the verifier’s metadata and creates current-generation
269- // document-verification tasks from them.
260+ // GenerateRecheckTasks fetches the rechecks enqueued for the current generation
261+ // from the verifier’s metadata and creates document-verification tasks from
262+ // them.
270263//
271264// Note that this function DOES NOT retry on failure, so callers should wrap
272265// calls to this function in a retryer.
273- //
274- // The verifier **MUST** be locked when this function is called (or panic).
275- func (verifier * Verifier ) GenerateRecheckTasksWhileLocked (ctx context.Context ) error {
276- prevGeneration := verifier .getPreviousGenerationWhileLocked ()
266+ func (verifier * Verifier ) GenerateRecheckTasks (ctx context.Context ) error {
267+ generation , _ := verifier .getGeneration ()
277268
278- verifier .logger .Debug ().
279- Int ("priorGeneration" , prevGeneration ).
280- Msgf ("Counting prior generation’s enqueued rechecks." )
281-
282- recheckColl := verifier .getRecheckQueueCollection (prevGeneration )
283-
284- rechecksCount , err := recheckColl .CountDocuments (ctx , bson.D {})
285- if err != nil {
286- return errors .Wrapf (err ,
287- "failed to count generation %d’s rechecks" ,
288- prevGeneration ,
289- )
290- }
291-
292- verifier .logger .Debug ().
293- Int ("priorGeneration" , prevGeneration ).
294- Int ("rechecksCount" , int (rechecksCount )).
295- Msgf ("Creating recheck tasks from prior generation’s enqueued rechecks." )
269+ recheckColl := verifier .getRecheckQueueCollection (generation )
296270
297271 startTime := time .Now ()
298272
@@ -428,7 +402,7 @@ func (verifier *Verifier) GenerateRecheckTasksWhileLocked(ctx context.Context) e
428402
429403 if err == nil && totalDocs > 0 {
430404 verifier .logger .Info ().
431- Int ("generation" , 1 + prevGeneration ).
405+ Int ("generation" , generation ).
432406 Int64 ("totalDocs" , int64 (totalDocs )).
433407 Str ("totalData" , reportutils .FmtBytes (totalRecheckData )).
434408 Stringer ("timeElapsed" , time .Since (startTime )).
@@ -439,6 +413,10 @@ func (verifier *Verifier) GenerateRecheckTasksWhileLocked(ctx context.Context) e
439413}
440414
441415func (v * Verifier ) getRecheckQueueCollection (generation int ) * mongo.Collection {
416+ if generation == 0 {
417+ panic ("Recheck for generation 0 is nonsense!" )
418+ }
419+
442420 return v .verificationDatabase ().
443421 Collection (fmt .Sprintf ("%s_gen%d" , recheckQueueCollectionNameBase , generation ))
444422}
0 commit comments