@@ -26,7 +26,13 @@ import (
26
26
//
27
27
// It checks for read and write permissions, drops all meta from the database
28
28
// and populate it again by reading meta from the storage.
29
- func Resync (ctx context.Context , conn connect.Client , cfg * config.StorageConf , node string ) error {
29
+ func Resync (
30
+ ctx context.Context ,
31
+ conn connect.Client ,
32
+ cfg * config.StorageConf ,
33
+ node string ,
34
+ skipRestores bool ,
35
+ ) error {
30
36
l := log .LogEventFromContext (ctx )
31
37
32
38
stg , err := util .StorageFromConfig (cfg , node , l )
@@ -62,7 +68,7 @@ func Resync(ctx context.Context, conn connect.Client, cfg *config.StorageConf, n
62
68
l .Error ("failed sync oplog range: %v" , err )
63
69
}
64
70
65
- err = resyncPhysicalRestores (ctx , conn , stg )
71
+ err = resyncPhysicalRestores (ctx , conn , stg , skipRestores )
66
72
if err != nil {
67
73
l .Error ("failed sync physical restore metadata: %v" , err )
68
74
}
@@ -244,6 +250,7 @@ func resyncPhysicalRestores(
244
250
ctx context.Context ,
245
251
conn connect.Client ,
246
252
stg storage.Storage ,
253
+ skipRestores bool ,
247
254
) error {
248
255
_ , err := conn .RestoresCollection ().DeleteMany (ctx , bson.D {})
249
256
if err != nil {
@@ -262,7 +269,7 @@ func resyncPhysicalRestores(
262
269
return nil
263
270
}
264
271
265
- restoreMeta , err := getAllRestoreMetaFromStorage (ctx , stg )
272
+ restoreMeta , err := getAllRestoreMetaFromStorage (ctx , stg , skipRestores )
266
273
if err != nil {
267
274
return errors .Wrap (err , "get all restore meta from storage" )
268
275
}
@@ -315,6 +322,7 @@ func getAllBackupMetaFromStorage(
315
322
func getAllRestoreMetaFromStorage (
316
323
ctx context.Context ,
317
324
stg storage.Storage ,
325
+ skipRestores bool ,
318
326
) ([]* restore.RestoreMeta , error ) {
319
327
l := log .LogEventFromContext (ctx )
320
328
@@ -323,8 +331,23 @@ func getAllRestoreMetaFromStorage(
323
331
return nil , errors .Wrap (err , "get physical restores list from the storage" )
324
332
}
325
333
326
- rv := make ([]* restore.RestoreMeta , 0 , len (restoreMeta ))
327
- for _ , file := range restoreMeta {
334
+ var targets []storage.FileInfo
335
+
336
+ if skipRestores && len (restoreMeta ) > 0 {
337
+ l .Debug ("only processing last restore" )
338
+ latest := restoreMeta [0 ]
339
+ for _ , f := range restoreMeta [1 :] {
340
+ if f .Name > latest .Name {
341
+ latest = f
342
+ }
343
+ }
344
+ targets = []storage.FileInfo {latest }
345
+ } else {
346
+ targets = restoreMeta
347
+ }
348
+
349
+ rv := make ([]* restore.RestoreMeta , 0 , len (targets ))
350
+ for _ , file := range targets {
328
351
filename := strings .TrimSuffix (file .Name , ".json" )
329
352
meta , err := restore .GetPhysRestoreMeta (filename , stg , l )
330
353
if err != nil {
0 commit comments