diff options
author | Jaime Martinez <jmartinez@gitlab.com> | 2020-10-14 09:28:12 +0300 |
---|---|---|
committer | Jaime Martinez <jmartinez@gitlab.com> | 2020-10-14 09:29:58 +0300 |
commit | b05139acee33d23743ff2211de2d3bd847a86d13 (patch) | |
tree | 2ab8cedd8d02a34aaf0ea47cd371ac5fb035edaa | |
parent | 858ccc0ee531a007345a187bb8eaed2186a28c9e (diff) |
WIP: Use etag as archive hash481-fix-zip-refresh-for-domain
-rw-r--r-- | internal/httprange/http_reader.go | 7 | ||||
-rw-r--r-- | internal/vfs/zip/archive.go | 8 | ||||
-rw-r--r-- | internal/vfs/zip/vfs.go | 20 |
3 files changed, 33 insertions, 2 deletions
diff --git a/internal/httprange/http_reader.go b/internal/httprange/http_reader.go index 44694e85..c5737813 100644 --- a/internal/httprange/http_reader.go +++ b/internal/httprange/http_reader.go @@ -6,6 +6,7 @@ import ( "fmt" "io" "net/http" + "net/http/httputil" "time" "gitlab.com/gitlab-org/gitlab-pages/internal/httptransport" @@ -76,12 +77,18 @@ func (r *Reader) ensureResponse() error { metrics.HTTPRangeOpenRequests.Inc() + dreq, err := httputil.DumpRequestOut(req, true) + fmt.Printf("req: %s err: %+v\n", dreq, err) + res, err := httpClient.Do(req) if err != nil { metrics.HTTPRangeOpenRequests.Dec() return err } + dres, err := httputil.DumpResponse(res, false) + fmt.Printf("res: %s err: %+v\n", dres, err) + err = r.setResponse(res) if err != nil { metrics.HTTPRangeOpenRequests.Dec() diff --git a/internal/vfs/zip/archive.go b/internal/vfs/zip/archive.go index 548ba651..7846c878 100644 --- a/internal/vfs/zip/archive.go +++ b/internal/vfs/zip/archive.go @@ -247,3 +247,11 @@ func (a *zipArchive) Readlink(ctx context.Context, name string) (string, error) func (a *zipArchive) onEvicted() { metrics.ZipArchiveEntriesCached.Sub(float64(len(a.files))) } + +func (a *zipArchive) Hash() string { + if a.resource == nil { + return "" + } + + return a.resource.ETag +} diff --git a/internal/vfs/zip/vfs.go b/internal/vfs/zip/vfs.go index 3b06f70d..82e63d72 100644 --- a/internal/vfs/zip/vfs.go +++ b/internal/vfs/zip/vfs.go @@ -10,6 +10,7 @@ import ( "github.com/patrickmn/go-cache" + "gitlab.com/gitlab-org/gitlab-pages/internal/httprange" "gitlab.com/gitlab-org/gitlab-pages/internal/vfs" "gitlab.com/gitlab-org/gitlab-pages/metrics" ) @@ -109,8 +110,23 @@ func (fs *zipVFS) findOrCreateArchive(ctx context.Context, path string) (*zipArc // TODO: do not refreshed errored archives https://gitlab.com/gitlab-org/gitlab-pages/-/merge_requests/351 if time.Until(expiry) < defaultCacheRefreshInterval { - // refresh item - fs.cache.SetDefault(key, archive) + + zipArchive := archive.(*zipArchive) + + res, err := httprange.NewResource(ctx, path) + if err != nil { + err := zipArchive.openArchive(ctx) + if err != nil { + return nil, err + } + // do not refresh on error + return zipArchive, nil + } + + if res.ETag != zipArchive.Hash() { + // refresh item with new path + fs.cache.SetDefault(key, archive) + } } } else { archive = newArchive(fs, path, DefaultOpenTimeout) |