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)
| 247 | // putInCold puts buf in the cold cache if its size fits it, otherwise the |
| 248 | // buffer is put into the hot cache. |
| 249 | func (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 |
no test coverage detected