pkg/api: use a rwlock when accessing storage

The original patch used a mutex, however, the workload patterns are
likely to be read-heavy, so use a rwlock instead.
This commit is contained in:
Ramkumar Chinchani
2020-03-20 10:56:19 -07:00
parent fe471a3c35
commit 2fd87b6a86
2 changed files with 20 additions and 10 deletions
+2 -2
View File
@@ -35,7 +35,7 @@ type BlobUpload struct {
// ImageStore provides the image storage operations.
type ImageStore struct {
rootDir string
lock *sync.Mutex
lock *sync.RWMutex
blobUploads map[string]BlobUpload
log zerolog.Logger
}
@@ -43,7 +43,7 @@ type ImageStore struct {
// NewImageStore returns a new image store backed by a file storage.
func NewImageStore(rootDir string, log zlog.Logger) *ImageStore {
is := &ImageStore{rootDir: rootDir,
lock: &sync.Mutex{},
lock: &sync.RWMutex{},
blobUploads: make(map[string]BlobUpload),
log: log.With().Caller().Logger(),
}