1# Copyright (c) 2012, 2020 Oracle and/or its affiliates. All rights reserved. 2# 3# See the file LICENSE for license information. 4# 5# $Id$ 6# 7# TEST test146 8# TEST Test the BLOB APIs. 9# TEST 1) Test that the db blob threshold value defaults to 10# TEST the env threshold value. 11# TEST 2) Test that the db blob threshold value is retained when re-opening 12# TEST the db. 13# TEST 3) Test that the db blob threshold value is retained when re-opening 14# TEST the db with a different threshold value. 15proc test146 { method {tnum "146"} args } { 16 global default_pagesize 17 global passwd 18 source ./include.tcl 19 20 # Blobs are supported for btree, hash and heap only. 21 if {[is_btree $method] != 1 && \ 22 [is_hash $method] != 1 && [is_heap $method] != 1} { 23 puts "Test$tnum skipping for method $method." 24 return 25 } 26 27 # If we are using an env, then skip this test. It needs its own. 28 set eindex [lsearch -exact $args "-env"] 29 if { $eindex != -1 } { 30 incr eindex 31 set env [lindex $args $eindex] 32 puts "Test$tnum skipping for env $env" 33 return 34 } 35 36 # Look for incompatible configurations of blob. 37 foreach conf { "-compress" "-dup" "-dupsort" \ 38 "-read_uncommitted" "-multiversion" } { 39 if { [lsearch -exact $args $conf] != -1 } { 40 puts "Test146 skipping $conf, incompatible with blobs." 41 return 42 } 43 } 44 45 # Move any encryption arguments from the database arguments 46 # to the environment arguments. 47 set earg "" 48 set pos [lsearch -exact $args "-encryptaes"] 49 if { $pos != -1 } { 50 set earg " -encryptaes $passwd " 51 set args [lreplace $args $pos [expr $pos + 1] ] 52 } 53 set pos [lsearch -exact $args "-encrypt"] 54 if { $pos != -1 } { 55 set earg " -encrypt $passwd " 56 set args [lreplace $args $pos [expr $pos + 1] ] 57 } 58 59 set pgindex [lsearch -exact $args "-pagesize"] 60 set end [expr $pgindex + 1] 61 if { $pgindex != -1 } { 62 set pgsize [lindex $args $end] 63 set args [lreplace $args $pgindex $end] 64 } else { 65 set pgsize $default_pagesize 66 } 67 set threshold1 [expr $pgsize * 10] 68 set threshold2 [expr $pgsize * 20] 69 set threshold3 [expr $pgsize * 30] 70 71 set args [convert_args $method $args] 72 set omethod [convert_method $method] 73 74 # Set the db open flags. 75 set oflags " -create -pagesize $pgsize $args $omethod " 76 set testfile blob001.db 77 78 puts "Test$tnum: $method ($args -pagesize $pgsize) Test the BLOB APIs." 79 env_cleanup $testdir 80 81 puts "\tTest$tnum.a: Test db blob threshold value\ 82 defaults to the env threshold value." 83 84 puts "\tTest$tnum.a.0: open env with the blob threshold value and then\ 85 open db." 86 # Open the env with a blob threshold value. 87 set env [eval {berkdb env} \ 88 -create -home $testdir $earg -blob_threshold $threshold1] 89 error_check_good is_valid_env [is_valid_env $env] TRUE 90 error_check_good env_get_blobthreshold \ 91 [$env get_blob_threshold] $threshold1 92 93 # Open the db with no blob threshold value. 94 set db [eval {berkdb_open_noerr} -env $env $oflags $testfile] 95 error_check_good db_open [is_valid_db $db] TRUE 96 97 # Verify the db blob threshold value. 98 error_check_good db_get_blobthreshold \ 99 [$db get_blob_threshold] $threshold1 100 101 puts "\tTest$tnum.a.1: change the env blob threshold value after\ 102 opening env and then open db." 103 # Change the env blob threshold value. 104 error_check_good set_blob_threshold \ 105 [$env set_blob_threshold $threshold2] 0 106 error_check_good env_get_blobthreshold \ 107 [$env get_blob_threshold] $threshold2 108 109 # Open the db with no blob threshold value. 110 set db1 [eval {berkdb_open_noerr} -env $env $oflags $testfile-1] 111 error_check_good db_open [is_valid_db $db1] TRUE 112 113 # Verify the db blob threshold value. 114 error_check_good db_get_blobthreshold \ 115 [$db1 get_blob_threshold] $threshold2 116 117 puts "\tTest$tnum.a.2: join the env with a different blob threshold\ 118 and then open db." 119 # Join the env with a different blob threshold value. 120 # We're going to get a warning message out this -- 121 # redirect to a file so it won't be tagged as unexpected 122 # output. 123 # Skip this portion of the test for HP-UX, where we 124 # can't open a second handle on an env. 125 if { $is_hp_test == 0 } { 126 set env1 [eval {berkdb env} -create -home $testdir $earg \ 127 -blob_threshold $threshold3 -msgfile $testdir/msgfile] 128 error_check_good is_valid_env [is_valid_env $env1] TRUE 129 error_check_good env_get_blobthreshold \ 130 [$env1 get_blob_threshold] $threshold2 131 132 # Open the db with no blob threshold value. 133 set db2 [eval {berkdb_open_noerr}\ 134 -env $env1 $oflags $testfile-2] 135 error_check_good db_open [is_valid_db $db2] TRUE 136 137 # Verify the db blob threshold value. 138 error_check_good db_get_blobthreshold \ 139 [$db2 get_blob_threshold] $threshold2 140 141 # Check for the expected message. 142 set msg "Ignoring blob_threshold size when joining environment" 143 set messagefound [eval findstring {$msg} $testdir/msgfile] 144 error_check_bad found_msg $messagefound "" 145 146 error_check_good db_close [$db2 close] 0 147 error_check_good env_close [$env1 close] 0 148 } 149 error_check_good db_close [$db1 close] 0 150 error_check_good db_close [$db close] 0 151 error_check_good env_close [$env close] 0 152 153 env_cleanup $testdir 154 155 puts "\tTest$tnum.b: Test the db blob threshold value is retained\ 156 when reopening the db." 157 # Open the env with no blob threshold value. 158 set env [eval {berkdb env} -create -home $testdir] 159 error_check_good is_valid_env [is_valid_env $env] TRUE 160 161 # Open the db with a blob threshold value and close it. 162 set db [eval {berkdb_open_noerr} \ 163 -env $env -blob_threshold $threshold1 $oflags $testfile] 164 error_check_good db_open [is_valid_db $db] TRUE 165 error_check_good db_get_blobthreshold \ 166 [$db get_blob_threshold] $threshold1 167 error_check_good db_close [$db close] 0 168 169 # Reopen the db with no blob threshold value. 170 set db [eval {berkdb_open_noerr} -env $env $oflags $testfile] 171 error_check_good db_open [is_valid_db $db] TRUE 172 173 # Verify the db blob threshold value is retained. 174 error_check_good db_get_blobthreshold \ 175 [$db get_blob_threshold] $threshold1 176 177 error_check_good db_close [$db close] 0 178 179 puts "\tTest$tnum.c: Test the db blob threshold value is retained\ 180 when reopening the db with a different threshold value." 181 set db [eval {berkdb_open_noerr} \ 182 -env $env -blob_threshold $threshold2 $oflags $testfile] 183 error_check_good db_open [is_valid_db $db] TRUE 184 185 # Verify the db blob threshold value is retained. 186 error_check_good db_get_blobthreshold \ 187 [$db get_blob_threshold] $threshold1 188 189 error_check_good db_close [$db close] 0 190 error_check_good env_close [$env close] 0 191 error_check_good env_remove [berkdb envremove -home $testdir] 0 192 193 # Verify the creation of the blob meta database is rolled 194 # back as well as the actual database when the creating 195 # txn is aborted. We run this only for a single case, btree, 196 # because other cases do not exercise different code paths. 197 if { $pgindex == -1 && [is_partitioned $args] == 0 && $omethod == "btree" } { 198 puts "\tTest$tnum.d: Verify that the blob meta database is\ 199 removed when txn is aborted." 200 set env [eval {berkdb_env} -txn -create -home $testdir] 201 error_check_good is_valid_env [is_valid_env $env] TRUE 202 set txn [$env txn] 203 error_check_good is_valid_txn [is_valid_txn $txn $env] TRUE 204 set db [eval {berkdb_open} -env $env -txn $txn\ 205 $omethod -create -blob_threshold 1 blob.db] 206 error_check_good db_put [$db put -txn $txn 1 2345] 0 207 error_check_good blob_meta_exists\ 208 [file exists $testdir/__db_bl/__db2/__db_blob_meta.db] 1 209 error_check_good txn_abort [$txn abort] 0 210 error_check_bad blob_meta_removed\ 211 [file exists $testdir/__db_bl/__db2/__db_blob_meta.db] 1 212 error_check_good db_close [$db close] 0 213 error_check_good env_close [$env close] 0 214 } 215 env_cleanup $testdir 216} 217