Skip to content

Commit 4fd213a

Browse files
authored
Merge pull request #30 from fly-apps/failover-verification
Failover verification
2 parents 2f7b4be + f956e8a commit 4fd213a

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ WORKDIR /go/src/github.com/fly-examples/fly-postgres
77
COPY . .
88

99
RUN CGO_ENABLED=0 GOOS=linux go build -v -o /fly/bin/event_handler ./cmd/event_handler
10+
RUN CGO_ENABLED=0 GOOS=linux go build -v -o /fly/bin/failover_validation ./cmd/failover_validation
11+
1012
RUN CGO_ENABLED=0 GOOS=linux go build -v -o /fly/bin/standby_cleaner ./cmd/standby_cleaner
1113
RUN CGO_ENABLED=0 GOOS=linux go build -v -o /fly/bin/start ./cmd/start
1214
COPY ./bin/* /fly/bin/

cmd/failover_validation/main.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package main
2+
3+
import (
4+
"flag"
5+
"fmt"
6+
"os"
7+
)
8+
9+
func main() {
10+
visibleNodes := flag.Int("visible-nodes", 0, "Total visible nodes from the perspective of the proposed leader")
11+
totalNodes := flag.Int("total-nodes", 0, "The total number of nodes registered")
12+
flag.Parse()
13+
14+
// TODO - This will ultimately remove HA from a 2-node cluster setup.
15+
// This will be the case until we come up with a strategy to differentiate
16+
// between a down node and a network partition.
17+
18+
if *visibleNodes == 0 || *visibleNodes < (*totalNodes/2+1) {
19+
fmt.Printf("Unable to perform failover as quorum can not be met. Total nodes: %d, Visible nodes: %d\n", *totalNodes, *visibleNodes)
20+
os.Exit(1)
21+
}
22+
23+
os.Exit(0)
24+
}

pkg/flypg/repmgr.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ func (r *RepMgr) setDefaults() {
135135
"event_notifications": "'repmgrd_failover_promote,standby_promote,standby_follow'",
136136
"location": r.Region,
137137
"primary_visibility_consensus": true,
138+
"failover_validation_command": fmt.Sprintf("'/usr/local/bin/failover_validation -visible-nodes %%v -total-nodes %%t'"),
138139
}
139140

140141
if !r.eligiblePrimary() {

0 commit comments

Comments
 (0)