pub struct ValuesWatcher { /* private fields */ }Expand description
Watches the values directory for changes, reloading if there are any. If the directory does not exist we do not panic
Does not do an initial fetch, assumes the caller has already loaded values. Child thread may panic if we run out of memory or cannot create more threads.
Uses polling for now, could use inotify or similar later on.
This thread will not be copied when a parent process is forked, so we track the initial PID and recreate the thread handle if it doesn’t match the current process PID.
Some important notes:
- If the thread panics and dies, there is no built in mechanism to catch it and restart
- If a config map is unmounted, we won’t reload until the next file modification (because we don’t catch the deletion event)
- If any namespace fails validation, we keep all old values (even the namespaces that passed validation)
- Values are swapped atomically via ArcSwap (lock-free, fork-safe)
- On drop, the thread is joined only if PID matches (skipped in forked processes)
Implementations§
Source§impl ValuesWatcher
impl ValuesWatcher
pub fn new( values_path: PathBuf, registry: Arc<SchemaRegistry>, values: Arc<ArcSwap<ValuesByNamespace>>, ) -> ValidationResult<Self>
Sourcepub fn ensure_alive(&self)
pub fn ensure_alive(&self)
Compares the current and stored PID. If they differ, we assume we are in a forked process and stored thread handle is dead and invalid. We then respawn the thread.
Auto Trait Implementations§
impl !Freeze for ValuesWatcher
impl !RefUnwindSafe for ValuesWatcher
impl Send for ValuesWatcher
impl Sync for ValuesWatcher
impl Unpin for ValuesWatcher
impl UnsafeUnpin for ValuesWatcher
impl !UnwindSafe for ValuesWatcher
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more