blob: 904ef5fdca089cdc763915b108a41e41e44fb89a (
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
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
|
# See the file LICENSE for redistribution information.
#
# Copyright (c) 1996, 1997, 1998, 1999, 2000
# Sleepycat Software. All rights reserved.
#
# $Id: txn.tcl,v 11.12 2000/12/31 19:26:23 bostic Exp $
#
# Options are:
# -dir <directory in which to store memp>
# -max <max number of concurrent transactions>
# -iterations <iterations>
# -stat
proc txn_usage {} {
puts "txn -dir <directory> -iterations <number of ops> \
-max <max number of transactions> -stat"
}
proc txntest { args } {
source ./include.tcl
# Set defaults
set iterations 50
set max 1024
set dostat 0
set flags ""
for { set i 0 } { $i < [llength $args] } {incr i} {
switch -regexp -- [lindex $args $i] {
-d.* { incr i; set testdir [lindex $args $i] }
-f.* { incr i; set flags [lindex $args $i] }
-i.* { incr i; set iterations [lindex $args $i] }
-m.* { incr i; set max [lindex $args $i] }
-s.* { set dostat 1 }
default {
puts -nonewline "FAIL:[timestamp] Usage: "
txn_usage
return
}
}
}
if { $max < $iterations } {
set max $iterations
}
# Now run the various functionality tests
txn001 $testdir $max $iterations $flags
txn002 $testdir $max $iterations
}
proc txn001 { dir max ntxns flags} {
source ./include.tcl
puts "Txn001: Basic begin, commit, abort"
# Open environment
env_cleanup $dir
set env [eval {berkdb \
env -create -mode 0644 -txn -txn_max $max -home $dir} $flags]
error_check_good evn_open [is_valid_env $env] TRUE
txn001_suba $ntxns $env
txn001_subb $ntxns $env
txn001_subc $ntxns $env
# Close and unlink the file
error_check_good env_close:$env [$env close] 0
}
proc txn001_suba { ntxns env } {
source ./include.tcl
# We will create a bunch of transactions and commit them.
set txn_list {}
set tid_list {}
puts "Txn001.a: Beginning/Committing $ntxns Transactions in $env"
for { set i 0 } { $i < $ntxns } { incr i } {
set txn [$env txn]
error_check_good txn_begin [is_valid_txn $txn $env] TRUE
lappend txn_list $txn
set tid [$txn id]
error_check_good tid_check [lsearch $tid_list $tid] -1
lappend tid_list $tid
}
# Now commit them all
foreach t $txn_list {
error_check_good txn_commit:$t [$t commit] 0
}
}
proc txn001_subb { ntxns env } {
# We will create a bunch of transactions and abort them.
set txn_list {}
set tid_list {}
puts "Txn001.b: Beginning/Aborting Transactions"
for { set i 0 } { $i < $ntxns } { incr i } {
set txn [$env txn]
error_check_good txn_begin [is_valid_txn $txn $env] TRUE
lappend txn_list $txn
set tid [$txn id]
error_check_good tid_check [lsearch $tid_list $tid] -1
lappend tid_list $tid
}
# Now abort them all
foreach t $txn_list {
error_check_good txn_abort:$t [$t abort] 0
}
}
proc txn001_subc { ntxns env } {
# We will create a bunch of transactions and commit them.
set txn_list {}
set tid_list {}
puts "Txn001.c: Beginning/Prepare/Committing Transactions"
for { set i 0 } { $i < $ntxns } { incr i } {
set txn [$env txn]
error_check_good txn_begin [is_valid_txn $txn $env] TRUE
lappend txn_list $txn
set tid [$txn id]
error_check_good tid_check [lsearch $tid_list $tid] -1
lappend tid_list $tid
}
# Now prepare them all
foreach t $txn_list {
error_check_good txn_prepare:$t [$t prepare] 0
}
# Now commit them all
foreach t $txn_list {
error_check_good txn_commit:$t [$t commit] 0
}
}
# Verify that read-only transactions do not create any log records
proc txn002 { dir max ntxns } {
source ./include.tcl
puts "Txn002: Read-only transaction test"
env_cleanup $dir
set env [berkdb \
env -create -mode 0644 -txn -txn_max $max -home $dir]
error_check_good dbenv [is_valid_env $env] TRUE
# We will create a bunch of transactions and commit them.
set txn_list {}
set tid_list {}
puts "Txn002.a: Beginning/Committing Transactions"
for { set i 0 } { $i < $ntxns } { incr i } {
set txn [$env txn]
error_check_good txn_begin [is_valid_txn $txn $env] TRUE
lappend txn_list $txn
set tid [$txn id]
error_check_good tid_check [lsearch $tid_list $tid] -1
lappend tid_list $tid
}
# Now commit them all
foreach t $txn_list {
error_check_good txn_commit:$t [$t commit] 0
}
# Now verify that there aren't any log records.
set r [$env log_get -first]
error_check_good log_get:$r [llength $r] 0
error_check_good env_close:$r [$env close] 0
}
|