blob: c12fd178371736c45afa73dff9f6a79d60b977e2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
# See the file LICENSE for redistribution information.
#
# Copyright (c)-2009 Oracle. All rights reserved.
#
# TEST repmgr028
# TEST Simple smoke test for repmgr elections with multi-process envs.
proc repmgr028 { } {
source ./include.tcl
set tnum "028"
puts "Repmgr$tnum:\
Smoke test for repmgr elections with multi-process envs."
env_cleanup $testdir
set ports [available_ports 3]
set dbconfig {
{rep_set_nsites 3}
{rep_set_timeout DB_REP_ELECTION_RETRY 2000000}
{rep_set_timeout DB_REP_ELECTION_TIMEOUT 1000000}
}
foreach d {A B C} {
file mkdir $testdir/$d
make_dbconfig $testdir/$d $dbconfig
}
puts "\tRepmgr$tnum.a: Start 3 sites (with 2 processes each)."
set cmds {
{home $testdir/A}
{local [lindex $ports 0]}
{open_env}
{start election}
}
set cmds [subst $cmds]
set a1 [open_site_prog [linsert $cmds 1 "output $testdir/a1output"]]
set a2 [open_site_prog [linsert $cmds 1 "output $testdir/a2output"]]
set cmds {
{home $testdir/B}
{local [lindex $ports 1]}
{remote localhost [lindex $ports 0]}
{open_env}
{start election}
}
set cmds [subst $cmds]
set b1 [open_site_prog [linsert $cmds 1 "output $testdir/b1output"]]
set b2 [open_site_prog [linsert $cmds 1 "output $testdir/b2output"]]
set cmds {
{home $testdir/C}
{local [lindex $ports 2]}
{remote localhost [lindex $ports 0]}
{open_env}
{start election}
}
set cmds [subst $cmds]
set c1 [open_site_prog [linsert $cmds 1 "output $testdir/c1output"]]
set c2 [open_site_prog [linsert $cmds 1 "output $testdir/c2output"]]
puts "\tRepmgr$tnum.b: Wait for an election to choose initial master."
set a [berkdb_env -home $testdir/A]
set b [berkdb_env -home $testdir/B]
set c [berkdb_env -home $testdir/C]
set sites "$a $b $c"
set menv [repmgr028_await_election $sites]
set i [lsearch -exact $sites $menv]
error_check_bad notfound $i -1
set site_names "abc"
set m [string range $site_names $i $i]
puts "\tRepmgr$tnum.c: (site $m is master)."
puts "\tRepmgr$tnum.d: Wait for other two sites to sync up."
set clients [lreplace $sites $i $i]
set site_names [string replace $site_names $i $i]
await_startup_done [lindex $clients 0]
await_startup_done [lindex $clients 1]
set m1 [subst $${m}1]
set m2 [subst $${m}2]
puts $m2 "open_db test.db"
puts $m2 "put key1 value1"
puts $m2 "echo done"
gets $m2
puts "\tRepmgr$tnum.e:\
Shut down master, wait for survivors to elect new master."
$menv close
close $m1
close $m2
set menv [repmgr028_await_election $clients]
set i [lsearch -exact $clients $menv]
error_check_bad notfound2 $i -1
set m [string range $site_names $i $i]
puts "\tRepmgr$tnum.f: (site $m is new master)."
puts "\tRepmgr$tnum.g: Wait for remaining client to sync to new master."
set client [lreplace $clients $i $i]
error_check_good master_changes \
[stat_field $client rep_stat "Master changes"] 2
await_startup_done $client
puts "\tRepmgr$tnum.h: Clean up."
$client close
$menv close
set c [string range $site_names 0 0]
close [subst $${c}1]
close [subst $${c}2]
set c [string range $site_names 1 1]
close [subst $${c}1]
close [subst $${c}2]
}
proc repmgr028_await_election { env_list } {
set cond {
foreach e $env_list {
if {[stat_field $e rep_stat "Role"] == "master"} {
set answer $e
break
}
}
expr {[info exists answer]}
}
await_condition {[eval $cond]} 20
return $answer
}
|