@@ -6,8 +6,6 @@ use std::str;
6
6
use thiserror:: Error ;
7
7
use zenith_utils:: lsn:: Lsn ;
8
8
9
- const XLOG_BLCKSZ : u32 = 8192 ;
10
-
11
9
// FIXME: this is configurable in PostgreSQL, 16 MB is the default
12
10
const WAL_SEGMENT_SIZE : u64 = 16 * 1024 * 1024 ;
13
11
@@ -111,10 +109,7 @@ impl WalStreamDecoder {
111
109
112
110
self . lsn += SizeOfXLogLongPHD as u64 ;
113
111
continue ;
114
- } else if self . lsn . 0 % ( XLOG_BLCKSZ as u64 ) == 0 {
115
- // FIXME: make this a member of Lsn, but what should it be called?
116
- // parse page header
117
-
112
+ } else if self . lsn . block_offset ( ) == 0 {
118
113
if self . inputbuf . remaining ( ) < SizeOfXLogShortPHD {
119
114
return Ok ( None ) ;
120
115
}
@@ -165,8 +160,7 @@ impl WalStreamDecoder {
165
160
continue ;
166
161
} else {
167
162
// we're continuing a record, possibly from previous page.
168
- // FIXME: Should any of this math be captured into Lsn or a related type?
169
- let pageleft: u32 = XLOG_BLCKSZ - ( self . lsn . 0 % ( XLOG_BLCKSZ as u64 ) ) as u32 ;
163
+ let pageleft = self . lsn . remaining_in_block ( ) as u32 ;
170
164
171
165
// read the rest of the record, or as much as fits on this page.
172
166
let n = min ( self . contlen , pageleft) as usize ;
@@ -188,12 +182,10 @@ impl WalStreamDecoder {
188
182
// to the next WAL segment.
189
183
if is_xlog_switch_record ( & recordbuf) {
190
184
trace ! ( "saw xlog switch record at {}" , self . lsn) ;
191
- self . padlen = ( WAL_SEGMENT_SIZE - ( self . lsn . 0 % WAL_SEGMENT_SIZE ) ) as u32 ;
192
- }
193
-
194
- // FIXME: what does this code do?
195
- if self . lsn . 0 % 8 != 0 {
196
- self . padlen = 8 - ( self . lsn . 0 % 8 ) as u32 ;
185
+ self . padlen = self . lsn . calc_padding ( WAL_SEGMENT_SIZE ) as u32 ;
186
+ } else {
187
+ // Pad to an 8-byte boundary
188
+ self . padlen = self . lsn . calc_padding ( 8u32 ) as u32 ;
197
189
}
198
190
199
191
let result = ( self . lsn , recordbuf) ;
0 commit comments