1# See the file LICENSE for redistribution information.
2#
3# Copyright (c) 2004,2008 Oracle.  All rights reserved.
4#
5# $Id: log009.tcl,v 12.9 2008/01/08 20:58:53 bostic Exp $
6#
7# TEST	log009
8# TEST	Test of logging and getting log file version information.
9# TEST	Each time we cross a log file boundary verify we can
10# TEST	get the version via the log cursorlag.
11# TEST	Do this both forward and backward.
12#
13proc log009 { } {
14	source ./include.tcl
15	global errorInfo
16
17	env_cleanup $testdir
18	set niter 200
19	set method btree
20
21	puts "Log009: Retrieve log version using log cursor."
22
23	# Log size is small so we quickly create more than one.
24	# The documentation says that the log file must be at least
25	# four times the size of the in-memory log buffer.
26	set pagesize 4096
27	append largs " -pagesize $pagesize "
28	set log_buf [expr $pagesize * 2]
29	set log_max [expr $log_buf * 4]
30
31	# Open an env.
32	set envcmd "berkdb_env_noerr -create \
33	    -log_buffer $log_buf -log_max $log_max -txn -home $testdir"
34	set env [eval $envcmd]
35	error_check_good env [is_valid_env $env] TRUE
36
37	set stop 0
38	set start 0
39	#
40	# Loop until we have at least 3 log files.
41	#
42	while { $stop == 0 } {
43		puts "\tLog009.a: Running test in to generate log files."
44	 	eval rep_test \
45		    $method $env NULL $niter $start $start 0 0 $largs
46		incr start $niter
47
48		set last_log [get_logfile $env last]
49		if { $last_log >= 3 } {
50			set stop 1
51		}
52	}
53
54	# We now have at least 3 log files.  Walk a cursor both ways
55	# through the log and make sure we can get the version when we
56	# cross a log file boundary.
57	set curfile 0
58	set logc [$env log_cursor]
59	error_check_good logc [is_valid_logc $logc $env] TRUE
60
61	puts "\tLog009.b: Try to get version on unset cursor."
62	set stat [catch {eval $logc version} ret]
63	error_check_bad stat $stat 0
64	error_check_good err [is_substr $ret "unset cursor"] 1
65
66	# Check walking forward through logs looking for log
67	# file boundaries.
68	#
69	puts "\tLog009.c: Walk log forward checking persist."
70	for { set logrec [$logc get -first] } \
71	    { [llength $logrec] != 0 } \
72	    { set logrec [$logc get -next] } {
73		set lsn [lindex $logrec 0]
74		set lsnfile [lindex $lsn 0]
75		if { $curfile != $lsnfile } {
76			log009_check $logc $logrec
77			set curfile $lsnfile
78		}
79	}
80	error_check_good logclose [$logc close] 0
81
82	set curfile 0
83	set logc [$env log_cursor]
84	error_check_good logc [is_valid_logc $logc $env] TRUE
85	#
86	# Check walking backward through logs looking for log
87	# file boundaries.
88	#
89	puts "\tLog009.d: Walk log backward checking persist."
90	for { set logrec [$logc get -last] } \
91	    { [llength $logrec] != 0 } \
92	    { set logrec [$logc get -prev] } {
93		set lsn [lindex $logrec 0]
94		set lsnfile [lindex $lsn 0]
95		if { $curfile != $lsnfile } {
96			log009_check $logc $logrec
97			set curfile $lsnfile
98		}
99	}
100	error_check_good logclose [$logc close] 0
101	error_check_good env_close [$env close] 0
102}
103
104proc log009_check { logc logrec } {
105	set version [$logc version]
106	#
107	# We don't have ready access to the current log
108	# version, but make sure it is something reasonable.
109	#
110	# !!!
111	# First readable log is 8, current log version
112	# is pretty far from 20.
113	#
114	set reasonable [expr $version > 7 && $version < 20]
115	error_check_good persist $reasonable 1
116	#
117	# Verify that getting the version doesn't move
118	# or change the log cursor in any way.
119	#
120	set logrec1 [$logc get -current]
121	error_check_good current $logrec $logrec1
122}
123