Files
kopia/repo/format/format_set_parameters.go
ashmrtn 21789ec9a4 fix(repository): Storage config blob caching (#3192)
* Fix caching issue of storage blob config blob
* Add tests to ensure retention is set during config

Ensure retention is properly set when either changing retention options
or initializing the repo with retention.
2023-08-11 20:36:48 -07:00

54 lines
1.4 KiB
Go

package format
import (
"context"
"github.com/pkg/errors"
"github.com/kopia/kopia/internal/feature"
"github.com/kopia/kopia/repo/blob"
)
// SetParameters sets the mutable repository parameters.
func (m *Manager) SetParameters(
ctx context.Context,
mp MutableParameters,
blobcfg BlobStorageConfiguration,
requiredFeatures []feature.Required,
) error {
m.mu.Lock()
defer m.mu.Unlock()
if err := mp.Validate(); err != nil {
return errors.Wrap(err, "invalid parameters")
}
if err := blobcfg.Validate(); err != nil {
return errors.Wrap(err, "invalid blob-config options")
}
m.repoConfig.ContentFormat.MutableParameters = mp
m.repoConfig.RequiredFeatures = requiredFeatures
if err := m.j.EncryptRepositoryConfig(m.repoConfig, m.formatEncryptionKey); err != nil {
return errors.Errorf("unable to encrypt format bytes")
}
if err := m.j.WriteBlobCfgBlob(ctx, m.blobs, blobcfg, m.formatEncryptionKey); err != nil {
return errors.Wrap(err, "unable to write blobcfg blob")
}
// At this point the new blobcfg is persisted in the blob layer. Setting this
// here also ensures the call below properly sets retention on the kopia
// repository blob.
m.blobCfgBlob = blobcfg
if err := m.j.WriteKopiaRepositoryBlob(ctx, m.blobs, m.blobCfgBlob); err != nil {
return errors.Wrap(err, "unable to write format blob")
}
m.cache.Remove(ctx, []blob.ID{KopiaRepositoryBlobID, KopiaBlobCfgBlobID})
return nil
}