MCPcopy
hub / github.com/kopia/kopia / sweepLocked

Method sweepLocked

internal/cache/persistent_lru_cache.go:292–327  ·  view source on GitHub ↗

+checklocks:c.listCacheMutex

(ctx context.Context)

Source from the content-addressed store, hash-verified

290
291// +checklocks:c.listCacheMutex
292func (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
329func (c *PersistentCache) initialScan(ctx context.Context) error {
330 timer := timetrack.StartTimer()

Callers 2

PutMethod · 0.95
initialScanMethod · 0.95

Calls 6

aboveSoftLimitMethod · 0.95
aboveHardLimitMethod · 0.95
SubMethod · 0.80
DeleteBlobMethod · 0.65
PopMethod · 0.45
PushMethod · 0.45

Tested by

no test coverage detected