1# See the file LICENSE for redistribution information. 2# 3# Copyright (c) 1996,2008 Oracle. All rights reserved. 4# 5# $Id: txn010.tcl,v 12.6 2008/01/08 20:58:53 bostic Exp $ 6# 7# TEST txn010 8# TEST Test DB_ENV->txn_checkpoint arguments/flags 9proc txn010 { } { 10 source ./include.tcl 11 12 puts "Txn010: test DB_ENV->txn_checkpoint arguments/flags." 13 env_cleanup $testdir 14 15 # Open an environment and database. 16 puts "\tTxn010.a: open the environment and a database, checkpoint." 17 set env [berkdb_env -create -home $testdir -txn] 18 error_check_good envopen [is_valid_env $env] TRUE 19 set db [berkdb_open \ 20 -env $env -create -mode 0644 -btree -auto_commit a.db] 21 error_check_good dbopen [is_valid_db $db] TRUE 22 23 # Insert some data and do a checkpoint. 24 for { set count 0 } { $count < 100 } { incr count } { 25 set t [$env txn] 26 error_check_good "init: put" \ 27 [$db put -txn $t "key_a_$count" "data"] 0 28 error_check_good "init: commit" [$t commit] 0 29 } 30 tclsleep 1 31 error_check_good checkpoint [$env txn_checkpoint] 0 32 33 # Test that checkpoint calls are ignored in quiescent systems. 34 puts "\tTxn010.b: test for checkpoints when system is quiescent" 35 set chkpt [txn010_stat $env "Time of last checkpoint"] 36 for { set count 0 } { $count < 5 } {incr count } { 37 tclsleep 1 38 error_check_good checkpoint [$env txn_checkpoint] 0 39 set test_chkpt [txn010_stat $env "Time of last checkpoint"] 40 error_check_good "quiescent: checkpoint time changed" \ 41 [expr $test_chkpt == $chkpt] 1 42 } 43 44 # Add a single record, and test that checkpoint does something. 45 set chkpt [txn010_stat $env "Time of last checkpoint"] 46 set t [$env txn] 47 error_check_good \ 48 "quiescent: put" [$db put -txn $t "key_b_$count" "data"] 0 49 error_check_good "quiescent: commit" [$t commit] 0 50 tclsleep 1 51 error_check_good checkpoint [$env txn_checkpoint] 0 52 set test_chkpt [txn010_stat $env "Time of last checkpoint"] 53 error_check_good "quiescent: checkpoint time unchanged" \ 54 [expr $test_chkpt > $chkpt] 1 55 56 # Test that -force causes a checkpoint. 57 puts "\tTxn010.c: test checkpoint -force" 58 set chkpt [txn010_stat $env "Time of last checkpoint"] 59 for { set count 0 } { $count < 5 } {incr count } { 60 tclsleep 1 61 error_check_good checkpoint [$env txn_checkpoint -force] 0 62 set test_chkpt [txn010_stat $env "Time of last checkpoint"] 63 error_check_good "force: checkpoint time unchanged" \ 64 [expr $test_chkpt > $chkpt] 1 65 set chkpt $test_chkpt 66 } 67 68 # Test that -kbyte doesn't cause a checkpoint unless there's 69 # enough activity. 70 puts "\tTxn010.d: test checkpoint -kbyte" 71 72 # Put in lots of data, and verify that -kbyte causes a checkpoint 73 for { set count 0 } { $count < 1000 } { incr count } { 74 set t [$env txn] 75 error_check_good "kbyte: put" \ 76 [$db put -txn $t "key_c_$count" "data"] 0 77 error_check_good "kbyte: commit" [$t commit] 0 78 } 79 80 set chkpt [txn010_stat $env "Time of last checkpoint"] 81 tclsleep 1 82 error_check_good checkpoint [$env txn_checkpoint -kbyte 2] 0 83 set test_chkpt [txn010_stat $env "Time of last checkpoint"] 84 error_check_good "kbytes: checkpoint time unchanged" \ 85 [expr $test_chkpt > $chkpt] 1 86 87 # Put in a little data and verify that -kbyte doesn't cause a 88 # checkpoint 89 set chkpt [txn010_stat $env "Time of last checkpoint"] 90 for { set count 0 } { $count < 20 } { incr count } { 91 set t [$env txn] 92 error_check_good "kbyte: put" \ 93 [$db put -txn $t "key_d_$count" "data"] 0 94 error_check_good "kbyte: commit" [$t commit] 0 95 tclsleep 1 96 error_check_good checkpoint [$env txn_checkpoint -kbyte 20] 0 97 set test_chkpt [txn010_stat $env "Time of last checkpoint"] 98 error_check_good "kbytes: checkpoint time changed" \ 99 [expr $test_chkpt == $chkpt] 1 100 } 101 102 # Test that -min doesn't cause a checkpoint unless enough time has 103 # passed. 104 puts "\tTxn010.e: test checkpoint -min" 105 set t [$env txn] 106 error_check_good "min: put" [$db put -txn $t "key_e_$count" "data"] 0 107 error_check_good "min: commit" [$t commit] 0 108 set chkpt [txn010_stat $env "Time of last checkpoint"] 109 for { set count 0 } { $count < 5 } {incr count } { 110 tclsleep 1 111 error_check_good checkpoint [$env txn_checkpoint -min 2] 0 112 set test_chkpt [txn010_stat $env "Time of last checkpoint"] 113 error_check_good "min: checkpoint time changed" \ 114 [expr $test_chkpt == $chkpt] 1 115 } 116 117 # Wait long enough, and then check to see if -min causes a checkpoint. 118 set chkpt [txn010_stat $env "Time of last checkpoint"] 119 tclsleep 120 120 error_check_good checkpoint [$env txn_checkpoint -min 2] 0 121 set test_chkpt [txn010_stat $env "Time of last checkpoint"] 122 error_check_good "min: checkpoint time unchanged" \ 123 [expr $test_chkpt > $chkpt] 1 124 125 # Close down the database and the environment. 126 error_check_good db_close [$db close] 0 127 error_check_good env_close [$env close] 0 128} 129 130# txn010_stat -- 131# Return the current log statistics. 132proc txn010_stat { env s } { 133 set stat [$env txn_stat] 134 foreach statpair $stat { 135 set statmsg [lindex $statpair 0] 136 set statval [lindex $statpair 1] 137 if {[is_substr $statmsg $s] != 0} { 138 return $statval 139 } 140 } 141 puts "FAIL: Txn010: stat string $s not found" 142 return 0 143} 144