Skip to content

Commit b5d28a9

Browse files
committed
Release version 0.9.
- Implement deterministic failover - Based on the version in ganesha-ha
1 parent 43a7685 commit b5d28a9

File tree

2 files changed

+100
-7
lines changed

2 files changed

+100
-7
lines changed

src/storhaug

Lines changed: 90 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ HA_SMB_MNT_DIR="lock"
3737
HA_NFS_MNT_DIR="state"
3838
STORAGE_SERVERS=""
3939
STORAGE_NUM_SERVERS=0
40+
DETERMINISTIC_FAILOVER=false
4041

4142
### Utility functions
4243

@@ -61,6 +62,15 @@ usage()
6162
echo -e " ${HA_CONF_INCDIR}*.conf"
6263
}
6364

65+
parsebool()
66+
{
67+
case $(eval echo \${${1}}) in
68+
TRUE | True | true | YES | Yes | yes) declare "${1}"=true ;;
69+
FALSE | False | false | NO | No | no) declare "${1}"=false ;;
70+
*) storlog "ERR" "Couldn't parse boolean: ${1}=$(eval echo \${${1}})" ;;
71+
esac
72+
}
73+
6474
storlog()
6575
{
6676
LEVEL=$1; shift
@@ -116,9 +126,14 @@ determine_servers()
116126
IFS=${tmp_ifs}
117127
HA_NUM_SERVERS=${num_servers}
118128
HA_SERVERS="${ha_servers}"
119-
# TODO: Determine storage servers from pcs status
120-
STORAGE_SERVERS="${STORAGE_NODES//,/ }"
121-
STORAGE_NUM_SERVERS=$(wc -w <<< "${STORAGE_SERVERS}")
129+
# TODO: Determine storage and vip servers from pcs status
130+
if [[ "x${STORAGE_NODES}" != "x" ]]; then
131+
STORAGE_SERVERS="${STORAGE_NODES//,/ }"
132+
STORAGE_NUM_SERVERS=$(wc -w <<< "${STORAGE_SERVERS}")
133+
fi
134+
if [[ "x${VIP_NODES}" != "x" ]]; then
135+
VIP_SERVERS="${VIP_NODES//,/ }"
136+
fi
122137
else
123138
IFS=$','
124139
for server in ${HA_CLUSTER_NODES} ; do
@@ -127,8 +142,13 @@ determine_servers()
127142
IFS=${tmp_ifs}
128143
HA_NUM_SERVERS=${num_servers}
129144
HA_SERVERS="${HA_CLUSTER_NODES//,/ }"
130-
STORAGE_SERVERS="${STORAGE_NODES//,/ }"
131-
STORAGE_NUM_SERVERS=$(wc -w <<< "${STORAGE_SERVERS}")
145+
if [[ "x${STORAGE_NODES}" != "x" ]]; then
146+
STORAGE_SERVERS="${STORAGE_NODES//,/ }"
147+
STORAGE_NUM_SERVERS=$(wc -w <<< "${STORAGE_SERVERS}")
148+
fi
149+
if [[ "x${VIP_NODES}" != "x" ]]; then
150+
VIP_SERVERS="${VIP_NODES//,/ }"
151+
fi
132152
fi
133153
}
134154

@@ -194,6 +214,65 @@ teardown_cluster()
194214
pcs cluster destroy || storlog "ERR" "Failed to destroy cluster ${name}"
195215
}
196216

217+
### Resource functions
218+
219+
do_create_virt_ip_constraints()
220+
{
221+
local cibfile=${1}; shift
222+
local ipcount=${1}; shift
223+
local primary=${1}; shift
224+
local weight="1000"
225+
226+
# A set of location constraints to set the prefered order
227+
# for where a VIP should move
228+
while [[ ${1} ]]; do
229+
pcs -f ${cibfile} constraint location vip${ipcount} prefers ${1}=${weight} || \
230+
storlog "WARN" "Failed: pcs constraint location vip${ipcount} prefers ${1}=${weight}"
231+
weight=$(expr ${weight} + 1000)
232+
shift
233+
done
234+
235+
# Set the highest preference for the VIP to its primary node
236+
pcs -f ${cibfile} constraint location vip${ipcount} prefers ${primary}=${weight} || \
237+
storlog "WARN" "Failed: pcs constraint location vip${ipcount} prefers ${primary}=${weight}"
238+
}
239+
240+
wrap_create_virt_ip_constraints()
241+
{
242+
local cibfile=${1}; shift
243+
local ipcount=${1}; shift
244+
local srvcount=${ipcount}
245+
local primary=""
246+
local head=""
247+
local tail=""
248+
249+
# build a list of failover peers, e.g. for a four node cluster, for node1,
250+
# the result is "node2 node3 node4"; for node2, "node3 node4 node1"
251+
# and so on.
252+
read -r -a servers <<< "${VIP_SERVERS:-STORAGE_SERVERS}"
253+
while [ ${srvcount} -gt ${STORAGE_NUM_SERVERS} ]; do
254+
srvcount=$((srvcount - STORAGE_NUM_SERVERS))
255+
done
256+
primary=${servers[${srvcount}-1]}
257+
if [ ${STORAGE_NUM_SERVERS} -gt 1 ]; then
258+
head=${servers[@]:${srvcount}-${STORAGE_NUM_SERVERS}-1}
259+
tail=${servers[@]:${srvcount}}
260+
fi
261+
262+
do_create_virt_ip_constraints ${cibfile} ${ipcount} ${primary} ${tail} ${head}
263+
}
264+
265+
create_virt_ip_constraints()
266+
{
267+
local cibfile=${1}; shift
268+
local ipcount=0
269+
270+
for ip in ${HA_VIPS}; do
271+
((ipcount++))
272+
wrap_create_virt_ip_constraints ${cibfile} ${ipcount}
273+
shift
274+
done
275+
}
197276

198277
setup_create_resources()
199278
{
@@ -293,6 +372,10 @@ setup_create_resources()
293372
# pcs -f ${cibfile} constraint order vip${ipcount} then vip${ipcount}_trigger
294373
done
295374

375+
if [[ ${DETERMINISTIC_FAILOVER} == true ]]; then
376+
create_virt_ip_constraints ${cibfile}
377+
fi
378+
296379
pcs cluster cib-push ${cibfile} || storlog "ERR" "Failed to create virtual IP resources."
297380

298381
rm -f ${cibfile}
@@ -357,6 +440,8 @@ done
357440
# Source/load the config
358441
. $HA_CONF_sec
359442

443+
parsebool "DETERMINISTIC_FAILOVER"
444+
360445
case "${cmd}" in
361446
setup | --setup)
362447
storlog "INFO" "Setting up ${HA_NAME}"

src/storhaug.conf.sample

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ HA_SERVER="server1"
1010

1111
# The set of nodes that forms the HA cluster.
1212
# Comma-deliminated IP/Hostname list
13-
HA_CLUSTER_NODES="server1,server2,..."
13+
HA_CLUSTER_NODES="server1,server2,server3,..."
1414

1515
# [OPTIONAL] A subset of HA nodes that will serve as storage servers.
1616
# Comma-deliminated IP/Hostname list
17-
STORAGE_NODES="server2,..."
17+
STORAGE_NODES="server2,server3,..."
1818

1919
# [OPTIONAL] Mount point for shared volumes used by HA resources.
2020
HA_MNT_DIR="/var/run/gluster"
@@ -23,6 +23,14 @@ HA_MNT_DIR="/var/run/gluster"
2323
# Whitespace-deliminated IP address list
2424
HA_VIPS="10.x.x.x 10.x.x.x"
2525

26+
# Deterministic Failover: If true, configures virtual IP failover to occur in
27+
# a deterministic order. The optional VIP_NODES setting specifies which node
28+
# will serve as the primary/home node for the corresponding virtual IP address.
29+
# NOTE: These nodes should also be configured as storage nodes, either
30+
# implicitly in HA_CLUSTER_NODES or explicitly in STORAGE_NODES
31+
DETERMINISTIC_FAILOVER=false
32+
VIP_NODES="server2,server3"
33+
2634
# Managed access methods
2735
# Whitespace-delimited list. Valid values:
2836
# nfs

0 commit comments

Comments
 (0)