1
# See the file LICENSE for redistribution information.
3
# Copyright (c) 1996-2002
4
# Sleepycat Software. All rights reserved.
10
# TEST Read/write log records.
15
berkdb srand $rand_init
17
set max [expr 1024 * 128]
18
log001_body $max $iter 1
19
log001_body $max $iter 0
20
log001_body $max $iter 1 "-encryptaes $passwd"
21
log001_body $max $iter 0 "-encryptaes $passwd"
22
log001_body $max [expr $iter * 15] 1
23
log001_body $max [expr $iter * 15] 0
24
log001_body $max [expr $iter * 15] 1 "-encryptaes $passwd"
25
log001_body $max [expr $iter * 15] 0 "-encryptaes $passwd"
28
proc log001_body { max nrecs fixedlength {encargs ""} } {
31
puts -nonewline "Log001: Basic put/get log records "
32
if { $fixedlength == 1 } {
33
puts "(fixed-length $encargs)"
35
puts "(variable-length $encargs)"
40
set env [eval {berkdb_env -log -create -home $testdir -mode 0644} \
41
$encargs -log_max $max]
42
error_check_good envopen [is_valid_env $env] TRUE
44
# We will write records to the log and make sure we can
45
# read them back correctly. We'll use a standard pattern
46
# repeated some number of times for each record.
49
puts "\tLog001.a: Writing $nrecs log records"
50
for { set i 0 } { $i < $nrecs } { incr i } {
52
for { set j 0 } { $j < [expr $i % 10 + 1] } {incr j} {
53
set rec $rec$i:logrec:$i
55
if { $fixedlength != 1 } {
56
set rec $rec:[random_data 237 0 0]
58
set lsn [$env log_put $rec]
59
error_check_bad log_put [is_substr $lsn log_cmd] 1
65
set logc [$env log_cursor]
66
error_check_good logc [is_valid_logc $logc $env] TRUE
68
puts "\tLog001.b: Retrieving log records sequentially (forward)"
70
for { set grec [$logc get -first] } { [llength $grec] != 0 } {
71
set grec [$logc get -next]} {
72
error_check_good log_get:seq [lindex $grec 1] \
77
puts "\tLog001.c: Retrieving log records sequentially (backward)"
78
set i [llength $rec_list]
79
for { set grec [$logc get -last] } { [llength $grec] != 0 } {
80
set grec [$logc get -prev] } {
83
log_get:seq [lindex $grec 1] [lindex $rec_list $i]
86
puts "\tLog001.d: Retrieving log records sequentially by LSN"
88
foreach lsn $lsn_list {
89
set grec [$logc get -set $lsn]
91
log_get:seq [lindex $grec 1] [lindex $rec_list $i]
95
puts "\tLog001.e: Retrieving log records randomly by LSN"
96
set m [expr [llength $lsn_list] - 1]
97
for { set i 0 } { $i < $nrecs } { incr i } {
98
set recno [berkdb random_int 0 $m ]
99
set lsn [lindex $lsn_list $recno]
100
set grec [$logc get -set $lsn]
102
log_get:seq [lindex $grec 1] [lindex $rec_list $recno]
105
puts "\tLog001.f: Retrieving first/current, last/current log record"
106
set grec [$logc get -first]
107
error_check_good log_get:seq [lindex $grec 1] [lindex $rec_list 0]
108
set grec [$logc get -current]
109
error_check_good log_get:seq [lindex $grec 1] [lindex $rec_list 0]
110
set i [expr [llength $rec_list] - 1]
111
set grec [$logc get -last]
112
error_check_good log_get:seq [lindex $grec 1] [lindex $rec_list $i]
113
set grec [$logc get -current]
114
error_check_good log_get:seq [lindex $grec 1] [lindex $rec_list $i]
116
# Close and unlink the file
117
error_check_good log_cursor:close:$logc [$logc close] 0
118
error_check_good env:close [$env close] 0
119
error_check_good envremove [berkdb envremove -home $testdir] 0