@@ -337,18 +337,39 @@ func (b *Backup) Run(ctx context.Context, bcp *ctrl.BackupCmd, opid ctrl.OPID, l
337
337
}
338
338
339
339
if inf .IsLeader () {
340
- err = b . reconcileStatus (ctx , bcp . Name , opid . String (), defs . StatusDone , nil )
340
+ shards , err := topo . ClusterMembers (ctx , b . leadConn . MongoClient () )
341
341
if err != nil {
342
- return errors .Wrap (err , "check cluster for backup done" )
342
+ return errors .Wrap (err , "check cluster for backup done: get cluster members" )
343
+ }
344
+
345
+ err = b .convergeCluster (ctx , bcp .Name , opid .String (), shards , defs .StatusDone )
346
+ err = errors .Wrap (err , "check cluster for backup done: convergeCluster" )
347
+ if err != nil {
348
+ return err
343
349
}
344
350
345
351
bcpm , err = NewDBManager (b .leadConn ).GetBackupByName (ctx , bcp .Name )
346
352
if err != nil {
347
353
return errors .Wrap (err , "get backup metadata" )
348
354
}
349
355
356
+ // PBM-1114: update file metadata with the same values as in database
357
+ unix := time .Now ().Unix ()
358
+ bcpm .Status = defs .StatusDone
359
+ bcpm .LastTransitionTS = unix
360
+ bcpm .Conditions = append (bcpm .Conditions , Condition {
361
+ Timestamp : unix ,
362
+ Status : defs .StatusDone ,
363
+ })
364
+
350
365
err = writeMeta (stg , bcpm )
351
- return errors .Wrap (err , "dump metadata" )
366
+ if err != nil {
367
+ return errors .Wrap (err , "dump metadata" )
368
+ }
369
+
370
+ err = ChangeBackupStateWithUnix (b .leadConn , bcp .Name , defs .StatusDone , unix , "" )
371
+ return errors .Wrapf (err , "check cluster for backup done: update backup meta with %s" ,
372
+ defs .StatusDone )
352
373
} else {
353
374
// to be sure the locks released only after the "done" status had written
354
375
err = b .waitForStatus (ctx , bcp .Name , defs .StatusDone , nil )
@@ -432,14 +453,18 @@ func (b *Backup) reconcileStatus(
432
453
}
433
454
434
455
if timeout != nil {
435
- return errors .Wrap (
436
- b .convergeClusterWithTimeout (ctx , bcpName , opid , shards , status , * timeout ),
437
- "convergeClusterWithTimeout" )
456
+ err = b .convergeClusterWithTimeout (ctx , bcpName , opid , shards , status , * timeout )
457
+ err = errors .Wrap (err , "convergeClusterWithTimeout" )
458
+ } else {
459
+ err = b .convergeCluster (ctx , bcpName , opid , shards , status )
460
+ err = errors .Wrap (err , "convergeCluster" )
461
+ }
462
+ if err != nil {
463
+ return err
438
464
}
439
465
440
- return errors .Wrap (
441
- b .convergeCluster (ctx , bcpName , opid , shards , status ),
442
- "convergeCluster" )
466
+ err = ChangeBackupState (b .leadConn , bcpName , status , "" )
467
+ return errors .Wrapf (err , "update backup meta with %s" , status )
443
468
}
444
469
445
470
// convergeCluster waits until all given shards reached `status` and updates a cluster status
@@ -480,10 +505,11 @@ func (b *Backup) convergeClusterWithTimeout(
480
505
status defs.Status ,
481
506
t time.Duration ,
482
507
) error {
483
- tk := time .NewTicker (time .Second * 1 )
508
+ tk := time .NewTicker (time .Second )
484
509
defer tk .Stop ()
485
510
486
- tout := time .After (t )
511
+ tout := time .NewTimer (t )
512
+ defer tout .Stop ()
487
513
488
514
for {
489
515
select {
@@ -495,7 +521,7 @@ func (b *Backup) convergeClusterWithTimeout(
495
521
if ok {
496
522
return nil
497
523
}
498
- case <- tout :
524
+ case <- tout . C :
499
525
return errors .Wrap (errConvergeTimeOut , t .String ())
500
526
case <- ctx .Done ():
501
527
return ctx .Err ()
@@ -554,15 +580,7 @@ func (b *Backup) converged(
554
580
}
555
581
}
556
582
557
- if shardsToFinish == 0 {
558
- err := ChangeBackupState (b .leadConn , bcpName , status , "" )
559
- if err != nil {
560
- return false , errors .Wrapf (err , "update backup meta with %s" , status )
561
- }
562
- return true , nil
563
- }
564
-
565
- return false , nil
583
+ return shardsToFinish == 0 , nil
566
584
}
567
585
568
586
func (b * Backup ) waitForStatus (
0 commit comments