Only set repo configuration on init (#2717)

Setting the repository policy calls `policy.SetPolicy` in Kopia which involves repository scan. This is an
expensive operation if the repository has a lot of snapshots.
 
This commit changes Corso behavior to only call this on repository init and not on every connect.

#### Does this PR need a docs update or release note?

- [ ]  Yes, it's included
- [x] 🕐 Yes, but in a later PR
- [ ]  No

#### Type of change

<!--- Please check the type of change your PR introduces: --->
- [ ] 🌻 Feature
- [x] 🐛 Bugfix
- [ ] 🗺️ Documentation
- [ ] 🤖 Test
- [ ] 💻 CI/Deployment
- [ ] 🧹 Tech Debt/Cleanup

#### Test Plan

<!-- How will this be tested prior to merging.-->
- [ ] 💪 Manual
- [x]  Unit test
- [ ] 💚 E2E
This commit is contained in:
Vaibhav Kamra 2023-03-07 10:10:53 -08:00 committed by GitHub
parent 0add271ebc
commit 1e56f5156a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 17 deletions

View File

@ -90,13 +90,22 @@ func (w *conn) Initialize(ctx context.Context) error {
return clues.Wrap(err, "initialzing repo").WithClues(ctx)
}
return w.commonConnect(
err = w.commonConnect(
ctx,
cfg.KopiaCfgDir,
bst,
cfg.CorsoPassphrase,
defaultCompressor,
)
if err != nil {
return err
}
if err := w.setDefaultConfigValues(ctx); err != nil {
return clues.Stack(err).WithClues(ctx)
}
return nil
}
func (w *conn) Connect(ctx context.Context) error {
@ -154,10 +163,6 @@ func (w *conn) commonConnect(
return clues.Stack(err).WithClues(ctx)
}
if err := w.setDefaultConfigValues(ctx); err != nil {
return clues.Stack(err).WithClues(ctx)
}
return nil
}

View File

@ -238,26 +238,36 @@ func (suite *WrapperIntegrationSuite) TestSetCompressor() {
)
}
func (suite *WrapperIntegrationSuite) TestConfigDefaultsSetOnInitAndConnect() {
func (suite *WrapperIntegrationSuite) TestConfigDefaultsSetOnInitAndNotOnConnect() {
newCompressor := "pgzip"
newRetentionDaily := policy.OptionalInt(42)
newRetention := policy.RetentionPolicy{KeepDaily: &newRetentionDaily}
newSchedInterval := time.Second * 42
table := []struct {
name string
checkFunc func(*testing.T, *policy.Policy)
mutator func(context.Context, *policy.Policy) error
name string
checkInitFunc func(*testing.T, *policy.Policy)
checkFunc func(*testing.T, *policy.Policy)
mutator func(context.Context, *policy.Policy) error
}{
{
name: "Compression",
checkFunc: func(t *testing.T, p *policy.Policy) {
checkInitFunc: func(t *testing.T, p *policy.Policy) {
t.Helper()
require.Equal(t, defaultCompressor, string(p.CompressionPolicy.CompressorName))
},
checkFunc: func(t *testing.T, p *policy.Policy) {
t.Helper()
require.Equal(t, newCompressor, string(p.CompressionPolicy.CompressorName))
},
mutator: func(innerCtx context.Context, p *policy.Policy) error {
_, res := updateCompressionOnPolicy("pgzip", p)
_, res := updateCompressionOnPolicy(newCompressor, p)
return res
},
},
{
name: "Retention",
checkFunc: func(t *testing.T, p *policy.Policy) {
checkInitFunc: func(t *testing.T, p *policy.Policy) {
t.Helper()
require.Equal(
t,
@ -270,9 +280,20 @@ func (suite *WrapperIntegrationSuite) TestConfigDefaultsSetOnInitAndConnect() {
p.RetentionPolicy.EffectiveKeepLatest().OrDefault(42),
)
},
checkFunc: func(t *testing.T, p *policy.Policy) {
t.Helper()
require.Equal(
t,
newRetention,
p.RetentionPolicy,
)
assert.Equal(
t,
42,
p.RetentionPolicy.EffectiveKeepLatest().OrDefault(42),
)
},
mutator: func(innerCtx context.Context, p *policy.Policy) error {
newRetentionDaily := policy.OptionalInt(42)
newRetention := policy.RetentionPolicy{KeepDaily: &newRetentionDaily}
updateRetentionOnPolicy(newRetention, p)
return nil
@ -280,12 +301,16 @@ func (suite *WrapperIntegrationSuite) TestConfigDefaultsSetOnInitAndConnect() {
},
{
name: "Scheduling",
checkInitFunc: func(t *testing.T, p *policy.Policy) {
t.Helper()
require.Equal(t, defaultSchedulingInterval, p.SchedulingPolicy.Interval())
},
checkFunc: func(t *testing.T, p *policy.Policy) {
t.Helper()
require.Equal(t, time.Second*0, p.SchedulingPolicy.Interval())
require.Equal(t, newSchedInterval, p.SchedulingPolicy.Interval())
},
mutator: func(innerCtx context.Context, p *policy.Policy) error {
updateSchedulingOnPolicy(time.Second*42, p)
updateSchedulingOnPolicy(newSchedInterval, p)
return nil
},
@ -305,7 +330,7 @@ func (suite *WrapperIntegrationSuite) TestConfigDefaultsSetOnInitAndConnect() {
p, err := k.getPolicyOrEmpty(ctx, policy.GlobalPolicySourceInfo)
require.NoError(t, err)
test.checkFunc(t, p)
test.checkInitFunc(t, p)
require.NoError(t, test.mutator(ctx, p))
require.NoError(t, k.writeGlobalPolicy(ctx, "TestDefaultPolicyConfigSet", p))