mirror of
https://github.com/neondatabase/neon.git
synced 2026-05-14 11:40:38 +00:00
storcon: Improve stably_attached readability (#12249)
## Problem The `stably_attached` function is hard to read due to deeply nested conditionals ## Summary of Changes - Refactored `stably_attached` to use early returns and the `?` operator for improved readability
This commit is contained in:
committed by
GitHub
parent
1a5f7ce6ad
commit
143500dc4f
@@ -1356,28 +1356,19 @@ impl TenantShard {
|
||||
/// Reconciliation may still be needed for other aspects of state such as secondaries (see [`Self::dirty`]): this
|
||||
/// funciton should not be used to decide whether to reconcile.
|
||||
pub(crate) fn stably_attached(&self) -> Option<NodeId> {
|
||||
if let Some(attach_intent) = self.intent.attached {
|
||||
match self.observed.locations.get(&attach_intent) {
|
||||
Some(loc) => match &loc.conf {
|
||||
Some(conf) => match conf.mode {
|
||||
LocationConfigMode::AttachedMulti
|
||||
| LocationConfigMode::AttachedSingle
|
||||
| LocationConfigMode::AttachedStale => {
|
||||
// Our intent and observed state agree that this node is in an attached state.
|
||||
Some(attach_intent)
|
||||
}
|
||||
// Our observed config is not an attached state
|
||||
_ => None,
|
||||
},
|
||||
// Our observed state is None, i.e. in flux
|
||||
None => None,
|
||||
},
|
||||
// We have no observed state for this node
|
||||
None => None,
|
||||
}
|
||||
} else {
|
||||
// Our intent is not to attach
|
||||
None
|
||||
// We have an intent to attach for this node
|
||||
let attach_intent = self.intent.attached?;
|
||||
// We have an observed state for this node
|
||||
let location = self.observed.locations.get(&attach_intent)?;
|
||||
// Our observed state is not None, i.e. not in flux
|
||||
let location_config = location.conf.as_ref()?;
|
||||
|
||||
// Check if our intent and observed state agree that this node is in an attached state.
|
||||
match location_config.mode {
|
||||
LocationConfigMode::AttachedMulti
|
||||
| LocationConfigMode::AttachedSingle
|
||||
| LocationConfigMode::AttachedStale => Some(attach_intent),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user