MCPcopy Index your code
hub / github.com/kopia/kopia / initialScan

Method initialScan

internal/cache/persistent_lru_cache.go:329–381  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

327}
328
329func (c *PersistentCache) initialScan(ctx context.Context) error {
330 timer := timetrack.StartTimer()
331
332 var (
333 tooRecentBytes int64
334 tooRecentCount int
335 now = c.timeNow()
336 )
337
338 c.listCacheMutex.Lock()
339 defer c.listCacheMutex.Unlock()
340
341 err := c.cacheStorage.ListBlobs(ctx, "", func(it blob.Metadata) error {
342 // count items below minimal age.
343 if age := now.Sub(it.Timestamp); age < c.sweep.MinSweepAge {
344 tooRecentCount++
345 tooRecentBytes += it.Length
346 }
347
348 heap.Push(&c.listCache, it) // +checklocksignore
349
350 return nil
351 })
352 if err != nil {
353 return errors.Wrapf(err, "error listing %v", c.description)
354 }
355
356 c.sweepLocked(ctx)
357
358 dur := timer.Elapsed()
359
360 const hundredPercent = 100
361
362 inUsePercent := int64(hundredPercent)
363
364 if c.sweep.MaxSizeBytes != 0 {
365 inUsePercent = hundredPercent * c.listCache.totalDataBytes / c.sweep.MaxSizeBytes
366 }
367
368 log(ctx).Debugw(
369 "finished initial cache scan",
370 "cache", c.description,
371 "duration", dur,
372 "totalRetainedSize", c.listCache.totalDataBytes,
373 "tooRecentBytes", tooRecentBytes,
374 "tooRecentCount", tooRecentCount,
375 "maxSizeBytes", c.sweep.MaxSizeBytes,
376 "limitBytes", c.sweep.LimitBytes,
377 "inUsePercent", inUsePercent,
378 )
379
380 return nil
381}
382
383func (c *PersistentCache) exclusiveLock(key string) {
384 if c != nil {

Callers 1

NewPersistentCacheFunction · 0.95

Calls 8

sweepLockedMethod · 0.95
StartTimerFunction · 0.92
SubMethod · 0.80
ElapsedMethod · 0.80
LockMethod · 0.65
UnlockMethod · 0.65
ListBlobsMethod · 0.65
PushMethod · 0.45

Tested by

no test coverage detected