//
// SPDX-License-Identifier: AGPL-3.0
-package main
+package keepweb
import (
"sync"
type cache struct {
cluster *arvados.Cluster
- config *arvados.WebDAVCacheConfig // TODO: use cluster.Collections.WebDAV instead
logger logrus.FieldLogger
registry *prometheus.Registry
metrics cacheMetrics
func (c *cache) setup() {
var err error
- c.pdhs, err = lru.New2Q(c.config.MaxUUIDEntries)
+ c.pdhs, err = lru.New2Q(c.cluster.Collections.WebDAVCache.MaxUUIDEntries)
if err != nil {
panic(err)
}
- c.collections, err = lru.New2Q(c.config.MaxCollectionEntries)
+ c.collections, err = lru.New2Q(c.cluster.Collections.WebDAVCache.MaxCollectionEntries)
if err != nil {
panic(err)
}
- c.sessions, err = lru.New2Q(c.config.MaxSessions)
+ c.sessions, err = lru.New2Q(c.cluster.Collections.WebDAVCache.MaxSessions)
if err != nil {
panic(err)
}
return err
}
c.collections.Add(client.AuthToken+"\000"+updated.PortableDataHash, &cachedCollection{
- expire: time.Now().Add(time.Duration(c.config.TTL)),
+ expire: time.Now().Add(time.Duration(c.cluster.Collections.WebDAVCache.TTL)),
collection: &updated,
})
c.pdhs.Add(coll.UUID, &cachedPDH{
- expire: time.Now().Add(time.Duration(c.config.TTL)),
- refresh: time.Now().Add(time.Duration(c.config.UUIDTTL)),
+ expire: time.Now().Add(time.Duration(c.cluster.Collections.WebDAVCache.TTL)),
+ refresh: time.Now().Add(time.Duration(c.cluster.Collections.WebDAVCache.UUIDTTL)),
pdh: updated.PortableDataHash,
})
return nil
if sess == nil {
c.metrics.sessionMisses.Inc()
sess = &cachedSession{
- expire: now.Add(c.config.TTL.Duration()),
+ expire: now.Add(c.cluster.Collections.WebDAVCache.TTL.Duration()),
}
var err error
sess.client, err = arvados.NewClientFromConfig(c.cluster)
if pdh == "" {
// UUID->PDH mapping is not cached, might as well get
// the whole collection record and be done (below).
+ c.logger.Debugf("cache(%s): have no pdh", targetID)
} else if cached := c.lookupCollection(arv.ApiToken + "\000" + pdh); cached == nil {
// PDH->manifest is not cached, might as well get the
// whole collection record (below).
+ c.logger.Debugf("cache(%s): have pdh %s but manifest is not cached", targetID, pdh)
} else if !pdhRefresh {
// We looked up UUID->PDH very recently, and we still
// have the manifest for that PDH.
+ c.logger.Debugf("cache(%s): have pdh %s and refresh not needed", targetID, pdh)
return cached, nil
} else {
// Get current PDH for this UUID (and confirm we still
if current.PortableDataHash == pdh {
// PDH has not changed, cached manifest is
// correct.
- return cached, err
+ c.logger.Debugf("cache(%s): verified cached pdh %s is still correct", targetID, pdh)
+ return cached, nil
}
if cached := c.lookupCollection(arv.ApiToken + "\000" + current.PortableDataHash); cached != nil {
// PDH changed, and we already have the
// manifest for that new PDH.
+ c.logger.Debugf("cache(%s): cached pdh %s was stale, new pdh is %s and manifest is already in cache", targetID, pdh, current.PortableDataHash)
return cached, nil
}
}
if err != nil {
return nil, err
}
- exp := time.Now().Add(time.Duration(c.config.TTL))
+ c.logger.Debugf("cache(%s): retrieved manifest, caching with pdh %s", targetID, retrieved.PortableDataHash)
+ exp := time.Now().Add(time.Duration(c.cluster.Collections.WebDAVCache.TTL))
if targetID != retrieved.PortableDataHash {
c.pdhs.Add(targetID, &cachedPDH{
expire: exp,
- refresh: time.Now().Add(time.Duration(c.config.UUIDTTL)),
+ refresh: time.Now().Add(time.Duration(c.cluster.Collections.WebDAVCache.UUIDTTL)),
pdh: retrieved.PortableDataHash,
})
}
expire: exp,
collection: &retrieved,
})
- if int64(len(retrieved.ManifestText)) > c.config.MaxCollectionBytes/int64(c.config.MaxCollectionEntries) {
+ if int64(len(retrieved.ManifestText)) > c.cluster.Collections.WebDAVCache.MaxCollectionBytes/int64(c.cluster.Collections.WebDAVCache.MaxCollectionEntries) {
select {
case c.chPruneCollections <- struct{}{}:
default:
}
}
for i, k := range keys {
- if size <= c.config.MaxCollectionBytes/2 {
+ if size <= c.cluster.Collections.WebDAVCache.MaxCollectionBytes/2 {
break
}
if expired[i] {