mirror of
https://github.com/MariaDB/server.git
synced 2025-01-18 13:02:28 +01:00
1a780eefc9
In MySQL 5.7, it was noticed that files are not portable between big-endian and little-endian processor architectures (such as SPARC and x86), because the original implementation of innodb_checksum_algorithm=crc32 was not byte order agnostic. A byte order agnostic implementation of innodb_checksum_algorithm=crc32 was only added to MySQL 5.7, not backported to 5.6. Consequently, MariaDB Server versions 10.0 and 10.1 only contain the CRC-32C implementation that works incorrectly on big-endian architectures, and MariaDB Server 10.2.2 got the byte-order agnostic CRC-32C implementation from MySQL 5.7. MySQL 5.7 introduced a "legacy crc32" variant that is functionally equivalent to the big-endian version of the original crc32 implementation. Thanks to this variant, old data files can be transferred from big-endian systems to newer versions. Introducing new variants of checksum algorithms (without introducing new names for them, or something on the pages themselves to identify the algorithm) generally is a bad idea, because each checksum algorithm is like a lottery ticket. The more algorithms you try, the more likely it will be for the checksum to match on a corrupted page. So, essentially MySQL 5.7 weakened innodb_checksum_algorithm=crc32, and MariaDB 10.2.2 inherited this weakening. We introduce a build option that together with MDEV-17957 makes innodb_checksum_algorithm=strict_crc32 strict again by only allowing one variant of the checksum to match. WITH_INNODB_BUG_ENDIAN_CRC32: A new cmake option for enabling the bug-compatible "legacy crc32" checksum. This is only enabled on big-endian systems by default, to facilitate an upgrade from MariaDB 10.0 or 10.1. Checked by #ifdef INNODB_BUG_ENDIAN_CRC32. ut_crc32_byte_by_byte: Remove (unused function). legacy_big_endian_checksum: Remove. This variable seems to have unnecessarily complicated the logic. When the weakening is enabled, we must always fall back to the buggy checksum. buf_page_check_crc32(): A helper function to compute one or two CRC-32C variants.
80 lines
3.2 KiB
C
80 lines
3.2 KiB
C
/*****************************************************************************
|
|
|
|
Copyright (c) 1995, 2016, Oracle and/or its affiliates. All Rights Reserved.
|
|
Copyright (c) 2017, 2018, MariaDB Corporation.
|
|
|
|
This program is free software; you can redistribute it and/or modify it under
|
|
the terms of the GNU General Public License as published by the Free Software
|
|
Foundation; version 2 of the License.
|
|
|
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License along with
|
|
this program; if not, write to the Free Software Foundation, Inc.,
|
|
51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
|
|
|
|
*****************************************************************************/
|
|
|
|
/**************************************************//**
|
|
@file buf/buf0checksum.h
|
|
Buffer pool checksum functions, also linked from /extra/innochecksum.cc
|
|
|
|
Created Aug 11, 2011 Vasil Dimov
|
|
*******************************************************/
|
|
|
|
#ifndef buf0checksum_h
|
|
#define buf0checksum_h
|
|
|
|
#include "buf0types.h"
|
|
|
|
#ifdef INNODB_BUG_ENDIAN_CRC32
|
|
/** Calculate 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. Note that we must be careful to calculate the same value on all
|
|
architectures.
|
|
@param[in] page buffer page (srv_page_size bytes)
|
|
@param[in] bug_endian whether to use big endian byteorder
|
|
when converting byte strings to integers, for bug-compatibility with
|
|
big-endian architecture running MySQL 5.6, MariaDB 10.0 or MariaDB 10.1
|
|
@return CRC-32C */
|
|
uint32_t buf_calc_page_crc32(const byte* page, bool bug_endian = false);
|
|
#else
|
|
/** Calculate 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. Note that we must be careful to calculate the same value on all
|
|
architectures.
|
|
@param[in] page buffer page (srv_page_size bytes)
|
|
@return CRC-32C */
|
|
uint32_t buf_calc_page_crc32(const byte* page);
|
|
#endif
|
|
|
|
/** Calculate a 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.
|
|
@param[in] page file page (srv_page_size bytes)
|
|
@return checksum */
|
|
uint32_t
|
|
buf_calc_page_new_checksum(const byte* page);
|
|
|
|
/** In MySQL before 4.0.14 or 4.1.1 there was an InnoDB bug that
|
|
the checksum only looked at the first few bytes of the page.
|
|
This calculates that old 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!
|
|
@param[in] page file page (srv_page_size bytes)
|
|
@return checksum */
|
|
uint32_t
|
|
buf_calc_page_old_checksum(const byte* page);
|
|
|
|
/** Return a printable string describing the checksum algorithm.
|
|
@param[in] algo algorithm
|
|
@return algorithm name */
|
|
const char*
|
|
buf_checksum_algorithm_name(srv_checksum_algorithm_t algo);
|
|
|
|
extern ulong srv_checksum_algorithm;
|
|
|
|
#endif /* buf0checksum_h */
|