mirror of
https://github.com/git-pkgs/proxy.git
synced 2026-11-09 15:49:16 -05:00
* max_size now counts cached metadata as well as artifacts, and eviction drops whichever was used least recently, so metadata no longer piles up for good (#461). Metadata rows record when they were last served, an artifact not yet served counts from its download, and Arch stores a database blob again if eviction removed it under a refreshed row. * Shorter comments on the metadata last-access migration. * Show evicted metadata on the analytics page next to evicted artifacts, and cover the new counter in the metric surface test. * Evicting metadata now drops the row and queues its path in one transaction, so a crash before the blob is deleted leaves it to reclaim instead of orphaning it. * The last-access backfill now runs in the background in batches of 1000 instead of inside the migration, resuming after a restart, and until a row is backfilled eviction orders it by its write time. --------- Co-authored-by: Andrew Nesbitt <andrewnez@gmail.com>
38 lines
933 B
Go
38 lines
933 B
Go
package server
|
|
|
|
import (
|
|
"context"
|
|
"log/slog"
|
|
"time"
|
|
|
|
"github.com/git-pkgs/proxy/internal/database"
|
|
)
|
|
|
|
// metadataBackfillBatch bounds each backfill transaction, so other writers
|
|
// get the database in between.
|
|
const metadataBackfillBatch = 1000
|
|
|
|
// backfillMetadataAccess gives metadata rows cached before last_accessed_at
|
|
// existed their write time, batch by batch. It is resumable: a restart picks
|
|
// up whatever rows are still empty.
|
|
func backfillMetadataAccess(ctx context.Context, db *database.DB, logger *slog.Logger, batch int) {
|
|
total := 0
|
|
for ctx.Err() == nil {
|
|
n, err := db.BackfillMetadataLastAccessed(batch)
|
|
if err != nil {
|
|
logger.Warn("metadata backfill failed, retrying", "error", err)
|
|
select {
|
|
case <-ctx.Done():
|
|
case <-time.After(time.Minute):
|
|
}
|
|
continue
|
|
}
|
|
total += n
|
|
if n < batch {
|
|
break
|
|
}
|
|
}
|
|
if total > 0 {
|
|
logger.Info("metadata backfill: completed", "rows", total)
|
|
}
|
|
}
|