Commit 6dd7577
authored
feat: validate remote archive/opcode caches against the origin (#195)
## Summary
Before this change, `pkg/executor` cached every HTTP(S) download under a
path derived from `sha256(URL)`. Once downloaded, the cached file was
reused forever for the same URL with zero revalidation against the
origin. If you republished a `.tar.gz` at the same URL (common for
GitHub release assets, re-built CI artifacts), every runner kept using
the stale copy indefinitely — you had to manually delete the cache dir
to force a re-download.
This PR validates cached remote files against the origin on every
resolve using standard HTTP validators (`ETag` / `Last-Modified` /
`Content-Length`):
- On each resolve, send a HEAD to the origin and compare the response to
a sidecar `<cached-file>.meta` JSON stored next to the cached blob.
- **Validators match** → reuse cache (just cost: one HEAD roundtrip).
- **Validators differ** → re-download and refresh the sidecar.
- **No validators returned** or **HEAD fails** → reuse the cache with a
warning so transient network errors or dumb servers don't force
re-downloads.
- **Legacy cache entry without a sidecar** (populated by an older
benchmarkoor) → re-download once to refresh the validators.
Applies to all three HTTP cache sites in `pkg/executor`:
- `archive.file` — single file
- `archive.parts[]` — each part validated independently
- `archive.parts` combined concatenated file — rebuilt when any
underlying part was re-downloaded
- `opcode_source.file`
### Cache layout
```
<cacheDir>/archive-<hash> # the cached file (unchanged)
<cacheDir>/archive-<hash>.meta # new: {url, etag, last_modified, content_length}
```
## Test plan
- [x] Unit tests (`pkg/executor/cache_test.go`):
- `TestFetchCached_HitWhenValidatorsMatch`
- `TestFetchCached_MissWhenETagChanges`
- `TestFetchCached_LegacySidecarMissingReDownloads`
- `TestFetchCached_NoValidatorsFallsBackToCache`
- `TestFetchCached_HeadFailureFallsBackToCache`
- `TestFetchCached_CacheMissCoexistsWithOtherPrefixes`
- [x] `TestArchiveSource_PartsReconcatenateOnOriginChange` verifies that
flipping a part's ETag triggers re-concatenation of the combined archive
- [x] All existing archive_source tests still pass
- [x] `go vet -tags exclude_graphdriver_btrfs ./...` clean
- [x] Manual: republish a `.tar.gz` at a previously-used URL and confirm
the next run re-downloads; confirm an unchanged URL continues to use the
cache (only adds one HEAD roundtrip)1 parent d72dfae commit 6dd7577
5 files changed
Lines changed: 697 additions & 134 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
107 | 107 | | |
108 | 108 | | |
109 | 109 | | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
114 | 116 | | |
115 | 117 | | |
116 | 118 | | |
| |||
119 | 121 | | |
120 | 122 | | |
121 | 123 | | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | 124 | | |
136 | 125 | | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
| 126 | + | |
| 127 | + | |
147 | 128 | | |
148 | 129 | | |
149 | 130 | | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
| 131 | + | |
159 | 132 | | |
160 | 133 | | |
161 | 134 | | |
| |||
175 | 148 | | |
176 | 149 | | |
177 | 150 | | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
184 | 157 | | |
185 | 158 | | |
186 | 159 | | |
187 | 160 | | |
188 | 161 | | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
| 162 | + | |
| 163 | + | |
199 | 164 | | |
200 | 165 | | |
201 | 166 | | |
202 | 167 | | |
203 | 168 | | |
204 | 169 | | |
205 | 170 | | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
| 171 | + | |
217 | 172 | | |
218 | 173 | | |
| 174 | + | |
| 175 | + | |
219 | 176 | | |
220 | 177 | | |
221 | 178 | | |
222 | 179 | | |
223 | 180 | | |
224 | 181 | | |
225 | 182 | | |
226 | | - | |
| 183 | + | |
227 | 184 | | |
228 | 185 | | |
229 | 186 | | |
230 | 187 | | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
231 | 192 | | |
232 | 193 | | |
233 | 194 | | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
234 | 205 | | |
235 | 206 | | |
236 | 207 | | |
| |||
251 | 222 | | |
252 | 223 | | |
253 | 224 | | |
254 | | - | |
255 | | - | |
256 | | - | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
257 | 231 | | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
266 | | - | |
267 | | - | |
268 | | - | |
269 | | - | |
270 | 232 | | |
271 | 233 | | |
272 | | - | |
273 | | - | |
274 | | - | |
275 | | - | |
276 | | - | |
277 | | - | |
278 | | - | |
279 | | - | |
280 | | - | |
281 | | - | |
282 | | - | |
283 | | - | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
284 | 237 | | |
285 | 238 | | |
286 | | - | |
| 239 | + | |
287 | 240 | | |
288 | 241 | | |
289 | 242 | | |
290 | 243 | | |
291 | 244 | | |
292 | 245 | | |
293 | | - | |
| 246 | + | |
294 | 247 | | |
295 | 248 | | |
296 | 249 | | |
297 | 250 | | |
298 | 251 | | |
299 | 252 | | |
300 | | - | |
| 253 | + | |
301 | 254 | | |
302 | 255 | | |
303 | | - | |
| 256 | + | |
304 | 257 | | |
305 | 258 | | |
306 | 259 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
10 | 12 | | |
11 | 13 | | |
12 | 14 | | |
13 | 15 | | |
14 | 16 | | |
15 | 17 | | |
| 18 | + | |
| 19 | + | |
16 | 20 | | |
17 | 21 | | |
18 | 22 | | |
| |||
356 | 360 | | |
357 | 361 | | |
358 | 362 | | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
359 | 488 | | |
360 | 489 | | |
361 | 490 | | |
| |||
0 commit comments