From 26411493537eeb54ddafa2e9e29a5723edcd0316 Mon Sep 17 00:00:00 2001 From: Tom Clegg Date: Thu, 22 Feb 2024 10:12:18 -0500 Subject: [PATCH] 2960: Rename parseLocator to getLocatorInfo, add comments. Arvados-DCO-1.1-Signed-off-by: Tom Clegg --- services/keepstore/keepstore.go | 16 +++++++++------- services/keepstore/keepstore_test.go | 2 +- services/keepstore/pull_worker.go | 2 +- services/keepstore/router.go | 2 +- services/keepstore/trash_worker.go | 2 +- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/services/keepstore/keepstore.go b/services/keepstore/keepstore.go index c9a8023059..d85961fd2a 100644 --- a/services/keepstore/keepstore.go +++ b/services/keepstore/keepstore.go @@ -223,7 +223,7 @@ func (ks *keepstore) signLocator(token, locator string) string { } func (ks *keepstore) BlockRead(ctx context.Context, opts arvados.BlockReadOptions) (n int, err error) { - li, err := parseLocator(opts.Locator) + li, err := getLocatorInfo(opts.Locator) if err != nil { return 0, err } @@ -611,7 +611,7 @@ func (ce *checkEqual) WriteAt(p []byte, offset int64) (int, error) { } func (ks *keepstore) BlockUntrash(ctx context.Context, locator string) error { - li, err := parseLocator(locator) + li, err := getLocatorInfo(locator) if err != nil { return err } @@ -631,7 +631,7 @@ func (ks *keepstore) BlockUntrash(ctx context.Context, locator string) error { } func (ks *keepstore) BlockTouch(ctx context.Context, locator string) error { - li, err := parseLocator(locator) + li, err := getLocatorInfo(locator) if err != nil { return err } @@ -655,7 +655,7 @@ func (ks *keepstore) BlockTrash(ctx context.Context, locator string) error { if !ks.cluster.Collections.BlobTrash { return errMethodNotAllowed } - li, err := parseLocator(locator) + li, err := getLocatorInfo(locator) if err != nil { return err } @@ -708,14 +708,16 @@ func ctxToken(ctx context.Context) string { } } +// locatorInfo expresses the attributes of a locator that are relevant +// for keepstore decision-making. type locatorInfo struct { hash string size int - remote bool - signed bool + remote bool // locator has a +R hint + signed bool // locator has a +A hint } -func parseLocator(loc string) (locatorInfo, error) { +func getLocatorInfo(loc string) (locatorInfo, error) { var li locatorInfo for i, part := range strings.Split(loc, "+") { if i == 0 { diff --git a/services/keepstore/keepstore_test.go b/services/keepstore/keepstore_test.go index 28049506f6..79d51829fe 100644 --- a/services/keepstore/keepstore_test.go +++ b/services/keepstore/keepstore_test.go @@ -638,7 +638,7 @@ func (s *keepstoreSuite) TestParseLocator(c *C) { ok: false}, } { c.Logf("=== %s", trial.locator) - li, err := parseLocator(trial.locator) + li, err := getLocatorInfo(trial.locator) if !trial.ok { c.Check(err, NotNil) continue diff --git a/services/keepstore/pull_worker.go b/services/keepstore/pull_worker.go index c131de02cb..dc5eabaa15 100644 --- a/services/keepstore/pull_worker.go +++ b/services/keepstore/pull_worker.go @@ -120,7 +120,7 @@ func (p *puller) runWorker(ctx context.Context) { logger := p.keepstore.logger.WithField("locator", item.Locator) - li, err := parseLocator(item.Locator) + li, err := getLocatorInfo(item.Locator) if err != nil { logger.Warn("ignoring pull request for invalid locator") return diff --git a/services/keepstore/router.go b/services/keepstore/router.go index 256bc18c26..0c8182c6ea 100644 --- a/services/keepstore/router.go +++ b/services/keepstore/router.go @@ -85,7 +85,7 @@ func (rtr *router) handleBlockRead(w http.ResponseWriter, req *http.Request) { out := w if req.Method == http.MethodHead { out = discardWrite{ResponseWriter: w} - } else if li, err := parseLocator(mux.Vars(req)["locator"]); err != nil { + } else if li, err := getLocatorInfo(mux.Vars(req)["locator"]); err != nil { rtr.handleError(w, req, err) return } else if li.size == 0 && li.hash != "d41d8cd98f00b204e9800998ecf8427e" { diff --git a/services/keepstore/trash_worker.go b/services/keepstore/trash_worker.go index d704c3a7d5..819c25acc1 100644 --- a/services/keepstore/trash_worker.go +++ b/services/keepstore/trash_worker.go @@ -107,7 +107,7 @@ func (t *trasher) runWorker(ctx context.Context, mntsAllowTrash []*mount) { defer t.inprogress.Add(-1) logger := t.keepstore.logger.WithField("locator", item.Locator) - li, err := parseLocator(item.Locator) + li, err := getLocatorInfo(item.Locator) if err != nil { logger.Warn("ignoring trash request for invalid locator") return -- 2.30.2