Skip to content

Commit 3e830a1

Browse files
authored
fix(git): freshen mirror in snapshot job, not per request (#366)
Snapshot and git request paths called maybeBackgroundFetch on every request, which is time-based and un-deduplicated. A parallel snapshot restore burst made every concurrent request enqueue its own fetch, flooding the per-repo fetch queue with back-to-back fetches. Move mirror freshening into the periodic snapshot job (fetch then snapshot) and drop maybeBackgroundFetch from the request paths.
1 parent 2c636d7 commit 3e830a1

2 files changed

Lines changed: 3 additions & 9 deletions

File tree

internal/strategy/git/git.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,6 @@ func (s *Strategy) serveReadyRepo(w http.ResponseWriter, r *http.Request, repo *
377377
s.forwardToUpstream(w, r, host, pathValue)
378378
return nil
379379
}
380-
s.maybeBackgroundFetch(repo)
381380

382381
// Buffer the request body so it can be replayed if serveFromBackend
383382
// signals a fallback to upstream (e.g. on "not our ref").
@@ -708,13 +707,6 @@ func (s *Strategy) tryRestoreSnapshot(ctx context.Context, repo *gitclone.Reposi
708707
return nil
709708
}
710709

711-
func (s *Strategy) maybeBackgroundFetch(repo *gitclone.Repository) {
712-
if !repo.NeedsFetch(s.cloneManager.Config().FetchInterval) {
713-
return
714-
}
715-
s.submitFetch(repo)
716-
}
717-
718710
// submitFetch schedules a fetch unconditionally. Use this when ls-remote has
719711
// already confirmed the mirror is behind upstream.
720712
func (s *Strategy) submitFetch(repo *gitclone.Repository) {

internal/strategy/git/snapshot.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ func (s *Strategy) generateAndUploadMirrorSnapshot(ctx context.Context, repo *gi
204204

205205
func (s *Strategy) scheduleSnapshotJobs(repo *gitclone.Repository) {
206206
s.scheduler.SubmitPeriodicJob(repo.UpstreamURL(), "snapshot-periodic", s.config.SnapshotInterval, func(ctx context.Context) error {
207+
if err := s.doFetch(ctx, repo); err != nil {
208+
logging.FromContext(ctx).WarnContext(ctx, "Pre-snapshot fetch failed", "upstream", repo.UpstreamURL(), "error", err)
209+
}
207210
return s.generateAndUploadSnapshot(ctx, repo)
208211
})
209212
s.scheduler.SubmitPeriodicJob(repo.UpstreamURL(), "lfs-snapshot-periodic", s.config.SnapshotInterval, func(ctx context.Context) error {
@@ -307,7 +310,6 @@ func (s *Strategy) handleSnapshotRequest(w http.ResponseWriter, r *http.Request,
307310
http.Error(w, "Repository unavailable", http.StatusServiceUnavailable)
308311
return
309312
}
310-
s.maybeBackgroundFetch(repo)
311313

312314
// Forward the full conditional/range set: the cache resolves If-Match /
313315
// If-None-Match before Range, so 304/412 already take precedence over a

0 commit comments

Comments
 (0)