Skip to content

Commit

Permalink
fix problem with failover and switchover when patroni.host != patroni…
Browse files Browse the repository at this point in the history
….name
  • Loading branch information
anselvo committed Sep 7, 2024
1 parent 6558037 commit c03aa32
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions service/src/model/general.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ const (
type Sidecar struct {
Host string `json:"host" form:"host"`
Port int `json:"port" form:"port"`
Name *string `json:"name" form:"name"`
Status *SidecarStatus `json:"status,omitempty" form:"status"`
}

Expand Down
2 changes: 1 addition & 1 deletion service/src/service/patroni.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (p *patroniInstanceService) Overview(instance InstanceRequest) ([]Instance,
Lag: lag,
PendingRestart: patroniInstance.PendingRestart,
Database: Database{Host: patroniInstance.Host, Port: patroniInstance.Port},
Sidecar: Sidecar{Host: host, Port: port, Status: &sidecarStatus},
Sidecar: Sidecar{Host: host, Port: port, Name: &patroniInstance.Name, Status: &sidecarStatus},
ScheduledRestart: scheduledRestart,
ScheduledSwitchover: scheduledSwitchover,
})
Expand Down
4 changes: 2 additions & 2 deletions web/src/component/shared/actions/FailoverButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export function FailoverButton(props: Props) {
const {request, cluster, disabled} = props

const failover = useRouterInstanceFailover(cluster)

const body = {candidate: request.sidecar.host}
// NOTE: in patroni we cannot use host for leader and candidate, we need to send patroni.name
const body = {candidate: request.sidecar.name}

return (
<AlertButton
Expand Down
6 changes: 4 additions & 2 deletions web/src/component/shared/actions/SwitchoverButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export function SwitchoverButton(props: Props) {
const [candidate, setCandidates] = useState("")
const [schedule, setSchedule] = useState<Dayjs>()
const switchover = useRouterInstanceSwitchover(cluster)
const body = {leader: request.sidecar.host, candidate, scheduled_at: schedule}
// NOTE: in patroni we cannot use host for leader and candidate, we need to send patroni.name
const body = {leader: request.sidecar.name, candidate, scheduled_at: schedule}

return (
<AlertButton
Expand All @@ -46,10 +47,11 @@ export function SwitchoverButton(props: Props) {
value={candidate}
onChange={(e) => setCandidates(e.target.value)}
fullWidth={true}
variant={"outlined"}
>
<MenuItem value={""}><em>none (will be chosen randomly)</em></MenuItem>
{candidates.map(sidecar => (
<MenuItem key={sidecar.host} value={sidecar.host}>{sidecar.host}</MenuItem>
<MenuItem key={sidecar.host} value={sidecar.name}>{sidecar.host}</MenuItem>
))}
</Select>
</FormControl>
Expand Down
1 change: 1 addition & 0 deletions web/src/type/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export enum SidecarStatus {
export interface Sidecar {
host: string,
port: number,
name?: string,
status?: SidecarStatus,
}

Expand Down

0 comments on commit c03aa32

Please sign in to comment.