Skip to content

Commit

Permalink
Add checking of wsrep_cluster_status
Browse files Browse the repository at this point in the history
  • Loading branch information
larrabee committed Sep 11, 2018
1 parent 5e48b44 commit b46c7df
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
35 changes: 24 additions & 11 deletions checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ import (
type ReasonCode int

const (
reasonInternalError ReasonCode = -1
reasonOk ReasonCode = 0
reasonForceEnabled ReasonCode = 1
reasonNodeNotAvailable ReasonCode = 2
reasonWSRepFailed ReasonCode = 3
reasonCheckTimeout ReasonCode = 4
reasonRWDisabled ReasonCode = 5
reasonInternalError ReasonCode = -1
reasonOk ReasonCode = 0
reasonForceEnabled ReasonCode = 1
reasonNodeNotAvailable ReasonCode = 2
reasonWSRepFailed ReasonCode = 3
reasonCheckTimeout ReasonCode = 4
reasonRWDisabled ReasonCode = 5
reasonNonPrimaryCluster ReasonCode = 6
)

type Response struct {
Expand All @@ -41,6 +42,10 @@ func checkerHandler(ctx *fasthttp.RequestCtx) {
ctx.SetStatusCode(fasthttp.StatusServiceUnavailable)
response.ReasonText = "Node is not available"
response.ReasonCode = reasonNodeNotAvailable
} else if !status.ClusterPrimary {
ctx.SetStatusCode(fasthttp.StatusServiceUnavailable)
response.ReasonText = "Node in non-Primary cluster"
response.ReasonCode = reasonNonPrimaryCluster
} else if (status.WSRepStatus != 4) && (status.WSRepStatus != 2) {
ctx.SetStatusCode(fasthttp.StatusServiceUnavailable)
response.ReasonText = "WSRep failed"
Expand Down Expand Up @@ -87,8 +92,7 @@ func checker(status *NodeStatus) {

err := row.Scan(&key, &value)
if err != nil {
*status = *curStatus
continue
goto Finish
}
if value == "OFF" {
curStatus.RWEnabled = true
Expand All @@ -99,11 +103,20 @@ func checker(status *NodeStatus) {
row = dbConn.QueryRow("SHOW STATUS LIKE 'wsrep_local_state';")
err = row.Scan(&key, &value)
if err != nil {
*status = *curStatus
continue
goto Finish
}
curStatus.WSRepStatus, _ = strconv.Atoi(value)

row = dbConn.QueryRow("SHOW STATUS LIKE 'wsrep_cluster_status';")
err = row.Scan(&key, &value)
if err != nil {
goto Finish
}
if value == "Primary" {
curStatus.ClusterPrimary = true
}

Finish:
*status = *curStatus
}
}
Expand Down
9 changes: 5 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import (
)

type NodeStatus struct {
WSRepStatus int
RWEnabled bool
NodeAvailable bool
Timestamp int64
WSRepStatus int
RWEnabled bool
NodeAvailable bool
ClusterPrimary bool
Timestamp int64
}

type Config struct {
Expand Down

0 comments on commit b46c7df

Please sign in to comment.