1
# See the file LICENSE for redistribution information.
3
# Copyright (c) 2001-2002
4
# Sleepycat Software. All rights reserved.
9
# TEST sindex002 with secondaries created and closed mid-test
10
# TEST Basic cursor-based secondary index put/delete test, with
11
# TEST secondaries created mid-test.
12
proc sindex004 { methods {nentries 200} {tnum 4} args } {
14
global dict nsecondaries
16
# Primary method/args.
17
set pmethod [lindex $methods 0]
18
set pargs [convert_args $pmethod $args]
19
set pomethod [convert_method $pmethod]
21
# Method/args for all the secondaries. If only one method
22
# was specified, assume the same method and a standard N
24
set methods [lrange $methods 1 end]
25
if { [llength $methods] == 0 } {
26
for { set i 0 } { $i < $nsecondaries } { incr i } {
27
lappend methods $pmethod
31
set argses [convert_argses $methods $args]
32
set omethods [convert_methods $methods]
34
puts "Sindex00$tnum ($pmethod/$methods) $nentries equal key/data pairs"
37
set pname "primary00$tnum.db"
38
set snamebase "secondary00$tnum"
41
# XXX if one is not supplied!
42
set env [berkdb_env -create -home $testdir]
43
error_check_good env_open [is_valid_env $env] TRUE
46
set pdb [eval {berkdb_open -create -env} $env $pomethod $pargs $pname]
47
error_check_good primary_open [is_valid_db $pdb] TRUE
50
"\tSindex00$tnum.a: Cursor put (-keyfirst/-keylast) loop ... "
52
set pdbc [$pdb cursor]
53
error_check_good pdb_cursor [is_valid_cursor $pdbc $pdb] TRUE
54
for { set n 0 } { [gets $did str] != -1 && $n < $nentries } { incr n } {
55
if { [is_record_based $pmethod] == 1 } {
64
set data($n) [pad_data $pmethod $datum]
67
set pflag " -keyfirst "
69
set pflag " -keylast "
72
set ret [eval {$pdbc put} $pflag \
73
{$key [chop_data $pmethod $datum]}]
74
error_check_good put($n) $ret 0
77
error_check_good pdbc_close [$pdbc close] 0
79
# Open and associate the secondaries
81
puts "\n\t\topening secondaries."
82
for { set i 0 } { $i < [llength $omethods] } { incr i } {
83
set sdb [eval {berkdb_open -create -env} $env \
84
[lindex $omethods $i] [lindex $argses $i] $snamebase.$i.db]
85
error_check_good second_open($i) [is_valid_db $sdb] TRUE
87
error_check_good db_associate($i) \
88
[$pdb associate -create [callback_n $i] $sdb] 0
91
check_secondaries $pdb $sdbs $nentries keys data "Sindex00$tnum.a"
93
puts "\tSindex00$tnum.b: Cursor put overwrite (-current) loop"
94
set pdbc [$pdb cursor]
95
error_check_good pdb_cursor [is_valid_cursor $pdbc $pdb] TRUE
96
for { set dbt [$pdbc get -first] } { [llength $dbt] > 0 } \
97
{ set dbt [$pdbc get -next] } {
98
set key [lindex [lindex $dbt 0] 0]
99
set datum [lindex [lindex $dbt 0] 1]
101
set ret [eval {$pdbc put -current} [chop_data $pmethod $newd]]
102
error_check_good put_overwrite($key) $ret 0
103
set data($ns($key)) [pad_data $pmethod $newd]
105
error_check_good pdbc_close [$pdbc close] 0
106
check_secondaries $pdb $sdbs $nentries keys data "Sindex00$tnum.b"
108
puts -nonewline "\tSindex00$tnum.c:\
109
Secondary c_pget/primary put overwrite loop ... "
110
# We walk the first secondary, then put-overwrite each primary key/data
111
# pair we find. This doubles as a DBC->c_pget test.
112
set sdb [lindex $sdbs 0]
113
set sdbc [$sdb cursor]
114
error_check_good sdb_cursor [is_valid_cursor $sdbc $sdb] TRUE
115
for { set dbt [$sdbc pget -first] } { [llength $dbt] > 0 } \
116
{ set dbt [$sdbc pget -next] } {
117
set pkey [lindex [lindex $dbt 0] 1]
118
set pdatum [lindex [lindex $dbt 0] 2]
120
# Extended entries will be showing up underneath us, in
121
# unpredictable places. Keep track of which pkeys
122
# we've extended, and don't extend them repeatedly.
123
if { [info exists pkeys_done($pkey)] == 1 } {
126
set pkeys_done($pkey) 1
129
set newd $pdatum.[string range $pdatum 0 2]
130
set ret [eval {$pdb put} $pkey [chop_data $pmethod $newd]]
131
error_check_good pdb_put($pkey) $ret 0
132
set data($ns($pkey)) [pad_data $pmethod $newd]
134
error_check_good sdbc_close [$sdbc close] 0
136
# Close the secondaries again.
137
puts "\n\t\tclosing secondaries."
138
for { set sdb [lindex $sdbs end] } { [string length $sdb] > 0 } \
139
{ set sdb [lindex $sdbs end] } {
140
error_check_good second_close($sdb) [$sdb close] 0
141
set sdbs [lrange $sdbs 0 end-1]
143
$pdb $sdbs $nentries keys data "Sindex00$tnum.b"
146
# Delete the second half of the entries through the primary.
147
# We do the second half so we can just pass keys(0 ... n/2)
148
# to check_secondaries.
149
set half [expr $nentries / 2]
150
puts -nonewline "\tSindex00$tnum.d:\
151
Primary cursor delete loop: deleting $half entries ... "
152
set pdbc [$pdb cursor]
153
error_check_good pdb_cursor [is_valid_cursor $pdbc $pdb] TRUE
154
set dbt [$pdbc get -first]
155
for { set i 0 } { [llength $dbt] > 0 && $i < $half } { incr i } {
156
error_check_good pdbc_del [$pdbc del] 0
157
set dbt [$pdbc get -next]
159
error_check_good pdbc_close [$pdbc close] 0
162
puts "\n\t\topening secondaries."
163
for { set i 0 } { $i < [llength $omethods] } { incr i } {
164
set sdb [eval {berkdb_open -create -env} $env \
165
[lindex $omethods $i] [lindex $argses $i] \
167
error_check_good second_open($i) [is_valid_db $sdb] TRUE
169
error_check_good db_associate($i) \
170
[$pdb associate -create [callback_n $i] $sdb] 0
173
cursor_check_secondaries $pdb $sdbs $half "Sindex00$tnum.d"
175
# Delete half of what's left, through the first secondary.
176
set quar [expr $half / 2]
177
puts "\tSindex00$tnum.e:\
178
Secondary cursor delete loop: deleting $quar entries"
179
set sdb [lindex $sdbs 0]
180
set sdbc [$sdb cursor]
181
set dbt [$sdbc get -first]
182
for { set i 0 } { [llength $dbt] > 0 && $i < $quar } { incr i } {
183
error_check_good sdbc_del [$sdbc del] 0
184
set dbt [$sdbc get -next]
186
error_check_good sdbc_close [$sdbc close] 0
187
cursor_check_secondaries $pdb $sdbs $quar "Sindex00$tnum.e"
190
error_check_good secondary_close [$sdb close] 0
192
error_check_good primary_close [$pdb close] 0
193
error_check_good env_close [$env close] 0