trivial: move CachingOptions out of content.Manager, where it's not needed (#775)

* trivial: move CachingOptions out of content.Manager, where it's not needed

* trivial: removed newManagerWithOptions which was the same as NewManager

also moved one-time initialization to newReadManager()
This commit is contained in:
Jarek Kowalski
2021-01-07 18:51:15 -08:00
committed by GitHub
parent 8e17edcdf6
commit 73a34ff7ff
10 changed files with 30 additions and 34 deletions

View File

@@ -13,7 +13,7 @@
var cacheClearCommand = cacheCommands.Command("clear", "Clears the cache")
func runCacheClearCommand(ctx context.Context, rep *repo.DirectRepository) error {
if d := rep.Content.CachingOptions.CacheDirectory; d != "" {
if d := rep.Cache.CacheDirectory; d != "" {
log(ctx).Infof("Clearing cache directory: %v.", d)
// close repository before removing cache

View File

@@ -19,18 +19,18 @@
func runCacheInfoCommand(ctx context.Context, rep *repo.DirectRepository) error {
if *cacheInfoPathOnly {
fmt.Println(rep.Content.CachingOptions.CacheDirectory)
fmt.Println(rep.Cache.CacheDirectory)
return nil
}
entries, err := ioutil.ReadDir(rep.Content.CachingOptions.CacheDirectory)
entries, err := ioutil.ReadDir(rep.Cache.CacheDirectory)
if err != nil {
return errors.Wrap(err, "unable to scan cache directory")
}
path2Limit := map[string]int64{
"contents": rep.Content.CachingOptions.MaxCacheSizeBytes,
"metadata": rep.Content.CachingOptions.MaxMetadataCacheSizeBytes,
"contents": rep.Cache.MaxCacheSizeBytes,
"metadata": rep.Cache.MaxMetadataCacheSizeBytes,
}
for _, ent := range entries {
@@ -38,7 +38,7 @@ func runCacheInfoCommand(ctx context.Context, rep *repo.DirectRepository) error
continue
}
subdir := filepath.Join(rep.Content.CachingOptions.CacheDirectory, ent.Name())
subdir := filepath.Join(rep.Cache.CacheDirectory, ent.Name())
fileCount, totalFileSize, err := scanCacheDir(subdir)
if err != nil {

View File

@@ -19,7 +19,7 @@
)
func runCacheSetCommand(ctx context.Context, rep *repo.DirectRepository) error {
opts := rep.Content.CachingOptions.CloneOrDefault()
opts := rep.Cache.CloneOrDefault()
changed := 0

View File

@@ -49,7 +49,7 @@ func (s *Server) handleRepoStatus(ctx context.Context, r *http.Request, body []b
return &serverapi.StatusResponse{
Connected: true,
ConfigFile: dr.ConfigFile,
CacheDir: dr.Content.CachingOptions.CacheDirectory,
CacheDir: dr.Cache.CacheDirectory,
Hash: dr.Content.Format.Hash,
Encryption: dr.Content.Format.Encryption,
MaxPackSize: dr.Content.Format.MaxPackSize,

View File

@@ -97,7 +97,7 @@ func verifyEndToEndFormatter(ctx context.Context, t *testing.T, hashAlgo, encryp
keyTime := map[blob.ID]time.Time{}
st := blobtesting.NewMapStorage(data, keyTime, nil)
bm, err := newManagerWithOptions(testlogging.Context(t), st, &FormattingOptions{
bm, err := NewManager(testlogging.Context(t), st, &FormattingOptions{
Hash: hashAlgo,
Encryption: encryptionAlgo,
HMACSecret: hmacSecret,

View File

@@ -74,8 +74,6 @@ type IndexBlobInfo struct {
// Manager builds content-addressable storage with encryption, deduplication and packaging on top of BLOB store.
type Manager struct {
CachingOptions CachingOptions
mu *sync.RWMutex
cond *sync.Cond
flushing bool
@@ -706,27 +704,18 @@ func NewManager(ctx context.Context, st blob.Storage, f *FormattingOptions, cach
options.TimeNow = clock.Now
}
return newManagerWithOptions(ctx, st, f, caching, options)
}
func newManagerWithOptions(ctx context.Context, st blob.Storage, f *FormattingOptions, caching *CachingOptions, options *ManagerOptions) (*Manager, error) {
if f.Version < minSupportedReadVersion || f.Version > currentWriteVersion {
return nil, errors.Errorf("can't handle repositories created using version %v (min supported %v, max supported %v)", f.Version, minSupportedReadVersion, maxSupportedReadVersion)
}
if f.Version < minSupportedWriteVersion || f.Version > currentWriteVersion {
return nil, errors.Errorf("can't handle repositories created using version %v (min supported %v, max supported %v)", f.Version, minSupportedWriteVersion, maxSupportedWriteVersion)
}
caching = caching.CloneOrDefault()
readManager, err := newReadManager(ctx, st, f, caching, options)
if err != nil {
return nil, errors.Wrap(err, "error initializing read manager")
}
return newManagerWithReadManager(ctx, f, readManager, options), nil
}
func newManagerWithReadManager(ctx context.Context, f *FormattingOptions, readManager *CommittedReadManager, options *ManagerOptions) *Manager {
mu := &sync.RWMutex{}
m := &Manager{
return &Manager{
lockFreeManager: lockFreeManager{
Format: *f,
maxPackSize: f.MaxPackSize,
@@ -739,7 +728,6 @@ func newManagerWithOptions(ctx context.Context, st blob.Storage, f *FormattingOp
encryptionBufferPool: buf.NewPool(ctx, defaultEncryptionBufferPoolSegmentSize+readManager.encryptor.MaxOverhead(), "content-manager-encryption"),
},
CachingOptions: *caching,
CommittedReadManager: readManager,
mu: mu,
@@ -749,10 +737,4 @@ func newManagerWithOptions(ctx context.Context, st blob.Storage, f *FormattingOp
pendingPacks: map[blob.ID]*pendingPackInfo{},
packIndexBuilder: make(packIndexBuilder),
}
if _, _, err := m.loadPackIndexesUnlocked(ctx); err != nil {
return nil, errors.Wrap(err, "error loading indexes")
}
return m, nil
}

View File

@@ -315,7 +315,7 @@ func TestContentManagerFailedToWritePack(t *testing.T) {
}
st = faulty
bm, err := newManagerWithOptions(testlogging.Context(t), st, &FormattingOptions{
bm, err := NewManager(testlogging.Context(t), st, &FormattingOptions{
Version: 1,
Hash: "HMAC-SHA256-128",
Encryption: "AES256-GCM-HMAC-SHA256",

View File

@@ -306,6 +306,14 @@ func (rm *CommittedReadManager) setupReadManagerCaches(ctx context.Context, cach
}
func newReadManager(ctx context.Context, st blob.Storage, f *FormattingOptions, caching *CachingOptions, opts *ManagerOptions) (*CommittedReadManager, error) {
if f.Version < minSupportedReadVersion || f.Version > currentWriteVersion {
return nil, errors.Errorf("can't handle repositories created using version %v (min supported %v, max supported %v)", f.Version, minSupportedReadVersion, maxSupportedReadVersion)
}
if f.Version < minSupportedWriteVersion || f.Version > currentWriteVersion {
return nil, errors.Errorf("can't handle repositories created using version %v (min supported %v, max supported %v)", f.Version, minSupportedWriteVersion, maxSupportedWriteVersion)
}
hasher, encryptor, err := CreateHashAndEncryptor(f)
if err != nil {
return nil, err
@@ -325,5 +333,9 @@ func newReadManager(ctx context.Context, st blob.Storage, f *FormattingOptions,
return nil, errors.Wrap(err, "error setting up read manager caches")
}
if _, _, err := rm.loadPackIndexesUnlocked(ctx); err != nil {
return nil, errors.Wrap(err, "error loading indexes")
}
return rm, nil
}

View File

@@ -183,6 +183,7 @@ func OpenWithConfig(ctx context.Context, st blob.Storage, lc *LocalConfig, passw
}
dr := &DirectRepository{
Cache: *caching,
Content: cm,
Objects: om,
Blobs: st,

View File

@@ -53,6 +53,7 @@ type DirectRepository struct {
Content *content.Manager
Objects *object.Manager
Manifests *manifest.Manager
Cache content.CachingOptions
UniqueID []byte
ConfigFile string