1313
1414use integer; # causes / operator to use integer math
1515
16+ # Is this a big-endian system ("network" byte order)? We can't use 'Q' in
17+ # pack() calls because it's not available in some perl builds, so we need to
18+ # break 64 bit LSN values into two 'I' values. Fortunately we don't need to
19+ # deal with high values, so we can just write 0 for the high order 32 bits, but
20+ # we need to know the endianness to do that.
21+ my $BIG_ENDIAN = pack (" L" , 0x12345678) eq pack (" N" , 0x12345678);
22+
1623# Header size of record header.
1724my $RECORD_HEADER_SIZE = 24;
1825
@@ -125,13 +132,16 @@ sub build_record_header
125132 # This needs to follow the structure XLogRecord:
126133 # I for xl_tot_len
127134 # I for xl_xid
128- # Q for xl_prev
135+ # II for xl_prev
129136 # C for xl_info
130137 # C for xl_rmid
131138 # BB for two bytes of padding
132139 # I for xl_crc
133- return pack (" IIQCCBBI" ,
134- $xl_tot_len , $xl_xid , $xl_prev , $xl_info , $xl_rmid , 0, 0, $xl_crc );
140+ return pack (" IIIICCBBI" ,
141+ $xl_tot_len , $xl_xid ,
142+ $BIG_ENDIAN ? 0 : $xl_prev ,
143+ $BIG_ENDIAN ? $xl_prev : 0,
144+ $xl_info , $xl_rmid , 0, 0, $xl_crc );
135145}
136146
137147# Build a fake WAL page header, based on the data given by the caller
@@ -149,10 +159,12 @@ sub build_page_header
149159 # S for xlp_magic
150160 # S for xlp_info
151161 # I for xlp_tli
152- # Q for xlp_pageaddr
162+ # II for xlp_pageaddr
153163 # I for xlp_rem_len
154- return pack (" SSIQI" ,
155- $xlp_magic , $xlp_info , $xlp_tli , $xlp_pageaddr , $xlp_rem_len );
164+ return pack (" SSIIII" ,
165+ $xlp_magic , $xlp_info , $xlp_tli ,
166+ $BIG_ENDIAN ? 0 : $xlp_pageaddr ,
167+ $BIG_ENDIAN ? $xlp_pageaddr : 0, $xlp_rem_len );
156168}
157169
158170# Make sure we are far away enough from the end of a page that we could insert
0 commit comments