1# See the file LICENSE for redistribution information.
2#
3# Copyright (c) 2005,2008 Oracle.  All rights reserved.
4#
5# $Id: log008script.tcl,v 12.7 2008/01/08 20:58:53 bostic Exp $
6#
7# Log008 script - dbreg_ckp and txn_ckp records spanning log files.
8#
9# Usage: log008script
10
11source ./include.tcl
12set tnum "008"
13set usage "log008script nhandles"
14
15# Verify usage
16if { $argc != 1 } {
17	puts stderr "FAIL:[timestamp] Usage: $usage"
18	exit
19}
20
21# Initialize arguments
22set nhandles [ lindex $argv 0 ]
23
24# We make the log files small so it's likely that the
25# records will end up in different files.
26set maxbsize [expr 8 * 1024]
27set maxfile [expr 32 * 1024]
28
29# Set up environment.
30set envcmd "berkdb_env -create -txn -home $testdir \
31    -log_buffer $maxbsize -log_max $maxfile"
32set dbenv [eval $envcmd]
33error_check_good dbenv [is_valid_env $dbenv] TRUE
34
35# Open a lot of database handles.
36set filename TESTFILE
37set handlelist {}
38for { set i 0 } { $i < $nhandles } { incr i } {
39	set db [berkdb_open \
40	    -create -env $dbenv -auto_commit -btree $filename]
41	lappend handlelist $db
42}
43
44# Fill log files, checking LSNs before and after a checkpoint,
45# until we generate a case where the records span two log files.
46set i 0
47while { 1 } {
48	set txn [$dbenv txn]
49	foreach handle $handlelist {
50		error_check_good \
51		    db_put [$handle put -txn $txn key.$i data.$i] 0
52		incr i
53	}
54	error_check_good txn_commit [$txn commit] 0
55
56	# Find current LSN file number.
57	set filenum [stat_field $dbenv log_stat "Current log file number"]
58
59	# Checkpoint.
60	error_check_good checkpoint [$dbenv txn_checkpoint] 0
61
62	# Find current LSN.
63	set newfilenum [stat_field $dbenv log_stat "Current log file number"]
64	if { [expr $newfilenum > $filenum] } {
65		break
66	}
67}
68
69# Do one more transactional operation per fileid.
70set txn [$dbenv txn]
71foreach handle $handlelist {
72	error_check_good \
73	    db_put [$handle put -txn $txn key.$i data.$i] 0
74	incr i
75}
76error_check_good txn_commit [$txn commit] 0
77
78# Archive, deleting the log files we think we no longer need.
79set stat [eval exec $util_path/db_archive -d -h $testdir]
80
81# Child is done.  Exit, abandoning the env instead of closing it.
82exit
83