summaryrefslogtreecommitdiff
path: root/storage/innobase/buf/buf0checksum.cc
diff options
context:
space:
mode:
Diffstat (limited to 'storage/innobase/buf/buf0checksum.cc')
-rw-r--r--storage/innobase/buf/buf0checksum.cc70
1 files changed, 34 insertions, 36 deletions
diff --git a/storage/innobase/buf/buf0checksum.cc b/storage/innobase/buf/buf0checksum.cc
index 4101d117896..935c8a7ceee 100644
--- a/storage/innobase/buf/buf0checksum.cc
+++ b/storage/innobase/buf/buf0checksum.cc
@@ -24,37 +24,37 @@ Created Aug 11, 2011 Vasil Dimov
*******************************************************/
#include "univ.i"
-#include "fil0fil.h" /* FIL_* */
-#include "ut0crc32.h" /* ut_crc32() */
-#include "ut0rnd.h" /* ut_fold_binary() */
+#include "fil0fil.h"
+#include "ut0crc32.h"
+#include "ut0rnd.h"
#include "buf0checksum.h"
#ifndef UNIV_INNOCHECKSUM
-#include "srv0srv.h" /* SRV_CHECKSUM_* */
-#include "buf0types.h"
-
+#include "srv0srv.h"
#endif /* !UNIV_INNOCHECKSUM */
+#include "buf0types.h"
/** the macro MYSQL_SYSVAR_ENUM() requires "long unsigned int" and if we
use srv_checksum_algorithm_t here then we get a compiler error:
ha_innodb.cc:12251: error: cannot convert 'srv_checksum_algorithm_t*' to
'long unsigned int*' in initialization */
-UNIV_INTERN ulong srv_checksum_algorithm = SRV_CHECKSUM_ALGORITHM_INNODB;
-
-/********************************************************************//**
-Calculates a page CRC32 which is stored to the page when it is written
-to a file. Note that we must be careful to calculate the same value on
-32-bit and 64-bit architectures.
-@return checksum */
-UNIV_INTERN
-ib_uint32_t
+ulong srv_checksum_algorithm = SRV_CHECKSUM_ALGORITHM_INNODB;
+
+/** Calculates the CRC32 checksum of a page. The value is stored to the page
+when it is written to a file and also checked for a match when reading from
+the file. When reading we allow both normal CRC32 and CRC-legacy-big-endian
+variants. Note that we must be careful to calculate the same value on 32-bit
+and 64-bit architectures.
+@param[in] page buffer page (UNIV_PAGE_SIZE bytes)
+@param[in] use_legacy_big_endian if true then use big endian
+byteorder when converting byte strings to integers
+@return checksum */
+uint32_t
buf_calc_page_crc32(
-/*================*/
- const byte* page) /*!< in: buffer page */
+ const byte* page,
+ bool use_legacy_big_endian /* = false */)
{
- ib_uint32_t checksum;
-
/* Since the field FIL_PAGE_FILE_FLUSH_LSN, and in versions <= 4.1.x
FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID, are written outside the buffer pool
to the first pages of data files, we have to skip them in the page
@@ -63,22 +63,26 @@ buf_calc_page_crc32(
checksum is stored, and also the last 8 bytes of page because
there we store the old formula checksum. */
- checksum = ut_crc32(page + FIL_PAGE_OFFSET,
- FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION
- - FIL_PAGE_OFFSET)
- ^ ut_crc32(page + FIL_PAGE_DATA,
- UNIV_PAGE_SIZE - FIL_PAGE_DATA
- - FIL_PAGE_END_LSN_OLD_CHKSUM);
+ ut_crc32_func_t crc32_func = use_legacy_big_endian
+ ? ut_crc32_legacy_big_endian
+ : ut_crc32;
- return(checksum);
+ const uint32_t c1 = crc32_func(
+ page + FIL_PAGE_OFFSET,
+ FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION - FIL_PAGE_OFFSET);
+
+ const uint32_t c2 = crc32_func(
+ page + FIL_PAGE_DATA,
+ UNIV_PAGE_SIZE - FIL_PAGE_DATA - FIL_PAGE_END_LSN_OLD_CHKSUM);
+
+ return(c1 ^ c2);
}
/********************************************************************//**
Calculates a page checksum which is stored to the page when it is written
to a file. Note that we must be careful to calculate the same value on
32-bit and 64-bit architectures.
-@return checksum */
-UNIV_INTERN
+@return checksum */
ulint
buf_calc_page_new_checksum(
/*=======================*/
@@ -112,8 +116,7 @@ checksum.
NOTE: we must first store the new formula checksum to
FIL_PAGE_SPACE_OR_CHKSUM before calculating and storing this old checksum
because this takes that field as an input!
-@return checksum */
-UNIV_INTERN
+@return checksum */
ulint
buf_calc_page_old_checksum(
/*=======================*/
@@ -128,12 +131,9 @@ buf_calc_page_old_checksum(
return(checksum);
}
-#ifndef UNIV_INNOCHECKSUM
-
/********************************************************************//**
Return a printable string describing the checksum algorithm.
-@return algorithm name */
-UNIV_INTERN
+@return algorithm name */
const char*
buf_checksum_algorithm_name(
/*========================*/
@@ -157,5 +157,3 @@ buf_checksum_algorithm_name(
ut_error;
return(NULL);
}
-
-#endif /* !UNIV_INNOCHECKSUM */