+checklocks:c.listCacheMutex
(ctx context.Context)
| 290 | |
| 291 | // +checklocks:c.listCacheMutex |
| 292 | func (c *PersistentCache) sweepLocked(ctx context.Context) { |
| 293 | var ( |
| 294 | unsuccessfulDeletes []blob.Metadata |
| 295 | unsuccessfulDeleteBytes int64 |
| 296 | now = c.timeNow() |
| 297 | ) |
| 298 | |
| 299 | for len(c.listCache.data) > 0 && (c.aboveSoftLimit(unsuccessfulDeleteBytes) || c.aboveHardLimit(unsuccessfulDeleteBytes)) { |
| 300 | // examine the oldest cache item without removing it from the heap. |
| 301 | oldest := c.listCache.data[0] |
| 302 | |
| 303 | if age := now.Sub(oldest.Timestamp); age < c.sweep.MinSweepAge && !c.aboveHardLimit(unsuccessfulDeleteBytes) { |
| 304 | // the oldest item is below the specified minimal sweep age and we're below the hard limit, stop here |
| 305 | break |
| 306 | } |
| 307 | |
| 308 | heap.Pop(&c.listCache) |
| 309 | |
| 310 | if delerr := c.cacheStorage.DeleteBlob(ctx, oldest.BlobID); delerr != nil { |
| 311 | log(ctx).Warnw("unable to remove cache item", "cache", c.description, "item", oldest.BlobID, "err", delerr) |
| 312 | |
| 313 | // accumulate unsuccessful deletes to be pushed back into the heap |
| 314 | // later so we do not attempt deleting the same blob multiple times |
| 315 | // |
| 316 | // after this we keep draining from the heap until we bring down |
| 317 | // c.listCache.DataSize() to zero |
| 318 | unsuccessfulDeletes = append(unsuccessfulDeletes, oldest) |
| 319 | unsuccessfulDeleteBytes += oldest.Length |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | // put all unsuccessful deletes back into the heap |
| 324 | for _, m := range unsuccessfulDeletes { |
| 325 | heap.Push(&c.listCache, m) |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | func (c *PersistentCache) initialScan(ctx context.Context) error { |
| 330 | timer := timetrack.StartTimer() |
no test coverage detected