From abf796d17c2b2776c155a20bc6493a177c1fda87 Mon Sep 17 00:00:00 2001 From: yixi zhang Date: Tue, 20 Dec 2016 22:21:29 -0800 Subject: [PATCH] Use app.driver.Stat for registry health check `app.driver.List` on `"/"` is very expensive if registry contains significant amount of images. And the result isn't used anyways. In most (if not all) storage drivers, `Stat` has a cheaper implementation, so use it instead to achieve the same goal. Signed-off-by: yixi zhang --- registry/handlers/app.go | 2 +- registry/storage/driver/base/base.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/registry/handlers/app.go b/registry/handlers/app.go index fde2a4acc..0f30603f0 100644 --- a/registry/handlers/app.go +++ b/registry/handlers/app.go @@ -341,7 +341,7 @@ func (app *App) RegisterHealthChecks(healthRegistries ...*health.Registry) { } storageDriverCheck := func() error { - _, err := app.driver.List(app, "/") // "/" should always exist + _, err := app.driver.Stat(app, "/") // "/" should always exist return err // any error will be treated as failure } diff --git a/registry/storage/driver/base/base.go b/registry/storage/driver/base/base.go index 064bda60f..e14f7edb1 100644 --- a/registry/storage/driver/base/base.go +++ b/registry/storage/driver/base/base.go @@ -137,7 +137,7 @@ func (base *Base) Stat(ctx context.Context, path string) (storagedriver.FileInfo ctx, done := context.WithTrace(ctx) defer done("%s.Stat(%q)", base.Name(), path) - if !storagedriver.PathRegexp.MatchString(path) { + if !storagedriver.PathRegexp.MatchString(path) && path != "/" { return nil, storagedriver.InvalidPathError{Path: path, DriverName: base.StorageDriver.Name()} }