Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failover verification #30

Merged
merged 3 commits into from
Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ WORKDIR /go/src/github.com/fly-examples/fly-postgres
COPY . .

RUN CGO_ENABLED=0 GOOS=linux go build -v -o /fly/bin/event_handler ./cmd/event_handler
RUN CGO_ENABLED=0 GOOS=linux go build -v -o /fly/bin/failover_validation ./cmd/failover_validation

RUN CGO_ENABLED=0 GOOS=linux go build -v -o /fly/bin/standby_cleaner ./cmd/standby_cleaner
RUN CGO_ENABLED=0 GOOS=linux go build -v -o /fly/bin/start ./cmd/start
COPY ./bin/* /fly/bin/
Expand Down
24 changes: 24 additions & 0 deletions cmd/failover_validation/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package main

import (
"flag"
"fmt"
"os"
)

func main() {
visibleNodes := flag.Int("visible-nodes", 0, "Total visible nodes from the perspective of the proposed leader")
totalNodes := flag.Int("total-nodes", 0, "The total number of nodes registered")
flag.Parse()

// TODO - This will ultimately remove HA from a 2-node cluster setup.
// This will be the case until we come up with a strategy to differentiate
// between a down node and a network partition.

if *visibleNodes == 0 || *visibleNodes < (*totalNodes/2+1) {
fmt.Printf("Unable to perform failover as quorum can not be met. Total nodes: %d, Visible nodes: %d\n", *totalNodes, *visibleNodes)
os.Exit(1)
}

os.Exit(0)
}
1 change: 1 addition & 0 deletions pkg/flypg/repmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ func (r *RepMgr) setDefaults() {
"event_notifications": "'repmgrd_failover_promote,standby_promote,standby_follow'",
"location": r.Region,
"primary_visibility_consensus": true,
"failover_validation_command": fmt.Sprintf("'/usr/local/bin/failover_validation -visible-nodes %%v -total-nodes %%t'"),
}

if !r.eligiblePrimary() {
Expand Down