mirror of
https://github.com/MariaDB/server.git
synced 2025-01-15 19:42:28 +01:00
MDEV-35049: Privatize ut_fold_ulint_pair()
Now that ut_fold_ulint_pair() and ut_fold_binary() are no longer needed for anything else than compatibility with old InnoDB data files that may use innodb_checksum_algorithm=innodb, let us move the code to a single compilation unit. Reviewed by: Vladislav Lesin
This commit is contained in:
parent
4dcb1b575b
commit
4dd6131711
7 changed files with 62 additions and 161 deletions
|
@ -54,12 +54,6 @@ The parts not included are excluded by #ifndef UNIV_INNOCHECKSUM. */
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#ifdef UNIV_NONINL
|
|
||||||
# include "fsp0fsp.inl"
|
|
||||||
# include "mach0data.inl"
|
|
||||||
# include "ut0rnd.inl"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef PRIuMAX
|
#ifndef PRIuMAX
|
||||||
#define PRIuMAX "llu"
|
#define PRIuMAX "llu"
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -358,7 +358,6 @@ SET(INNOBASE_SOURCES
|
||||||
include/ut0pool.h
|
include/ut0pool.h
|
||||||
include/ut0rbt.h
|
include/ut0rbt.h
|
||||||
include/ut0rnd.h
|
include/ut0rnd.h
|
||||||
include/ut0rnd.inl
|
|
||||||
include/ut0sort.h
|
include/ut0sort.h
|
||||||
include/ut0stage.h
|
include/ut0stage.h
|
||||||
include/ut0ut.h
|
include/ut0ut.h
|
||||||
|
|
|
@ -26,10 +26,10 @@ Created Aug 11, 2011 Vasil Dimov
|
||||||
|
|
||||||
#include "buf0checksum.h"
|
#include "buf0checksum.h"
|
||||||
#include "fil0fil.h"
|
#include "fil0fil.h"
|
||||||
#include "ut0rnd.h"
|
#include "my_sys.h"
|
||||||
|
|
||||||
#ifndef UNIV_INNOCHECKSUM
|
#ifndef UNIV_INNOCHECKSUM
|
||||||
#include "srv0srv.h"
|
# include "srv0srv.h"
|
||||||
#endif /* !UNIV_INNOCHECKSUM */
|
#endif /* !UNIV_INNOCHECKSUM */
|
||||||
|
|
||||||
/** Calculate the CRC32 checksum of a page. The value is stored to the page
|
/** Calculate the CRC32 checksum of a page. The value is stored to the page
|
||||||
|
@ -38,7 +38,7 @@ the file. Note that we must be careful to calculate the same value on all
|
||||||
architectures.
|
architectures.
|
||||||
@param[in] page buffer page (srv_page_size bytes)
|
@param[in] page buffer page (srv_page_size bytes)
|
||||||
@return CRC-32C */
|
@return CRC-32C */
|
||||||
uint32_t buf_calc_page_crc32(const byte* page)
|
uint32_t buf_calc_page_crc32(const byte *page) noexcept
|
||||||
{
|
{
|
||||||
/* Note: innodb_checksum_algorithm=crc32 could and should have
|
/* Note: innodb_checksum_algorithm=crc32 could and should have
|
||||||
included the entire page in the checksum, and CRC-32 values
|
included the entire page in the checksum, and CRC-32 values
|
||||||
|
@ -54,13 +54,60 @@ uint32_t buf_calc_page_crc32(const byte* page)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef UNIV_INNOCHECKSUM
|
#ifndef UNIV_INNOCHECKSUM
|
||||||
|
static inline ulint ut_fold_ulint_pair(ulint n1, ulint n2)
|
||||||
|
{
|
||||||
|
return ((((n1 ^ n2 ^ 1653893711) << 8) + n1) ^ 1463735687) + n2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Fold a binary string, similar to innodb_checksum_algorithm=innodb.
|
||||||
|
@return folded value */
|
||||||
|
ulint ut_fold_binary(const byte *str, size_t len) noexcept
|
||||||
|
{
|
||||||
|
ulint fold= 0;
|
||||||
|
for (const byte *const str_end= str + (len & 0xFFFFFFF8); str < str_end;
|
||||||
|
str+= 8)
|
||||||
|
{
|
||||||
|
fold= ut_fold_ulint_pair(fold, str[0]);
|
||||||
|
fold= ut_fold_ulint_pair(fold, str[1]);
|
||||||
|
fold= ut_fold_ulint_pair(fold, str[2]);
|
||||||
|
fold= ut_fold_ulint_pair(fold, str[3]);
|
||||||
|
fold= ut_fold_ulint_pair(fold, str[4]);
|
||||||
|
fold= ut_fold_ulint_pair(fold, str[5]);
|
||||||
|
fold= ut_fold_ulint_pair(fold, str[6]);
|
||||||
|
fold= ut_fold_ulint_pair(fold, str[7]);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (len & 0x7) {
|
||||||
|
case 7:
|
||||||
|
fold= ut_fold_ulint_pair(fold, *str++);
|
||||||
|
/* fall through */
|
||||||
|
case 6:
|
||||||
|
fold= ut_fold_ulint_pair(fold, *str++);
|
||||||
|
/* fall through */
|
||||||
|
case 5:
|
||||||
|
fold= ut_fold_ulint_pair(fold, *str++);
|
||||||
|
/* fall through */
|
||||||
|
case 4:
|
||||||
|
fold= ut_fold_ulint_pair(fold, *str++);
|
||||||
|
/* fall through */
|
||||||
|
case 3:
|
||||||
|
fold= ut_fold_ulint_pair(fold, *str++);
|
||||||
|
/* fall through */
|
||||||
|
case 2:
|
||||||
|
fold= ut_fold_ulint_pair(fold, *str++);
|
||||||
|
/* fall through */
|
||||||
|
case 1:
|
||||||
|
fold= ut_fold_ulint_pair(fold, *str++);
|
||||||
|
}
|
||||||
|
return fold;
|
||||||
|
}
|
||||||
|
|
||||||
/** Calculate a checksum which is stored to the page when it is written
|
/** 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
|
to a file. Note that we must be careful to calculate the same value on
|
||||||
32-bit and 64-bit architectures.
|
32-bit and 64-bit architectures.
|
||||||
@param[in] page file page (srv_page_size bytes)
|
@param[in] page file page (srv_page_size bytes)
|
||||||
@return checksum */
|
@return checksum */
|
||||||
uint32_t
|
uint32_t buf_calc_page_new_checksum(const byte *page) noexcept
|
||||||
buf_calc_page_new_checksum(const byte* page)
|
|
||||||
{
|
{
|
||||||
ulint checksum;
|
ulint checksum;
|
||||||
|
|
||||||
|
@ -80,19 +127,4 @@ buf_calc_page_new_checksum(const byte* page)
|
||||||
- FIL_PAGE_END_LSN_OLD_CHKSUM);
|
- FIL_PAGE_END_LSN_OLD_CHKSUM);
|
||||||
return(static_cast<uint32_t>(checksum));
|
return(static_cast<uint32_t>(checksum));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 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(static_cast<uint32_t>
|
|
||||||
(ut_fold_binary(page, FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION)));
|
|
||||||
}
|
|
||||||
#endif /* !UNIV_INNOCHECKSUM */
|
#endif /* !UNIV_INNOCHECKSUM */
|
||||||
|
|
|
@ -33,25 +33,23 @@ the file. Note that we must be careful to calculate the same value on all
|
||||||
architectures.
|
architectures.
|
||||||
@param[in] page buffer page (srv_page_size bytes)
|
@param[in] page buffer page (srv_page_size bytes)
|
||||||
@return CRC-32C */
|
@return CRC-32C */
|
||||||
uint32_t buf_calc_page_crc32(const byte* page);
|
uint32_t buf_calc_page_crc32(const byte *page) noexcept;
|
||||||
|
|
||||||
#ifndef UNIV_INNOCHECKSUM
|
#ifndef UNIV_INNOCHECKSUM
|
||||||
|
/** Fold a binary string, similar to innodb_checksum_algorithm=innodb.
|
||||||
|
@return folded value */
|
||||||
|
ulint ut_fold_binary(const byte *str, size_t len) noexcept;
|
||||||
|
|
||||||
/** Calculate a checksum which is stored to the page when it is written
|
/** 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
|
to a file. Note that we must be careful to calculate the same value on
|
||||||
32-bit and 64-bit architectures.
|
32-bit and 64-bit architectures.
|
||||||
@param[in] page file page (srv_page_size bytes)
|
@param[in] page file page (srv_page_size bytes)
|
||||||
@return checksum */
|
@return checksum */
|
||||||
uint32_t
|
uint32_t
|
||||||
buf_calc_page_new_checksum(const byte* page);
|
buf_calc_page_new_checksum(const byte *page) noexcept;
|
||||||
|
|
||||||
/** In MySQL before 4.0.14 or 4.1.1 there was an InnoDB bug that
|
/** 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.
|
the checksum only looked at the first few bytes of the page.
|
||||||
This calculates that old checksum.
|
This calculates that old checksum. */
|
||||||
NOTE: we must first store the new formula checksum to
|
# define buf_calc_page_old_checksum(page) uint32_t(ut_fold_binary(page, 26))
|
||||||
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);
|
|
||||||
#endif /* !UNIV_INNOCHECKSUM */
|
#endif /* !UNIV_INNOCHECKSUM */
|
||||||
|
|
|
@ -24,13 +24,11 @@ Random numbers and hashing
|
||||||
Created 1/20/1994 Heikki Tuuri
|
Created 1/20/1994 Heikki Tuuri
|
||||||
***********************************************************************/
|
***********************************************************************/
|
||||||
|
|
||||||
#ifndef ut0rnd_h
|
#pragma once
|
||||||
#define ut0rnd_h
|
|
||||||
|
|
||||||
#include "ut0byte.h"
|
#include "ut0byte.h"
|
||||||
#include <my_sys.h>
|
#include <my_sys.h>
|
||||||
|
|
||||||
#ifndef UNIV_INNOCHECKSUM
|
|
||||||
/** Seed value of ut_rnd_gen() */
|
/** Seed value of ut_rnd_gen() */
|
||||||
extern std::atomic<uint32_t> ut_rnd_current;
|
extern std::atomic<uint32_t> ut_rnd_current;
|
||||||
|
|
||||||
|
@ -87,30 +85,3 @@ ut_find_prime(
|
||||||
/*==========*/
|
/*==========*/
|
||||||
ulint n) /*!< in: positive number > 100 */
|
ulint n) /*!< in: positive number > 100 */
|
||||||
MY_ATTRIBUTE((const));
|
MY_ATTRIBUTE((const));
|
||||||
|
|
||||||
#endif /* !UNIV_INNOCHECKSUM */
|
|
||||||
|
|
||||||
/*************************************************************//**
|
|
||||||
Folds a pair of ulints.
|
|
||||||
@return folded value */
|
|
||||||
UNIV_INLINE
|
|
||||||
ulint
|
|
||||||
ut_fold_ulint_pair(
|
|
||||||
/*===============*/
|
|
||||||
ulint n1, /*!< in: ulint */
|
|
||||||
ulint n2) /*!< in: ulint */
|
|
||||||
MY_ATTRIBUTE((const));
|
|
||||||
/*************************************************************//**
|
|
||||||
Folds a binary string.
|
|
||||||
@return folded value */
|
|
||||||
UNIV_INLINE
|
|
||||||
ulint
|
|
||||||
ut_fold_binary(
|
|
||||||
/*===========*/
|
|
||||||
const byte* str, /*!< in: string of bytes */
|
|
||||||
ulint len) /*!< in: length */
|
|
||||||
MY_ATTRIBUTE((pure));
|
|
||||||
|
|
||||||
#include "ut0rnd.inl"
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
|
@ -1,94 +0,0 @@
|
||||||
/*****************************************************************************
|
|
||||||
|
|
||||||
Copyright (c) 1994, 2016, Oracle and/or its affiliates. All Rights Reserved.
|
|
||||||
Copyright (c) 2017, 2021, 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, Fifth Floor, Boston, MA 02110-1335 USA
|
|
||||||
|
|
||||||
*****************************************************************************/
|
|
||||||
|
|
||||||
/**************************************************************//**
|
|
||||||
@file include/ut0rnd.ic
|
|
||||||
Random numbers and hashing
|
|
||||||
|
|
||||||
Created 5/30/1994 Heikki Tuuri
|
|
||||||
*******************************************************************/
|
|
||||||
|
|
||||||
#define UT_HASH_RANDOM_MASK 1463735687
|
|
||||||
#define UT_HASH_RANDOM_MASK2 1653893711
|
|
||||||
|
|
||||||
/*************************************************************//**
|
|
||||||
Folds a pair of ulints.
|
|
||||||
@return folded value */
|
|
||||||
UNIV_INLINE
|
|
||||||
ulint
|
|
||||||
ut_fold_ulint_pair(
|
|
||||||
/*===============*/
|
|
||||||
ulint n1, /*!< in: ulint */
|
|
||||||
ulint n2) /*!< in: ulint */
|
|
||||||
{
|
|
||||||
return(((((n1 ^ n2 ^ UT_HASH_RANDOM_MASK2) << 8) + n1)
|
|
||||||
^ UT_HASH_RANDOM_MASK) + n2);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*************************************************************//**
|
|
||||||
Folds a binary string.
|
|
||||||
@return folded value */
|
|
||||||
UNIV_INLINE
|
|
||||||
ulint
|
|
||||||
ut_fold_binary(
|
|
||||||
/*===========*/
|
|
||||||
const byte* str, /*!< in: string of bytes */
|
|
||||||
ulint len) /*!< in: length */
|
|
||||||
{
|
|
||||||
ulint fold = 0;
|
|
||||||
const byte* str_end = str + (len & 0xFFFFFFF8);
|
|
||||||
|
|
||||||
ut_ad(str || !len);
|
|
||||||
|
|
||||||
while (str < str_end) {
|
|
||||||
fold = ut_fold_ulint_pair(fold, (ulint)(*str++));
|
|
||||||
fold = ut_fold_ulint_pair(fold, (ulint)(*str++));
|
|
||||||
fold = ut_fold_ulint_pair(fold, (ulint)(*str++));
|
|
||||||
fold = ut_fold_ulint_pair(fold, (ulint)(*str++));
|
|
||||||
fold = ut_fold_ulint_pair(fold, (ulint)(*str++));
|
|
||||||
fold = ut_fold_ulint_pair(fold, (ulint)(*str++));
|
|
||||||
fold = ut_fold_ulint_pair(fold, (ulint)(*str++));
|
|
||||||
fold = ut_fold_ulint_pair(fold, (ulint)(*str++));
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (len & 0x7) {
|
|
||||||
case 7:
|
|
||||||
fold = ut_fold_ulint_pair(fold, (ulint)(*str++));
|
|
||||||
/* fall through */
|
|
||||||
case 6:
|
|
||||||
fold = ut_fold_ulint_pair(fold, (ulint)(*str++));
|
|
||||||
/* fall through */
|
|
||||||
case 5:
|
|
||||||
fold = ut_fold_ulint_pair(fold, (ulint)(*str++));
|
|
||||||
/* fall through */
|
|
||||||
case 4:
|
|
||||||
fold = ut_fold_ulint_pair(fold, (ulint)(*str++));
|
|
||||||
/* fall through */
|
|
||||||
case 3:
|
|
||||||
fold = ut_fold_ulint_pair(fold, (ulint)(*str++));
|
|
||||||
/* fall through */
|
|
||||||
case 2:
|
|
||||||
fold = ut_fold_ulint_pair(fold, (ulint)(*str++));
|
|
||||||
/* fall through */
|
|
||||||
case 1:
|
|
||||||
fold = ut_fold_ulint_pair(fold, (ulint)(*str++));
|
|
||||||
}
|
|
||||||
|
|
||||||
return(fold);
|
|
||||||
}
|
|
|
@ -41,6 +41,7 @@ Created 9/20/1997 Heikki Tuuri
|
||||||
#include "buf0buf.h"
|
#include "buf0buf.h"
|
||||||
#include "buf0dblwr.h"
|
#include "buf0dblwr.h"
|
||||||
#include "buf0flu.h"
|
#include "buf0flu.h"
|
||||||
|
#include "buf0checksum.h"
|
||||||
#include "mtr0mtr.h"
|
#include "mtr0mtr.h"
|
||||||
#include "mtr0log.h"
|
#include "mtr0log.h"
|
||||||
#include "page0page.h"
|
#include "page0page.h"
|
||||||
|
|
Loading…
Reference in a new issue