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:
parent
0add271ebc
commit
1e56f5156a
@ -90,13 +90,22 @@ func (w *conn) Initialize(ctx context.Context) error {
|
|||||||
return clues.Wrap(err, "initialzing repo").WithClues(ctx)
|
return clues.Wrap(err, "initialzing repo").WithClues(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
return w.commonConnect(
|
err = w.commonConnect(
|
||||||
ctx,
|
ctx,
|
||||||
cfg.KopiaCfgDir,
|
cfg.KopiaCfgDir,
|
||||||
bst,
|
bst,
|
||||||
cfg.CorsoPassphrase,
|
cfg.CorsoPassphrase,
|
||||||
defaultCompressor,
|
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 {
|
func (w *conn) Connect(ctx context.Context) error {
|
||||||
@ -154,10 +163,6 @@ func (w *conn) commonConnect(
|
|||||||
return clues.Stack(err).WithClues(ctx)
|
return clues.Stack(err).WithClues(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := w.setDefaultConfigValues(ctx); err != nil {
|
|
||||||
return clues.Stack(err).WithClues(ctx)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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 {
|
table := []struct {
|
||||||
name string
|
name string
|
||||||
checkFunc func(*testing.T, *policy.Policy)
|
checkInitFunc func(*testing.T, *policy.Policy)
|
||||||
mutator func(context.Context, *policy.Policy) error
|
checkFunc func(*testing.T, *policy.Policy)
|
||||||
|
mutator func(context.Context, *policy.Policy) error
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "Compression",
|
name: "Compression",
|
||||||
checkFunc: func(t *testing.T, p *policy.Policy) {
|
checkInitFunc: func(t *testing.T, p *policy.Policy) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
require.Equal(t, defaultCompressor, string(p.CompressionPolicy.CompressorName))
|
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 {
|
mutator: func(innerCtx context.Context, p *policy.Policy) error {
|
||||||
_, res := updateCompressionOnPolicy("pgzip", p)
|
_, res := updateCompressionOnPolicy(newCompressor, p)
|
||||||
return res
|
return res
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Retention",
|
name: "Retention",
|
||||||
checkFunc: func(t *testing.T, p *policy.Policy) {
|
checkInitFunc: func(t *testing.T, p *policy.Policy) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
require.Equal(
|
require.Equal(
|
||||||
t,
|
t,
|
||||||
@ -270,9 +280,20 @@ func (suite *WrapperIntegrationSuite) TestConfigDefaultsSetOnInitAndConnect() {
|
|||||||
p.RetentionPolicy.EffectiveKeepLatest().OrDefault(42),
|
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 {
|
mutator: func(innerCtx context.Context, p *policy.Policy) error {
|
||||||
newRetentionDaily := policy.OptionalInt(42)
|
|
||||||
newRetention := policy.RetentionPolicy{KeepDaily: &newRetentionDaily}
|
|
||||||
updateRetentionOnPolicy(newRetention, p)
|
updateRetentionOnPolicy(newRetention, p)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -280,12 +301,16 @@ func (suite *WrapperIntegrationSuite) TestConfigDefaultsSetOnInitAndConnect() {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Scheduling",
|
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) {
|
checkFunc: func(t *testing.T, p *policy.Policy) {
|
||||||
t.Helper()
|
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 {
|
mutator: func(innerCtx context.Context, p *policy.Policy) error {
|
||||||
updateSchedulingOnPolicy(time.Second*42, p)
|
updateSchedulingOnPolicy(newSchedInterval, p)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
@ -305,7 +330,7 @@ func (suite *WrapperIntegrationSuite) TestConfigDefaultsSetOnInitAndConnect() {
|
|||||||
p, err := k.getPolicyOrEmpty(ctx, policy.GlobalPolicySourceInfo)
|
p, err := k.getPolicyOrEmpty(ctx, policy.GlobalPolicySourceInfo)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
test.checkFunc(t, p)
|
test.checkInitFunc(t, p)
|
||||||
|
|
||||||
require.NoError(t, test.mutator(ctx, p))
|
require.NoError(t, test.mutator(ctx, p))
|
||||||
require.NoError(t, k.writeGlobalPolicy(ctx, "TestDefaultPolicyConfigSet", p))
|
require.NoError(t, k.writeGlobalPolicy(ctx, "TestDefaultPolicyConfigSet", p))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user