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

« back to all changes in this revision

Viewing changes to test/rep003.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) 2002, 2010 Oracle and/or its affiliates.  All rights reserved.
4
 
#
5
 
# $Id$
6
 
#
7
 
# TEST          rep003
8
 
# TEST  Repeated shutdown/restart replication test
9
 
# TEST
10
 
# TEST  Run a quick put test in a replicated master environment;
11
 
# TEST  start up, shut down, and restart client processes, with
12
 
# TEST  and without recovery.  To ensure that environment state
13
 
# TEST  is transient, use DB_PRIVATE.
14
 
 
15
 
proc rep003 { method { tnum "003" } args } {
16
 
        source ./include.tcl
17
 
        global rep003_dbname rep003_omethod rep003_oargs
18
 
        global repfiles_in_memory
19
 
 
20
 
        # Skip for record-based methods.
21
 
        if { $checking_valid_methods } {
22
 
                set test_methods {}
23
 
                foreach method $valid_methods {
24
 
                        if { [is_record_based $method] != 1 } {
25
 
                                lappend test_methods $method
26
 
                        }
27
 
                }
28
 
                return $test_methods
29
 
        }
30
 
        if { [is_record_based $method] } {
31
 
                puts "Rep$tnum: Skipping for method $method"
32
 
                return
33
 
        }
34
 
 
35
 
        set msg2 "with on-disk replication files"
36
 
        if { $repfiles_in_memory } {
37
 
                set msg2 "with in-memory replication files"
38
 
        }
39
 
 
40
 
        set rep003_dbname rep003.db
41
 
        set rep003_omethod [convert_method $method]
42
 
        set rep003_oargs [convert_args $method $args]
43
 
 
44
 
        # Run the body of the test with and without recovery.  If we're
45
 
        # testing in-memory logging, skip the combination of recovery
46
 
        # and in-memory logging -- it doesn't make sense.
47
 
 
48
 
        set logsets [create_logsets 2]
49
 
        foreach recopt $test_recopts {
50
 
                foreach l $logsets {
51
 
                        set logindex [lsearch -exact $l "in-memory"]
52
 
                        if { $recopt == "-recover" && $logindex != -1 } {
53
 
                                puts "Rep$tnum: Skipping for\
54
 
                                    in-memory logs with -recover."
55
 
                                continue
56
 
                        }
57
 
                        puts "Rep$tnum ($method $recopt):\
58
 
                            Replication repeated-startup test $msg2."
59
 
                        puts "Rep$tnum: Master logs are [lindex $l 0]"
60
 
                        puts "Rep$tnum: Client logs are [lindex $l 1]"
61
 
                        rep003_sub $method $tnum $l $recopt $args
62
 
                }
63
 
        }
64
 
}
65
 
 
66
 
proc rep003_sub { method tnum logset recargs largs } {
67
 
        source ./include.tcl
68
 
        global repfiles_in_memory
69
 
        global rep_verbose
70
 
        global verbose_type
71
 
 
72
 
        set verbargs ""
73
 
        if { $rep_verbose == 1 } {
74
 
                set verbargs " -verbose {$verbose_type on} "
75
 
        }
76
 
 
77
 
        set repmemargs ""
78
 
        if { $repfiles_in_memory } {
79
 
                set repmemargs "-rep_inmem_files "
80
 
        }
81
 
 
82
 
        env_cleanup $testdir
83
 
 
84
 
        replsetup $testdir/MSGQUEUEDIR
85
 
 
86
 
        set masterdir $testdir/MASTERDIR
87
 
        set clientdir $testdir/CLIENTDIR
88
 
 
89
 
        file mkdir $masterdir
90
 
        file mkdir $clientdir
91
 
 
92
 
        set m_logtype [lindex $logset 0]
93
 
        set c_logtype [lindex $logset 1]
94
 
 
95
 
        # In-memory logs require a large log buffer, and cannot
96
 
        # be used with -txn nosync.  This test already requires
97
 
        # -txn, so adjust the logargs only.
98
 
        set m_logargs [adjust_logargs $m_logtype]
99
 
        set c_logargs [adjust_logargs $c_logtype]
100
 
 
101
 
        # Open a master.
102
 
        repladd 1
103
 
        set env_cmd(M) "berkdb_env_noerr -create -log_max 1000000 \
104
 
            -errpfx MASTER $verbargs $repmemargs \
105
 
            -home $masterdir -txn $m_logargs -rep_master \
106
 
            -rep_transport \[list 1 replsend\]"
107
 
        set masterenv [eval $env_cmd(M) $recargs]
108
 
        error_check_good master_env [is_valid_env $masterenv] TRUE
109
 
 
110
 
        puts "\tRep$tnum.a: Simple client startup test."
111
 
 
112
 
        # Put item one.
113
 
        rep003_put $masterenv A1 a-one
114
 
 
115
 
        # Open a client.
116
 
        repladd 2
117
 
        set env_cmd(C) "berkdb_env_noerr -create -private -home $clientdir \
118
 
            -txn $c_logargs -errpfx CLIENT $verbargs $repmemargs \
119
 
            -rep_client -rep_transport \[list 2 replsend\]"
120
 
        set clientenv [eval $env_cmd(C) $recargs]
121
 
        error_check_good client_env [is_valid_env $clientenv] TRUE
122
 
 
123
 
        # Put another quick item.
124
 
        rep003_put $masterenv A2 a-two
125
 
 
126
 
        # Loop, processing first the master's messages, then the client's,
127
 
        # until both queues are empty.
128
 
        set envlist "{$masterenv 1} {$clientenv 2}"
129
 
        process_msgs $envlist
130
 
 
131
 
        rep003_check $clientenv A1 a-one
132
 
        rep003_check $clientenv A2 a-two
133
 
 
134
 
        error_check_good clientenv_close [$clientenv close] 0
135
 
        replclear 2
136
 
 
137
 
        # Now reopen the client after doing another put.
138
 
        puts "\tRep$tnum.b: Client restart."
139
 
        rep003_put $masterenv B1 b-one
140
 
 
141
 
        set clientenv [eval $env_cmd(C)]
142
 
        error_check_good client_env [is_valid_env $clientenv] TRUE
143
 
 
144
 
        # Loop letting the client and master sync up and get the
145
 
        # environment initialized.  It's a new client env so
146
 
        # reinitialize the envlist as well.
147
 
        set envlist "{$masterenv 1} {$clientenv 2}"
148
 
        process_msgs $envlist
149
 
 
150
 
        # The items from part A should be present at all times--
151
 
        # if we roll them back, we've screwed up. [#5709]
152
 
        rep003_check $clientenv A1 a-one
153
 
        rep003_check $clientenv A2 a-two
154
 
 
155
 
        rep003_put $masterenv B2 b-two
156
 
 
157
 
        # Loop, processing first the master's messages, then the client's,
158
 
        # until both queues are empty.
159
 
        while { 1 } {
160
 
                set nproced 0
161
 
 
162
 
                incr nproced [replprocessqueue $masterenv 1]
163
 
                incr nproced [replprocessqueue $clientenv 2]
164
 
 
165
 
                # The items from part A should be present at all times--
166
 
                # if we roll them back, we've screwed up. [#5709]
167
 
                rep003_check $clientenv A1 a-one
168
 
                rep003_check $clientenv A2 a-two
169
 
 
170
 
                if { $nproced == 0 } {
171
 
                        break
172
 
                }
173
 
        }
174
 
 
175
 
        rep003_check $clientenv B1 b-one
176
 
        rep003_check $clientenv B2 b-two
177
 
 
178
 
        error_check_good clientenv_close [$clientenv close] 0
179
 
 
180
 
        replclear 2
181
 
 
182
 
        # Now reopen the client after a recovery.
183
 
        puts "\tRep$tnum.c: Client restart after recovery."
184
 
        rep003_put $masterenv C1 c-one
185
 
 
186
 
        set clientenv [eval $env_cmd(C) -recover]
187
 
        error_check_good client_env [is_valid_env $clientenv] TRUE
188
 
 
189
 
        # Loop, processing first the master's messages, then the client's,
190
 
        # until both queues are empty.
191
 
        set envlist "{$masterenv 1} {$clientenv 2}"
192
 
        process_msgs $envlist
193
 
 
194
 
        # The items from part A should be present at all times--
195
 
        # if we roll them back, we've screwed up. [#5709]
196
 
        rep003_check $clientenv A1 a-one
197
 
        rep003_check $clientenv A2 a-two
198
 
        rep003_check $clientenv B1 b-one
199
 
        rep003_check $clientenv B2 b-two
200
 
 
201
 
        rep003_put $masterenv C2 c-two
202
 
 
203
 
        # Loop, processing first the master's messages, then the client's,
204
 
        # until both queues are empty.
205
 
        while { 1 } {
206
 
                set nproced 0
207
 
 
208
 
                # The items from part A should be present at all times--
209
 
                # if we roll them back, we've screwed up. [#5709]
210
 
                rep003_check $clientenv A1 a-one
211
 
                rep003_check $clientenv A2 a-two
212
 
                rep003_check $clientenv B1 b-one
213
 
                rep003_check $clientenv B2 b-two
214
 
 
215
 
                incr nproced [replprocessqueue $masterenv 1]
216
 
                incr nproced [replprocessqueue $clientenv 2]
217
 
 
218
 
                if { $nproced == 0 } {
219
 
                        break
220
 
                }
221
 
        }
222
 
 
223
 
        rep003_check $clientenv C1 c-one
224
 
        rep003_check $clientenv C2 c-two
225
 
 
226
 
        error_check_good clientenv_close [$clientenv close] 0
227
 
 
228
 
        replclear 2
229
 
 
230
 
        # Now reopen the client after a catastrophic recovery.
231
 
        puts "\tRep$tnum.d: Client restart after catastrophic recovery."
232
 
        rep003_put $masterenv D1 d-one
233
 
 
234
 
        set clientenv [eval $env_cmd(C) -recover_fatal]
235
 
        error_check_good client_env [is_valid_env $clientenv] TRUE
236
 
 
237
 
        # Loop, processing first the master's messages, then the client's,
238
 
        # until both queues are empty.
239
 
        set envlist "{$masterenv 1} {$clientenv 2}"
240
 
        process_msgs $envlist
241
 
        rep003_put $masterenv D2 d-two
242
 
 
243
 
        # Loop, processing first the master's messages, then the client's,
244
 
        # until both queues are empty.
245
 
        while { 1 } {
246
 
                set nproced 0
247
 
 
248
 
                # The items from part A should be present at all times--
249
 
                # if we roll them back, we've screwed up. [#5709]
250
 
                rep003_check $clientenv A1 a-one
251
 
                rep003_check $clientenv A2 a-two
252
 
                rep003_check $clientenv B1 b-one
253
 
                rep003_check $clientenv B2 b-two
254
 
                rep003_check $clientenv C1 c-one
255
 
                rep003_check $clientenv C2 c-two
256
 
 
257
 
                incr nproced [replprocessqueue $masterenv 1]
258
 
                incr nproced [replprocessqueue $clientenv 2]
259
 
 
260
 
                if { $nproced == 0 } {
261
 
                        break
262
 
                }
263
 
        }
264
 
 
265
 
        rep003_check $clientenv D1 d-one
266
 
        rep003_check $clientenv D2 d-two
267
 
 
268
 
        error_check_good clientenv_close [$clientenv close] 0
269
 
 
270
 
        error_check_good masterenv_close [$masterenv close] 0
271
 
        replclose $testdir/MSGQUEUEDIR
272
 
}
273
 
 
274
 
proc rep003_put { masterenv key data } {
275
 
        global rep003_dbname rep003_omethod rep003_oargs
276
 
 
277
 
        set db [eval {berkdb_open_noerr -create -env $masterenv -auto_commit} \
278
 
            $rep003_omethod $rep003_oargs $rep003_dbname]
279
 
        error_check_good rep3_put_open($key,$data) [is_valid_db $db] TRUE
280
 
 
281
 
        set txn [$masterenv txn]
282
 
        error_check_good rep3_put($key,$data) [$db put -txn $txn $key $data] 0
283
 
        error_check_good rep3_put_txn_commit($key,$data) [$txn commit] 0
284
 
 
285
 
        error_check_good rep3_put_close($key,$data) [$db close] 0
286
 
}
287
 
 
288
 
proc rep003_check { env key data } {
289
 
        global rep003_dbname
290
 
 
291
 
        set db [berkdb_open_noerr -rdonly -env $env $rep003_dbname]
292
 
        error_check_good rep3_check_open($key,$data) [is_valid_db $db] TRUE
293
 
 
294
 
        set dbt [$db get $key]
295
 
        error_check_good rep3_check($key,$data) \
296
 
            [lindex [lindex $dbt 0] 1] $data
297
 
 
298
 
        error_check_good rep3_put_close($key,$data) [$db close] 0
299
 
}