@@ -37,6 +37,7 @@ HA_SMB_MNT_DIR="lock"
37
37
HA_NFS_MNT_DIR=" state"
38
38
STORAGE_SERVERS=" "
39
39
STORAGE_NUM_SERVERS=0
40
+ DETERMINISTIC_FAILOVER=false
40
41
41
42
# ## Utility functions
42
43
@@ -61,6 +62,15 @@ usage()
61
62
echo -e " ${HA_CONF_INCDIR} *.conf"
62
63
}
63
64
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
+
64
74
storlog ()
65
75
{
66
76
LEVEL=$1 ; shift
@@ -116,9 +126,14 @@ determine_servers()
116
126
IFS=${tmp_ifs}
117
127
HA_NUM_SERVERS=${num_servers}
118
128
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
122
137
else
123
138
IFS=$' ,'
124
139
for server in ${HA_CLUSTER_NODES} ; do
@@ -127,8 +142,13 @@ determine_servers()
127
142
IFS=${tmp_ifs}
128
143
HA_NUM_SERVERS=${num_servers}
129
144
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
132
152
fi
133
153
}
134
154
@@ -194,6 +214,65 @@ teardown_cluster()
194
214
pcs cluster destroy || storlog " ERR" " Failed to destroy cluster ${name} "
195
215
}
196
216
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
+ }
197
276
198
277
setup_create_resources ()
199
278
{
@@ -293,6 +372,10 @@ setup_create_resources()
293
372
# pcs -f ${cibfile} constraint order vip${ipcount} then vip${ipcount}_trigger
294
373
done
295
374
375
+ if [[ ${DETERMINISTIC_FAILOVER} == true ]]; then
376
+ create_virt_ip_constraints ${cibfile}
377
+ fi
378
+
296
379
pcs cluster cib-push ${cibfile} || storlog " ERR" " Failed to create virtual IP resources."
297
380
298
381
rm -f ${cibfile}
357
440
# Source/load the config
358
441
. $HA_CONF_sec
359
442
443
+ parsebool " DETERMINISTIC_FAILOVER"
444
+
360
445
case " ${cmd} " in
361
446
setup | --setup)
362
447
storlog " INFO" " Setting up ${HA_NAME} "
0 commit comments