Skip to content

Commit 18a62eb

Browse files
committed
MDEV-21133 follow-up: Use fil_page_get_type()
Let us use the common accessor function fil_page_get_type() instead of accessing the page header field FIL_PAGE_TYPE directly.
1 parent ba573c4 commit 18a62eb

File tree

11 files changed

+30
-33
lines changed

11 files changed

+30
-33
lines changed

extra/innochecksum.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ is_page_corrupted(
467467
/* use to store LSN values. */
468468
ulint logseq;
469469
ulint logseqfield;
470-
ulint page_type = mach_read_from_2(buf+FIL_PAGE_TYPE);
470+
const uint16_t page_type = fil_page_get_type(buf);
471471
uint key_version = buf_page_get_key_version(buf, flags);
472472
ulint space_id = mach_read_from_4(
473473
buf + FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID);
@@ -835,7 +835,7 @@ parse_page(
835835
strcpy(str, "-");
836836
}
837837

838-
switch (mach_read_from_2(page + FIL_PAGE_TYPE)) {
838+
switch (fil_page_get_type(page)) {
839839

840840
case FIL_PAGE_INDEX: {
841841
uint key_version = mach_read_from_4(page + FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION);
@@ -1933,7 +1933,7 @@ int main(
19331933
skip_page = false;
19341934
}
19351935

1936-
ulint cur_page_type = mach_read_from_2(buf+FIL_PAGE_TYPE);
1936+
const uint16_t cur_page_type = fil_page_get_type(buf);
19371937

19381938
/* FIXME: Page compressed or Page compressed and encrypted
19391939
pages do not contain checksum. */

extra/mariabackup/fil_cur.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ static bool page_is_corrupted(const byte *page, ulint page_no,
276276
byte tmp_frame[UNIV_PAGE_SIZE_MAX];
277277
byte tmp_page[UNIV_PAGE_SIZE_MAX];
278278
const ulint page_size = cursor->page_size;
279-
ulint page_type = mach_read_from_2(page + FIL_PAGE_TYPE);
279+
uint16_t page_type = fil_page_get_type(page);
280280

281281
/* We ignore the doublewrite buffer pages.*/
282282
if (cursor->space_id == TRX_SYS_SPACE
@@ -359,7 +359,7 @@ static bool page_is_corrupted(const byte *page, ulint page_no,
359359
|| page_type == FIL_PAGE_PAGE_COMPRESSED_ENCRYPTED) {
360360
ulint decomp = fil_page_decompress(tmp_frame, tmp_page,
361361
space->flags);
362-
page_type = mach_read_from_2(tmp_page + FIL_PAGE_TYPE);
362+
page_type = fil_page_get_type(tmp_page);
363363

364364
return (!decomp
365365
|| (decomp != srv_page_size

storage/innobase/buf/buf0buf.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ buf_page_is_corrupted(
794794
bool crc32_inited = false;
795795
bool crc32_chksum = false;
796796
const ulint zip_size = fil_space_t::zip_size(fsp_flags);
797-
ulint page_type = mach_read_from_2(read_buf + FIL_PAGE_TYPE);
797+
const uint16_t page_type = fil_page_get_type(read_buf);
798798

799799
/* We can trust page type if page compression is set on tablespace
800800
flags because page compression flag means file must have been
@@ -3908,8 +3908,7 @@ buf_page_get_low(
39083908
}
39093909

39103910
if (allow_ibuf_merge
3911-
&& mach_read_from_2(fix_block->frame + FIL_PAGE_TYPE)
3912-
== FIL_PAGE_INDEX
3911+
&& fil_page_get_type(fix_block->frame) == FIL_PAGE_INDEX
39133912
&& page_is_leaf(fix_block->frame)) {
39143913
rw_lock_x_lock_inline(&fix_block->lock, 0, file, line);
39153914

storage/innobase/fil/fil0crypt.cc

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,8 @@ static byte* fil_encrypt_buf_for_non_full_checksum(
455455
ut_ad(!ut_align_offset(src_frame, 8));
456456
ut_ad(!ut_align_offset(dst_frame, 8));
457457

458-
ulint orig_page_type = mach_read_from_2(src_frame+FIL_PAGE_TYPE);
459-
ibool page_compressed = (orig_page_type == FIL_PAGE_PAGE_COMPRESSED_ENCRYPTED);
458+
const bool page_compressed = fil_page_get_type(src_frame)
459+
== FIL_PAGE_PAGE_COMPRESSED_ENCRYPTED;
460460
uint header_len = FIL_PAGE_DATA;
461461

462462
if (page_compressed) {
@@ -609,9 +609,9 @@ byte* fil_encrypt_buf(
609609
@return true if it is valid page type */
610610
static bool fil_space_encrypt_valid_page_type(
611611
const fil_space_t* space,
612-
byte* src_frame)
612+
const byte* src_frame)
613613
{
614-
switch (mach_read_from_2(src_frame+FIL_PAGE_TYPE)) {
614+
switch (fil_page_get_type(src_frame)) {
615615
case FIL_PAGE_RTREE:
616616
return space->full_crc32();
617617
case FIL_PAGE_TYPE_FSP_HDR:
@@ -735,10 +735,9 @@ static bool fil_space_decrypt_for_non_full_checksum(
735735
byte* src_frame,
736736
dberr_t* err)
737737
{
738-
ulint page_type = mach_read_from_2(src_frame+FIL_PAGE_TYPE);
739738
uint key_version = mach_read_from_4(
740739
src_frame + FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION);
741-
bool page_compressed = (page_type
740+
bool page_compressed = (fil_page_get_type(src_frame)
742741
== FIL_PAGE_PAGE_COMPRESSED_ENCRYPTED);
743742
uint offset = mach_read_from_4(src_frame + FIL_PAGE_OFFSET);
744743
uint space = mach_read_from_4(
@@ -2439,8 +2438,7 @@ bool fil_space_verify_crypt_checksum(const byte* page, ulint zip_size)
24392438
/* Compressed and encrypted pages do not have checksum. Assume not
24402439
corrupted. Page verification happens after decompression in
24412440
buf_page_io_complete() using buf_page_is_corrupted(). */
2442-
if (mach_read_from_2(page + FIL_PAGE_TYPE)
2443-
== FIL_PAGE_PAGE_COMPRESSED_ENCRYPTED) {
2441+
if (fil_page_get_type(page) == FIL_PAGE_PAGE_COMPRESSED_ENCRYPTED) {
24442442
return true;
24452443
}
24462444

storage/innobase/fil/fil0pagecompress.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -581,10 +581,9 @@ ulint fil_page_decompress_for_non_full_crc32(
581581
byte* tmp_buf,
582582
byte* buf)
583583
{
584-
const unsigned ptype = mach_read_from_2(buf+FIL_PAGE_TYPE);
585584
ulint header_len;
586585
uint comp_algo;
587-
switch (ptype) {
586+
switch (fil_page_get_type(buf)) {
588587
case FIL_PAGE_PAGE_COMPRESSED_ENCRYPTED:
589588
header_len= FIL_PAGE_DATA + FIL_PAGE_ENCRYPT_COMP_METADATA_LEN;
590589
comp_algo = mach_read_from_2(

storage/innobase/fsp/fsp0fsp.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1782,7 +1782,7 @@ fseg_create(
17821782
}
17831783

17841784
ut_ad(rw_lock_get_sx_lock_count(&block->lock) == 1);
1785-
ut_ad(!mach_read_from_2(FIL_PAGE_TYPE + block->frame));
1785+
ut_ad(!fil_page_get_type(block->frame));
17861786
mtr->write<1>(*block, FIL_PAGE_TYPE + 1 + block->frame,
17871787
FIL_PAGE_TYPE_SYS);
17881788
}

storage/innobase/include/buf0buf.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -588,8 +588,7 @@ stored in page type.
588588
@return true if page is compressed. */
589589
inline bool buf_page_is_compressed(const byte* read_buf, ulint fsp_flags)
590590
{
591-
uint16_t page_type= mach_read_from_2(my_assume_aligned<2>
592-
(read_buf + FIL_PAGE_TYPE));
591+
uint16_t page_type= fil_page_get_type(read_buf);
593592
return fil_space_t::full_crc32(fsp_flags)
594593
? !!(page_type & 1U << FIL_PAGE_COMPRESS_FCRC32_MARKER)
595594
: page_type == FIL_PAGE_PAGE_COMPRESSED;
@@ -602,7 +601,7 @@ inline bool buf_page_is_compressed(const byte* read_buf, ulint fsp_flags)
602601
@return the payload size in the file page */
603602
inline uint buf_page_full_crc32_size(const byte* buf, bool* comp, bool* cr)
604603
{
605-
uint t = mach_read_from_2(my_assume_aligned<2>(buf + FIL_PAGE_TYPE));
604+
uint t = fil_page_get_type(buf);
606605
uint page_size = uint(srv_page_size);
607606

608607
if (!(t & 1U << FIL_PAGE_COMPRESS_FCRC32_MARKER)) {

storage/innobase/include/fil0fil.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ Created 10/25/1995 Heikki Tuuri
2828
#define fil0fil_h
2929

3030
#include "fsp0types.h"
31+
#include "mach0data.h"
32+
#include "assume_aligned.h"
3133

3234
#ifndef UNIV_INNOCHECKSUM
3335

@@ -827,6 +829,14 @@ enum fil_encryption_t {
827829
FIL_ENCRYPTION_OFF
828830
};
829831

832+
/** Get the file page type.
833+
@param[in] page file page
834+
@return page type */
835+
inline uint16_t fil_page_get_type(const byte *page)
836+
{
837+
return mach_read_from_2(my_assume_aligned<2>(page + FIL_PAGE_TYPE));
838+
}
839+
830840
#ifndef UNIV_INNOCHECKSUM
831841

832842
/** Number of pending tablespace flushes */

storage/innobase/include/fil0fil.ic

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ fil_page_type_validate(
8686
fil_space_t* space,
8787
const byte* page)
8888
{
89-
ulint page_type = mach_read_from_2(page + FIL_PAGE_TYPE);
89+
const uint16_t page_type = fil_page_get_type(page);
9090

9191
if ((page_type & 1U << FIL_PAGE_COMPRESS_FCRC32_MARKER)
9292
&& space->full_crc32()

storage/innobase/include/fsp0fsp.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -568,14 +568,6 @@ Any other pages were written with uninitialized bytes in FIL_PAGE_TYPE.
568568
ATTRIBUTE_COLD
569569
void fil_block_reset_type(const buf_block_t& block, ulint type, mtr_t* mtr);
570570

571-
/** Get the file page type.
572-
@param[in] page file page
573-
@return page type */
574-
inline uint16_t fil_page_get_type(const byte* page)
575-
{
576-
return mach_read_from_2(my_assume_aligned<2>(page + FIL_PAGE_TYPE));
577-
}
578-
579571
/** Check (and if needed, reset) the page type.
580572
Data files created before MySQL 5.1.48 may contain
581573
garbage in the FIL_PAGE_TYPE field.

0 commit comments

Comments
 (0)