Skip to content

Commit

Permalink
Actually re-apply unloaded configs on future read
Browse files Browse the repository at this point in the history
Signed-off-by: Bob Weinand <[email protected]>
  • Loading branch information
bwoebi committed Sep 27, 2024
1 parent 97feefb commit b459aa2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
16 changes: 16 additions & 0 deletions sidecar/src/shm_remote_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,8 @@ impl RemoteConfigManager {
if *instant < Instant::now() - Duration::from_secs(3666) {
let (target, _) = self.unexpired_targets.pop().unwrap();
self.encountered_targets.remove(&target);
} else {
break;
}
}
}
Expand Down Expand Up @@ -526,13 +528,16 @@ impl RemoteConfigManager {
self.active_configs.clear();
}

/// Can be used to fast-remove configs temporarily. Will be re-applied on next fetch_update().
pub fn unload_configs(&mut self, configs: &[RemoteConfigProduct]) {
self.active_configs.retain(|key, path| {
if configs.contains(&path.product) {
// self.check_configs should generally be empty here, but be safe
if let Some(pos) = self.check_configs.iter().position(|x| x == key) {
self.check_configs.swap_remove(pos);
}
// And re-apply it on next read
self.last_read_configs.push(key.clone());
false
} else {
true
Expand Down Expand Up @@ -654,6 +659,17 @@ mod tests {
unreachable!();
}

// just one update
assert!(matches!(manager.fetch_update(), RemoteConfigUpdate::None));

manager.unload_configs(&[PATH_FIRST.product]);

if let RemoteConfigUpdate::Add { value, .. } = manager.fetch_update() {
assert_eq!(value.config_id, PATH_FIRST.config_id);
} else {
unreachable!();
}

// just one update
assert!(matches!(manager.fetch_update(), RemoteConfigUpdate::None));

Expand Down
1 change: 1 addition & 0 deletions spawn_worker/src/unix/spawn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ fn write_to_tmp_file(data: &[u8]) -> anyhow::Result<tempfile::NamedTempFile> {

use std::fs::File;

#[cfg(target_os = "linux")]
use std::ffi::CStr;
use std::io;
use std::ops::RangeInclusive;
Expand Down

0 comments on commit b459aa2

Please sign in to comment.