1 # See the file LICENSE for redistribution information.
3 # Copyright (c) 2001, 2012 Oracle and/or its affiliates. All rights reserved.
8 # TEST Replication and basic bulk transfer.
9 # TEST Set bulk transfer replication option.
10 # TEST Run long txns on master and then commit. Process on client
11 # TEST and verify contents. Run a very long txn so that logging
12 # TEST must send the log. Process and verify on client.
14 proc rep046 { method { nentries 200 } { tnum "046" } args } {
16 global databases_in_memory
17 global repfiles_in_memory
20 if { $checking_valid_methods } {
24 set args [convert_args $method $args]
25 set logsets [create_logsets 3]
27 # Set up for on-disk or in-memory databases.
28 set msg "using on-disk databases"
29 if { $databases_in_memory } {
30 set msg "using named in-memory databases"
31 if { [is_queueext $method] } {
32 puts -nonewline "Skipping rep$tnum for method "
33 puts "$method with named in-memory databases."
38 set msg2 "and on-disk replication files"
39 if { $repfiles_in_memory } {
40 set msg2 "and in-memory replication files"
45 set msg3 "with private env"
48 # Run the body of the test with and without recovery.
49 set throttle { "throttle" "" }
50 foreach r $test_recopts {
52 set logindex [lsearch -exact $l "in-memory"]
53 if { $r == "-recover" && $logindex != -1 } {
54 puts "Skipping test with -recover for \
59 puts "Rep$tnum ($method $r $t):\
60 Replication and bulk transfer\
62 puts "Rep$tnum: Master logs are [lindex $l 0]"
63 puts "Rep$tnum: Client 0 logs are [lindex $l 1]"
64 puts "Rep$tnum: Client 1 logs are [lindex $l 2]"
65 rep046_sub $method $nentries $tnum $l $r \
72 proc rep046_sub { method niter tnum logset recargs throttle largs } {
75 global databases_in_memory
76 global repfiles_in_memory
83 if { $rep_verbose == 1 } {
84 set verbargs " -verbose {$verbose_type on} "
88 if { $repfiles_in_memory } {
89 set repmemargs "-rep_inmem_files "
93 if { $env_private == 1 } {
94 set privargs " -private "
97 set orig_tdir $testdir
100 replsetup $testdir/MSGQUEUEDIR
102 set masterdir $testdir/MASTERDIR
103 set clientdir $testdir/CLIENTDIR
104 file mkdir $masterdir
105 file mkdir $clientdir
107 set m_logtype [lindex $logset 0]
108 set c_logtype [lindex $logset 1]
109 set c2_logtype [lindex $logset 2]
112 [expr { $m_logtype == "in-memory" || $c_logtype == "in-memory" || \
113 $c2_logtype == "in-memory" }]
115 # In-memory logs require a large log buffer, and can not
116 # be used with -txn nosync. Adjust the args for master
118 # This test has a long transaction, allocate a larger log
119 # buffer for in-memory test.
120 set m_logargs [adjust_logargs $m_logtype [expr 60 * 1024 * 1024]]
121 set c_logargs [adjust_logargs $c_logtype [expr 60 * 1024 * 1024]]
122 set c2_logargs [adjust_logargs $c2_logtype [expr 60 * 1024 * 1024]]
123 set m_txnargs [adjust_txnargs $m_logtype]
124 set c_txnargs [adjust_txnargs $c_logtype]
125 set c2_txnargs [adjust_txnargs $c2_logtype]
127 # If replication files or databases are in-memory we'll need a bigger
131 if { $repfiles_in_memory } {
132 set cacheadj [expr $cacheadj + 8]
134 if { $databases_in_memory } {
135 set cacheadj [expr $cacheadj + 20]
137 if { $repfiles_in_memory || $databases_in_memory } {
138 set cachesize [expr $cacheadj * (1024 * 1024)]
139 set cacheargs "-cachesize {0 $cachesize 1} "
142 set bigniter [expr 10000 - [expr 2 * $niter]]
143 set lkmax [expr $bigniter * 2]
147 set ma_envcmd "berkdb_env_noerr -create $m_txnargs $m_logargs \
148 $repmemargs $cacheargs $privargs \
149 $verbargs -lock_max_locks 10000 -lock_max_objects 10000 \
150 -errpfx MASTER -home $masterdir -rep_master -rep_transport \
152 set masterenv [eval $ma_envcmd $recargs]
153 error_check_good master_env [is_valid_env $masterenv] TRUE
156 set cl_envcmd "berkdb_env_noerr -create $c_txnargs $c_logargs \
157 $repmemargs $cacheargs $privargs \
158 $verbargs -home $clientdir -errpfx CLIENT \
159 -lock_max_locks 10000 -lock_max_objects 10000 \
160 -rep_client -rep_transport \[list 2 replsend\]"
161 set clientenv [eval $cl_envcmd $recargs]
163 if { $throttle == "throttle" } {
164 set clientdir2 $testdir/CLIENTDIR2
165 file mkdir $clientdir2
167 set cl2_envcmd "berkdb_env_noerr -create $c2_txnargs $verbargs \
168 $repmemargs $cacheargs $privargs \
169 $c2_logargs -home $clientdir2 -errpfx CLIENT2 \
170 -lock_max_locks 10000 -lock_max_objects 10000 \
171 -rep_client -rep_transport \[list 3 replsend\]"
172 set cl2env [eval $cl2_envcmd $recargs]
173 set envlist "{$masterenv 1} {$clientenv 2} {$cl2env 3}"
175 # Turn throttling on in master
177 error_check_good thr [$masterenv rep_limit 0 [expr 32 * 1024]] 0
179 set envlist "{$masterenv 1} {$clientenv 2}"
181 # Bring the client online by processing the startup messages.
182 process_msgs $envlist
185 # Turn on bulk processing now on the master.
187 error_check_good set_bulk [$masterenv rep_config {bulk on}] 0
189 puts "\tRep$tnum.a: Create and open master database"
190 # Set up databases as in-memory or on-disk.
191 if { $databases_in_memory } {
192 set dbname { "" "test.db" }
197 set omethod [convert_method $method]
198 set masterdb [eval {berkdb_open_noerr -env $masterenv -auto_commit \
199 -create -mode 0644} $largs $omethod $dbname]
200 error_check_good dbopen [is_valid_db $masterdb] TRUE
203 process_msgs $envlist
205 # Run a modified test001 in the master (and update clients).
206 puts "\tRep$tnum.b: Basic long running txn"
207 set bulkrec1 [stat_field $masterenv rep_stat "Bulk records stored"]
208 set bulkxfer1 [stat_field $masterenv rep_stat "Bulk buffer transfers"]
210 set overflowword1 "0"
211 set overflowword2 "0"
212 rep_test_bulk $method $masterenv $masterdb $niter 0 0
213 process_msgs $envlist
214 set bulkrec2 [stat_field $masterenv rep_stat "Bulk records stored"]
215 set bulkxfer2 [stat_field $masterenv rep_stat "Bulk buffer transfers"]
216 error_check_good recstat [expr $bulkrec2 > $bulkrec1] 1
217 error_check_good xferstat [expr $bulkxfer2 > $bulkxfer1] 1
218 rep_verify $masterdir $masterenv\
219 $clientdir $clientenv $in_memory_log 1 1
221 puts "\tRep$tnum.c: Very long txn"
222 # Determine whether this build is configured with --enable-debug_rop
223 # or --enable-debug_wop.
224 set conf [berkdb getconfig]
226 if { [is_substr $conf "debug_rop"] == 1 || \
227 [is_substr $conf "debug_wop"] == 1 } {
231 # If debug_rop/wop is set test will write more info to log.
232 # An in-memory log has a smaller "file" size than the large
233 # items written in this part of the test, so skip this section
234 # if any in-memory logs and debug_rop/wop is set.
235 if { $in_memory_log == 1 && $debug_rop_wop == 1 } {
236 puts "\t\tSkipping for in-memory log and debug_rop/wop"
241 set bulkfill1 [stat_field $masterenv rep_stat \
243 rep_test_bulk $method $masterenv $masterdb $bigniter \
245 set start [expr $niter + $bigniter]
246 if { $throttle == "throttle" } {
248 # If we're throttling clear all messages from client 3
249 # so that we force a huge gap that the client will have
250 # to ask for to invoke a rerequest that throttles.
254 [stat_field $masterenv rep_stat \
255 "Transmission limited"]
257 process_msgs $envlist
258 set bulkfill2 [stat_field $masterenv rep_stat \
260 error_check_good fillstat [expr $bulkfill2 > $bulkfill1] 1
261 rep_verify $masterdir $masterenv $clientdir $clientenv \
265 puts "\tRep$tnum.d: Very large data"
267 # If debug_rop/wop is set test will write entire item to log.
268 # An in-memory log has a smaller "file" size than the large
269 # items written in this part of the test, so skip this section
270 # if any in-memory logs and debug_rop/wop is set.
271 if { $in_memory_log == 1 && $debug_rop_wop == 1 } {
272 puts "\t\tSkipping for in-memory log and debug_rop/wop"
274 set bulkovf1 [stat_field $masterenv rep_stat \
275 "Bulk buffer overflows"]
276 set bulkfill1 [stat_field $masterenv rep_stat \
279 # Send in '2' exactly because we're sending in the flag to use
280 # the overflow entries. We have 2 overflow entries.
281 # If it's fixed length, we can't overflow. Induce throttling
282 # by putting in a bunch more entries. Create a gap by
283 # forcing a checkpoint record.
285 $masterenv txn_checkpoint -force
286 process_msgs $envlist
288 if { [is_fixed_length $method] == 1 } {
289 rep_test_bulk $method $masterenv $masterdb $niter \
292 rep_test_bulk $method $masterenv $masterdb 2 0 0 1
294 process_msgs $envlist
296 # Generally overflows cannot happen because large data gets
297 # broken up into overflow pages, and none will be larger than
298 # the buffer. However, if we're configured for debug_rop/wop
299 # then we record the data as is and will overflow.
301 set bulkovf2 [stat_field $masterenv rep_stat \
302 "Bulk buffer overflows"]
303 set bulkfill2 [stat_field $masterenv rep_stat \
305 if { [is_fixed_length $method] == 0 } {
306 error_check_good fillstat1 \
307 [expr $bulkfill2 > $bulkfill1] 1
308 if { $debug_rop_wop == 1 } {
309 error_check_good overflows \
310 [expr $bulkovf2 > $bulkovf1] 1
312 error_check_good no_overflows $bulkovf2 0
318 # Turn off bulk processing now on the master. We need to do
319 # this because some configurations (like debug_rop/wop) will
320 # generate log records when verifying the logs and databases.
321 # We want to control processing those messages.
323 error_check_good set_bulk [$masterenv rep_config {bulk off}] 0
325 if { $in_memory_log == 1 && $debug_rop_wop == 1 } {
326 puts "\t\tSkipping for in-memory log and debug_rop/wop"
328 rep_verify $masterdir $masterenv $clientdir $clientenv \
331 if { $throttle == "throttle" } {
332 puts "\tRep$tnum.e: Verify throttling."
334 [stat_field $masterenv rep_stat \
335 "Transmission limited"]
336 error_check_bad nthrottles1 $new_thr -1
337 error_check_bad nthrottles0 $new_thr 0
338 error_check_good nthrottles \
339 [expr $old_thr < $new_thr] 1
340 process_msgs $envlist
341 rep_verify $masterdir $masterenv $clientdir2 $cl2env \
346 if { $throttle == "throttle" } {
347 error_check_good cclose [$cl2env close] 0
350 error_check_good dbclose [$masterdb close] 0
351 error_check_good mclose [$masterenv close] 0
352 error_check_good cclose [$clientenv close] 0
353 replclose $testdir/MSGQUEUEDIR