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 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303
|
# See the file LICENSE for redistribution information.
#
# Copyright (c) 2011, 2013 Oracle and/or its affiliates. All rights reserved.
#
# $Id$
#
# TEST rep101
# TEST Test of exclusive access to databases and HA.
# TEST Confirm basic functionality with master and client.
# TEST Confirm excl access after checkpoint and archive.
# TEST Confirm internal init with open excl databases.
# TEST
proc rep101 { method { niter 100 } { tnum "101" } args } {
source ./include.tcl
global repfiles_in_memory
# Run for just btree.
if { $checking_valid_methods } {
return "btree"
}
if { [is_btree $method] == 0 } {
puts "Rep$tnum: skipping for non-btree method $method."
return
}
set args [convert_args $method $args]
set logsets [create_logsets 4]
set msg2 "and on-disk replication files"
if { $repfiles_in_memory } {
set msg2 "and in-memory replication files"
}
# Run the body of the test with and without recovery.
foreach r $test_recopts {
foreach l $logsets {
set logindex [lsearch -exact $l "in-memory"]
if { $logindex != -1 } {
puts "Rep$tnum: Skipping for in-memory logs."
continue
}
puts "Rep$tnum ($method $r): Exclusive databases and HA."
puts "Rep$tnum: Master logs are [lindex $l 0]"
puts "Rep$tnum: Client logs are [lindex $l 1]"
puts "Rep$tnum: Client2 logs are [lindex $l 2]"
puts "Rep$tnum: Client3 logs are [lindex $l 3]"
rep101_sub $method $niter $tnum $l $r $args
}
}
}
proc rep101_sub { method niter tnum logset recargs largs } {
source ./include.tcl
global databases_in_memory
global repfiles_in_memory
global rep_verbose
global verbose_type
set verbargs ""
if { $rep_verbose == 1 } {
set verbargs " -verbose {$verbose_type on} "
}
set repmemargs ""
if { $repfiles_in_memory } {
set repmemargs "-rep_inmem_files "
}
env_cleanup $testdir
set omethod [convert_method $method]
replsetup $testdir/MSGQUEUEDIR
set masterdir $testdir/MASTERDIR
set clientdir $testdir/CLIENTDIR
set clientdir2 $testdir/CLIENTDIR2
set clientdir3 $testdir/CLIENTDIR3
file mkdir $masterdir
file mkdir $clientdir
file mkdir $clientdir2
file mkdir $clientdir3
# Log size is small so we quickly create more than one.
# The documentation says that the log file must be at least
# four times the size of the in-memory log buffer.
set pagesize 4096
append largs " -pagesize $pagesize "
set log_max [expr $pagesize * 8]
set m_logtype [lindex $logset 0]
set c_logtype [lindex $logset 1]
set c2_logtype [lindex $logset 2]
set c3_logtype [lindex $logset 3]
# Since we're sure to be using on-disk logs, txnargs will be -txn nosync.
set m_logargs [adjust_logargs $m_logtype]
set c_logargs [adjust_logargs $c_logtype]
set c2_logargs [adjust_logargs $c2_logtype]
set c3_logargs [adjust_logargs $c3_logtype]
set m_txnargs [adjust_txnargs $m_logtype]
set c_txnargs [adjust_txnargs $c_logtype]
set c2_txnargs [adjust_txnargs $c2_logtype]
set c3_txnargs [adjust_txnargs $c3_logtype]
# Open a master.
repladd 1
set ma_cmd "berkdb_env_noerr -create $verbargs \
-log_max $log_max $m_txnargs $m_logargs $repmemargs \
-home $masterdir -rep_master -errpfx MASTER \
-rep_transport \[list 1 replsend\]"
set masterenv [eval $ma_cmd $recargs]
# Open some clients
repladd 2
set cl_cmd "berkdb_env_noerr -create -home $clientdir $verbargs \
$c_txnargs $c_logargs -rep_client -errpfx CLIENT $repmemargs \
-log_max $log_max -rep_transport \[list 2 replsend\]"
set clientenv [eval $cl_cmd $recargs]
repladd 3
set cl2_cmd "berkdb_env_noerr -create -home $clientdir2 $verbargs \
$c2_txnargs $c2_logargs -rep_client -errpfx CLIENT2 $repmemargs \
-log_max $log_max -rep_transport \[list 3 replsend\]"
set clientenv2 [eval $cl2_cmd $recargs]
#
# Set up the command but don't do the repladd nor open the
# environment until we need it.
#
set cl3_cmd "berkdb_env_noerr -create -home $clientdir3 $verbargs \
$c3_txnargs $c3_logargs -rep_client -errpfx CLIENT3 $repmemargs \
-log_max $log_max -rep_transport \[list 4 replsend\]"
#
# Need this so that clientenv2 does not later need an internal
# init because we must match while having a checkpoint in the log.
#
$masterenv txn_checkpoint -force
# Bring the clients online.
process_msgs "{$masterenv 1} {$clientenv 2} {$clientenv2 3}"
# Close client2. We want it later to synchronize with the
# master, but not doing an internal init. That is, we want
# to test that running sync-up recovery does the right thing
# regarding exclusive databases.
$clientenv2 log_flush
error_check_good env_close [$clientenv2 close] 0
# Open exclusive database in master. Process messages to client1.
# Confirm client cannot open the database.
puts "\tRep$tnum.a: Running rep_test to exclusive db."
set start 0
if { $databases_in_memory } {
set testfile { "" "test.db" }
} else {
set testfile "test.db"
}
set omethod [convert_method $method]
set dbargs [convert_args $method $largs]
set mdb [eval {berkdb_open} -env $masterenv -auto_commit -create $omethod \
-lk_exclusive 0 -mode 0644 $dbargs $testfile ]
error_check_good reptest_db [is_valid_db $mdb] TRUE
eval rep_test\
$method $masterenv $mdb $niter $start $start 0 $largs
incr start $niter
process_msgs "{$masterenv 1} {$clientenv 2}"
puts "\tRep$tnum.a.1: Confirm client cannot access excl db."
rep_client_access $clientenv $testfile FAIL
# Open client2 with recovery.
replclear 3
puts "\tRep$tnum.a.2: Confirm client2 cannot access excl db after start."
set clientenv2 [eval $cl2_cmd -recover]
process_msgs "{$masterenv 1} {$clientenv 2} {$clientenv2 3}"
rep_client_access $clientenv2 $testfile FAIL
puts "\tRep$tnum.a.3: Close excl database and confirm client access."
error_check_good dbclose [$mdb close] 0
process_msgs "{$masterenv 1} {$clientenv 2} {$clientenv2 3}"
# Only need to check on one client.
rep_client_access $clientenv $testfile SUCCESS
puts "\tRep$tnum.b: Confirm checkpoints and archiving."
puts "\tRep$tnum.b.1: Reopen excl db and move log forward."
set mdb [eval {berkdb_open} -env $masterenv -auto_commit $omethod \
-lk_exclusive 0 -mode 0644 $dbargs $testfile ]
error_check_good reptest_db [is_valid_db $mdb] TRUE
process_msgs "{$masterenv 1} {$clientenv 2} {$clientenv2 3}"
#
# Test here that processing the open log records from the master
# (as opposed to the create-then-open log records the master
# originally wrote for exclusive access) also works to
# provide exclusive access. Testing one client is sufficient.
#
rep_client_access $clientenv2 $testfile FAIL
#
# Clobber replication's 30 second anti-archive timer.
$masterenv test force noarchive_timeout
#
# We want to move all sites forward, beyond log file 1, and
# then archive the logs to remove the exclusive creation and
# open records from the log. This entire test section tests
# the ability to restore the exclusive property from just
# running recovery with checkpoint records in the log.
#
set stop 0
set orig_master_last [get_logfile $masterenv last]
while { $stop == 0 } {
# Run rep_test in the master beyond the first log file.
eval rep_test\
$method $masterenv $mdb $niter $start $start 0 $largs
incr start $niter
puts "\tRep$tnum.b.2: Run db_archive on master."
if { $m_logtype == "on-disk" } {
$masterenv log_flush
$masterenv log_archive -arch_remove
}
#
# Make sure we have moved beyond the master's original logs.
#
set curr_master_first [get_logfile $masterenv first]
if { $curr_master_first > $orig_master_last } {
set stop 1
}
}
puts "\tRep$tnum.b.3: Run db_archive on clients."
process_msgs "{$masterenv 1} {$clientenv 2} {$clientenv2 3}"
eval exec $util_path/db_archive -d -h $clientdir
eval exec $util_path/db_archive -d -h $clientdir2
#
# Client2 is now in a state where it no longer has the
# the original exclusive open of the database in the
# log. Open with recovery to force it to use checkpoint
# records and then run sync-up recovery.
puts "\tRep$tnum.b.4: Close client, do more txns, reopen client."
$clientenv2 log_flush
error_check_good env_close [$clientenv2 close] 0
eval rep_test $method $masterenv $mdb $niter $start $start 0 $largs
incr start $niter
replclear 3
process_msgs "{$masterenv 1} {$clientenv 2}"
set clientenv2 [eval $cl2_cmd -recover]
process_msgs "{$masterenv 1} {$clientenv 2} {$clientenv2 3}"
puts "\tRep$tnum.b.5: Confirm client cannot access excl db."
rep_client_access $clientenv2 $testfile FAIL
# Close the client and then close the exclusive db.
# Confirm that when the client runs recovery it is able
# to access the database.
puts "\tRep$tnum.b.6: Confirm client recovery and closed excl db."
$clientenv2 log_flush
error_check_good env_close [$clientenv2 close] 0
eval rep_test $method $masterenv $mdb $niter $start $start 0 $largs
incr start $niter
error_check_good dbclose [$mdb close] 0
replclear 3
process_msgs "{$masterenv 1} {$clientenv 2}"
set clientenv2 [eval $cl2_cmd -recover]
process_msgs "{$masterenv 1} {$clientenv 2} {$clientenv2 3}"
#
# Check both clients to make sure they can both now access the db.
#
rep_client_access $clientenv $testfile SUCCESS
rep_client_access $clientenv2 $testfile SUCCESS
puts "\tRep$tnum.c: Add new client while excl db is open."
set mdb [eval {berkdb_open} -env $masterenv -auto_commit $omethod \
-lk_exclusive 0 -mode 0644 $dbargs $testfile ]
error_check_good reptest_db [is_valid_db $mdb] TRUE
repladd 4
set clientenv3 [eval $cl3_cmd $recargs]
eval rep_test $method $masterenv $mdb $niter $start $start 0 $largs
incr start $niter
process_msgs "{$masterenv 1} {$clientenv 2} {$clientenv2 3} {$clientenv3 4}"
puts "\tRep$tnum.c.1: Confirm new client cannot access db."
rep_client_access $clientenv3 $testfile FAIL
puts "\tRep$tnum.c.2: Close db and confirm access."
error_check_good dbclose [$mdb close] 0
process_msgs "{$masterenv 1} {$clientenv 2} {$clientenv2 3} {$clientenv3 4}"
rep_client_access $clientenv3 $testfile SUCCESS
error_check_good masterenv_close [$masterenv close] 0
error_check_good clientenv_close [$clientenv close] 0
error_check_good clientenv_close [$clientenv2 close] 0
error_check_good clientenv_close [$clientenv3 close] 0
replclose $testdir/MSGQUEUEDIR
}
|