Skip to content

Commit 45a0635

Browse files
author
ztzhou
committed
refactor: exclude draft background refresh
Keep rolandjitsu#72, rolandjitsu#76 and rolandjitsu#77 with internal maintenance while deferring rolandjitsu#67. Preserve the previous tree on its archive branch and in normal history. Assisted-by: OpenAI:Codex
1 parent 8b1e58c commit 45a0635

14 files changed

Lines changed: 97 additions & 1551 deletions

File tree

‎README.md‎

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -79,24 +79,6 @@ Every flag has an environment-variable equivalent; the full reference is in
7979
- `--serve-token` / `--auth-provider`: how clients authenticate to the proxy.
8080
- `--cache-max-mb`: cap on-disk cache size (LRU eviction; `0` = unlimited).
8181

82-
With a positive `--max-stale-seconds`, an existing mirror can serve cached refs
83-
while one background fetch updates it. Age is measured from the start of the last
84-
successful clone or fetch. When its age exceeds the limit, a request waits for a
85-
refresh or fails. After restart, a mirror's age is unknown and it must refresh
86-
before serving. Background attempts are limited globally and retried no sooner
87-
than the fetch TTL, or one second, after the previous attempt completes.
88-
89-
Fetch-triggered automatic Git maintenance is disabled in this mode so a refresh
90-
does not delete objects just advertised to a client. Active requests are protected
91-
from proxy eviction until their Git process exits. There is no fixed limit between
92-
advertisement and upload-pack, so eviction or external Git maintenance between
93-
requests can remove an old object. A missing SHA is fetched on demand when the
94-
upstream permits it; this is best effort. In this mode a client with access to a
95-
mirror can request any object already present in that mirror by SHA, including an
96-
object no longer reachable from an advertised ref.
97-
98-
Endpoints: `/healthz`, `/readyz`, `/metrics` (see [Metrics](#metrics)).
99-
10082
## Metrics
10183

10284
`GET /metrics` serves Prometheus text-format metrics - per-repo request and
@@ -147,7 +129,8 @@ Pin a version and try it against your own setup before relying on it.
147129

148130
Not yet implemented:
149131

150-
- Scheduled refresh. Background refresh is triggered by requests.
132+
- A background/scheduled refresh (today every `info/refs` triggers an on-demand,
133+
TTL-coalesced fetch).
151134

152135
**Non-goal: a git-free image.** The `git` binary is a permanent runtime
153136
dependency: the proxy serves clients by running `git upload-pack`, and no
@@ -174,8 +157,7 @@ SIGTERM and Ctrl-C reject new upstream work and cancel active commands, retry
174157
backoff and repository lock waits before HTTP drain. Upstream owners kill process
175158
groups on Unix and wait for the direct child before releasing repository locks.
176159
Dropped requests also cancel their upstream owner. Library hosts call
177-
`GitCache::cancel_upstream` before draining HTTP, `wait_for_shutdown` after
178-
draining, then the async `shutdown` method to drain detached request and refresh tasks.
160+
`GitCache::shutdown` before draining HTTP and `wait_for_shutdown` after draining.
179161
Active local upload-pack responses continue to drain. This does not impose a hard
180162
shutdown bound on active uploads or blocking filesystem work. On non-Unix targets,
181163
cancellation terminates only the direct child.

‎chart/README.md‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,6 @@ pointing at the Service.
115115
| `clientAuth.signingKey.key` | `signing-key` | Key in that Secret |
116116
| `config.upstreamTimeoutSeconds` | `3600` | Positive total seconds per upstream operation, including retries |
117117
| `config.fetchTtlSeconds` | `10` | Skip upstream fetch if refreshed within this window (`0` = always) |
118-
| `config.maxStaleSeconds` | `0` | Maximum age of cached refs served while refreshing (`0` = disabled) |
119-
| `config.maxBackgroundFetches` | `4` | Maximum concurrent background refreshes (at least `1`) |
120118
| `config.cacheMaxMb` | `0` | Cap on on-disk cache, MiB; evicts LRU idle mirrors (`0` = unlimited) |
121119
| `config.maxConcurrentRequests` | `64` | Max concurrent in-flight requests (`0` = unlimited) |
122120
| `config.maxDecodedBodyMb` | `512` | Cap on a decoded upload-pack request body, MiB |

‎chart/templates/deployment.yaml‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,6 @@ spec:
7070
value: {{ .Values.config.upstreamTimeoutSeconds | quote }}
7171
- name: GITCACHEPROXY_FETCH_TTL_SECONDS
7272
value: {{ .Values.config.fetchTtlSeconds | quote }}
73-
- name: GITCACHEPROXY_MAX_STALE_SECONDS
74-
value: {{ .Values.config.maxStaleSeconds | quote }}
75-
- name: GITCACHEPROXY_MAX_BACKGROUND_FETCHES
76-
value: {{ .Values.config.maxBackgroundFetches | quote }}
7773
- name: GITCACHEPROXY_CACHE_MAX_MB
7874
value: {{ .Values.config.cacheMaxMb | quote }}
7975
- name: GITCACHEPROXY_MAX_CONCURRENT_REQUESTS

‎chart/values.yaml‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,6 @@ config:
8181
# Skip the upstream fetch on info/refs if the mirror was refreshed within this
8282
# many seconds; coalesces bursts of clones for one repo. 0 = always fetch.
8383
fetchTtlSeconds: 10
84-
# Serve cached refs for at most this age while refreshing. 0 disables it.
85-
maxStaleSeconds: 0
86-
# Maximum simultaneous background refreshes, at least 1.
87-
maxBackgroundFetches: 4
8884
# Total upstream command budget, including retries (positive seconds).
8985
upstreamTimeoutSeconds: 3600
9086
# Cap on total on-disk mirror cache, in MiB; evicts least-recently-used idle

‎docs/configuration.md‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ Every flag has an environment-variable equivalent.
1919
| `--auth-ttl-seconds` | `GITCACHEPROXY_AUTH_TTL_SECONDS` | `0` | Reuse a validation verdict per `(credential, repo)` for this many seconds, so the requests of one clone, or repeated submodule fetches, validate once (`0` = validate every request) |
2020
| `--auth-max-concurrent` | `GITCACHEPROXY_AUTH_MAX_CONCURRENT` | `32` | Max token-validation requests in flight; a check waits up to `--auth-timeout-seconds` for a slot, then fails with 503 (`0` = unlimited) |
2121
| `--auth-allow-http` | `GITCACHEPROXY_AUTH_ALLOW_HTTP` | `false` | Provider modes: accept a plain `http://` validation endpoint, which sends client credentials in cleartext |
22+
| `--upstream-timeout-seconds` | `GITCACHEPROXY_UPSTREAM_TIMEOUT_SECONDS` | `3600` | Positive total budget per clone, full-ref fetch or SHA backfill, including all attempts and retry delays |
2223
| `--fetch-ttl-seconds` | `GITCACHEPROXY_FETCH_TTL_SECONDS` | `10` | Skip upstream fetch if the last one started within this window (`0` = always fetch) |
23-
| `--max-stale-seconds` | `GITCACHEPROXY_MAX_STALE_SECONDS` | `0` | Maximum age of cached refs served during background refresh (`0` = disabled) |
24-
| `--max-background-fetches` | `GITCACHEPROXY_MAX_BACKGROUND_FETCHES` | `4` | Maximum concurrent background refreshes (at least `1`) |
2524
| `--max-concurrent-requests` | `GITCACHEPROXY_MAX_CONCURRENT_REQUESTS` | `64` | Max concurrent in-flight requests; excess queue (`0` = unlimited) |
2625
| `--max-concurrent-upload-packs` | `GITCACHEPROXY_MAX_CONCURRENT_UPLOAD_PACKS` | `0` | Max concurrent `git upload-pack` processes, held until each exits; bounds `pack-objects` memory. Clones waiting for a slot hold a `--max-concurrent-requests` slot (`0` = unlimited) |
2726
| `--max-decoded-body-mb` | `GITCACHEPROXY_MAX_DECODED_BODY_MB` | `512` | Cap on a decoded upload-pack request body, in MiB (bounds memory / gzip bombs) |

‎docs/internal-maintenance.md‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,15 @@ This policy applies to profiling/git-cache-proxy only.
99
- Contribution branches: one change per community PR, based on official main.
1010
- `archive/main-before-internal-20261114`: the original fork main, retained for recovery.
1111

12-
The initial internal tree combines community PR #67 at `17c8719` and #72 at
13-
`205fc39`. PR #51 is already in official main. The upload-pack owner retains
14-
both the mirror read guard from #67 and the concurrent writer from #72.
12+
The current internal tree combines official main at `6c4ff31`, PR #72 at
13+
`205fc39`, PR #76 at `a14cc00`, and PR #77 at `78ce674`. PR #51 is already in
14+
official main. The upload-pack owner retains the concurrent writer and cleanup
15+
from #72; upstream operations retain the total budget and cancellation from #77.
16+
17+
Draft PR #67 is excluded until it is ready for reassessment. The previous tree,
18+
including its earlier integration, is retained at
19+
`archive/internal-main-with-draft67-8b1e58c`. Removing its behavior uses a normal
20+
commit on internal/main; existing history and community PR branches are preserved.
1521

1622
## Automation
1723

‎src/config.rs‎

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,6 @@ use std::path::PathBuf;
77
use anyhow::{Result, bail};
88
use clap::{Parser, ValueEnum};
99

10-
fn positive_usize(value: &str) -> Result<usize, String> {
11-
let value: usize = value.parse().map_err(|_| "expected a positive integer")?;
12-
if value == 0 || value > tokio::sync::Semaphore::MAX_PERMITS {
13-
return Err("value is outside the semaphore range".into());
14-
}
15-
Ok(value)
16-
}
17-
1810
/// Log output format.
1911
#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
2012
pub enum LogFormat {
@@ -229,14 +221,6 @@ pub struct Config {
229221
#[arg(long, env = "GITCACHEPROXY_FETCH_TTL_SECONDS", default_value_t = 10)]
230222
pub fetch_ttl_seconds: u64,
231223

232-
/// Maximum age of cached refs served while refreshing; 0 disables this mode.
233-
#[arg(long, env = "GITCACHEPROXY_MAX_STALE_SECONDS", default_value_t = 0)]
234-
pub max_stale_seconds: u64,
235-
236-
/// Maximum number of concurrent background refreshes.
237-
#[arg(long, env = "GITCACHEPROXY_MAX_BACKGROUND_FETCHES", default_value_t = 4, value_parser = positive_usize)]
238-
pub max_background_fetches: usize,
239-
240224
/// Maximum number of requests handled concurrently, shared across all
241225
/// connections. Excess requests queue until a slot frees. This bounds the
242226
/// concurrent upstream clone/fetch work a burst can trigger (the slot is held
@@ -387,12 +371,4 @@ mod tests {
387371
.to_string();
388372
assert!(err.contains("--upstream-auth-header"), "{err}");
389373
}
390-
391-
#[test]
392-
fn background_fetch_limit_must_be_positive_and_fit_a_semaphore() {
393-
assert_eq!(positive_usize("1").unwrap(), 1);
394-
assert!(positive_usize("0").is_err());
395-
assert!(positive_usize("invalid").is_err());
396-
assert!(positive_usize(&usize::MAX.to_string()).is_err());
397-
}
398374
}

0 commit comments

Comments
 (0)