blob: 635bac2577465e827bb5045d989acb7bccb3348f (
plain)
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
|
# See the file LICENSE for redistribution information.
#
# Copyright (c) 1996-2009 Oracle. All rights reserved.
#
# $Id$
#
# Deadlock Test 4.
# This test is designed to make sure that we handle youngest and oldest
# deadlock detection even when the youngest and oldest transactions in the
# system are not involved in the deadlock (that is, we want to abort the
# youngest/oldest which is actually involved in the deadlock, not simply
# the youngest/oldest in the system).
# Since this is used for transaction systems, the locker ID is what we
# use to identify age (smaller number is older).
#
# The set up is that we have a total of 6 processes. The oldest (locker 0)
# and the youngest (locker 5) simply acquire a lock, hold it for a long time
# and then release it. The rest form a ring, obtaining lock N and requesting
# a lock on (N+1) mod 4. The deadlock detector ought to pick locker 1 or 4
# to abort and not 0 or 5.
proc dead004 { {tnum "004"} } {
source ./include.tcl
global lock_curid
global lock_maxid
foreach a { o y } {
puts "Dead$tnum: Deadlock detector test -a $a"
env_cleanup $testdir
# Create the environment.
puts "\tDead$tnum.a: creating environment"
set env [berkdb_env -create -mode 0644 -lock -home $testdir]
error_check_good lock_env:open [is_valid_env $env] TRUE
set dpid [exec $util_path/db_deadlock -v -t 5 -a $a \
-h $testdir >& $testdir/dd.out &]
set procs 6
foreach n $procs {
sentinel_init
set pidlist ""
set ret [$env lock_id_set $lock_curid $lock_maxid]
error_check_good lock_id_set $ret 0
# Fire off the tests
puts "\tDead$tnum: $n procs"
for { set i 0 } { $i < $n } { incr i } {
set locker [$env lock_id]
puts "$tclsh_path $test_path/wrap.tcl \
$testdir/dead$tnum.log.$i \
ddoyscript.tcl $testdir $locker $n $a $i"
set p [exec $tclsh_path \
$test_path/wrap.tcl \
ddoyscript.tcl $testdir/dead$tnum.log.$i \
$testdir $locker $n $a $i &]
lappend pidlist $p
}
watch_procs $pidlist 5
}
# Now check output
set dead 0
set clean 0
set other 0
for { set i 0 } { $i < $n } { incr i } {
set did [open $testdir/dead$tnum.log.$i]
while { [gets $did val] != -1 } {
switch $val {
DEADLOCK { incr dead }
1 { incr clean }
default { incr other }
}
}
close $did
}
tclkill $dpid
puts "\tDead$tnum: dead check..."
dead_check oldyoung $n 0 $dead $clean $other
# Now verify that neither the oldest nor the
# youngest were the deadlock.
set did [open $testdir/dead$tnum.log.0]
error_check_bad file:young [gets $did val] -1
error_check_good read:young $val 1
close $did
set did [open $testdir/dead$tnum.log.[expr $procs - 1]]
error_check_bad file:old [gets $did val] -1
error_check_good read:old $val 1
close $did
# Windows needs files closed before deleting files,
# so pause a little
tclsleep 2
fileremove -f $testdir/dd.out
# Remove log files
for { set i 0 } { $i < $n } { incr i } {
fileremove -f $testdir/dead$tnum.log.$i
}
error_check_good lock_env:close [$env close] 0
}
}
|