Commit 70f0dbe4 authored by Marko Mäkelä's avatar Marko Mäkelä

Cleanup: log upgrade and encryption

log_crypt_101_read_checkpoint(), log_crypt_101_read_block():
Declare as ATTRIBUTE_COLD. These are only used when
checking that a MariaDB 10.1 encrypted redo log is clean.

log_block_calc_checksum_format_0(): Define in the only
compilation unit where it is needed. This is only used
when reading the checkpoint information from redo logs
before MariaDB 10.2.2.

crypt_info_t: Declare the byte arrays directly with alignas().

log_crypt(): Use memcpy_aligned instead of reinterpret_cast
on integers.
parent 522fbfcb
/***************************************************************************** /*****************************************************************************
Copyright (C) 2013, 2015, Google Inc. All Rights Reserved. Copyright (C) 2013, 2015, Google Inc. All Rights Reserved.
Copyright (C) 2014, 2018, MariaDB Corporation. Copyright (C) 2014, 2020, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under 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 the terms of the GNU General Public License as published by the Free Software
...@@ -55,22 +55,18 @@ log_crypt_write_checkpoint_buf( ...@@ -55,22 +55,18 @@ log_crypt_write_checkpoint_buf(
/** Read the MariaDB 10.1 checkpoint crypto (version, msg and iv) info. /** Read the MariaDB 10.1 checkpoint crypto (version, msg and iv) info.
@param[in] buf checkpoint buffer @param[in] buf checkpoint buffer
@return whether the operation was successful */ @return whether the operation was successful */
UNIV_INTERN ATTRIBUTE_COLD bool log_crypt_101_read_checkpoint(const byte* buf);
bool
log_crypt_101_read_checkpoint(const byte* buf);
/** Decrypt a MariaDB 10.1 redo log block. /** Decrypt a MariaDB 10.1 redo log block.
@param[in,out] buf log block @param[in,out] buf log block
@param[in] start_lsn server start LSN @param[in] start_lsn server start LSN
@return whether the decryption was successful */ @return whether the decryption was successful */
bool log_crypt_101_read_block(byte* buf, lsn_t start_lsn); ATTRIBUTE_COLD bool log_crypt_101_read_block(byte* buf, lsn_t start_lsn);
/** Read the checkpoint crypto (version, msg and iv) info. /** Read the checkpoint crypto (version, msg and iv) info.
@param[in] buf checkpoint buffer @param[in] buf checkpoint buffer
@return whether the operation was successful */ @return whether the operation was successful */
UNIV_INTERN bool log_crypt_read_checkpoint_buf(const byte* buf);
bool
log_crypt_read_checkpoint_buf(const byte* buf);
/** log_crypt() operation code */ /** log_crypt() operation code */
enum log_crypt_t { enum log_crypt_t {
......
...@@ -624,7 +624,7 @@ struct log_t{ ...@@ -624,7 +624,7 @@ struct log_t{
@param[in] lsn log sequence number @param[in] lsn log sequence number
@return offset within the log */ @return offset within the log */
inline lsn_t calc_lsn_offset(lsn_t lsn) const; inline lsn_t calc_lsn_offset(lsn_t lsn) const;
lsn_t calc_lsn_offset_old(lsn_t lsn) const; inline lsn_t calc_lsn_offset_old(lsn_t lsn) const;
/** Set the field values to correspond to a given lsn. */ /** Set the field values to correspond to a given lsn. */
void set_fields(lsn_t lsn) void set_fields(lsn_t lsn)
......
/***************************************************************************** /*****************************************************************************
Copyright (c) 1995, 2015, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 1995, 2015, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2017, 2019, MariaDB Corporation. Copyright (c) 2017, 2020, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under 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 the terms of the GNU General Public License as published by the Free Software
...@@ -187,35 +187,6 @@ log_block_convert_lsn_to_no( ...@@ -187,35 +187,6 @@ log_block_convert_lsn_to_no(
0xFUL, 0x3FFFFFFFUL)) + 1); 0xFUL, 0x3FFFFFFFUL)) + 1);
} }
/** Calculate the checksum for a log block using the pre-5.7.9 algorithm.
@param[in] block log block
@return checksum */
UNIV_INLINE
ulint
log_block_calc_checksum_format_0(
const byte* block)
{
ulint sum;
ulint sh;
ulint i;
sum = 1;
sh = 0;
for (i = 0; i < OS_FILE_LOG_BLOCK_SIZE - LOG_BLOCK_CHECKSUM; i++) {
ulint b = (ulint) block[i];
sum &= 0x7FFFFFFFUL;
sum += b;
sum += b << sh;
sh++;
if (sh > 24) {
sh = 0;
}
}
return(sum);
}
/** Calculate the CRC-32C checksum of a log block. /** Calculate the CRC-32C checksum of a log block.
@param[in] block log block @param[in] block log block
@return checksum */ @return checksum */
......
This diff is collapsed.
...@@ -1320,15 +1320,32 @@ static bool redo_file_sizes_are_correct() ...@@ -1320,15 +1320,32 @@ static bool redo_file_sizes_are_correct()
return false; return false;
} }
/** Calculate the checksum for a log block using the pre-10.2.2 algorithm. */
inline uint32_t log_block_calc_checksum_format_0(const byte *b)
{
uint32_t sum= 1;
const byte *const end= &b[512 - 4];
for (uint32_t sh= 0; b < end; )
{
sum&= 0x7FFFFFFFUL;
sum+= uint32_t{*b} << sh++;
sum+= *b++;
if (sh > 24)
sh= 0;
}
return sum;
}
/** Determine if a redo log from before MariaDB 10.2.2 is clean. /** Determine if a redo log from before MariaDB 10.2.2 is clean.
@return error code @return error code
@retval DB_SUCCESS if the redo log is clean @retval DB_SUCCESS if the redo log is clean
@retval DB_CORRUPTION if the redo log is corrupted @retval DB_CORRUPTION if the redo log is corrupted
@retval DB_ERROR if the redo log is not empty */ @retval DB_ERROR if the redo log is not empty */
static dberr_t recv_log_recover_pre_10_2() ATTRIBUTE_COLD static dberr_t recv_log_recover_pre_10_2()
{ {
uint64_t max_no= 0; uint64_t max_no= 0;
uint64_t checkpoint_no;
byte *buf= log_sys.buf; byte *buf= log_sys.buf;
ut_ad(log_sys.log.format == 0); ut_ad(log_sys.log.format == 0);
...@@ -1364,17 +1381,17 @@ static dberr_t recv_log_recover_pre_10_2() ...@@ -1364,17 +1381,17 @@ static dberr_t recv_log_recover_pre_10_2()
continue; continue;
} }
checkpoint_no = mach_read_from_8(buf + LOG_CHECKPOINT_NO);
if (!log_crypt_101_read_checkpoint(buf)) if (!log_crypt_101_read_checkpoint(buf))
{ {
ib::error() << "Decrypting checkpoint failed"; ib::error() << "Decrypting checkpoint failed";
continue; continue;
} }
const uint64_t checkpoint_no= mach_read_from_8(buf);
DBUG_PRINT("ib_log", ("checkpoint " UINT64PF " at " LSN_PF " found", DBUG_PRINT("ib_log", ("checkpoint " UINT64PF " at " LSN_PF " found",
checkpoint_no, checkpoint_no,
mach_read_from_8(buf + LOG_CHECKPOINT_LSN))); mach_read_from_8(buf + CHECKPOINT_LSN)));
if (checkpoint_no >= max_no) if (checkpoint_no >= max_no)
{ {
...@@ -1435,10 +1452,12 @@ static dberr_t recv_log_recover_pre_10_2() ...@@ -1435,10 +1452,12 @@ static dberr_t recv_log_recover_pre_10_2()
return DB_ERROR; return DB_ERROR;
} }
/** Same as cals_lsn_offset() except that it supports multiple files */ /** Calculate the offset of a log sequence number
lsn_t log_t::file::calc_lsn_offset_old(lsn_t lsn) const in an old redo log file (during upgrade check).
@param[in] lsn log sequence number
@return byte offset within the log */
inline lsn_t log_t::file::calc_lsn_offset_old(lsn_t lsn) const
{ {
ut_ad(log_sys.mutex.is_owned() || log_write_lock_own());
const lsn_t size= capacity() * recv_sys.files_size(); const lsn_t size= capacity() * recv_sys.files_size();
lsn_t l= lsn - this->lsn; lsn_t l= lsn - this->lsn;
if (longlong(l) < 0) if (longlong(l) < 0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment