mirror of
https://github.com/neondatabase/neon.git
synced 2026-05-25 09:00:37 +00:00
storage_controller: make address for peers mandatory
This commit is contained in:
@@ -1762,23 +1762,19 @@ async fn maybe_forward(req: Request<Body>) -> ForwardOutcome {
|
||||
};
|
||||
|
||||
let cfg = state.service.get_config();
|
||||
if let Some(ref self_addr) = cfg.address_for_peers {
|
||||
let leader_addr = match Uri::from_str(leader.address.as_str()) {
|
||||
Ok(uri) => uri,
|
||||
Err(err) => {
|
||||
return ForwardOutcome::Forwarded(Err(ApiError::InternalServerError(
|
||||
anyhow::anyhow!(
|
||||
"Failed to parse leader uri for forwarding while in stepped down state: {err}"
|
||||
),
|
||||
)));
|
||||
}
|
||||
};
|
||||
|
||||
if *self_addr == leader_addr {
|
||||
return ForwardOutcome::Forwarded(Err(ApiError::ResourceUnavailable(
|
||||
"Leader is stepped down instance".into(),
|
||||
)));
|
||||
let leader_addr = match Uri::from_str(leader.address.as_str()) {
|
||||
Ok(uri) => uri,
|
||||
Err(err) => {
|
||||
return ForwardOutcome::Forwarded(Err(ApiError::InternalServerError(anyhow::anyhow!(
|
||||
"Failed to parse leader uri for forwarding while in stepped down state: {err}"
|
||||
))));
|
||||
}
|
||||
};
|
||||
|
||||
if cfg.address_for_peers == leader_addr {
|
||||
return ForwardOutcome::Forwarded(Err(ApiError::ResourceUnavailable(
|
||||
"Leader is stepped down instance".into(),
|
||||
)));
|
||||
}
|
||||
|
||||
tracing::info!("Forwarding {} to leader at {}", uri, leader.address);
|
||||
|
||||
@@ -62,22 +62,15 @@ impl Leadership {
|
||||
&self,
|
||||
current_leader: Option<ControllerPersistence>,
|
||||
) -> Result<()> {
|
||||
if let Some(address_for_peers) = &self.config.address_for_peers {
|
||||
// TODO: `address-for-peers` can become a mandatory cli arg
|
||||
// after we update the k8s setup
|
||||
let proposed_leader = ControllerPersistence {
|
||||
address: address_for_peers.to_string(),
|
||||
started_at: chrono::Utc::now(),
|
||||
};
|
||||
let proposed_leader = ControllerPersistence {
|
||||
address: self.config.address_for_peers.to_string(),
|
||||
started_at: chrono::Utc::now(),
|
||||
};
|
||||
|
||||
self.persistence
|
||||
.update_leader(current_leader, proposed_leader)
|
||||
.await
|
||||
.map_err(Error::Database)
|
||||
} else {
|
||||
tracing::info!("No address-for-peers provided. Skipping leader persistence.");
|
||||
Ok(())
|
||||
}
|
||||
self.persistence
|
||||
.update_leader(current_leader, proposed_leader)
|
||||
.await
|
||||
.map_err(Error::Database)
|
||||
}
|
||||
|
||||
async fn current_leader(&self) -> DatabaseResult<Option<ControllerPersistence>> {
|
||||
|
||||
@@ -429,7 +429,7 @@ pub struct Config {
|
||||
|
||||
pub heartbeat_interval: Duration,
|
||||
|
||||
pub address_for_peers: Option<Uri>,
|
||||
pub address_for_peers: Uri,
|
||||
|
||||
pub start_as_candidate: bool,
|
||||
|
||||
|
||||
Reference in New Issue
Block a user