chore(server): Remove "layer seen" cache

This cache is no longer required as it is implicit because the layer
cache (mapping store path hashes to layer hashes) implies that a layer
has been seen.
This commit is contained in:
Vincent Ambo 2019-10-02 17:48:58 +01:00 committed by Vincent Ambo
parent 64fca61ea1
commit 0698d7f2aa

View file

@ -25,8 +25,6 @@ import (
"cloud.google.com/go/storage" "cloud.google.com/go/storage"
) )
type void struct{}
type Build struct { type Build struct {
SHA256 string `json:"sha256"` SHA256 string `json:"sha256"`
MD5 string `json:"md5"` MD5 string `json:"md5"`
@ -39,40 +37,18 @@ type LocalCache struct {
mmtx sync.RWMutex mmtx sync.RWMutex
mcache map[string]string mcache map[string]string
// Layer (tarball) cache // Layer cache
lmtx sync.RWMutex lmtx sync.RWMutex
lcache map[string]void lcache map[string]Build
// Layer (build) cache
bmtx sync.RWMutex
bcache map[string]Build
} }
func NewCache() LocalCache { func NewCache() LocalCache {
return LocalCache{ return LocalCache{
mcache: make(map[string]string), mcache: make(map[string]string),
lcache: make(map[string]void), lcache: make(map[string]Build),
bcache: make(map[string]Build),
} }
} }
// Has this layer hash already been seen by this Nixery instance? If
// yes, we can skip upload checking and such because it has already
// been done.
func (c *LocalCache) hasSeenLayer(hash string) bool {
c.lmtx.RLock()
defer c.lmtx.RUnlock()
_, seen := c.lcache[hash]
return seen
}
// Layer has now been seen and should be stored.
func (c *LocalCache) sawLayer(hash string) {
c.lmtx.Lock()
defer c.lmtx.Unlock()
c.lcache[hash] = void{}
}
// Retrieve a cached manifest if the build is cacheable and it exists. // Retrieve a cached manifest if the build is cacheable and it exists.
func (c *LocalCache) manifestFromLocalCache(key string) (string, bool) { func (c *LocalCache) manifestFromLocalCache(key string) (string, bool) {
c.mmtx.RLock() c.mmtx.RLock()
@ -97,7 +73,7 @@ func (c *LocalCache) localCacheManifest(key, path string) {
// Retrieve a cached build from the local cache. // Retrieve a cached build from the local cache.
func (c *LocalCache) buildFromLocalCache(key string) (*Build, bool) { func (c *LocalCache) buildFromLocalCache(key string) (*Build, bool) {
c.bmtx.RLock() c.bmtx.RLock()
b, ok := c.bcache[key] b, ok := c.lcache[key]
c.bmtx.RUnlock() c.bmtx.RUnlock()
return &b, ok return &b, ok
@ -106,7 +82,7 @@ func (c *LocalCache) buildFromLocalCache(key string) (*Build, bool) {
// Add a build result to the local cache. // Add a build result to the local cache.
func (c *LocalCache) localCacheBuild(key string, b Build) { func (c *LocalCache) localCacheBuild(key string, b Build) {
c.bmtx.Lock() c.bmtx.Lock()
c.bcache[key] = b c.lcache[key] = b
c.bmtx.Unlock() c.bmtx.Unlock()
} }