1# Copyright (c) 1999, 2020 Oracle and/or its affiliates. All rights reserved. 2# 3# See the file LICENSE for license information. 4# 5# $Id$ 6# 7# TEST env028 8# TEST Test of SET_REGION_DIR. 9# TEST With an environment path specified using -home, and then again 10# TEST with it specified by the environment variable DB_HOME: 11# TEST 1) Make sure that the set_region_dir option is respected 12# TEST a) as a relative pathname. 13# TEST b) as an absolute pathname. 14# TEST 2) Make sure that the SET_REGION_DIR db_config argument is respected, 15# TEST again as relative and absolute pathnames. 16# TEST 3) Make sure that if -both- db_config and a file are present, 17# TEST only the file is respected (see doc/env/naming.html). 18# TEST 4) Check that setting the region dir is incompatible with 19# TEST DB_PRIVATE and DB_SYSTEM_MEM 20# TEST 5) Check that MVCC freezer files go into the region dir. 21proc env028 { } { 22 # env028 is essentially just a small driver that runs 23 # env028_body twice; once, it 24 # supplies a "home" argument to use with environment opens, 25 # and the second time it sets DB_HOME instead. 26 # Note that env028_body itself calls env028_run_test to run 27 # the body of the actual test and check for the presence 28 # of logs. The nesting, I hope, makes this test's structure simpler. 29 30 global env 31 source ./include.tcl 32 33 puts "Env028: set_region_dir test." 34 35 puts "\tEnv028: Running with -home argument to berkdb_env." 36 env028_body "-home $testdir" 37 38 puts "\tEnv028: Running with environment variable DB_HOME set." 39 set env(DB_HOME) $testdir 40 env028_body "-use_environ" 41 42 unset env(DB_HOME) 43 44 puts "\tEnv028: Running with both DB_HOME and -home set." 45 # Should respect -only- -home, so we give it a bogus 46 # environment variable setting. 47 set env(DB_HOME) $testdir/bogus_home 48 env028_body "-use_environ -home $testdir" 49 unset env(DB_HOME) 50 51 puts "\tEnv028: Cannot set Region dir with DB_PRIVATE." 52 env_cleanup $testdir 53 set regdir "REGIONDIR" 54 file mkdir $testdir/$regdir 55 set ret [catch {berkdb_env_noerr -create -home $testdir \ 56 -region_dir $regdir -private} msg] 57 set expected_err "region directory cannot be set" 58 error_check_good system_mem_err [is_substr $msg $expected_err] 1 59 60 puts "\tEnv028: Cannot set Region dir with DB_SYSTEM_MEM." 61 env_cleanup $testdir 62 file mkdir $testdir/$regdir 63 set ret [catch {berkdb_env_noerr -create -home $testdir \ 64 -region_dir $regdir -system_mem} msg] 65 error_check_good system_mem_err [is_substr $msg $expected_err] 1 66 67 puts "\tEnv028: MVCC freezer files go in the Region dir." 68 env_cleanup $testdir 69 file mkdir $testdir/$regdir 70 71 # Create an environment that supports MVCC 72 set dbenv [eval {berkdb_env -home $testdir -create -mode 0644\ 73 -cachesize {0 70000 1} -multiversion -txn \ 74 -region_dir $regdir} ] 75 error_check_good dbenv_open [is_valid_env $dbenv] TRUE 76 77 # Create a DB with txn support. 78 set db [eval {berkdb_open -env $dbenv -auto_commit -create \ 79 -btree -mode 0644 "freeze.db"} ] 80 81 # Write data until some frozen buckets appear. 82 puts "\tEnv028: Writing data until some freezer files appear." 83 set k 0 84 set data 0 85 set t [$dbenv txn -snapshot] 86 set found 0 87 88 while { $k < 10000 } { 89 set ret [catch {$db put -txn $t $k $data }] 90 # Check for frozen buckets. 91 set file_list [glob -nocomplain \ 92 -directory $testdir/$regdir __db.freezer*K] 93 if { [llength $file_list] > 0 } { 94 puts "\tEnv028: Freezer file found in\ 95 Region dir." 96 $t abort 97 set found 1 98 break 99 } 100 incr k 101 } 102 error_check_good found_freezer $found 1 103 error_check_good db_close [$db close] 0 104 error_check_good env_close [$dbenv close] 0 105} 106 107proc env028_body { home_arg } { 108 source ./include.tcl 109 110 env_cleanup $testdir 111 set regdir "REGIONDIR" 112 113 file mkdir $testdir/$regdir 114 115 # Set up full path to $regdir for when we test absolute paths. 116 set curdir [pwd] 117 cd $testdir/$regdir 118 set fullregdir [pwd] 119 cd $curdir 120 121 env028_make_config $regdir 122 123 # Run the meat of the test. 124 env028_run_test a 1 "relative path, config file" $home_arg \ 125 $testdir/$regdir 126 127 env_cleanup $testdir 128 129 file mkdir $fullregdir 130 env028_make_config $fullregdir 131 132 # Run the test again 133 env028_run_test a 2 "absolute path, config file" $home_arg \ 134 $fullregdir 135 136 env_cleanup $testdir 137 138 # Now we try without a config file, but instead with db_config 139 # relative paths 140 file mkdir $testdir/$regdir 141 env028_run_test b 1 "relative path, db_config" "$home_arg \ 142 -region_dir $regdir -data_dir ." \ 143 $testdir/$regdir 144 145 env_cleanup $testdir 146 147 # absolute 148 file mkdir $fullregdir 149 env028_run_test b 2 "absolute path, db_config" "$home_arg \ 150 -region_dir $fullregdir -data_dir ." \ 151 $fullregdir 152 153 env_cleanup $testdir 154 155 # Now, set db_config -and- have a # DB_CONFIG file, and make 156 # sure only the latter is honored. 157 158 file mkdir $testdir/$regdir 159 env028_make_config $regdir 160 161 # note that we supply a -nonexistent- region dir to the 162 # commandline. 163 env028_run_test c 1 "relative path, both db_config and file" \ 164 "$home_arg -region_dir $testdir/bogus \ 165 -data_dir ." $testdir/$regdir 166 env_cleanup $testdir 167 168 file mkdir $fullregdir 169 env028_make_config $fullregdir 170 171 # note that we supply a -nonexistent- region dir to db_config 172 env028_run_test c 2 "relative path, both db_config and file" \ 173 "$home_arg -region_dir $fullregdir/bogus \ 174 -data_dir ." $fullregdir 175} 176 177proc env028_run_test { major minor msg env_args reg_path} { 178 global testdir 179 set testfile "env028.db" 180 181 puts "\t\tEnv028.$major.$minor: $msg" 182 183 # Create an environment then close it 184 set dbenv [eval {berkdb_env -create } $env_args] 185 error_check_good env_open [is_valid_env $dbenv] TRUE 186 error_check_good env_close [$dbenv close] 0 187 188 # Now make sure the region file is where we want it to be. 189 error_check_good region_exists \ 190 [file exists $reg_path/__db.001] 1 191} 192 193proc env028_make_config { regdir } { 194 global testdir 195 196 set cid [open $testdir/DB_CONFIG w] 197 puts $cid "set_data_dir ." 198 puts $cid "set_region_dir $regdir" 199 close $cid 200} 201