Skip to content

Commit 7a7a072

Browse files
committed
Say that a background fetch can evict at max_size, and trim comments
1 parent c75883a commit 7a7a072

4 files changed

Lines changed: 13 additions & 25 deletions

File tree

‎docs/configuration.md‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -929,10 +929,12 @@ and fetched if its branches or tags moved. It is checked at the URL its last
929929
successful check used, so a repository cached by an older version waits for
930930
a client to refresh it once. After a failed check it waits a quarter of that
931931
interval, at least 10 minutes, so a few retries fit before the copy goes
932-
stale. Checks run one at a time and do not count as use, so they neither keep
933-
a repository from expiring out of `warm_max_idle` nor change which one
934-
`max_size` evicts first. Repositories the upstream refused, and those the
935-
configuration no longer serves, are skipped. `warm_max_idle: 0`, or a
932+
stale. Checks run one at a time and do not count as use, so they do not keep
933+
a repository from expiring out of `warm_max_idle`. With the cache at
934+
`max_size`, a background fetch makes room as any other fetch does, by
935+
evicting the least recently used idle repositories, which can be ones used
936+
more recently than the repository being checked. Repositories the upstream
937+
refused, and those the configuration no longer serves, are skipped. `warm_max_idle: 0`, or a
936938
`stale_max_age` under `20m` (which includes `0`), turns the background
937939
checks off. They run in `proxy serve` only, each process for its own
938940
`cache_dir`.

‎internal/gitcache/warm.go‎

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,8 @@ const (
3434
// quarter of that interval, at least warmMinInterval. Refreshes stop when
3535
// the cache is closed.
3636
//
37-
// A repository is checked at the URL its last successful refresh used, so
38-
// one cached before that URL was kept waits for a client to refresh it.
3937
// serves reports whether the configuration still serves a repository's
4038
// directory in the cache, such as github-1a2b3c4d/acme/widgets.git.
41-
//
42-
// It does nothing with WarmMaxIdle 0, or StaleMaxAge under twice
43-
// warmMinInterval, which includes 0.
4439
func (c *Cache) Warm(serves func(dir string) bool) {
4540
if !c.warmEnabled() {
4641
return
@@ -71,22 +66,18 @@ func (c *Cache) Warm(serves func(dir string) bool) {
7166
}()
7267
}
7368

74-
// warmEnabled reports whether Warm checks repositories at all: not with
75-
// WarmMaxIdle 0, nor when checks every half StaleMaxAge would come more
76-
// often than warmMinInterval.
69+
// warmEnabled reports whether Warm checks repositories at all.
7770
func (c *Cache) warmEnabled() bool {
7871
return c.opts.WarmMaxIdle > 0 && c.warmInterval() >= warmMinInterval
7972
}
8073

81-
// warmInterval is how long after a check a repository is checked again in
82-
// the background: half of StaleMaxAge.
74+
// warmInterval is how long after a check a repository is checked again.
8375
func (c *Cache) warmInterval() time.Duration {
8476
return c.opts.StaleMaxAge / warmStaleFraction
8577
}
8678

8779
// warmRetryInterval is how long after a failed check a repository is tried
88-
// again in the background: a quarter of warmInterval, at least
89-
// warmMinInterval.
80+
// again.
9081
func (c *Cache) warmRetryInterval() time.Duration {
9182
return max(c.warmInterval()/warmRetryFraction, warmMinInterval)
9283
}
@@ -149,11 +140,8 @@ func (c *Cache) warmDue(now time.Time) []*repo {
149140
return due
150141
}
151142

152-
// warmDueLocked reports whether rp is due for a background check: cached,
153-
// with a URL a refresh succeeded with, used by a client within WarmMaxIdle,
154-
// not checked within warmInterval nor failed within warmRetryInterval, not
155-
// refreshing, and not refused upstream or waiting after passing
156-
// git.max_repo_size. c.mu must be held.
143+
// warmDueLocked reports whether rp is due for a background check. c.mu must
144+
// be held.
157145
func (c *Cache) warmDueLocked(rp *repo, now time.Time) bool {
158146
used := rp.lastUsed.Load()
159147
if rp.refused != nil || rp.refreshing != nil || used == 0 || rp.repoURL() == "" ||

‎internal/gitcache/warm_test.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ func TestWarmPassRefreshesARepositoryDueForACheck(t *testing.T) {
5151
if checked := time.Unix(0, rp.lastChecked.Load()); time.Since(checked) > time.Minute {
5252
t.Errorf("lastChecked = %v, want just now", checked)
5353
}
54-
// A background refresh is no use by a client, so it neither renews the
55-
// repository's idle window nor changes the eviction order.
54+
// A background refresh is no use by a client, so it does not renew the
55+
// repository's idle window.
5656
if got := rp.lastUsed.Load(); got != used {
5757
t.Errorf("lastUsed moved from %v to %v", time.Unix(0, used), time.Unix(0, got))
5858
}

‎internal/server/server.go‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,8 +472,6 @@ func (s *Server) serve(listener net.Listener) error {
472472
return s.http.ListenAndServe()
473473
}
474474

475-
// mountProtocolHandlers constructs every ecosystem handler and mounts it on
476-
// r under its protocol prefix.
477475
// mountProtocolHandlers mounts every ecosystem handler at the server's base
478476
// URL, and returns the Git handler, or nil without a Git cache.
479477
func (s *Server) mountProtocolHandlers(r chi.Router, proxy *handler.Proxy) *handler.GitHandler {

0 commit comments

Comments
 (0)