struct DiscoveryLimiter {
restart_imminent_lock: Arc<RwLock<bool>>,
restart_imminent_cached: OnceCell<()>,
}Expand description
Encapsulates the handling of running just one discovery process per server
Fields§
§restart_imminent_lock: Arc<RwLock<bool>>Lock that makes sure only one discovery task is running at the same time.
The protected value is true when restart due to a changed constellation is imminent.
restart_imminent_cached: OnceCell<()>Set when contents of restart_imminent_lock lock was observed to be true,
reducing the load on this lock.
Implementations§
Source§impl DiscoveryLimiter
impl DiscoveryLimiter
fn new() -> Self
Sourceasync fn request_discovery<S: Server>(
&self,
app: Rc<S::AppT>,
) -> Result<DiscoveryRunResp>
async fn request_discovery<S: Server>( &self, app: Rc<S::AppT>, ) -> Result<DiscoveryRunResp>
This functions contains the discovery logic that’s shared between servers.
Discovery can be invoked for two reasons:
-
This server has just been restarted and is not aware of the current constellation. Perhaps part of our configuration has changed that makes the current constellation obsolete.
-
The
.ph/discovery/runendpoint was triggered. This should happen when another server detects that our constellation is out-of-date, but since the.ph/discovery/runendpoint is unprotected, anyone can invoke it at any time.The non-PHC servers check during their discovery whether the constellation PHC advertises is up-to-date with respect to their own configuration. If it isn’t, the non-PHC server triggers PHC to run discovery.
PHC checks during its discovery (after it obtained recent details from each of the other servers) whether the constellations of the other servers are up-to-date, and will trigger their discovery routine when these aren’t.
Thus the procedure for discovery is as follows.
Non-PHC:
- Obtain constellation from PHC. Return if it coincides with the constellation that we already got - if we already got one.
- Check the constellation against our own configuration. If it’s up-to-date, restart this server but with the new constellation.
- Invoke discovery on PHC, and return a retryable error - effectively go back to step 1.
PHC:
- Obtain discovery info from ourselves - i.e. check whether
phc_urlis configured correctly. - Retrieve discovery info from the other servers and construct a constellation from it.
- If the constellation has changed, restart to update it.
- Invoke discovery on those servers that have no or outdated constellations, and return a retryable error - effectively go back to step 1.
Sourceasync fn obtain_lock(&self) -> Option<RwLockWriteGuard<'_, bool>>
async fn obtain_lock(&self) -> Option<RwLockWriteGuard<'_, bool>>
Obtains write lock to self.restart_imminent_lock when restart is not imminent.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for DiscoveryLimiter
impl !RefUnwindSafe for DiscoveryLimiter
impl Send for DiscoveryLimiter
impl !Sync for DiscoveryLimiter
impl Unpin for DiscoveryLimiter
impl UnsafeUnpin for DiscoveryLimiter
impl !UnwindSafe for DiscoveryLimiter
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more