1 # See the file LICENSE for redistribution information.
3 # Copyright (c) 1996, 2012 Oracle and/or its affiliates. All rights reserved.
9 # TEST Read/write log records.
10 # TEST Test with and without fixed-length, in-memory logging,
11 # TEST and encryption.
17 berkdb srand $rand_init
20 set max [expr 1024 * 128]
21 foreach fixedlength { 0 1 } {
22 foreach inmem { 1 0 } {
23 log001_body $max $iter $fixedlength $inmem
24 log001_body $max [expr $iter * 15] $fixedlength $inmem
26 # Skip encrypted tests if not supported.
27 if { $has_crypto == 0 } {
31 $iter $fixedlength $inmem "-encryptaes $passwd"
33 [expr $iter * 15] $fixedlength $inmem "-encryptaes $passwd"
38 proc log001_body { max nrecs fixedlength inmem {encargs ""} } {
41 puts -nonewline "Log001: Basic put/get log records: "
42 if { $fixedlength == 1 } {
43 puts -nonewline "fixed-length ($encargs)"
45 puts -nonewline "variable-length ($encargs)"
48 # In-memory logging requires a large enough log buffer that
49 # any active transaction can be aborted.
51 set lbuf [expr 8 * [expr 1024 * 1024]]
52 puts " with in-memory logging."
54 puts " with on-disk logging."
61 set logargs "-log_inmemory -log_buffer $lbuf"
63 set env [eval {berkdb_env -log -create -home $testdir -mode 0644} \
64 $encargs $logargs -log_max $max]
65 error_check_good envopen [is_valid_env $env] TRUE
67 # We will write records to the log and make sure we can
68 # read them back correctly. We'll use a standard pattern
69 # repeated some number of times for each record.
72 puts "\tLog001.a: Writing $nrecs log records"
73 for { set i 0 } { $i < $nrecs } { incr i } {
75 for { set j 0 } { $j < [expr $i % 10 + 1] } {incr j} {
76 set rec $rec$i:logrec:$i
78 if { $fixedlength != 1 } {
79 set rec $rec:[random_data 237 0 0]
81 set lsn [$env log_put $rec]
82 error_check_bad log_put [is_substr $lsn log_cmd] 1
88 set logc [$env log_cursor]
89 error_check_good logc [is_valid_logc $logc $env] TRUE
91 puts "\tLog001.b: Retrieving log records sequentially (forward)"
93 for { set grec [$logc get -first] } { [llength $grec] != 0 } {
94 set grec [$logc get -next]} {
95 error_check_good log_get:seq [lindex $grec 1] \
100 puts "\tLog001.c: Retrieving log records sequentially (backward)"
101 set i [llength $rec_list]
102 for { set grec [$logc get -last] } { [llength $grec] != 0 } {
103 set grec [$logc get -prev] } {
106 log_get:seq [lindex $grec 1] [lindex $rec_list $i]
109 puts "\tLog001.d: Retrieving log records sequentially by LSN"
111 foreach lsn $lsn_list {
112 set grec [$logc get -set $lsn]
114 log_get:seq [lindex $grec 1] [lindex $rec_list $i]
118 puts "\tLog001.e: Retrieving log records randomly by LSN"
119 set m [expr [llength $lsn_list] - 1]
120 for { set i 0 } { $i < $nrecs } { incr i } {
121 set recno [berkdb random_int 0 $m ]
122 set lsn [lindex $lsn_list $recno]
123 set grec [$logc get -set $lsn]
125 log_get:seq [lindex $grec 1] [lindex $rec_list $recno]
128 puts "\tLog001.f: Retrieving first/current, last/current log record"
129 set grec [$logc get -first]
130 error_check_good log_get:seq [lindex $grec 1] [lindex $rec_list 0]
131 set grec [$logc get -current]
132 error_check_good log_get:seq [lindex $grec 1] [lindex $rec_list 0]
133 set i [expr [llength $rec_list] - 1]
134 set grec [$logc get -last]
135 error_check_good log_get:seq [lindex $grec 1] [lindex $rec_list $i]
136 set grec [$logc get -current]
137 error_check_good log_get:seq [lindex $grec 1] [lindex $rec_list $i]
139 # Close and unlink the file
140 error_check_good log_cursor:close:$logc [$logc close] 0
141 error_check_good env:close [$env close] 0
142 error_check_good envremove [berkdb envremove -home $testdir] 0