From dfe023225f8931ac5804c97e82334d1be26f7f27 Mon Sep 17 00:00:00 2001 From: Ramkumar Chinchani Date: Fri, 20 Mar 2020 10:56:19 -0700 Subject: [PATCH] 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. --- WORKSPACE | 4 ++-- pkg/api/routes.go | 6 ++++-- pkg/storage/storage_test.go | 1 - 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index 0c6232d9..c26fbd20 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -1362,8 +1362,8 @@ go_repository( go_repository( name = "com_github_opensuse_umoci", importpath = "github.com/openSUSE/umoci", - sum = "h1:MZgFLy5Jl3VKe5uEOU9c25FoySbx3vUXeXLw4Jf6aRs=", - version = "v0.4.5", + sum = "h1:/8Yu54FufyHHQgIZ/wLy+BLQyzk0gbOG24xf5suWOOI=", + version = "v0.4.6-0.20200320140503-9aa268eeb258", ) go_repository( diff --git a/pkg/api/routes.go b/pkg/api/routes.go index 24bc5588..75e0b2ee 100644 --- a/pkg/api/routes.go +++ b/pkg/api/routes.go @@ -53,7 +53,8 @@ func NewRouteHandler(c *Controller) *RouteHandler { } // blobRLockWrapper calls the real handler with read-lock held -func (rh *RouteHandler) blobRLockWrapper(f func(w http.ResponseWriter, r *http.Request)) func(w http.ResponseWriter, r *http.Request) { +func (rh *RouteHandler) blobRLockWrapper(f func(w http.ResponseWriter, + r *http.Request)) func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) { rh.blobLock.RLock() f(w, r) @@ -62,7 +63,8 @@ func (rh *RouteHandler) blobRLockWrapper(f func(w http.ResponseWriter, r *http.R } // blobLockWrapper calls the real handler with write-lock held -func (rh *RouteHandler) blobLockWrapper(f func(w http.ResponseWriter, r *http.Request)) func(w http.ResponseWriter, r *http.Request) { +func (rh *RouteHandler) blobLockWrapper(f func(w http.ResponseWriter, + r *http.Request)) func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) { rh.blobLock.Lock() f(w, r) diff --git a/pkg/storage/storage_test.go b/pkg/storage/storage_test.go index f194af89..6d017fc5 100644 --- a/pkg/storage/storage_test.go +++ b/pkg/storage/storage_test.go @@ -148,7 +148,6 @@ func TestAPIs(t *testing.T) { _, _, _, err = il.GetImageManifest("test", d.String()) So(err, ShouldNotBeNil) }) - }) err = il.DeleteBlobUpload("test", v)