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
|
# See the file LICENSE for redistribution information.
#
# Copyright (c) 2004, 2013 Oracle and/or its affiliates. All rights reserved.
#
# $Id$
#
# TEST rep054
# TEST Test of internal initialization where a far-behind
# TEST client takes over as master.
# TEST
# TEST One master, two clients.
# TEST Run rep_test and process.
# TEST Close client 1.
# TEST Run rep_test, opening new databases, and processing
# TEST messages. Archive as we go so that log files get removed.
# TEST Close master and reopen client 1 as master. Process messages.
# TEST Verify that new master and client are in sync.
# TEST Run rep_test again, adding data to one of the new
# TEST named databases.
proc rep054 { method { nentries 200 } { tnum "054" } args } {
source ./include.tcl
global databases_in_memory
global repfiles_in_memory
# Valid for all access methods.
if { $checking_valid_methods } {
return "ALL"
}
# Skip this test for named in-memory databases; it tries
# to close and re-open envs, which just won't work.
if { $databases_in_memory } {
puts "Skipping Rep$tnum for in-memory databases."
return
}
# This test needs to set its own pagesize.
set pgindex [lsearch -exact $args "-pagesize"]
if { $pgindex != -1 } {
puts "Rep$tnum: skipping for specific pagesizes"
return
}
set args [convert_args $method $args]
set logsets [create_logsets 3]
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,
# and with and without cleaning. Skip recovery with in-memory
# logging - it doesn't make sense.
foreach r $test_recopts {
foreach l $logsets {
set logindex [lsearch -exact $l "in-memory"]
if { $r == "-recover" && $logindex != -1 } {
puts "Skipping rep$tnum for -recover\
with in-memory logs."
continue
}
puts "Rep$tnum ($method $r $args): Internal\
initialization test: far-behind client\
becomes master $msg2."
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]"
rep054_sub $method $nentries $tnum $l $r $args
}
}
}
proc rep054_sub { method nentries tnum logset recargs largs } {
global testdir
global util_path
global errorInfo
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
file mkdir $masterdir
file mkdir $clientdir
file mkdir $clientdir2
# 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]
# In-memory logs cannot be used with -txn nosync.
set m_logargs [adjust_logargs $m_logtype 1048576]
set c_logargs [adjust_logargs $c_logtype 1048576]
set c2_logargs [adjust_logargs $c2_logtype 1048576]
set m_txnargs [adjust_txnargs $m_logtype]
set c_txnargs [adjust_txnargs $c_logtype]
set c2_txnargs [adjust_txnargs $c2_logtype]
# Open a master.
repladd 1
set ma_envcmd "berkdb_env_noerr -create $m_txnargs \
$m_logargs -log_max $log_max $verbargs $repmemargs \
-home $masterdir -rep_transport \[list 1 replsend\]"
set masterenv [eval $ma_envcmd $recargs -rep_master]
error_check_good master_env [is_valid_env $masterenv] TRUE
# Open a client
repladd 2
set cl_envcmd "berkdb_env_noerr -create $c_txnargs \
$c_logargs -log_max $log_max $verbargs $repmemargs \
-home $clientdir -rep_transport \[list 2 replsend\]"
set clientenv [eval $cl_envcmd $recargs -rep_client]
error_check_good client_env [is_valid_env $clientenv] TRUE
# Open 2nd client
repladd 3
set cl2_envcmd "berkdb_env_noerr -create $c2_txnargs \
$c2_logargs -log_max $log_max $verbargs $repmemargs \
-home $clientdir2 -rep_transport \[list 3 replsend\]"
set clientenv2 [eval $cl2_envcmd $recargs -rep_client]
error_check_good client2_env [is_valid_env $clientenv2] TRUE
# Bring the clients online by processing the startup messages.
set envlist "{$masterenv 1} {$clientenv 2} {$clientenv2 3}"
process_msgs $envlist
# Clobber replication's 30-second anti-archive timer, which will have
# been started by client sync-up internal init, so that we can do a
# log_archive in a moment.
#
$masterenv test force noarchive_timeout
# Run rep_test in the master and in each client.
puts "\tRep$tnum.a: Running rep_test in master & clients."
set start 0
eval rep_test $method $masterenv NULL $nentries $start $start 0 $largs
incr start $nentries
process_msgs $envlist
# Master is in sync with both clients.
rep_verify $masterdir $masterenv $clientdir $clientenv
# Process messages again in case we are running with debug_rop.
process_msgs $envlist
rep_verify $masterdir $masterenv $clientdir2 $clientenv2
# Create a gap requiring internal initialization. This is the
# standard gap between the master and the first client -- we will
# make a much larger gap after we've created a new database that
# the first client doesn't know about.
#
set flags ""
set cid 2
set dbhandle NULL
set start [push_master_ahead $method $masterenv $masterdir $m_logtype \
$clientenv $cid $dbhandle $start $nentries $flags $largs]
# Create a database that does not even exist on closed client 1.
set newfile "newtest.db"
set newdb [eval {berkdb_open_noerr -env $masterenv -create \
-auto_commit -mode 0644} $largs $omethod $newfile]
error_check_good newdb_open [is_valid_db $newdb] TRUE
eval rep_test $method $masterenv $newdb $nentries $start $start 0 $largs
set start [expr $start + $nentries]
set envlist "{$masterenv 1} {$clientenv2 3}"
process_msgs $envlist
# Identify last master log file.
set last_master_log [get_logfile $masterenv last]
set stop 0
# Send the master and client2 far ahead of client 1. Archive
# so there will be a gap between the log files of the closed
# client and the active master and client and we've
# archived away the creation of the new database.
puts "\tRep$tnum.e: Running rep_test in master & remaining client."
while { $stop == 0 } {
eval rep_test \
$method $masterenv NULL $nentries $start $start 0 $largs
incr start $nentries
process_msgs $envlist
puts "\tRep$tnum.f: Send master ahead of closed client."
if { $m_logtype != "in-memory" } {
$masterenv log_flush
set res [eval exec $util_path/db_archive -d -h $masterdir]
}
if { $c2_logtype != "in-memory" } {
$clientenv2 log_flush
set res [eval exec $util_path/db_archive -d -h $clientdir2]
}
set first_master_log [get_logfile $masterenv first]
if { $first_master_log > $last_master_log } {
set stop 1
}
}
process_msgs $envlist
# Master is in sync with client 2.
rep_verify $masterdir $masterenv $clientdir2 $clientenv2 1
# Close master.
puts "\tRep$tnum.g: Close master."
error_check_good newdb_close [$newdb close] 0
error_check_good close_master [$masterenv close] 0
# The new database is still there.
error_check_good newfile_exists [file exists $masterdir/$newfile] 1
puts "\tRep$tnum.h: Reopen client1 as master."
replclear 2
set newmasterenv [eval $cl_envcmd $recargs -rep_master]
error_check_good newmasterenv [is_valid_env $newmasterenv] TRUE
# Force something into the log
$newmasterenv txn_checkpoint -force
puts "\tRep$tnum.i: Reopen master as client."
set oldmasterenv [eval $ma_envcmd $recargs -rep_client]
error_check_good oldmasterenv [is_valid_env $oldmasterenv] TRUE
set envlist "{$oldmasterenv 1} {$newmasterenv 2} {$clientenv2 3}"
process_msgs $envlist
rep_verify $clientdir $newmasterenv $masterdir $oldmasterenv 1
error_check_good newmasterenv_close [$newmasterenv close] 0
error_check_good oldmasterenv_close [$oldmasterenv close] 0
error_check_good clientenv2_close [$clientenv2 close] 0
replclose $testdir/MSGQUEUEDIR
}
|