summaryrefslogtreecommitdiff
path: root/db-4.8.30/test/log009.tcl
blob: 29211dbb65e5584ad0e3f3254423046259cf618a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# See the file LICENSE for redistribution information.
#
# Copyright (c) 2004-2009 Oracle.  All rights reserved.
#
# $Id$
#
# TEST	log009
# TEST	Test of logging and getting log file version information.
# TEST	Each time we cross a log file boundary verify we can
# TEST	get the version via the log cursorlag.
# TEST	Do this both forward and backward.
#
proc log009 { } {
	source ./include.tcl
	global errorInfo

	env_cleanup $testdir
	set niter 200
	set method btree

	puts "Log009: Retrieve log version using log cursor."

	# Log size is small so we quickly create more than one.
	# The documentation says that the log file must be at least
	# four times the size of the in-memory log buffer.
	set pagesize 4096
	append largs " -pagesize $pagesize "
	set log_buf [expr $pagesize * 2]
	set log_max [expr $log_buf * 4]

	# Open an env.
	set envcmd "berkdb_env_noerr -create \
	    -log_buffer $log_buf -log_max $log_max -txn -home $testdir"
	set env [eval $envcmd]
	error_check_good env [is_valid_env $env] TRUE

	set stop 0
	set start 0
	#
	# Loop until we have at least 3 log files.
	#
	while { $stop == 0 } {
		puts "\tLog009.a: Running test in to generate log files."
	 	eval rep_test \
		    $method $env NULL $niter $start $start 0 0 $largs
		incr start $niter

		set last_log [get_logfile $env last]
		if { $last_log >= 3 } {
			set stop 1
		}
	}

	# We now have at least 3 log files.  Walk a cursor both ways
	# through the log and make sure we can get the version when we
	# cross a log file boundary.
	set curfile 0
	set logc [$env log_cursor]
	error_check_good logc [is_valid_logc $logc $env] TRUE

	puts "\tLog009.b: Try to get version on unset cursor."
	set stat [catch {eval $logc version} ret]
	error_check_bad stat $stat 0
	error_check_good err [is_substr $ret "unset cursor"] 1

	# Check walking forward through logs looking for log
	# file boundaries.
	#
	puts "\tLog009.c: Walk log forward checking persist."
	for { set logrec [$logc get -first] } \
	    { [llength $logrec] != 0 } \
	    { set logrec [$logc get -next] } {
		set lsn [lindex $logrec 0]
		set lsnfile [lindex $lsn 0]
		if { $curfile != $lsnfile } {
			log009_check $logc $logrec
			set curfile $lsnfile
		}
	}
	error_check_good logclose [$logc close] 0

	set curfile 0
	set logc [$env log_cursor]
	error_check_good logc [is_valid_logc $logc $env] TRUE
	#
	# Check walking backward through logs looking for log
	# file boundaries.
	#
	puts "\tLog009.d: Walk log backward checking persist."
	for { set logrec [$logc get -last] } \
	    { [llength $logrec] != 0 } \
	    { set logrec [$logc get -prev] } {
		set lsn [lindex $logrec 0]
		set lsnfile [lindex $lsn 0]
		if { $curfile != $lsnfile } {
			log009_check $logc $logrec
			set curfile $lsnfile
		}
	}
	error_check_good logclose [$logc close] 0
	error_check_good env_close [$env close] 0
}

proc log009_check { logc logrec } {
	set version [$logc version]
	#
	# We don't have ready access to the current log
	# version, but make sure it is something reasonable.
	#
	# !!!
	# First readable log is 8, current log version
	# is pretty far from 20.
	#
	set reasonable [expr $version > 7 && $version < 20]
	error_check_good persist $reasonable 1
	#
	# Verify that getting the version doesn't move
	# or change the log cursor in any way.
	#
	set logrec1 [$logc get -current]
	error_check_good current $logrec $logrec1
}