projects
/
arvados.git
/ blobdiff
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'master' into 9426-collection-tags
[arvados.git]
/
services
/
keep-web
/
cache.go
diff --git
a/services/keep-web/cache.go
b/services/keep-web/cache.go
index ab7c65310b0abbf6b9ba1c5eb2b8a22142ab8347..886e5910b5b26ea93a9428e441f273fe316330f6 100644
(file)
--- a/
services/keep-web/cache.go
+++ b/
services/keep-web/cache.go
@@
-1,7
+1,6
@@
package main
import (
package main
import (
- "fmt"
"sync"
"sync/atomic"
"time"
"sync"
"sync/atomic"
"time"
@@
-42,7
+41,7
@@
type cachedPDH struct {
type cachedCollection struct {
expire time.Time
type cachedCollection struct {
expire time.Time
- collection
map[string]interface{}
+ collection
*arvados.Collection
}
type cachedPermission struct {
}
type cachedPermission struct {
@@
-82,7
+81,7
@@
func (c *cache) Stats() cacheStats {
}
}
}
}
-func (c *cache) Get(arv *arvadosclient.ArvadosClient, targetID string, forceReload bool) (
map[string]interface{}
, error) {
+func (c *cache) Get(arv *arvadosclient.ArvadosClient, targetID string, forceReload bool) (
*arvados.Collection
, error) {
c.setupOnce.Do(c.setup)
atomic.AddUint64(&c.stats.Requests, 1)
c.setupOnce.Do(c.setup)
atomic.AddUint64(&c.stats.Requests, 1)
@@
-103,7
+102,6
@@
func (c *cache) Get(arv *arvadosclient.ArvadosClient, targetID string, forceRelo
var pdh string
if arvadosclient.PDHMatch(targetID) {
pdh = targetID
var pdh string
if arvadosclient.PDHMatch(targetID) {
pdh = targetID
- } else if forceReload {
} else if ent, cached := c.pdhs.Get(targetID); cached {
ent := ent.(*cachedPDH)
if ent.expire.Before(time.Now()) {
} else if ent, cached := c.pdhs.Get(targetID); cached {
ent := ent.(*cachedPDH)
if ent.expire.Before(time.Now()) {
@@
-114,7
+112,7
@@
func (c *cache) Get(arv *arvadosclient.ArvadosClient, targetID string, forceRelo
}
}
}
}
- var collection
map[string]interface{}
+ var collection
*arvados.Collection
if pdh != "" {
collection = c.lookupCollection(pdh)
}
if pdh != "" {
collection = c.lookupCollection(pdh)
}
@@
-127,14
+125,12
@@
func (c *cache) Get(arv *arvadosclient.ArvadosClient, targetID string, forceRelo
// _and_ the current token has permission, we can
// use our cached manifest.
atomic.AddUint64(&c.stats.APICalls, 1)
// _and_ the current token has permission, we can
// use our cached manifest.
atomic.AddUint64(&c.stats.APICalls, 1)
- var current
map[string]interface{}
+ var current
arvados.Collection
err := arv.Get("collections", targetID, selectPDH, ¤t)
if err != nil {
return nil, err
}
err := arv.Get("collections", targetID, selectPDH, ¤t)
if err != nil {
return nil, err
}
- if checkPDH, ok := current["portable_data_hash"].(string); !ok {
- return nil, fmt.Errorf("API response for %q had no PDH", targetID)
- } else if checkPDH == pdh {
+ if current.PortableDataHash == pdh {
exp := time.Now().Add(time.Duration(c.TTL))
c.permissions.Add(permKey, &cachedPermission{
expire: exp,
exp := time.Now().Add(time.Duration(c.TTL))
c.permissions.Add(permKey, &cachedPermission{
expire: exp,
@@
-150,7
+146,7
@@
func (c *cache) Get(arv *arvadosclient.ArvadosClient, targetID string, forceRelo
// PDH changed, but now we know we have
// permission -- and maybe we already have the
// new PDH in the cache.
// PDH changed, but now we know we have
// permission -- and maybe we already have the
// new PDH in the cache.
- if coll := c.lookupCollection(c
heckPDH
); coll != nil {
+ if coll := c.lookupCollection(c
urrent.PortableDataHash
); coll != nil {
return coll, nil
}
}
return coll, nil
}
}
@@
-162,23
+158,19
@@
func (c *cache) Get(arv *arvadosclient.ArvadosClient, targetID string, forceRelo
if err != nil {
return nil, err
}
if err != nil {
return nil, err
}
- pdh, ok := collection["portable_data_hash"].(string)
- if !ok {
- return nil, fmt.Errorf("API response for %q had no PDH", targetID)
- }
exp := time.Now().Add(time.Duration(c.TTL))
c.permissions.Add(permKey, &cachedPermission{
expire: exp,
})
c.pdhs.Add(targetID, &cachedPDH{
expire: exp,
exp := time.Now().Add(time.Duration(c.TTL))
c.permissions.Add(permKey, &cachedPermission{
expire: exp,
})
c.pdhs.Add(targetID, &cachedPDH{
expire: exp,
- pdh:
pd
h,
+ pdh:
collection.PortableDataHas
h,
})
})
- c.collections.Add(
pd
h, &cachedCollection{
+ c.collections.Add(
collection.PortableDataHas
h, &cachedCollection{
expire: exp,
collection: collection,
})
expire: exp,
collection: collection,
})
- if int64(len(collection
["manifest_text"].(string)
)) > c.MaxCollectionBytes/int64(c.MaxCollectionEntries) {
+ if int64(len(collection
.ManifestText
)) > c.MaxCollectionBytes/int64(c.MaxCollectionEntries) {
go c.pruneCollections()
}
return collection, nil
go c.pruneCollections()
}
return collection, nil
@@
-203,7
+195,7
@@
func (c *cache) pruneCollections() {
continue
}
ent := v.(*cachedCollection)
continue
}
ent := v.(*cachedCollection)
- n := len(ent.collection
["manifest_text"].(string)
)
+ n := len(ent.collection
.ManifestText
)
size += int64(n)
entsize[i] = n
expired[i] = ent.expire.Before(now)
size += int64(n)
entsize[i] = n
expired[i] = ent.expire.Before(now)
@@
-236,12
+228,12
@@
func (c *cache) collectionBytes() uint64 {
if !ok {
continue
}
if !ok {
continue
}
- size += uint64(len(v.(*cachedCollection).collection
["manifest_text"].(string)
))
+ size += uint64(len(v.(*cachedCollection).collection
.ManifestText
))
}
return size
}
}
return size
}
-func (c *cache) lookupCollection(pdh string)
map[string]interface{}
{
+func (c *cache) lookupCollection(pdh string)
*arvados.Collection
{
if pdh == "" {
return nil
} else if ent, cached := c.collections.Get(pdh); !cached {
if pdh == "" {
return nil
} else if ent, cached := c.collections.Get(pdh); !cached {