1# See the file LICENSE for redistribution information.
2#
3# Copyright (c) 1996-2009 Oracle.  All rights reserved.
4#
5# $Id$
6#
7# TEST	txn002
8# TEST	Verify that  read-only transactions do not write log records.
9proc txn002 { {tnum "002" } { max 1024 } { ntxns 50 } } {
10	source ./include.tcl
11	global txn_curid
12	global txn_maxid
13
14	puts -nonewline "Txn$tnum: Read-only transaction test ($max) ($ntxns)"
15
16	if { $tnum != "002" } {
17		puts " (with ID wrap)"
18	} else {
19		puts ""
20	}
21
22	env_cleanup $testdir
23	set env [berkdb \
24	    env -create -mode 0644 -txn -txn_max $max -home $testdir]
25	error_check_good dbenv [is_valid_env $env] TRUE
26	error_check_good txn_id_set \
27	    [$env txn_id_set $txn_curid $txn_maxid ] 0
28
29	# Save the current bytes in the log.
30	set off_start [txn002_logoff $env]
31
32	# We will create a bunch of transactions and commit them.
33	set txn_list {}
34	set tid_list {}
35	puts "\tTxn$tnum.a: Beginning/Committing Transactions"
36	for { set i 0 } { $i < $ntxns } { incr i } {
37		set txn [$env txn]
38		error_check_good txn_begin [is_valid_txn $txn $env] TRUE
39
40		lappend txn_list $txn
41
42		set tid [$txn id]
43		error_check_good tid_check [lsearch $tid_list $tid] -1
44
45		lappend tid_list $tid
46	}
47	foreach t $txn_list {
48		error_check_good txn_commit:$t [$t commit] 0
49	}
50
51	# Make sure we haven't written any new log records except
52	# potentially some recycle records if we were wrapping txnids.
53	set off_stop [txn002_logoff $env]
54	if { $off_stop != $off_start } {
55		txn002_recycle_only $testdir
56	}
57
58	error_check_good env_close [$env close] 0
59}
60
61proc txn002_logoff { env } {
62	set stat [$env log_stat]
63	foreach i $stat {
64		foreach {txt val} $i {break}
65			if { [string compare \
66			    $txt {Current log file offset}] == 0 } {
67			return $val
68		}
69	}
70}
71
72# Make sure that the only log records found are txn_recycle records
73proc txn002_recycle_only { dir } {
74	global util_path
75
76	set tmpfile $dir/printlog.out
77	set stat [catch {exec $util_path/db_printlog -h $dir > $tmpfile} ret]
78	error_check_good db_printlog $stat 0
79
80	set f [open $tmpfile r]
81	while { [gets $f record] >= 0 } {
82		set r [regexp {\[[^\]]*\]\[[^\]]*\]([^\:]*)\:} $record whl name]
83		if { $r == 1 } {
84			error_check_good record_type __txn_recycle $name
85		}
86	}
87	close $f
88	fileremove $tmpfile
89}
90