1# See the file LICENSE for redistribution information. 2# 3# Copyright (c) 1999,2008 Oracle. All rights reserved. 4# 5# $Id: sdbtest001.tcl,v 12.6 2008/01/08 20:58:53 bostic Exp $ 6# 7# TEST sdbtest001 8# TEST Tests multiple access methods in one subdb 9# TEST Open several subdbs, each with a different access method 10# TEST Small keys, small data 11# TEST Put/get per key per subdb 12# TEST Dump file, verify per subdb 13# TEST Close, reopen per subdb 14# TEST Dump file, verify per subdb 15# TEST 16# TEST Make several subdb's of different access methods all in one DB. 17# TEST Rotate methods and repeat [#762]. 18# TEST Use the first 10,000 entries from the dictionary. 19# TEST Insert each with self as key and data; retrieve each. 20# TEST After all are entered, retrieve all; compare output to original. 21# TEST Close file, reopen, do retrieve and re-verify. 22proc sdbtest001 { {nentries 10000} } { 23 source ./include.tcl 24 25 puts "Subdbtest001: many different subdb access methods in one" 26 27 # Create the database and open the dictionary 28 set testfile $testdir/subdbtest001.db 29 set t1 $testdir/t1 30 set t2 $testdir/t2 31 set t3 $testdir/t3 32 set t4 $testdir/t4 33 34 set txn "" 35 set count 0 36 37 # Set up various methods to rotate through 38 lappend method_list [list "-rrecno" "-rbtree" "-hash" "-recno" "-btree"] 39 lappend method_list [list "-recno" "-hash" "-btree" "-rbtree" "-rrecno"] 40 lappend method_list [list "-btree" "-recno" "-rbtree" "-rrecno" "-hash"] 41 lappend method_list [list "-hash" "-recno" "-rbtree" "-rrecno" "-btree"] 42 lappend method_list [list "-rbtree" "-hash" "-btree" "-rrecno" "-recno"] 43 lappend method_list [list "-rrecno" "-recno"] 44 lappend method_list [list "-recno" "-rrecno"] 45 lappend method_list [list "-hash" "-dhash"] 46 lappend method_list [list "-dhash" "-hash"] 47 lappend method_list [list "-rbtree" "-btree" "-dbtree" "-ddbtree"] 48 lappend method_list [list "-btree" "-rbtree" "-ddbtree" "-dbtree"] 49 lappend method_list [list "-dbtree" "-ddbtree" "-btree" "-rbtree"] 50 lappend method_list [list "-ddbtree" "-dbtree" "-rbtree" "-btree"] 51 set plist [list 512 8192 1024 4096 2048 16384] 52 set mlen [llength $method_list] 53 set plen [llength $plist] 54 while { $plen < $mlen } { 55 set plist [concat $plist $plist] 56 set plen [llength $plist] 57 } 58 set pgsz 0 59 foreach methods $method_list { 60 cleanup $testdir NULL 61 puts "\tSubdbtest001.a: create subdbs of different access methods:" 62 puts "\tSubdbtest001.a: $methods" 63 set nsubdbs [llength $methods] 64 set duplist "" 65 for { set i 0 } { $i < $nsubdbs } { incr i } { 66 lappend duplist -1 67 } 68 set psize [lindex $plist $pgsz] 69 incr pgsz 70 set newent [expr $nentries / $nsubdbs] 71 build_all_subdb $testfile $methods $psize $duplist $newent 72 73 # Now we will get each key from the DB and compare the results 74 # to the original. 75 for { set subdb 0 } { $subdb < $nsubdbs } { incr subdb } { 76 77 set method [lindex $methods $subdb] 78 set method [convert_method $method] 79 if { [is_record_based $method] == 1 } { 80 set checkfunc subdbtest001_recno.check 81 } else { 82 set checkfunc subdbtest001.check 83 } 84 85 puts "\tSubdbtest001.b: dump file sub$subdb.db" 86 set db [berkdb_open -unknown $testfile sub$subdb.db] 87 dump_file $db $txn $t1 $checkfunc 88 error_check_good db_close [$db close] 0 89 90 # Now compare the keys to see if they match the 91 # dictionary (or ints) 92 if { [is_record_based $method] == 1 } { 93 set oid [open $t2 w] 94 for {set i 1} {$i <= $newent} {incr i} { 95 puts $oid [expr $subdb * $newent + $i] 96 } 97 close $oid 98 file rename -force $t1 $t3 99 } else { 100 # filehead uses 1-based line numbers 101 set beg [expr $subdb * $newent] 102 incr beg 103 set end [expr $beg + $newent - 1] 104 filehead $end $dict $t3 $beg 105 filesort $t3 $t2 106 filesort $t1 $t3 107 } 108 109 error_check_good Subdbtest001:diff($t3,$t2) \ 110 [filecmp $t3 $t2] 0 111 112 puts "\tSubdbtest001.c: sub$subdb.db: close, open, and dump file" 113 # Now, reopen the file and run the last test again. 114 open_and_dump_subfile $testfile NULL $t1 $checkfunc \ 115 dump_file_direction "-first" "-next" sub$subdb.db 116 if { [string compare $method "-recno"] != 0 } { 117 filesort $t1 $t3 118 } 119 120 error_check_good Subdbtest001:diff($t2,$t3) \ 121 [filecmp $t2 $t3] 0 122 123 # Now, reopen the file and run the last test again in the 124 # reverse direction. 125 puts "\tSubdbtest001.d: sub$subdb.db: close, open, and dump file in reverse direction" 126 open_and_dump_subfile $testfile NULL $t1 $checkfunc \ 127 dump_file_direction "-last" "-prev" sub$subdb.db 128 129 if { [string compare $method "-recno"] != 0 } { 130 filesort $t1 $t3 131 } 132 133 error_check_good Subdbtest001:diff($t3,$t2) \ 134 [filecmp $t3 $t2] 0 135 } 136 } 137} 138 139# Check function for Subdbtest001; keys and data are identical 140proc subdbtest001.check { key data } { 141 error_check_good "key/data mismatch" $data $key 142} 143 144proc subdbtest001_recno.check { key data } { 145global dict 146global kvals 147 error_check_good key"$key"_exists [info exists kvals($key)] 1 148 error_check_good "key/data mismatch, key $key" $data $kvals($key) 149} 150