~ubuntu-branches/ubuntu/saucy/db/saucy-proposed

« back to all changes in this revision

Viewing changes to test/rep045.tcl

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson
  • Date: 2010-11-05 15:02:09 UTC
  • mfrom: (13.1.12 sid)
  • Revision ID: james.westby@ubuntu.com-20101105150209-ppvyn0619pu014xo
Tags: 5.1.19-1ubuntu1
* Resynchronise with Debian.  Remaining changes:
  - Pass --build/--host to configure to support cross-building, and don't
    override CC.
  - Disable the Java build when cross-building, for now.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# See the file LICENSE for redistribution information.
2
 
#
3
 
# Copyright (c) 2005, 2010 Oracle and/or its affiliates.  All rights reserved.
4
 
#
5
 
# $Id$
6
 
#
7
 
# TEST  rep045
8
 
# TEST
9
 
# TEST  Replication with versions.
10
 
# TEST
11
 
# TEST  Mimic an application where a database is set up in the
12
 
# TEST  background and then put into a replication group for use.
13
 
# TEST  The "version database" identifies the current live
14
 
# TEST  version, the database against which queries are made.
15
 
# TEST  For example, the version database might say the current
16
 
# TEST  version is 3, and queries would then be sent to db.3.
17
 
# TEST  Version 4 is prepared for use while version 3 is in use.
18
 
# TEST  When version 4 is complete, the version database is updated
19
 
# TEST  to point to version 4 so queries can be directed there.
20
 
# TEST
21
 
# TEST  This test has a master and two clients.  One client swaps
22
 
# TEST  roles with the master, and the other client runs constantly
23
 
# TEST  in another process.
24
 
 
25
 
proc rep045 { method { tnum "045" } args } {
26
 
 
27
 
        source ./include.tcl
28
 
        global databases_in_memory
29
 
        global repfiles_in_memory
30
 
 
31
 
        # Valid for all access methods.
32
 
        if { $checking_valid_methods } {
33
 
                return "ALL"
34
 
        }
35
 
 
36
 
        set args [convert_args $method $args]
37
 
        set logsets [create_logsets 3]
38
 
 
39
 
        # Set up for on-disk or in-memory databases.
40
 
        set msg "using on-disk databases"
41
 
        if { $databases_in_memory } {
42
 
                set msg "using named in-memory databases"
43
 
                if { [is_queueext $method] } { 
44
 
                        puts -nonewline "Skipping rep$tnum for method "
45
 
                        puts "$method with named in-memory databases."
46
 
                        return
47
 
                }
48
 
        }
49
 
 
50
 
        set msg2 "and on-disk replication files"
51
 
        if { $repfiles_in_memory } {
52
 
                set msg2 "and in-memory replication files"
53
 
        }
54
 
 
55
 
        foreach l $logsets {
56
 
                set logindex [lsearch -exact $l "in-memory"]
57
 
                puts "Rep$tnum ($method): Replication with version\
58
 
                    databases $msg $msg2."
59
 
                puts "Rep$tnum: Master logs are [lindex $l 0]"
60
 
                puts "Rep$tnum: Client 0 logs are [lindex $l 1]"
61
 
                puts "Rep$tnum: Client 1 logs are [lindex $l 2]"
62
 
                rep045_sub $method $tnum $l $args
63
 
        }
64
 
}
65
 
 
66
 
proc rep045_sub { method tnum logset largs } {
67
 
        source ./include.tcl
68
 
        set orig_tdir $testdir
69
 
        global databases_in_memory
70
 
        global repfiles_in_memory
71
 
        global rep_verbose
72
 
        global verbose_type
73
 
 
74
 
        set verbargs ""
75
 
        if { $rep_verbose == 1 } {
76
 
                set verbargs " -verbose {$verbose_type on} "
77
 
        }
78
 
 
79
 
        set repmemargs ""
80
 
        if { $repfiles_in_memory } {
81
 
                set repmemargs "-rep_inmem_files "
82
 
        }
83
 
 
84
 
        set masterdir $testdir/MASTERDIR
85
 
        set clientdir0 $testdir/CLIENTDIR0
86
 
        set clientdir1 $testdir/CLIENTDIR1
87
 
 
88
 
        env_cleanup $testdir
89
 
        replsetup $testdir/MSGQUEUEDIR
90
 
        file mkdir $masterdir
91
 
        file mkdir $clientdir0
92
 
        file mkdir $clientdir1
93
 
 
94
 
        set m_logtype [lindex $logset 0]
95
 
        set c_logtype [lindex $logset 1]
96
 
        set c2_logtype [lindex $logset 2]
97
 
 
98
 
        # In-memory logs require a large log buffer, and cannot
99
 
        # be used with -txn nosync.
100
 
        set m_logargs [adjust_logargs $m_logtype]
101
 
        set c_logargs [adjust_logargs $c_logtype]
102
 
        set c2_logargs [adjust_logargs $c2_logtype]
103
 
        set m_txnargs [adjust_txnargs $m_logtype]
104
 
        set c_txnargs [adjust_txnargs $c_logtype]
105
 
        set c2_txnargs [adjust_txnargs $c2_logtype]
106
 
 
107
 
        set omethod [convert_method $method]
108
 
 
109
 
        # Open a master.
110
 
        repladd 1
111
 
        set envcmd(M0) "berkdb_env_noerr -create $m_txnargs \
112
 
            $m_logargs -errpfx ENV.M0 $verbargs $repmemargs \
113
 
            -errfile /dev/stderr -lock_detect default \
114
 
            -home $masterdir -rep_transport \[list 1 replsend\]"
115
 
        set menv [eval $envcmd(M0) -rep_master]
116
 
 
117
 
        # Open a client
118
 
        repladd 2
119
 
        set envcmd(C0) "berkdb_env_noerr -create $c_txnargs \
120
 
            $c_logargs -errpfx ENV.C0 $verbargs $repmemargs \
121
 
            -errfile /dev/stderr -lock_detect default \
122
 
            -home $clientdir0 -rep_transport \[list 2 replsend\]"
123
 
        set cenv0 [eval $envcmd(C0) -rep_client]
124
 
 
125
 
        # Open second client.
126
 
        repladd 3
127
 
        set envcmd(C1) "berkdb_env_noerr -create $c2_txnargs \
128
 
            $c2_logargs -errpfx ENV.C1 $verbargs $repmemargs \
129
 
            -errfile /dev/stderr -lock_detect default \
130
 
            -home $clientdir1 -rep_transport \[list 3 replsend\]"
131
 
        set cenv1 [eval $envcmd(C1) -rep_client]
132
 
 
133
 
        # Bring the clients online by processing the startup messages.
134
 
        set envlist "{$menv 1} {$cenv0 2} {$cenv1 3}"
135
 
        process_msgs $envlist
136
 
 
137
 
        # Clobber replication's 30-second anti-archive timer, which will have
138
 
        # been started by client sync-up internal init, so that we can do a
139
 
        # db_remove in a moment.
140
 
        #
141
 
        $menv test force noarchive_timeout
142
 
 
143
 
        puts "\tRep$tnum.a: Initialize version database."
144
 
        # Set up variables so we cycle through version numbers 1
145
 
        # through maxversion several times.
146
 
        if { $databases_in_memory } {
147
 
                set vname { "" "version.db" }
148
 
        } else {
149
 
                set vname "version.db"
150
 
        }
151
 
        set version 0
152
 
        set maxversion 5
153
 
        set iter 12
154
 
        set nentries 100
155
 
        set start 0
156
 
 
157
 
        # The version db is always btree.
158
 
        set vdb [eval {berkdb_open_noerr -env $menv -create \
159
 
            -auto_commit -mode 0644} -btree $vname]
160
 
        error_check_good init_version [$vdb put VERSION $version] 0
161
 
        error_check_good vdb_close [$vdb close] 0
162
 
        process_msgs $envlist
163
 
 
164
 
        # Start up a separate process that constantly reads data
165
 
        # from the current official version.
166
 
        puts "\tRep$tnum.b: Spawn a child tclsh to do client work."
167
 
        set pid [exec $tclsh_path $test_path/wrap.tcl \
168
 
            rep045script.tcl $testdir/rep045script.log \
169
 
                   $clientdir1 $vname $databases_in_memory &]
170
 
 
171
 
        # Main loop: update query database, process messages (or don't,
172
 
        # simulating a failure), announce the new version, process
173
 
        # messages (or don't), and swap masters.
174
 
        set version 1
175
 
        for { set i 1 } { $i < $iter } { incr i } {
176
 
 
177
 
                # If database.N exists on disk, clean it up.
178
 
                if { $databases_in_memory } {
179
 
                        set dbname { "" "db.$version" }
180
 
                } else {
181
 
                        set dbname "db.$version"
182
 
                }
183
 
                if { [file exists $masterdir/$dbname] == 1 } {
184
 
                        puts "\tRep$tnum.c.$i: Removing old version $version."
185
 
                        error_check_good dbremove \
186
 
                           [$menv dbremove -auto_commit $dbname] 0
187
 
                }
188
 
 
189
 
                puts "\tRep$tnum.c.$i: Set up query database $version."
190
 
                set db [eval berkdb_open_noerr -create -env $menv\
191
 
                    -auto_commit -mode 0644 $largs $omethod $dbname]
192
 
                error_check_good db_open [is_valid_db $db] TRUE
193
 
                eval rep_test $method $menv $db $nentries $start $start 0 $largs
194
 
                incr start $nentries
195
 
                error_check_good db_close [$db close] 0
196
 
 
197
 
                # We alternate between processing the messages and
198
 
                # clearing the messages to simulate a failure.
199
 
 
200
 
                set process [expr $i % 2]
201
 
                if { $process == 1 } {
202
 
                        process_msgs $envlist
203
 
                } else {
204
 
                        replclear 2
205
 
                        replclear 3
206
 
                }
207
 
 
208
 
                # Announce new version.
209
 
                puts "\tRep$tnum.d.$i: Announce new version $version."
210
 
                set vdb [eval {berkdb_open_noerr -env $menv \
211
 
                    -auto_commit -mode 0644} $vname]
212
 
                error_check_good update_version [$vdb put VERSION $version] 0
213
 
                error_check_good vdb_close [$vdb close] 0
214
 
 
215
 
                # Process messages or simulate failure.
216
 
                if { $process == 1 } {
217
 
                        process_msgs $envlist
218
 
                } else {
219
 
                        replclear 2
220
 
                        replclear 3
221
 
                }
222
 
 
223
 
                # Switch master, update envlist.
224
 
                puts "\tRep$tnum.e.$i: Switch masters."
225
 
                set envlist [switch_master $envlist]
226
 
 
227
 
                # Update values for next iteration.
228
 
                set menv [lindex [lindex $envlist 0] 0]
229
 
                set cenv0 [lindex [lindex $envlist 1] 0]
230
 
                incr version
231
 
                if { $version > $maxversion } {
232
 
                        set version 1
233
 
                }
234
 
        }
235
 
 
236
 
        # Signal to child that we are done.
237
 
        set vdb [eval {berkdb_open_noerr -env $menv \
238
 
            -auto_commit -mode 0644} $vname]
239
 
        error_check_good version_done [$vdb put VERSION DONE] 0
240
 
        error_check_good vdb_close [$vdb close] 0
241
 
        process_msgs $envlist
242
 
 
243
 
        # Watch for child to finish.
244
 
        watch_procs $pid 5
245
 
 
246
 
        puts "\tRep$tnum.f: Clean up."
247
 
        error_check_good menv_close [$menv close] 0
248
 
        error_check_good cenv0_close [$cenv0 close] 0
249
 
        error_check_good cenv1_close [$cenv1 close] 0
250
 
 
251
 
        replclose $testdir/MSGQUEUEDIR
252
 
 
253
 
        # Check for failures in child's log file.
254
 
        set errstrings [eval findfail $testdir/rep045script.log]
255
 
        foreach str $errstrings {
256
 
                puts "FAIL: error message in log file: $str"
257
 
        }
258
 
 
259
 
        set testdir $orig_tdir
260
 
        return
261
 
}
262
 
 
263
 
proc switch_master { envlist } {
264
 
        # Find env handles and machine ids.
265
 
        set menv [lindex [lindex $envlist 0] 0]
266
 
        set mid [lindex [lindex $envlist 0] 1]
267
 
        set cenv [lindex [lindex $envlist 1] 0]
268
 
        set cid [lindex [lindex $envlist 1] 1]
269
 
        set cenv1 [lindex [lindex $envlist 2] 0]
270
 
        set cid1 [lindex [lindex $envlist 2] 1]
271
 
 
272
 
        # Downgrade master, upgrade client.
273
 
        error_check_good master_downgrade [$menv rep_start -client] 0
274
 
        error_check_good client_upgrade [$cenv rep_start -master] 0
275
 
        process_msgs $envlist
276
 
 
277
 
        # Adjust envlist.  The former client env is the new master,
278
 
        # and vice versa.
279
 
        set newenvlist "{$cenv $cid} {$menv $mid} {$cenv1 $cid1}"
280
 
        return $newenvlist
281
 
}