Skip to content

Commit b94019c

Browse files
authored
PBM-1258: Fix for unnecessary resync operation when applied config's storage params are the same (#935)
* Fix unnecessary resync op after config is applied ... without any change PBM triggers resync operation in case when any storage parameter has been changed. If the config file and actual config doc in db have the same storage level parameters, resync operation is unnecessary. * Remove storage provider aligment hack
1 parent c77b09f commit b94019c

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

cmd/pbm/config.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,10 @@ func runConfig(ctx context.Context, conn connect.Client, pbm sdk.Client, c *conf
127127
oldCfg = &config.Config{}
128128
}
129129

130-
if err := config.SetConfig(ctx, conn, newCfg); err != nil {
130+
if err := config.SetConfig(ctx, conn, &newCfg); err != nil {
131131
return nil, errors.Wrap(err, "unable to set config: write to db")
132132
}
133133

134-
// provider value may differ as it set automatically after config parsing
135-
oldCfg.Storage.S3.Provider = newCfg.Storage.S3.Provider
136134
// resync storage only if Storage options have changed
137135
if !reflect.DeepEqual(newCfg.Storage, oldCfg.Storage) {
138136
if _, err := pbm.SyncFromStorage(ctx); err != nil {

pbm/config/config.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,10 @@ func GetConfig(ctx context.Context, m connect.Client) (*Config, error) {
263263
return cfg, nil
264264
}
265265

266-
func SetConfig(ctx context.Context, m connect.Client, cfg Config) error {
266+
// SetConfig stores config doc within the database.
267+
// It also applies default storage parameters depending on the type of storage
268+
// and assigns those possible default values to the cfg parameter.
269+
func SetConfig(ctx context.Context, m connect.Client, cfg *Config) error {
267270
switch cfg.Storage.Type {
268271
case storage.S3:
269272
err := cfg.Storage.S3.Cast()
@@ -299,7 +302,7 @@ func SetConfig(ctx context.Context, m connect.Client, cfg Config) error {
299302
_, err = m.ConfigCollection().UpdateOne(
300303
ctx,
301304
bson.D{},
302-
bson.M{"$set": cfg},
305+
bson.M{"$set": *cfg},
303306
options.Update().SetUpsert(true),
304307
)
305308
return errors.Wrap(err, "mongo defs.ConfigCollection UpdateOne")

sdk/impl.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func (c *clientImpl) GetConfig(ctx context.Context) (*Config, error) {
7979
}
8080

8181
func (c *clientImpl) SetConfig(ctx context.Context, cfg Config) (CommandID, error) {
82-
return NoOpID, config.SetConfig(ctx, c.conn, cfg)
82+
return NoOpID, config.SetConfig(ctx, c.conn, &cfg)
8383
}
8484

8585
func (c *clientImpl) GetAllBackups(ctx context.Context) ([]BackupMetadata, error) {

0 commit comments

Comments
 (0)