summaryrefslogtreecommitdiff
path: root/registry/service.go
diff options
context:
space:
mode:
authorSebastiaan van Stijn <github@gone.nl>2022-02-26 14:52:12 +0100
committerSebastiaan van Stijn <github@gone.nl>2022-03-17 17:12:23 +0100
commitdae2173568d70c87e29c85cf106606ab77db2b92 (patch)
treed3a208dc4ed3dd5fcd840d3a47c3d9cc8a33893d /registry/service.go
parent9cb0aa4c9164268f72da13bd74b827390ff511ff (diff)
downloaddocker-dae2173568d70c87e29c85cf106606ab77db2b92.tar.gz
registry: defaultService: use sync.RWMutex
Most operations only require read access, so change this to use an RWMutex, and some minor refactoring in lookupV2Endpoints() so that we are not constructing tlsconfig multiple times in some cases. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Diffstat (limited to 'registry/service.go')
-rw-r--r--registry/service.go34
1 files changed, 15 insertions, 19 deletions
diff --git a/registry/service.go b/registry/service.go
index d66736cb4f..cf53472c52 100644
--- a/registry/service.go
+++ b/registry/service.go
@@ -39,7 +39,7 @@ type Service interface {
// of mirrors.
type defaultService struct {
config *serviceConfig
- mu sync.Mutex
+ mu sync.RWMutex
}
// NewService returns a new instance of defaultService ready to be
@@ -52,8 +52,8 @@ func NewService(options ServiceOptions) (Service, error) {
// ServiceConfig returns the public registry service configuration.
func (s *defaultService) ServiceConfig() *registry.ServiceConfig {
- s.mu.Lock()
- defer s.mu.Unlock()
+ s.mu.RLock()
+ defer s.mu.RUnlock()
servConfig := registry.ServiceConfig{
AllowNondistributableArtifactsCIDRs: make([]*(registry.NetIPNet), 0),
@@ -167,9 +167,9 @@ func (s *defaultService) Search(ctx context.Context, term string, limit int, aut
indexName, remoteName := splitReposSearchTerm(term)
// Search is a long-running operation, just lock s.config to avoid block others.
- s.mu.Lock()
+ s.mu.RLock()
index, err := newIndexInfo(s.config, indexName)
- s.mu.Unlock()
+ s.mu.RUnlock()
if err != nil {
return nil, err
@@ -226,8 +226,8 @@ func (s *defaultService) Search(ctx context.Context, term string, limit int, aut
// ResolveRepository splits a repository name into its components
// and configuration of the associated registry.
func (s *defaultService) ResolveRepository(name reference.Named) (*RepositoryInfo, error) {
- s.mu.Lock()
- defer s.mu.Unlock()
+ s.mu.RLock()
+ defer s.mu.RUnlock()
return newRepositoryInfo(s.config, name)
}
@@ -244,22 +244,18 @@ type APIEndpoint struct {
// TLSConfig constructs a client TLS configuration based on server defaults
func (s *defaultService) TLSConfig(hostname string) (*tls.Config, error) {
- s.mu.Lock()
- defer s.mu.Unlock()
+ s.mu.RLock()
+ secure := isSecureIndex(s.config, hostname)
+ s.mu.RUnlock()
- return s.tlsConfig(hostname)
-}
-
-// tlsConfig constructs a client TLS configuration based on server defaults
-func (s *defaultService) tlsConfig(hostname string) (*tls.Config, error) {
- return newTLSConfig(hostname, isSecureIndex(s.config, hostname))
+ return newTLSConfig(hostname, secure)
}
// LookupPullEndpoints creates a list of v2 endpoints to try to pull from, in order of preference.
// It gives preference to mirrors over the actual registry, and HTTPS over plain HTTP.
func (s *defaultService) LookupPullEndpoints(hostname string) (endpoints []APIEndpoint, err error) {
- s.mu.Lock()
- defer s.mu.Unlock()
+ s.mu.RLock()
+ defer s.mu.RUnlock()
return s.lookupV2Endpoints(hostname)
}
@@ -267,8 +263,8 @@ func (s *defaultService) LookupPullEndpoints(hostname string) (endpoints []APIEn
// LookupPushEndpoints creates a list of v2 endpoints to try to push to, in order of preference.
// It gives preference to HTTPS over plain HTTP. Mirrors are not included.
func (s *defaultService) LookupPushEndpoints(hostname string) (endpoints []APIEndpoint, err error) {
- s.mu.Lock()
- defer s.mu.Unlock()
+ s.mu.RLock()
+ defer s.mu.RUnlock()
allEndpoints, err := s.lookupV2Endpoints(hostname)
if err == nil {