Skip to content

Commit cbfe2b9

Browse files
authored
Merge pull request #1136 from percona/PBM-1514-Improve-resync-performance-updates
PBM-1514 improve resync performance - update default behavior
2 parents c049081 + 55f81e6 commit cbfe2b9

File tree

6 files changed

+30
-33
lines changed

6 files changed

+30
-33
lines changed

cmd/pbm-agent/resync.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func (a *Agent) Resync(ctx context.Context, cmd *ctrl.ResyncCmd, opid ctrl.OPID,
7171
} else if cmd.Name != "" {
7272
err = a.handleSyncProfile(ctx, cmd.Name, cmd.Clear)
7373
} else {
74-
err = a.handleSyncMainStorage(ctx, cmd.SkipRestores)
74+
err = a.handleSyncMainStorage(ctx, cmd.IncludeRestores)
7575
}
7676
if err != nil {
7777
l.Error(err.Error())
@@ -134,13 +134,13 @@ func (a *Agent) helpSyncProfileBackups(ctx context.Context, profile *config.Conf
134134
return errors.Wrapf(err, "sync backup list for %q", profile.Name)
135135
}
136136

137-
func (a *Agent) handleSyncMainStorage(ctx context.Context, skipRestores bool) error {
137+
func (a *Agent) handleSyncMainStorage(ctx context.Context, includeRestores bool) error {
138138
cfg, err := config.GetConfig(ctx, a.leadConn)
139139
if err != nil {
140140
return errors.Wrap(err, "get config")
141141
}
142142

143-
err = resync.Resync(ctx, a.leadConn, &cfg.Storage, a.brief.Me, skipRestores)
143+
err = resync.Resync(ctx, a.leadConn, &cfg.Storage, a.brief.Me, includeRestores)
144144
if err != nil {
145145
return errors.Wrap(err, "resync")
146146
}

cmd/pbm/config.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ import (
1818
)
1919

2020
type configOpts struct {
21-
rsync bool
22-
skipRestores bool
23-
wait bool
24-
waitTime time.Duration
25-
list bool
26-
file string
27-
set map[string]string
28-
key string
21+
rsync bool
22+
includeRestores bool
23+
wait bool
24+
waitTime time.Duration
25+
list bool
26+
file string
27+
set map[string]string
28+
key string
2929
}
3030

3131
type confKV struct {
@@ -92,7 +92,7 @@ func runConfig(
9292
}
9393
return confKV{c.key, fmt.Sprint(k)}, nil
9494
case c.rsync:
95-
cid, err := pbm.SyncFromStorage(ctx, c.skipRestores)
95+
cid, err := pbm.SyncFromStorage(ctx, c.includeRestores)
9696
if err != nil {
9797
return nil, errors.Wrap(err, "resync")
9898
}

cmd/pbm/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,8 @@ func (app *pbmApp) buildConfigCmd() *cobra.Command {
368368
Use: "config [key]",
369369
Short: "Set, change or list the config",
370370
RunE: app.wrapRunE(func(cmd *cobra.Command, args []string) (fmt.Stringer, error) {
371-
if cfg.skipRestores && !cfg.rsync {
372-
return nil, errors.New("--skip-restores cannot be used without --force-resync")
371+
if cfg.includeRestores && !cfg.rsync {
372+
return nil, errors.New("--include-restores cannot be used without --force-resync")
373373
}
374374

375375
if len(args) == 1 {
@@ -381,7 +381,7 @@ func (app *pbmApp) buildConfigCmd() *cobra.Command {
381381

382382
configCmd.Flags().BoolVar(&cfg.rsync, "force-resync", false, "Resync backup list with the current store")
383383
configCmd.Flags().BoolVar(
384-
&cfg.skipRestores, "skip-restores", false, "Skip physical restore metadata during force-resync",
384+
&cfg.includeRestores, "include-restores", false, "Include physical restore metadata during force-resync",
385385
)
386386
configCmd.Flags().BoolVar(&cfg.list, "list", false, "List current settings")
387387
configCmd.Flags().StringVar(&cfg.file, "file", "", "Upload config from YAML file")

pbm/ctrl/cmd.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,10 @@ type ProfileCmd struct {
121121
}
122122

123123
type ResyncCmd struct {
124-
Name string `bson:"name,omitempty"`
125-
All bool `bson:"all,omitempty"`
126-
Clear bool `bson:"clear,omitempty"`
127-
SkipRestores bool `bson:"skipRestores,omitempty"`
124+
Name string `bson:"name,omitempty"`
125+
All bool `bson:"all,omitempty"`
126+
Clear bool `bson:"clear,omitempty"`
127+
IncludeRestores bool `bson:"includeRestores,omitempty"`
128128
}
129129

130130
type BackupCmd struct {

pbm/resync/rsync.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func Resync(
3131
conn connect.Client,
3232
cfg *config.StorageConf,
3333
node string,
34-
skipRestores bool,
34+
includeRestores bool,
3535
) error {
3636
l := log.LogEventFromContext(ctx)
3737

@@ -68,7 +68,7 @@ func Resync(
6868
l.Error("failed sync oplog range: %v", err)
6969
}
7070

71-
err = resyncPhysicalRestores(ctx, conn, stg, skipRestores)
71+
err = resyncPhysicalRestores(ctx, conn, stg, includeRestores)
7272
if err != nil {
7373
l.Error("failed sync physical restore metadata: %v", err)
7474
}
@@ -250,7 +250,7 @@ func resyncPhysicalRestores(
250250
ctx context.Context,
251251
conn connect.Client,
252252
stg storage.Storage,
253-
skipRestores bool,
253+
includeRestores bool,
254254
) error {
255255
_, err := conn.RestoresCollection().DeleteMany(ctx, bson.D{})
256256
if err != nil {
@@ -269,7 +269,7 @@ func resyncPhysicalRestores(
269269
return nil
270270
}
271271

272-
restoreMeta, err := getAllRestoreMetaFromStorage(ctx, stg, skipRestores)
272+
restoreMeta, err := getAllRestoreMetaFromStorage(ctx, stg, includeRestores)
273273
if err != nil {
274274
return errors.Wrap(err, "get all restore meta from storage")
275275
}
@@ -322,7 +322,7 @@ func getAllBackupMetaFromStorage(
322322
func getAllRestoreMetaFromStorage(
323323
ctx context.Context,
324324
stg storage.Storage,
325-
skipRestores bool,
325+
includeRestores bool,
326326
) ([]*restore.RestoreMeta, error) {
327327
l := log.LogEventFromContext(ctx)
328328

@@ -331,19 +331,16 @@ func getAllRestoreMetaFromStorage(
331331
return nil, errors.Wrap(err, "get physical restores list from the storage")
332332
}
333333

334-
var targets []storage.FileInfo
335-
336-
if skipRestores && len(restoreMeta) > 0 {
334+
targets := restoreMeta
335+
if !includeRestores && len(restoreMeta) > 0 {
337336
l.Debug("only processing last restore")
338337
latest := restoreMeta[0]
339-
for _, f := range restoreMeta[1:] {
338+
for _, f := range restoreMeta {
340339
if f.Name > latest.Name {
341340
latest = f
342341
}
343342
}
344343
targets = []storage.FileInfo{latest}
345-
} else {
346-
targets = restoreMeta
347344
}
348345

349346
rv := make([]*restore.RestoreMeta, 0, len(targets))

sdk/impl.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,10 @@ func (c *Client) GetRestoreByOpID(ctx context.Context, opid string) (*RestoreMet
262262
return restore.GetRestoreMetaByOPID(ctx, c.conn, opid)
263263
}
264264

265-
func (c *Client) SyncFromStorage(ctx context.Context, skipRestores bool) (CommandID, error) {
265+
func (c *Client) SyncFromStorage(ctx context.Context, includeRestores bool) (CommandID, error) {
266266
var opts *ctrl.ResyncCmd
267-
if skipRestores {
268-
opts = &ctrl.ResyncCmd{SkipRestores: true}
267+
if includeRestores {
268+
opts = &ctrl.ResyncCmd{IncludeRestores: true}
269269
}
270270
opid, err := ctrl.SendResync(ctx, c.conn, opts)
271271
return CommandID(opid.String()), err

0 commit comments

Comments
 (0)