Skip to content

Commit de16c05

Browse files
committed
update rsync
1 parent 416d1bd commit de16c05

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

pbm/resync/rsync.go

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ import (
2626
//
2727
// It checks for read and write permissions, drops all meta from the database
2828
// 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 {
3036
l := log.LogEventFromContext(ctx)
3137

3238
stg, err := util.StorageFromConfig(cfg, node, l)
@@ -62,7 +68,7 @@ func Resync(ctx context.Context, conn connect.Client, cfg *config.StorageConf, n
6268
l.Error("failed sync oplog range: %v", err)
6369
}
6470

65-
err = resyncPhysicalRestores(ctx, conn, stg)
71+
err = resyncPhysicalRestores(ctx, conn, stg, skipRestores)
6672
if err != nil {
6773
l.Error("failed sync physical restore metadata: %v", err)
6874
}
@@ -244,6 +250,7 @@ func resyncPhysicalRestores(
244250
ctx context.Context,
245251
conn connect.Client,
246252
stg storage.Storage,
253+
skipRestores bool,
247254
) error {
248255
_, err := conn.RestoresCollection().DeleteMany(ctx, bson.D{})
249256
if err != nil {
@@ -262,7 +269,7 @@ func resyncPhysicalRestores(
262269
return nil
263270
}
264271

265-
restoreMeta, err := getAllRestoreMetaFromStorage(ctx, stg)
272+
restoreMeta, err := getAllRestoreMetaFromStorage(ctx, stg, skipRestores)
266273
if err != nil {
267274
return errors.Wrap(err, "get all restore meta from storage")
268275
}
@@ -315,6 +322,7 @@ func getAllBackupMetaFromStorage(
315322
func getAllRestoreMetaFromStorage(
316323
ctx context.Context,
317324
stg storage.Storage,
325+
skipRestores bool,
318326
) ([]*restore.RestoreMeta, error) {
319327
l := log.LogEventFromContext(ctx)
320328

@@ -323,8 +331,23 @@ func getAllRestoreMetaFromStorage(
323331
return nil, errors.Wrap(err, "get physical restores list from the storage")
324332
}
325333

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 {
328351
filename := strings.TrimSuffix(file.Name, ".json")
329352
meta, err := restore.GetPhysRestoreMeta(filename, stg, l)
330353
if err != nil {

0 commit comments

Comments
 (0)