Skip to content

Commit 9056dd3

Browse files
committed
[registry] Disable token refresh thread when prefetch is enabled
Add a new RegistryConfig field called `disable_token_refresh` that will decide whether the registry refresh token thread is started or not. It will be set to false by default but will be enabled when prefetch is enabled. The refresh thread is disabled in this case because it becomes useless once everything has been prefetched and it's unlikely that tokens would expire during the time it takes for the prefetch to run (as it would mean that regular image pulls would be likely to fail as well because they download the layers in a similar time to the prefetch) Signed-off-by: Baptiste Girard-Carrabin <baptiste.girardcarrabin@datadoghq.com>
1 parent c100686 commit 9056dd3

2 files changed

Lines changed: 36 additions & 4 deletions

File tree

api/src/config.rs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,9 @@ pub struct RegistryConfig {
626626
/// Enable HTTP proxy for the read request.
627627
#[serde(default)]
628628
pub proxy: ProxyConfig,
629+
/// Disable background token refresh thread. Defaults to false.
630+
#[serde(skip_deserializing)]
631+
pub disable_token_refresh: bool,
629632
}
630633

631634
/// Configuration information for blob cache manager.
@@ -1364,7 +1367,7 @@ impl TryFrom<RafsConfig> for ConfigV2 {
13641367
type Error = std::io::Error;
13651368

13661369
fn try_from(v: RafsConfig) -> std::result::Result<Self, Self::Error> {
1367-
let backend: BackendConfigV2 = (&v.device.backend).try_into()?;
1370+
let mut backend: BackendConfigV2 = (&v.device.backend).try_into()?;
13681371
let mut cache: CacheConfigV2 = (&v.device.cache).try_into()?;
13691372
let rafs = RafsConfigV2 {
13701373
mode: v.mode,
@@ -1380,6 +1383,13 @@ impl TryFrom<RafsConfig> for ConfigV2 {
13801383
cache.prefetch = rafs.prefetch.clone();
13811384
}
13821385

1386+
// If prefetch is enabled, disable token refresh by default
1387+
if cache.prefetch.enable {
1388+
if let Some(registry) = backend.registry.as_mut() {
1389+
registry.disable_token_refresh = true;
1390+
}
1391+
}
1392+
13831393
Ok(ConfigV2 {
13841394
version: 2,
13851395
id: v.device.id,
@@ -1509,10 +1519,19 @@ impl TryFrom<&BlobCacheEntryConfig> for BlobCacheEntryConfigV2 {
15091519
cache_validate: false,
15101520
prefetch_config: v.prefetch_config.clone(),
15111521
};
1522+
let mut backend: BackendConfigV2 = (&backend_config).try_into()?;
1523+
1524+
// If prefetch is enabled, disable token refresh by default
1525+
if cache_config.prefetch_config.enable {
1526+
if let Some(registry) = backend.registry.as_mut() {
1527+
registry.disable_token_refresh = true;
1528+
}
1529+
}
1530+
15121531
Ok(BlobCacheEntryConfigV2 {
15131532
version: 2,
15141533
id: v.id.clone(),
1515-
backend: (&backend_config).try_into()?,
1534+
backend,
15161535
external_backends: v.external_backends.clone(),
15171536
cache: (&cache_config).try_into()?,
15181537
metadata_path: v.metadata_path.clone(),
@@ -2099,6 +2118,15 @@ mod tests {
20992118
"#;
21002119
let config = ConfigV2::from_str(content).unwrap();
21012120
assert_eq!(&config.id, "");
2121+
// token refresh should be disabled when prefetch is enabled
2122+
assert!(
2123+
config
2124+
.get_backend_config()
2125+
.unwrap()
2126+
.get_registry_config()
2127+
.unwrap()
2128+
.disable_token_refresh
2129+
);
21022130
}
21032131

21042132
#[test]

storage/src/backend/registry.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -883,8 +883,12 @@ impl Registry {
883883
first: First::new(),
884884
};
885885

886-
registry.start_refresh_token_thread();
887-
info!("Refresh token thread started.");
886+
if config.disable_token_refresh {
887+
info!("Refresh token thread is disabled.");
888+
} else {
889+
registry.start_refresh_token_thread();
890+
info!("Refresh token thread started.");
891+
}
888892

889893
Ok(registry)
890894
}

0 commit comments

Comments
 (0)