Allow control over which storage cache to use

This allows one to better control the usage of the cache and turn it off
completely. The storage configuration module was modified to allow parameters
to be passed to just the storage implementation, rather than to the driver.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
Stephen J Day 2015-04-02 16:38:01 -07:00
parent 44b14ceadc
commit 919d972e65
4 changed files with 52 additions and 8 deletions

View file

@ -5,6 +5,8 @@ log:
service: registry service: registry
environment: development environment: development
storage: storage:
cache:
layerinfo: inmemory
filesystem: filesystem:
rootdirectory: /tmp/registry-dev rootdirectory: /tmp/registry-dev
http: http:

View file

@ -187,7 +187,12 @@ type Storage map[string]Parameters
func (storage Storage) Type() string { func (storage Storage) Type() string {
// Return only key in this map // Return only key in this map
for k := range storage { for k := range storage {
return k switch k {
case "cache":
// allow configuration of caching
default:
return k
}
} }
return "" return ""
} }
@ -211,9 +216,17 @@ func (storage *Storage) UnmarshalYAML(unmarshal func(interface{}) error) error {
if len(storageMap) > 1 { if len(storageMap) > 1 {
types := make([]string, 0, len(storageMap)) types := make([]string, 0, len(storageMap))
for k := range storageMap { for k := range storageMap {
types = append(types, k) switch k {
case "cache":
// allow configuration of caching
default:
types = append(types, k)
}
}
if len(types) > 1 {
return fmt.Errorf("Must provide exactly one storage type. Provided: %v", types)
} }
return fmt.Errorf("Must provide exactly one storage type. Provided: %v", types)
} }
*storage = storageMap *storage = storageMap
return nil return nil

View file

@ -28,6 +28,8 @@ storage:
v4auth: true v4auth: true
chunksize: 5242880 chunksize: 5242880
rootdirectory: /s3/object/name/prefix rootdirectory: /s3/object/name/prefix
cache:
layerinfo: inmemory
auth: auth:
silly: silly:
realm: silly-realm realm: silly-realm
@ -162,10 +164,20 @@ storage:
v4auth: true v4auth: true
chunksize: 5242880 chunksize: 5242880
rootdirectory: /s3/object/name/prefix rootdirectory: /s3/object/name/prefix
cache:
layerinfo: inmemory
``` ```
The storage option is **required** and defines which storage backend is in use. At the moment only one backend may be configured, an error is returned when the registry is started with more than one storage backend configured. The storage option is **required** and defines which storage backend is in use. At the moment only one backend may be configured, an error is returned when the registry is started with more than one storage backend configured.
A `cache` subsection can be used to enable caching of data accessed in the
storage backend. Currently, the only available cache provides fast access to
layer metadata. This if configured using the `layerinfo` field. The following
cache implementations are available:
- redis: using the redis pool to cache layer meta data.
- inmemory: use an in memory map to cache layer meta data.
The following backends may be configured, **all options for a given storage backend are required**: The following backends may be configured, **all options for a given storage backend are required**:
### filesystem ### filesystem

View file

@ -103,11 +103,28 @@ func NewApp(ctx context.Context, configuration configuration.Configuration) *App
app.configureEvents(&configuration) app.configureEvents(&configuration)
app.configureRedis(&configuration) app.configureRedis(&configuration)
if app.redis != nil { // configure storage caches
app.registry = storage.NewRegistryWithDriver(app.driver, cache.NewRedisLayerInfoCache(app.redis)) if cc, ok := configuration.Storage["cache"]; ok {
} else { switch cc["layerinfo"] {
// always fall back to inmemory storage case "redis":
app.registry = storage.NewRegistryWithDriver(app.driver, cache.NewInMemoryLayerInfoCache()) if app.redis == nil {
panic("redis configuration required to use for layerinfo cache")
}
app.registry = storage.NewRegistryWithDriver(app.driver, cache.NewRedisLayerInfoCache(app.redis))
ctxu.GetLogger(app).Infof("using redis layerinfo cache")
case "inmemory":
app.registry = storage.NewRegistryWithDriver(app.driver, cache.NewInMemoryLayerInfoCache())
ctxu.GetLogger(app).Infof("using inmemory layerinfo cache")
default:
if cc["layerinfo"] != "" {
ctxu.GetLogger(app).Warnf("unkown cache type %q, caching disabled", configuration.Storage["cache"])
}
}
}
if app.registry == nil {
// configure the registry if no cache section is available.
app.registry = storage.NewRegistryWithDriver(app.driver, nil)
} }
app.registry, err = applyRegistryMiddleware(app.registry, configuration.Middleware["registry"]) app.registry, err = applyRegistryMiddleware(app.registry, configuration.Middleware["registry"])