MCPcopy Create free account
hub / github.com/AdRoll/baker / putInCold

Method putInCold

pkg/buffercache/cache.go:249–271  ·  view source on GitHub ↗

putInCold puts buf in the cold cache if its size fits it, otherwise the buffer is put into the hot cache.

(key string, buf []byte, compressed bool)

Source from the content-addressed store, hash-verified

247// putInCold puts buf in the cold cache if its size fits it, otherwise the
248// buffer is put into the hot cache.
249func (c *BufferCache) putInCold(key string, buf []byte, compressed bool) {
250 bidx := c.cold.smallestFitBucket(len(buf))
251 if bidx < 0 {
252 // can't fit in no bucket, only destination is the hot cache.
253 c.m.m[key] = hotCacheLocation
254 c.putInHot(key, buf, compressed)
255 return
256 }
257
258 // First try: find a free cell and copy buf into it
259 cidx, ok := c.cold.buckets[bidx].put(buf, compressed)
260 if !ok {
261 // Bucket is full: flush it
262 c.cold.buckets[bidx].flush(c.decompressAndFlush)
263 c.m.removeCold(bidx)
264 cidx, ok = c.cold.buckets[bidx].put(buf, compressed)
265 if !ok {
266 panic("still can't find a free cell in a bucket we just flushed")
267 }
268 }
269 // Update the location entry
270 c.m.m[key] = coldLocation(bidx, cidx)
271}
272
273// putInHot places buf in the hot cache, copying it into a new hot cache buffer
274// if that's the first with that key, or appending to the previous buffer with

Callers 2

PutMethod · 0.95
putInHotMethod · 0.95

Calls 6

putInHotMethod · 0.95
coldLocationFunction · 0.85
smallestFitBucketMethod · 0.80
putMethod · 0.80
removeColdMethod · 0.80
flushMethod · 0.45

Tested by

no test coverage detected