1# See the file LICENSE for redistribution information. 2# 3# Copyright (c) 2003,2008 Oracle. All rights reserved. 4# 5# $Id: rep078script.tcl,v 12.3 2008/01/08 20:58:53 bostic Exp $ 6# 7# Rep078 script - Master leases. 8# 9# Test master leases and write operations. 10# 11# Usage: rep078script masterdir dbfile method 12# masterdir: master env directory 13# dbfile: name of database file 14# method: access method 15# 16source ./include.tcl 17source $test_path/test.tcl 18source $test_path/testutils.tcl 19source $test_path/reputils.tcl 20 21set usage "repscript masterdir dbfile method" 22 23# Verify usage 24if { $argc != 3 } { 25 puts stderr "FAIL:[timestamp] Usage: $usage" 26 exit 27} 28 29# Initialize arguments 30set masterdir [ lindex $argv 0 ] 31set dbfile [ lindex $argv 1 ] 32set method [ lindex $argv 2 ] 33 34# Join the queue env. We assume the rep test convention of 35# placing the messages in $testdir/MSGQUEUEDIR. 36set queueenv [eval berkdb_env -home $testdir/MSGQUEUEDIR] 37error_check_good script_qenv_open [is_valid_env $queueenv] TRUE 38 39# 40# We need to set up our own machids. 41# Add 2 for master env id, and 3 and 4 for the clientenv ids. 42# 43repladd 2 44repladd 3 45repladd 4 46 47# Join the master env. 48set ma_cmd "berkdb_env_noerr -home $masterdir \ 49 -txn -rep_transport \[list 2 replsend\]" 50# set ma_cmd "berkdb_env_noerr -home $masterdir \ 51# -verbose {rep on} -errfile /dev/stderr \ 52# -txn -rep_transport \[list 2 replsend\]" 53puts "Joining master env" 54set masterenv [eval $ma_cmd] 55error_check_good script_menv_open [is_valid_env $masterenv] TRUE 56 57# Create a marker file. Don't put anything in it yet. The parent 58# process will be processing messages while it looks for our 59# marker. 60 61 62puts "Create marker file" 63set markerenv [berkdb_env -create -home $testdir -txn] 64error_check_good markerenv_open [is_valid_env $markerenv] TRUE 65set marker \ 66 [eval "berkdb_open -create -btree -auto_commit -env $markerenv marker.db"] 67 68# 69# Create the database and then do a lease operation. Don't 70# process messages in the child process. 71# 72puts "Open database" 73set args [convert_args $method] 74puts "args is $args" 75set omethod [convert_method $method] 76set db [eval "berkdb_open -env $masterenv -auto_commit -create \ 77 $omethod $args $dbfile"] 78error_check_good script_db_open [is_valid_db $db] TRUE 79 80puts "Do lease op" 81set key 1 82do_leaseop $masterenv $db $method $key NULL 0 83 84puts "Put CHILD1" 85error_check_good child_key \ 86 [$marker put CHILD1 $key] 0 87 88puts "Wait for PARENT1" 89# Give the parent a chance to process messages and check leases. 90while { [llength [$marker get PARENT1]] == 0 } { 91 tclsleep 1 92} 93 94puts "Do lease op 2" 95incr key 96do_leaseop $masterenv $db $method $key NULL 0 97puts "Put CHILD2" 98error_check_good child2_key \ 99 [$marker put CHILD2 $key] 0 100 101puts "Wait for PARENT2" 102# Give the parent a chance to process messages and check leases. 103while { [llength [$marker get PARENT2]] == 0 } { 104 tclsleep 1 105} 106 107# 108# After we get PARENT2, do a checkpoint. 109# Then our work is done and we clean up. 110# 111puts "Write a checkpoint" 112$masterenv txn_checkpoint 113puts "Put CHILD3" 114error_check_good child2_key \ 115 [$marker put CHILD3 $key] 0 116 117puts "Clean up and exit" 118# Clean up the child so the parent can go forward. 119error_check_good master_db_close [$db close] 0 120error_check_good marker_db_close [$marker close] 0 121error_check_good markerenv_close [$markerenv close] 0 122error_check_good script_master_close [$masterenv close] 0 123 124