1# See the file LICENSE for redistribution information.
2#
3# Copyright (c) 1996,2008 Oracle.  All rights reserved.
4#
5# $Id: log005.tcl,v 12.6 2008/01/08 20:58:53 bostic Exp $
6#
7# TEST	log005
8# TEST	Check that log file sizes can change on the fly.
9proc log005 { } {
10
11	# Skip the test for HP-UX, where we can't do the second
12	# env open.
13	global is_hp_test
14	if { $is_hp_test == 1 } {
15		puts "Log005: Skipping for HP-UX."
16		return
17	}
18
19	foreach inmem { 1 0 } {
20		log005_body $inmem
21	}
22}
23proc log005_body { inmem } {
24	source ./include.tcl
25	env_cleanup $testdir
26
27	puts -nonewline "Log005: Check that log file sizes can change"
28	if { $inmem == 0 } {
29		puts " (on-disk logging)."
30	} else {
31		puts " (in-memory logging)."
32	}
33
34	# Open the environment, set and check the log file size.
35	puts "\tLog005.a: open, set and check the log file size."
36	set logargs ""
37	if { $inmem == 1 } {
38		set lbuf [expr 1024 * 1024]
39		set logargs "-log_inmemory -log_buffer $lbuf"
40	}
41	set env [eval {berkdb_env} -create -home $testdir \
42	    $logargs -log_max 1000000 -txn]
43	error_check_good envopen [is_valid_env $env] TRUE
44	set db [berkdb_open \
45	    -env $env -create -mode 0644 -btree -auto_commit a.db]
46	error_check_good dbopen [is_valid_db $db] TRUE
47
48	# Get the current log file maximum.
49	set max [log005_stat $env "Current log file size"]
50	error_check_good max_set $max 1000000
51
52	# Reset the log file size using a second open, and make sure
53	# it changes.
54	puts "\tLog005.b: reset during open, check the log file size."
55	set envtmp [berkdb_env -home $testdir -log_max 900000 -txn]
56	error_check_good envtmp_open [is_valid_env $envtmp] TRUE
57	error_check_good envtmp_close [$envtmp close] 0
58
59	set tmp [log005_stat $env "Current log file size"]
60	error_check_good max_changed 900000 $tmp
61
62	puts "\tLog005.c: fill in the current log file size."
63	# Fill in the current log file.
64	set new_lsn 0
65	set data [repeat "a" 1024]
66	for { set i 1 } \
67	    { [log005_stat $env "Current log file number"] != 2 } \
68	    { incr i } {
69		set t [$env txn]
70		error_check_good txn [is_valid_txn $t $env] TRUE
71		set ret [$db put -txn $t $i $data]
72		error_check_good put $ret 0
73		error_check_good txn [$t commit] 0
74
75		set last_lsn $new_lsn
76		set new_lsn [log005_stat $env "Current log file offset"]
77	}
78
79	# The last LSN in the first file should be more than our new
80	# file size.
81	error_check_good "lsn check < 900000" [expr 900000 < $last_lsn] 1
82
83	# Close down the environment.
84	error_check_good db_close [$db close] 0
85	error_check_good env_close [$env close] 0
86
87	if { $inmem == 1 } {
88		puts "Log005: Skipping remainder of test for in-memory logging."
89		return
90	}
91
92	puts "\tLog005.d: check the log file size is unchanged after recovery."
93	# Open again, running recovery.  Verify the log file size is as we
94	# left it.
95	set env [berkdb_env -create -home $testdir -recover -txn]
96	error_check_good env_open [is_valid_env $env] TRUE
97
98	set tmp [log005_stat $env "Current log file size"]
99	error_check_good after_recovery 900000 $tmp
100
101	error_check_good env_close [$env close] 0
102}
103
104# log005_stat --
105#	Return the current log statistics.
106proc log005_stat { env s } {
107	set stat [$env log_stat]
108	foreach statpair $stat {
109		set statmsg [lindex $statpair 0]
110		set statval [lindex $statpair 1]
111		if {[is_substr $statmsg $s] != 0} {
112			return $statval
113		}
114	}
115	puts "FAIL: log005: stat string $s not found"
116	return 0
117}
118