(ctx context.Context)
| 327 | } |
| 328 | |
| 329 | func (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 | |
| 383 | func (c *PersistentCache) exclusiveLock(key string) { |
| 384 | if c != nil { |
no test coverage detected