2014-02-28 07:53:09 +01:00
|
|
|
/*
|
2016-09-29 12:59:41 +02:00
|
|
|
Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
|
2022-01-21 15:13:04 +01:00
|
|
|
Copyright (c) 2014, 2022, MariaDB Corporation.
|
2014-02-28 07:53:09 +01:00
|
|
|
|
|
|
|
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
|
2019-05-11 21:19:05 +02:00
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA
|
2014-02-28 07:53:09 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
InnoDB offline file checksum utility. 85% of the code in this utility
|
|
|
|
is included from the InnoDB codebase.
|
|
|
|
|
|
|
|
The final 15% was originally written by Mark Smith of Danga
|
|
|
|
Interactive, Inc. <junior@danga.com>
|
|
|
|
|
|
|
|
Published with a permission.
|
|
|
|
*/
|
|
|
|
|
2022-12-11 00:11:43 +01:00
|
|
|
#define VER "1.0"
|
|
|
|
|
2014-02-28 07:53:09 +01:00
|
|
|
#include <my_global.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2021-06-06 13:21:03 +02:00
|
|
|
#ifndef _WIN32
|
2014-02-28 07:53:09 +01:00
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#include <my_getopt.h>
|
|
|
|
#include <m_string.h>
|
2017-08-04 12:57:26 +02:00
|
|
|
#include <welcome_copyright_notice.h> /* ORACLE_WELCOME_COPYRIGHT_NOTICE */
|
2014-02-28 07:53:09 +01:00
|
|
|
|
|
|
|
/* Only parts of these files are included from the InnoDB codebase.
|
|
|
|
The parts not included are excluded by #ifndef UNIV_INNOCHECKSUM. */
|
|
|
|
|
2016-09-29 12:59:41 +02:00
|
|
|
#include "mach0data.h"
|
2018-11-27 20:25:11 +01:00
|
|
|
#include "page0page.h"
|
2017-08-04 12:57:26 +02:00
|
|
|
#include "buf0checksum.h" /* buf_calc_page_*() */
|
|
|
|
#include "buf0buf.h" /* buf_page_is_corrupted */
|
|
|
|
#include "page0zip.h" /* page_zip_*() */
|
|
|
|
#include "trx0undo.h" /* TRX_* */
|
|
|
|
#include "fil0crypt.h" /* fil_space_verify_crypt_checksum */
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2016-09-29 12:59:41 +02:00
|
|
|
#ifndef PRIuMAX
|
|
|
|
#define PRIuMAX "llu"
|
|
|
|
#endif
|
|
|
|
|
2014-02-28 07:53:09 +01:00
|
|
|
/* Global variables */
|
2016-08-12 10:17:45 +02:00
|
|
|
static bool verbose;
|
|
|
|
static bool just_count;
|
2021-07-22 16:53:43 +02:00
|
|
|
static uint32_t start_page;
|
|
|
|
static uint32_t end_page;
|
|
|
|
static uint32_t do_page;
|
2016-08-12 10:17:45 +02:00
|
|
|
static bool use_end_page;
|
|
|
|
static bool do_one_page;
|
2017-08-04 12:57:26 +02:00
|
|
|
static my_bool do_leaf;
|
|
|
|
static my_bool per_page_details;
|
2017-09-19 19:45:17 +02:00
|
|
|
static ulint n_merge;
|
2018-02-06 13:55:58 +01:00
|
|
|
static ulint physical_page_size; /* Page size in bytes on disk. */
|
2024-11-27 08:30:51 +01:00
|
|
|
static ulint extent_size;
|
|
|
|
static ulint xdes_size;
|
2017-08-04 12:57:26 +02:00
|
|
|
ulong srv_page_size;
|
2021-07-22 10:22:47 +02:00
|
|
|
uint32_t srv_page_size_shift;
|
2016-08-12 10:17:45 +02:00
|
|
|
/* Current page number (0 based). */
|
2021-07-22 16:53:43 +02:00
|
|
|
uint32_t cur_page_num;
|
2019-06-28 15:19:43 +02:00
|
|
|
/* Current space. */
|
2021-07-22 16:53:43 +02:00
|
|
|
uint32_t cur_space;
|
2016-08-12 10:17:45 +02:00
|
|
|
/* Skip the checksum verification. */
|
|
|
|
static bool no_check;
|
|
|
|
/* Enabled for rewrite checksum. */
|
|
|
|
static bool do_write;
|
|
|
|
/* Mismatches count allowed (0 by default). */
|
2017-08-04 12:57:26 +02:00
|
|
|
static unsigned long long allow_mismatches=0;
|
2016-08-12 10:17:45 +02:00
|
|
|
static bool page_type_summary;
|
|
|
|
static bool page_type_dump;
|
|
|
|
/* Store filename for page-type-dump option. */
|
|
|
|
char* page_dump_filename = 0;
|
|
|
|
/* skip the checksum verification & rewrite if page is doublewrite buffer. */
|
|
|
|
static bool skip_page = 0;
|
|
|
|
const char *dbug_setting = "FALSE";
|
|
|
|
char* log_filename = NULL;
|
|
|
|
/* User defined filename for logging. */
|
|
|
|
FILE* log_file = NULL;
|
|
|
|
/* Enabled for log write option. */
|
|
|
|
static bool is_log_enabled = false;
|
2024-11-27 08:30:51 +01:00
|
|
|
static bool skip_freed_pages;
|
2021-07-22 08:50:20 +02:00
|
|
|
static byte field_ref_zero_buf[UNIV_PAGE_SIZE_MAX];
|
|
|
|
const byte *field_ref_zero = field_ref_zero_buf;
|
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
#ifndef _WIN32
|
|
|
|
/* advisory lock for non-window system. */
|
|
|
|
struct flock lk;
|
|
|
|
#endif /* _WIN32 */
|
|
|
|
|
|
|
|
/* Innodb page type. */
|
|
|
|
struct innodb_page_type {
|
|
|
|
int n_undo_state_active;
|
|
|
|
int n_undo_state_cached;
|
|
|
|
int n_undo_state_to_purge;
|
|
|
|
int n_undo_state_prepared;
|
|
|
|
int n_undo_state_other;
|
2021-06-21 11:34:07 +02:00
|
|
|
int n_undo;
|
2016-08-12 10:17:45 +02:00
|
|
|
int n_fil_page_index;
|
|
|
|
int n_fil_page_undo_log;
|
|
|
|
int n_fil_page_inode;
|
|
|
|
int n_fil_page_ibuf_free_list;
|
|
|
|
int n_fil_page_ibuf_bitmap;
|
|
|
|
int n_fil_page_type_sys;
|
|
|
|
int n_fil_page_type_trx_sys;
|
|
|
|
int n_fil_page_type_fsp_hdr;
|
|
|
|
int n_fil_page_type_allocated;
|
|
|
|
int n_fil_page_type_xdes;
|
|
|
|
int n_fil_page_type_blob;
|
|
|
|
int n_fil_page_type_zblob;
|
|
|
|
int n_fil_page_type_other;
|
|
|
|
int n_fil_page_type_zblob2;
|
2016-09-29 12:59:41 +02:00
|
|
|
int n_fil_page_type_page_compressed;
|
|
|
|
int n_fil_page_type_page_compressed_encrypted;
|
2016-08-12 10:17:45 +02:00
|
|
|
} page_type;
|
|
|
|
|
2016-09-29 12:59:41 +02:00
|
|
|
#define SIZE_RANGES_FOR_PAGE 10
|
|
|
|
#define NUM_RETRIES 3
|
|
|
|
#define DEFAULT_RETRY_DELAY 1000000
|
|
|
|
|
|
|
|
struct per_page_stats {
|
|
|
|
ulint n_recs;
|
|
|
|
ulint data_size;
|
|
|
|
ulint left_page_no;
|
|
|
|
ulint right_page_no;
|
|
|
|
per_page_stats(ulint n, ulint data, ulint left, ulint right) :
|
|
|
|
n_recs(n), data_size(data), left_page_no(left), right_page_no(right) {}
|
|
|
|
per_page_stats() : n_recs(0), data_size(0), left_page_no(0), right_page_no(0) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct per_index_stats {
|
|
|
|
unsigned long long pages;
|
|
|
|
unsigned long long leaf_pages;
|
|
|
|
ulint first_leaf_page;
|
|
|
|
ulint count;
|
|
|
|
ulint free_pages;
|
|
|
|
ulint max_data_size;
|
|
|
|
unsigned long long total_n_recs;
|
|
|
|
unsigned long long total_data_bytes;
|
|
|
|
|
|
|
|
/*!< first element for empty pages,
|
|
|
|
last element for pages with more than logical_page_size */
|
|
|
|
unsigned long long pages_in_size_range[SIZE_RANGES_FOR_PAGE+2];
|
|
|
|
|
|
|
|
std::map<unsigned long long, per_page_stats> leaves;
|
|
|
|
|
|
|
|
per_index_stats():pages(0), leaf_pages(0), first_leaf_page(0),
|
|
|
|
count(0), free_pages(0), max_data_size(0), total_n_recs(0),
|
|
|
|
total_data_bytes(0)
|
|
|
|
{
|
|
|
|
memset(pages_in_size_range, 0, sizeof(pages_in_size_range));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
std::map<unsigned long long, per_index_stats> index_ids;
|
|
|
|
|
|
|
|
void print_index_leaf_stats(
|
|
|
|
unsigned long long id,
|
|
|
|
const per_index_stats& index,
|
|
|
|
FILE* fil_out)
|
|
|
|
|
|
|
|
{
|
|
|
|
ulint page_no = index.first_leaf_page;
|
|
|
|
std::map<unsigned long long, per_page_stats>::const_iterator it_page = index.leaves.find(page_no);
|
|
|
|
fprintf(fil_out, "\nindex: %llu leaf page stats: n_pages = %llu\n",
|
|
|
|
id, index.leaf_pages);
|
|
|
|
fprintf(fil_out, "page_no\tdata_size\tn_recs\n");
|
|
|
|
while (it_page != index.leaves.end()) {
|
|
|
|
const per_page_stats& stat = it_page->second;
|
2017-08-04 12:57:26 +02:00
|
|
|
fprintf(fil_out, "%llu\t" ULINTPF "\t" ULINTPF "\n", it_page->first, stat.data_size, stat.n_recs);
|
2016-09-29 12:59:41 +02:00
|
|
|
page_no = stat.right_page_no;
|
|
|
|
it_page = index.leaves.find(page_no);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void defrag_analysis(
|
|
|
|
unsigned long long id,
|
|
|
|
const per_index_stats& index,
|
|
|
|
FILE* fil_out)
|
|
|
|
{
|
|
|
|
// TODO: make it work for compressed pages too
|
|
|
|
std::map<unsigned long long, per_page_stats>::const_iterator it = index.leaves.find(index.first_leaf_page);
|
|
|
|
ulint n_pages = 0;
|
|
|
|
ulint n_leaf_pages = 0;
|
|
|
|
while (it != index.leaves.end()) {
|
|
|
|
ulint data_size_total = 0;
|
|
|
|
for (ulong i = 0; i < n_merge; i++) {
|
|
|
|
const per_page_stats& stat = it->second;
|
|
|
|
n_leaf_pages ++;
|
|
|
|
data_size_total += stat.data_size;
|
|
|
|
it = index.leaves.find(stat.right_page_no);
|
|
|
|
if (it == index.leaves.end()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-08-04 12:57:26 +02:00
|
|
|
|
2016-09-29 12:59:41 +02:00
|
|
|
if (index.max_data_size) {
|
|
|
|
n_pages += data_size_total / index.max_data_size;
|
|
|
|
if (data_size_total % index.max_data_size != 0) {
|
|
|
|
n_pages += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (index.leaf_pages) {
|
2017-08-04 12:57:26 +02:00
|
|
|
fprintf(fil_out, "count = " ULINTPF " free = " ULINTPF "\n", index.count, index.free_pages);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!n_leaf_pages) {
|
|
|
|
n_leaf_pages = 1;
|
2016-09-29 12:59:41 +02:00
|
|
|
}
|
|
|
|
|
2017-08-04 12:57:26 +02:00
|
|
|
fprintf(fil_out, "%llu\t\t%llu\t\t" ULINTPF "\t\t" ULINTPF "\t\t" ULINTPF "\t\t%.2f\t" ULINTPF "\n",
|
2016-09-29 12:59:41 +02:00
|
|
|
id, index.leaf_pages, n_leaf_pages, n_merge, n_pages,
|
2017-08-04 12:57:26 +02:00
|
|
|
1.0 - (double)n_pages / (double)n_leaf_pages, index.max_data_size);
|
2016-09-29 12:59:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void print_leaf_stats(
|
|
|
|
FILE* fil_out)
|
|
|
|
{
|
|
|
|
fprintf(fil_out, "\n**************************************************\n");
|
|
|
|
fprintf(fil_out, "index_id\t#leaf_pages\t#actual_leaf_pages\tn_merge\t"
|
|
|
|
"#leaf_after_merge\tdefrag\n");
|
|
|
|
for (std::map<unsigned long long, per_index_stats>::const_iterator it = index_ids.begin();
|
|
|
|
it != index_ids.end(); it++) {
|
|
|
|
const per_index_stats& index = it->second;
|
|
|
|
|
|
|
|
if (verbose) {
|
|
|
|
print_index_leaf_stats(it->first, index, fil_out);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n_merge) {
|
|
|
|
defrag_analysis(it->first, index, fil_out);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
MDEV-12026: Implement innodb_checksum_algorithm=full_crc32
MariaDB data-at-rest encryption (innodb_encrypt_tables)
had repurposed the same unused data field that was repurposed
in MySQL 5.7 (and MariaDB 10.2) for the Split Sequence Number (SSN)
field of SPATIAL INDEX. Because of this, MariaDB was unable to
support encryption on SPATIAL INDEX pages.
Furthermore, InnoDB page checksums skipped some bytes, and there
are multiple variations and checksum algorithms. By default,
InnoDB accepts all variations of all algorithms that ever existed.
This unnecessarily weakens the page checksums.
We hereby introduce two more innodb_checksum_algorithm variants
(full_crc32, strict_full_crc32) that are special in a way:
When either setting is active, newly created data files will
carry a flag (fil_space_t::full_crc32()) that indicates that
all pages of the file will use a full CRC-32C checksum over the
entire page contents (excluding the bytes where the checksum
is stored, at the very end of the page). Such files will always
use that checksum, no matter what the parameter
innodb_checksum_algorithm is assigned to.
For old files, the old checksum algorithms will continue to be
used. The value strict_full_crc32 will be equivalent to strict_crc32
and the value full_crc32 will be equivalent to crc32.
ROW_FORMAT=COMPRESSED tables will only use the old format.
These tables do not support new features, such as larger
innodb_page_size or instant ADD/DROP COLUMN. They may be
deprecated in the future. We do not want an unnecessary
file format change for them.
The new full_crc32() format also cleans up the MariaDB tablespace
flags. We will reserve flags to store the page_compressed
compression algorithm, and to store the compressed payload length,
so that checksum can be computed over the compressed (and
possibly encrypted) stream and can be validated without
decrypting or decompressing the page.
In the full_crc32 format, there no longer are separate before-encryption
and after-encryption checksums for pages. The single checksum is
computed on the page contents that is written to the file.
We do not make the new algorithm the default for two reasons.
First, MariaDB 10.4.2 was a beta release, and the default values
of parameters should not change after beta. Second, we did not
yet implement the full_crc32 format for page_compressed pages.
This will be fixed in MDEV-18644.
This is joint work with Marko Mäkelä.
2019-02-19 20:00:00 +01:00
|
|
|
/** Init the page size for the tablespace.
|
|
|
|
@param[in] buf buffer used to read the page */
|
|
|
|
static void init_page_size(const byte* buf)
|
2016-08-12 10:17:45 +02:00
|
|
|
{
|
2018-04-27 13:26:43 +02:00
|
|
|
const unsigned flags = mach_read_from_4(buf + FIL_PAGE_DATA
|
2016-08-12 10:17:45 +02:00
|
|
|
+ FSP_SPACE_FLAGS);
|
|
|
|
|
MDEV-18644: Support full_crc32 for page_compressed
This is a follow-up task to MDEV-12026, which introduced
innodb_checksum_algorithm=full_crc32 and a simpler page format.
MDEV-12026 did not enable full_crc32 for page_compressed tables,
which we will be doing now.
This is joint work with Thirunarayanan Balathandayuthapani.
For innodb_checksum_algorithm=full_crc32 we change the
page_compressed format as follows:
FIL_PAGE_TYPE: The most significant bit will be set to indicate
page_compressed format. The least significant bits will contain
the compressed page size, rounded up to a multiple of 256 bytes.
The checksum will be stored in the last 4 bytes of the page
(whether it is the full page or a page_compressed page whose
size is determined by FIL_PAGE_TYPE), covering all preceding
bytes of the page. If encryption is used, then the page will
be encrypted between compression and computing the checksum.
For page_compressed, FIL_PAGE_LSN will not be repeated at
the end of the page.
FSP_SPACE_FLAGS (already implemented as part of MDEV-12026):
We will store the innodb_compression_algorithm that may be used
to compress pages. Previously, the choice of algorithm was written
to each compressed data page separately, and one would be unable
to know in advance which compression algorithm(s) are used.
fil_space_t::full_crc32_page_compressed_len(): Determine if the
page_compressed algorithm of the tablespace needs to know the
exact length of the compressed data. If yes, we will reserve and
write an extra byte for this right before the checksum.
buf_page_is_compressed(): Determine if a page uses page_compressed
(in any innodb_checksum_algorithm).
fil_page_decompress(): Pass also fil_space_t::flags so that the
format can be determined.
buf_page_is_zeroes(): Check if a page is full of zero bytes.
buf_page_full_crc32_is_corrupted(): Renamed from
buf_encrypted_full_crc32_page_is_corrupted(). For full_crc32,
we always simply validate the checksum to the page contents,
while the physical page size is explicitly specified by an
unencrypted part of the page header.
buf_page_full_crc32_size(): Determine the size of a full_crc32 page.
buf_dblwr_check_page_lsn(): Make this a debug-only function, because
it involves potentially costly lookups of fil_space_t.
create_table_info_t::check_table_options(),
ha_innobase::check_if_supported_inplace_alter(): Do allow the creation
of SPATIAL INDEX with full_crc32 also when page_compressed is used.
commit_cache_norebuild(): Preserve the compression algorithm when
updating the page_compression_level.
dict_tf_to_fsp_flags(): Set the flags for page compression algorithm.
FIXME: Maybe there should be a table option page_compression_algorithm
and a session variable to back it?
2019-03-18 13:08:43 +01:00
|
|
|
if (fil_space_t::full_crc32(flags)) {
|
2021-07-22 13:36:30 +02:00
|
|
|
const uint32_t ssize = FSP_FLAGS_FCRC32_GET_PAGE_SSIZE(flags);
|
2019-07-02 20:44:58 +02:00
|
|
|
srv_page_size_shift = UNIV_ZIP_SIZE_SHIFT_MIN - 1 + ssize;
|
|
|
|
srv_page_size = 512U << ssize;
|
MDEV-12026: Implement innodb_checksum_algorithm=full_crc32
MariaDB data-at-rest encryption (innodb_encrypt_tables)
had repurposed the same unused data field that was repurposed
in MySQL 5.7 (and MariaDB 10.2) for the Split Sequence Number (SSN)
field of SPATIAL INDEX. Because of this, MariaDB was unable to
support encryption on SPATIAL INDEX pages.
Furthermore, InnoDB page checksums skipped some bytes, and there
are multiple variations and checksum algorithms. By default,
InnoDB accepts all variations of all algorithms that ever existed.
This unnecessarily weakens the page checksums.
We hereby introduce two more innodb_checksum_algorithm variants
(full_crc32, strict_full_crc32) that are special in a way:
When either setting is active, newly created data files will
carry a flag (fil_space_t::full_crc32()) that indicates that
all pages of the file will use a full CRC-32C checksum over the
entire page contents (excluding the bytes where the checksum
is stored, at the very end of the page). Such files will always
use that checksum, no matter what the parameter
innodb_checksum_algorithm is assigned to.
For old files, the old checksum algorithms will continue to be
used. The value strict_full_crc32 will be equivalent to strict_crc32
and the value full_crc32 will be equivalent to crc32.
ROW_FORMAT=COMPRESSED tables will only use the old format.
These tables do not support new features, such as larger
innodb_page_size or instant ADD/DROP COLUMN. They may be
deprecated in the future. We do not want an unnecessary
file format change for them.
The new full_crc32() format also cleans up the MariaDB tablespace
flags. We will reserve flags to store the page_compressed
compression algorithm, and to store the compressed payload length,
so that checksum can be computed over the compressed (and
possibly encrypted) stream and can be validated without
decrypting or decompressing the page.
In the full_crc32 format, there no longer are separate before-encryption
and after-encryption checksums for pages. The single checksum is
computed on the page contents that is written to the file.
We do not make the new algorithm the default for two reasons.
First, MariaDB 10.4.2 was a beta release, and the default values
of parameters should not change after beta. Second, we did not
yet implement the full_crc32 format for page_compressed pages.
This will be fixed in MDEV-18644.
This is joint work with Marko Mäkelä.
2019-02-19 20:00:00 +01:00
|
|
|
physical_page_size = srv_page_size;
|
2024-11-27 08:30:51 +01:00
|
|
|
extent_size = FSP_EXTENT_SIZE;
|
|
|
|
xdes_size = XDES_SIZE;
|
MDEV-12026: Implement innodb_checksum_algorithm=full_crc32
MariaDB data-at-rest encryption (innodb_encrypt_tables)
had repurposed the same unused data field that was repurposed
in MySQL 5.7 (and MariaDB 10.2) for the Split Sequence Number (SSN)
field of SPATIAL INDEX. Because of this, MariaDB was unable to
support encryption on SPATIAL INDEX pages.
Furthermore, InnoDB page checksums skipped some bytes, and there
are multiple variations and checksum algorithms. By default,
InnoDB accepts all variations of all algorithms that ever existed.
This unnecessarily weakens the page checksums.
We hereby introduce two more innodb_checksum_algorithm variants
(full_crc32, strict_full_crc32) that are special in a way:
When either setting is active, newly created data files will
carry a flag (fil_space_t::full_crc32()) that indicates that
all pages of the file will use a full CRC-32C checksum over the
entire page contents (excluding the bytes where the checksum
is stored, at the very end of the page). Such files will always
use that checksum, no matter what the parameter
innodb_checksum_algorithm is assigned to.
For old files, the old checksum algorithms will continue to be
used. The value strict_full_crc32 will be equivalent to strict_crc32
and the value full_crc32 will be equivalent to crc32.
ROW_FORMAT=COMPRESSED tables will only use the old format.
These tables do not support new features, such as larger
innodb_page_size or instant ADD/DROP COLUMN. They may be
deprecated in the future. We do not want an unnecessary
file format change for them.
The new full_crc32() format also cleans up the MariaDB tablespace
flags. We will reserve flags to store the page_compressed
compression algorithm, and to store the compressed payload length,
so that checksum can be computed over the compressed (and
possibly encrypted) stream and can be validated without
decrypting or decompressing the page.
In the full_crc32 format, there no longer are separate before-encryption
and after-encryption checksums for pages. The single checksum is
computed on the page contents that is written to the file.
We do not make the new algorithm the default for two reasons.
First, MariaDB 10.4.2 was a beta release, and the default values
of parameters should not change after beta. Second, we did not
yet implement the full_crc32 format for page_compressed pages.
This will be fixed in MDEV-18644.
This is joint work with Marko Mäkelä.
2019-02-19 20:00:00 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-07-22 13:36:30 +02:00
|
|
|
const uint32_t ssize = FSP_FLAGS_GET_PAGE_SSIZE(flags);
|
2016-08-12 10:17:45 +02:00
|
|
|
|
2018-04-27 13:26:43 +02:00
|
|
|
srv_page_size_shift = ssize
|
|
|
|
? UNIV_ZIP_SIZE_SHIFT_MIN - 1 + ssize
|
|
|
|
: UNIV_PAGE_SIZE_SHIFT_ORIG;
|
|
|
|
|
2019-02-20 08:07:13 +01:00
|
|
|
srv_page_size = fil_space_t::logical_size(flags);
|
MDEV-12026: Implement innodb_checksum_algorithm=full_crc32
MariaDB data-at-rest encryption (innodb_encrypt_tables)
had repurposed the same unused data field that was repurposed
in MySQL 5.7 (and MariaDB 10.2) for the Split Sequence Number (SSN)
field of SPATIAL INDEX. Because of this, MariaDB was unable to
support encryption on SPATIAL INDEX pages.
Furthermore, InnoDB page checksums skipped some bytes, and there
are multiple variations and checksum algorithms. By default,
InnoDB accepts all variations of all algorithms that ever existed.
This unnecessarily weakens the page checksums.
We hereby introduce two more innodb_checksum_algorithm variants
(full_crc32, strict_full_crc32) that are special in a way:
When either setting is active, newly created data files will
carry a flag (fil_space_t::full_crc32()) that indicates that
all pages of the file will use a full CRC-32C checksum over the
entire page contents (excluding the bytes where the checksum
is stored, at the very end of the page). Such files will always
use that checksum, no matter what the parameter
innodb_checksum_algorithm is assigned to.
For old files, the old checksum algorithms will continue to be
used. The value strict_full_crc32 will be equivalent to strict_crc32
and the value full_crc32 will be equivalent to crc32.
ROW_FORMAT=COMPRESSED tables will only use the old format.
These tables do not support new features, such as larger
innodb_page_size or instant ADD/DROP COLUMN. They may be
deprecated in the future. We do not want an unnecessary
file format change for them.
The new full_crc32() format also cleans up the MariaDB tablespace
flags. We will reserve flags to store the page_compressed
compression algorithm, and to store the compressed payload length,
so that checksum can be computed over the compressed (and
possibly encrypted) stream and can be validated without
decrypting or decompressing the page.
In the full_crc32 format, there no longer are separate before-encryption
and after-encryption checksums for pages. The single checksum is
computed on the page contents that is written to the file.
We do not make the new algorithm the default for two reasons.
First, MariaDB 10.4.2 was a beta release, and the default values
of parameters should not change after beta. Second, we did not
yet implement the full_crc32 format for page_compressed pages.
This will be fixed in MDEV-18644.
This is joint work with Marko Mäkelä.
2019-02-19 20:00:00 +01:00
|
|
|
physical_page_size = fil_space_t::physical_size(flags);
|
2024-11-27 08:30:51 +01:00
|
|
|
extent_size = FSP_EXTENT_SIZE;
|
|
|
|
xdes_size = XDES_SIZE;
|
2016-08-12 10:17:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
/***********************************************//*
|
|
|
|
@param [in] error error no. from the getLastError().
|
2014-02-28 07:53:09 +01:00
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
@retval error message corresponding to error no.
|
|
|
|
*/
|
|
|
|
static
|
|
|
|
char*
|
|
|
|
error_message(
|
|
|
|
int error)
|
|
|
|
{
|
|
|
|
static char err_msg[1024] = {'\0'};
|
|
|
|
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
|
|
|
|
NULL, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
|
|
|
(LPTSTR)err_msg, sizeof(err_msg), NULL );
|
2014-02-28 07:53:09 +01:00
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
return (err_msg);
|
|
|
|
}
|
|
|
|
#endif /* _WIN32 */
|
2014-02-28 07:53:09 +01:00
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
/***********************************************//*
|
|
|
|
@param>>_______[in] name>_____name of file.
|
2018-12-21 21:06:08 +01:00
|
|
|
@retval file pointer; file pointer is NULL when error occurred.
|
2016-08-12 10:17:45 +02:00
|
|
|
*/
|
2014-02-28 07:53:09 +01:00
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
FILE*
|
|
|
|
open_file(
|
|
|
|
const char* name)
|
|
|
|
{
|
|
|
|
int fd; /* file descriptor. */
|
|
|
|
FILE* fil_in;
|
|
|
|
#ifdef _WIN32
|
|
|
|
HANDLE hFile; /* handle to open file. */
|
|
|
|
DWORD access; /* define access control */
|
|
|
|
int flags = 0; /* define the mode for file
|
|
|
|
descriptor */
|
|
|
|
|
|
|
|
if (do_write) {
|
|
|
|
access = GENERIC_READ | GENERIC_WRITE;
|
|
|
|
flags = _O_RDWR | _O_BINARY;
|
|
|
|
} else {
|
|
|
|
access = GENERIC_READ;
|
|
|
|
flags = _O_RDONLY | _O_BINARY;
|
|
|
|
}
|
2017-08-04 12:57:26 +02:00
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
/* CreateFile() also provide advisory lock with the usage of
|
|
|
|
access and share mode of the file.*/
|
|
|
|
hFile = CreateFile(
|
|
|
|
(LPCTSTR) name, access, 0L, NULL,
|
|
|
|
OPEN_EXISTING, NULL, NULL);
|
|
|
|
|
|
|
|
if (hFile == INVALID_HANDLE_VALUE) {
|
|
|
|
/* print the error message. */
|
2016-09-29 12:59:41 +02:00
|
|
|
fprintf(stderr, "Filename::%s %s\n", name,
|
2016-08-12 10:17:45 +02:00
|
|
|
error_message(GetLastError()));
|
|
|
|
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get the file descriptor. */
|
|
|
|
fd= _open_osfhandle((intptr_t)hFile, flags);
|
|
|
|
#else /* _WIN32 */
|
|
|
|
|
|
|
|
int create_flag;
|
|
|
|
/* define the advisory lock and open file mode. */
|
|
|
|
if (do_write) {
|
|
|
|
create_flag = O_RDWR;
|
|
|
|
lk.l_type = F_WRLCK;
|
2017-08-04 12:57:26 +02:00
|
|
|
} else {
|
2016-08-12 10:17:45 +02:00
|
|
|
create_flag = O_RDONLY;
|
|
|
|
lk.l_type = F_RDLCK;
|
|
|
|
}
|
|
|
|
|
|
|
|
fd = open(name, create_flag);
|
|
|
|
|
|
|
|
lk.l_whence = SEEK_SET;
|
|
|
|
lk.l_start = lk.l_len = 0;
|
|
|
|
|
|
|
|
if (fcntl(fd, F_SETLK, &lk) == -1) {
|
|
|
|
fprintf(stderr, "Error: Unable to lock file::"
|
|
|
|
" %s\n", name);
|
|
|
|
perror("fcntl");
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
#endif /* _WIN32 */
|
2015-09-19 10:30:18 +02:00
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
if (do_write) {
|
|
|
|
fil_in = fdopen(fd, "rb+");
|
|
|
|
} else {
|
|
|
|
fil_in = fdopen(fd, "rb");
|
|
|
|
}
|
2015-09-19 10:30:18 +02:00
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
return (fil_in);
|
2014-02-28 07:53:09 +01:00
|
|
|
}
|
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
/************************************************************//*
|
|
|
|
Read the content of file
|
|
|
|
|
|
|
|
@param [in,out] buf read the file in buffer
|
|
|
|
@param [in] partial_page_read enable when to read the
|
|
|
|
remaining buffer for first page.
|
|
|
|
@param [in] physical_page_size Physical/Commpressed page size.
|
|
|
|
@param [in,out] fil_in file pointer created for the
|
|
|
|
tablespace.
|
|
|
|
@retval no. of bytes read.
|
|
|
|
*/
|
2018-02-06 13:55:58 +01:00
|
|
|
ulint read_file(
|
2016-08-12 10:17:45 +02:00
|
|
|
byte* buf,
|
|
|
|
bool partial_page_read,
|
2018-02-06 13:55:58 +01:00
|
|
|
ulint physical_page_size,
|
2016-08-12 10:17:45 +02:00
|
|
|
FILE* fil_in)
|
|
|
|
{
|
2018-02-06 13:55:58 +01:00
|
|
|
ulint bytes = 0;
|
2014-02-28 07:53:09 +01:00
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
DBUG_ASSERT(physical_page_size >= UNIV_ZIP_SIZE_MIN);
|
2014-02-28 07:53:09 +01:00
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
if (partial_page_read) {
|
|
|
|
buf += UNIV_ZIP_SIZE_MIN;
|
|
|
|
physical_page_size -= UNIV_ZIP_SIZE_MIN;
|
|
|
|
bytes = UNIV_ZIP_SIZE_MIN;
|
|
|
|
}
|
|
|
|
|
2018-02-06 13:55:58 +01:00
|
|
|
bytes += ulint(fread(buf, 1, physical_page_size, fil_in));
|
2016-08-12 10:17:45 +02:00
|
|
|
|
|
|
|
return bytes;
|
|
|
|
}
|
|
|
|
|
2019-06-28 15:19:43 +02:00
|
|
|
/** Check whether the page contains all zeroes.
|
|
|
|
@param[in] buf page
|
|
|
|
@param[in] size physical size of the page
|
|
|
|
@return true if the page is all zeroes; else false */
|
|
|
|
static bool is_page_all_zeroes(
|
|
|
|
byte* buf,
|
|
|
|
ulint size)
|
|
|
|
{
|
|
|
|
/* On pages that are not all zero, the page number
|
|
|
|
must match. */
|
|
|
|
const ulint* p = reinterpret_cast<const ulint*>(buf);
|
|
|
|
const ulint* const end = reinterpret_cast<const ulint*>(buf + size);
|
|
|
|
do {
|
|
|
|
if (*p++) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} while (p != end);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
/** Check if page is corrupted or not.
|
|
|
|
@param[in] buf page frame
|
2017-08-04 12:57:26 +02:00
|
|
|
@param[in] is_encrypted true if page0 contained cryp_data
|
|
|
|
with crypt_scheme encrypted
|
MDEV-12026: Implement innodb_checksum_algorithm=full_crc32
MariaDB data-at-rest encryption (innodb_encrypt_tables)
had repurposed the same unused data field that was repurposed
in MySQL 5.7 (and MariaDB 10.2) for the Split Sequence Number (SSN)
field of SPATIAL INDEX. Because of this, MariaDB was unable to
support encryption on SPATIAL INDEX pages.
Furthermore, InnoDB page checksums skipped some bytes, and there
are multiple variations and checksum algorithms. By default,
InnoDB accepts all variations of all algorithms that ever existed.
This unnecessarily weakens the page checksums.
We hereby introduce two more innodb_checksum_algorithm variants
(full_crc32, strict_full_crc32) that are special in a way:
When either setting is active, newly created data files will
carry a flag (fil_space_t::full_crc32()) that indicates that
all pages of the file will use a full CRC-32C checksum over the
entire page contents (excluding the bytes where the checksum
is stored, at the very end of the page). Such files will always
use that checksum, no matter what the parameter
innodb_checksum_algorithm is assigned to.
For old files, the old checksum algorithms will continue to be
used. The value strict_full_crc32 will be equivalent to strict_crc32
and the value full_crc32 will be equivalent to crc32.
ROW_FORMAT=COMPRESSED tables will only use the old format.
These tables do not support new features, such as larger
innodb_page_size or instant ADD/DROP COLUMN. They may be
deprecated in the future. We do not want an unnecessary
file format change for them.
The new full_crc32() format also cleans up the MariaDB tablespace
flags. We will reserve flags to store the page_compressed
compression algorithm, and to store the compressed payload length,
so that checksum can be computed over the compressed (and
possibly encrypted) stream and can be validated without
decrypting or decompressing the page.
In the full_crc32 format, there no longer are separate before-encryption
and after-encryption checksums for pages. The single checksum is
computed on the page contents that is written to the file.
We do not make the new algorithm the default for two reasons.
First, MariaDB 10.4.2 was a beta release, and the default values
of parameters should not change after beta. Second, we did not
yet implement the full_crc32 format for page_compressed pages.
This will be fixed in MDEV-18644.
This is joint work with Marko Mäkelä.
2019-02-19 20:00:00 +01:00
|
|
|
@param[in] flags tablespace flags
|
2016-08-12 10:17:45 +02:00
|
|
|
@retval true if page is corrupted otherwise false. */
|
2021-07-22 13:36:30 +02:00
|
|
|
static bool is_page_corrupted(byte *buf, bool is_encrypted, uint32_t flags)
|
2014-02-28 07:53:09 +01:00
|
|
|
{
|
2016-08-12 10:17:45 +02:00
|
|
|
|
|
|
|
/* enable if page is corrupted. */
|
|
|
|
bool is_corrupted;
|
|
|
|
/* use to store LSN values. */
|
2021-07-22 16:53:43 +02:00
|
|
|
uint32_t logseq;
|
|
|
|
uint32_t logseqfield;
|
2021-07-31 23:19:51 +02:00
|
|
|
const uint16_t page_type = mach_read_from_2(buf+FIL_PAGE_TYPE);
|
2021-07-31 22:59:58 +02:00
|
|
|
uint32_t key_version = buf_page_get_key_version(buf, flags);
|
2021-07-22 16:53:43 +02:00
|
|
|
uint32_t space_id = mach_read_from_4(
|
2017-08-04 12:57:26 +02:00
|
|
|
buf + FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID);
|
MDEV-12026: Implement innodb_checksum_algorithm=full_crc32
MariaDB data-at-rest encryption (innodb_encrypt_tables)
had repurposed the same unused data field that was repurposed
in MySQL 5.7 (and MariaDB 10.2) for the Split Sequence Number (SSN)
field of SPATIAL INDEX. Because of this, MariaDB was unable to
support encryption on SPATIAL INDEX pages.
Furthermore, InnoDB page checksums skipped some bytes, and there
are multiple variations and checksum algorithms. By default,
InnoDB accepts all variations of all algorithms that ever existed.
This unnecessarily weakens the page checksums.
We hereby introduce two more innodb_checksum_algorithm variants
(full_crc32, strict_full_crc32) that are special in a way:
When either setting is active, newly created data files will
carry a flag (fil_space_t::full_crc32()) that indicates that
all pages of the file will use a full CRC-32C checksum over the
entire page contents (excluding the bytes where the checksum
is stored, at the very end of the page). Such files will always
use that checksum, no matter what the parameter
innodb_checksum_algorithm is assigned to.
For old files, the old checksum algorithms will continue to be
used. The value strict_full_crc32 will be equivalent to strict_crc32
and the value full_crc32 will be equivalent to crc32.
ROW_FORMAT=COMPRESSED tables will only use the old format.
These tables do not support new features, such as larger
innodb_page_size or instant ADD/DROP COLUMN. They may be
deprecated in the future. We do not want an unnecessary
file format change for them.
The new full_crc32() format also cleans up the MariaDB tablespace
flags. We will reserve flags to store the page_compressed
compression algorithm, and to store the compressed payload length,
so that checksum can be computed over the compressed (and
possibly encrypted) stream and can be validated without
decrypting or decompressing the page.
In the full_crc32 format, there no longer are separate before-encryption
and after-encryption checksums for pages. The single checksum is
computed on the page contents that is written to the file.
We do not make the new algorithm the default for two reasons.
First, MariaDB 10.4.2 was a beta release, and the default values
of parameters should not change after beta. Second, we did not
yet implement the full_crc32 format for page_compressed pages.
This will be fixed in MDEV-18644.
This is joint work with Marko Mäkelä.
2019-02-19 20:00:00 +01:00
|
|
|
ulint zip_size = fil_space_t::zip_size(flags);
|
|
|
|
ulint is_compressed = fil_space_t::is_compressed(flags);
|
|
|
|
const bool use_full_crc32 = fil_space_t::full_crc32(flags);
|
2017-08-04 12:57:26 +02:00
|
|
|
|
2019-06-28 15:19:43 +02:00
|
|
|
if (mach_read_from_4(buf + FIL_PAGE_OFFSET) != cur_page_num
|
2019-07-02 20:44:58 +02:00
|
|
|
|| (space_id != cur_space
|
|
|
|
&& (!use_full_crc32 || (!is_encrypted && !is_compressed)))) {
|
2019-06-28 15:19:43 +02:00
|
|
|
/* On pages that are not all zero, the page number
|
|
|
|
must match. */
|
2019-07-02 20:44:58 +02:00
|
|
|
if (is_page_all_zeroes(buf,
|
|
|
|
fil_space_t::physical_size(flags))) {
|
2019-06-28 15:19:43 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_log_enabled) {
|
|
|
|
fprintf(log_file,
|
2021-07-22 16:53:43 +02:00
|
|
|
"page id mismatch space::" UINT32PF
|
|
|
|
" page::" UINT32PF " \n",
|
2019-06-28 15:19:43 +02:00
|
|
|
space_id, cur_page_num);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-08-04 12:57:26 +02:00
|
|
|
/* We can't trust only a page type, thus we take account
|
|
|
|
also fsp_flags or crypt_data on page 0 */
|
|
|
|
if ((page_type == FIL_PAGE_PAGE_COMPRESSED && is_compressed) ||
|
|
|
|
(page_type == FIL_PAGE_PAGE_COMPRESSED_ENCRYPTED &&
|
|
|
|
is_compressed && is_encrypted)) {
|
|
|
|
/* Page compressed tables do not contain post compression
|
|
|
|
checksum. */
|
|
|
|
return (false);
|
|
|
|
}
|
2016-08-12 10:17:45 +02:00
|
|
|
|
MDEV-18644: Support full_crc32 for page_compressed
This is a follow-up task to MDEV-12026, which introduced
innodb_checksum_algorithm=full_crc32 and a simpler page format.
MDEV-12026 did not enable full_crc32 for page_compressed tables,
which we will be doing now.
This is joint work with Thirunarayanan Balathandayuthapani.
For innodb_checksum_algorithm=full_crc32 we change the
page_compressed format as follows:
FIL_PAGE_TYPE: The most significant bit will be set to indicate
page_compressed format. The least significant bits will contain
the compressed page size, rounded up to a multiple of 256 bytes.
The checksum will be stored in the last 4 bytes of the page
(whether it is the full page or a page_compressed page whose
size is determined by FIL_PAGE_TYPE), covering all preceding
bytes of the page. If encryption is used, then the page will
be encrypted between compression and computing the checksum.
For page_compressed, FIL_PAGE_LSN will not be repeated at
the end of the page.
FSP_SPACE_FLAGS (already implemented as part of MDEV-12026):
We will store the innodb_compression_algorithm that may be used
to compress pages. Previously, the choice of algorithm was written
to each compressed data page separately, and one would be unable
to know in advance which compression algorithm(s) are used.
fil_space_t::full_crc32_page_compressed_len(): Determine if the
page_compressed algorithm of the tablespace needs to know the
exact length of the compressed data. If yes, we will reserve and
write an extra byte for this right before the checksum.
buf_page_is_compressed(): Determine if a page uses page_compressed
(in any innodb_checksum_algorithm).
fil_page_decompress(): Pass also fil_space_t::flags so that the
format can be determined.
buf_page_is_zeroes(): Check if a page is full of zero bytes.
buf_page_full_crc32_is_corrupted(): Renamed from
buf_encrypted_full_crc32_page_is_corrupted(). For full_crc32,
we always simply validate the checksum to the page contents,
while the physical page size is explicitly specified by an
unencrypted part of the page header.
buf_page_full_crc32_size(): Determine the size of a full_crc32 page.
buf_dblwr_check_page_lsn(): Make this a debug-only function, because
it involves potentially costly lookups of fil_space_t.
create_table_info_t::check_table_options(),
ha_innobase::check_if_supported_inplace_alter(): Do allow the creation
of SPATIAL INDEX with full_crc32 also when page_compressed is used.
commit_cache_norebuild(): Preserve the compression algorithm when
updating the page_compression_level.
dict_tf_to_fsp_flags(): Set the flags for page compression algorithm.
FIXME: Maybe there should be a table option page_compression_algorithm
and a session variable to back it?
2019-03-18 13:08:43 +01:00
|
|
|
if (!zip_size && (!is_compressed || !use_full_crc32)) {
|
2016-08-12 10:17:45 +02:00
|
|
|
/* check the stored log sequence numbers
|
|
|
|
for uncompressed tablespace. */
|
|
|
|
logseq = mach_read_from_4(buf + FIL_PAGE_LSN + 4);
|
MDEV-12026: Implement innodb_checksum_algorithm=full_crc32
MariaDB data-at-rest encryption (innodb_encrypt_tables)
had repurposed the same unused data field that was repurposed
in MySQL 5.7 (and MariaDB 10.2) for the Split Sequence Number (SSN)
field of SPATIAL INDEX. Because of this, MariaDB was unable to
support encryption on SPATIAL INDEX pages.
Furthermore, InnoDB page checksums skipped some bytes, and there
are multiple variations and checksum algorithms. By default,
InnoDB accepts all variations of all algorithms that ever existed.
This unnecessarily weakens the page checksums.
We hereby introduce two more innodb_checksum_algorithm variants
(full_crc32, strict_full_crc32) that are special in a way:
When either setting is active, newly created data files will
carry a flag (fil_space_t::full_crc32()) that indicates that
all pages of the file will use a full CRC-32C checksum over the
entire page contents (excluding the bytes where the checksum
is stored, at the very end of the page). Such files will always
use that checksum, no matter what the parameter
innodb_checksum_algorithm is assigned to.
For old files, the old checksum algorithms will continue to be
used. The value strict_full_crc32 will be equivalent to strict_crc32
and the value full_crc32 will be equivalent to crc32.
ROW_FORMAT=COMPRESSED tables will only use the old format.
These tables do not support new features, such as larger
innodb_page_size or instant ADD/DROP COLUMN. They may be
deprecated in the future. We do not want an unnecessary
file format change for them.
The new full_crc32() format also cleans up the MariaDB tablespace
flags. We will reserve flags to store the page_compressed
compression algorithm, and to store the compressed payload length,
so that checksum can be computed over the compressed (and
possibly encrypted) stream and can be validated without
decrypting or decompressing the page.
In the full_crc32 format, there no longer are separate before-encryption
and after-encryption checksums for pages. The single checksum is
computed on the page contents that is written to the file.
We do not make the new algorithm the default for two reasons.
First, MariaDB 10.4.2 was a beta release, and the default values
of parameters should not change after beta. Second, we did not
yet implement the full_crc32 format for page_compressed pages.
This will be fixed in MDEV-18644.
This is joint work with Marko Mäkelä.
2019-02-19 20:00:00 +01:00
|
|
|
logseqfield = use_full_crc32
|
|
|
|
? mach_read_from_4(buf + srv_page_size
|
|
|
|
- FIL_PAGE_FCRC32_END_LSN)
|
|
|
|
: mach_read_from_4(buf + srv_page_size
|
|
|
|
- FIL_PAGE_END_LSN_OLD_CHKSUM + 4);
|
2016-08-12 10:17:45 +02:00
|
|
|
|
|
|
|
if (is_log_enabled) {
|
|
|
|
fprintf(log_file,
|
2021-07-22 16:53:43 +02:00
|
|
|
"space::" UINT32PF " page::" UINT32PF
|
|
|
|
"; log sequence number:first = " UINT32PF
|
|
|
|
"; second = " UINT32PF "\n",
|
2017-08-04 12:57:26 +02:00
|
|
|
space_id, cur_page_num, logseq, logseqfield);
|
2016-08-12 10:17:45 +02:00
|
|
|
if (logseq != logseqfield) {
|
|
|
|
fprintf(log_file,
|
2021-07-22 16:53:43 +02:00
|
|
|
"Fail; space::" UINT32PF
|
|
|
|
" page::" UINT32PF
|
2016-09-29 12:59:41 +02:00
|
|
|
" invalid (fails log "
|
2016-08-12 10:17:45 +02:00
|
|
|
"sequence number check)\n",
|
2017-08-04 12:57:26 +02:00
|
|
|
space_id, cur_page_num);
|
2016-08-12 10:17:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-04 12:57:26 +02:00
|
|
|
/* Again we can't trust only FIL_PAGE_FILE_FLUSH_LSN field
|
|
|
|
now repurposed as FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION,
|
|
|
|
we need to check also crypt_data contents.
|
2017-03-30 12:48:42 +02:00
|
|
|
|
2017-08-04 12:57:26 +02:00
|
|
|
If page is encrypted, use different checksum calculation
|
2017-01-03 13:35:08 +01:00
|
|
|
as innochecksum can't decrypt pages. Note that some old InnoDB
|
|
|
|
versions did not initialize FIL_PAGE_FILE_FLUSH_LSN field
|
|
|
|
so if crypt checksum does not match we verify checksum using
|
2017-08-04 12:57:26 +02:00
|
|
|
normal method. */
|
|
|
|
if (is_encrypted && key_version != 0) {
|
MDEV-12026: Implement innodb_checksum_algorithm=full_crc32
MariaDB data-at-rest encryption (innodb_encrypt_tables)
had repurposed the same unused data field that was repurposed
in MySQL 5.7 (and MariaDB 10.2) for the Split Sequence Number (SSN)
field of SPATIAL INDEX. Because of this, MariaDB was unable to
support encryption on SPATIAL INDEX pages.
Furthermore, InnoDB page checksums skipped some bytes, and there
are multiple variations and checksum algorithms. By default,
InnoDB accepts all variations of all algorithms that ever existed.
This unnecessarily weakens the page checksums.
We hereby introduce two more innodb_checksum_algorithm variants
(full_crc32, strict_full_crc32) that are special in a way:
When either setting is active, newly created data files will
carry a flag (fil_space_t::full_crc32()) that indicates that
all pages of the file will use a full CRC-32C checksum over the
entire page contents (excluding the bytes where the checksum
is stored, at the very end of the page). Such files will always
use that checksum, no matter what the parameter
innodb_checksum_algorithm is assigned to.
For old files, the old checksum algorithms will continue to be
used. The value strict_full_crc32 will be equivalent to strict_crc32
and the value full_crc32 will be equivalent to crc32.
ROW_FORMAT=COMPRESSED tables will only use the old format.
These tables do not support new features, such as larger
innodb_page_size or instant ADD/DROP COLUMN. They may be
deprecated in the future. We do not want an unnecessary
file format change for them.
The new full_crc32() format also cleans up the MariaDB tablespace
flags. We will reserve flags to store the page_compressed
compression algorithm, and to store the compressed payload length,
so that checksum can be computed over the compressed (and
possibly encrypted) stream and can be validated without
decrypting or decompressing the page.
In the full_crc32 format, there no longer are separate before-encryption
and after-encryption checksums for pages. The single checksum is
computed on the page contents that is written to the file.
We do not make the new algorithm the default for two reasons.
First, MariaDB 10.4.2 was a beta release, and the default values
of parameters should not change after beta. Second, we did not
yet implement the full_crc32 format for page_compressed pages.
This will be fixed in MDEV-18644.
This is joint work with Marko Mäkelä.
2019-02-19 20:00:00 +01:00
|
|
|
is_corrupted = use_full_crc32
|
MDEV-34830: LSN in the future is not being treated as serious corruption
The invariant of write-ahead logging is that before any change to a
page is written to the data file, the corresponding log record must
must first have been durably written.
In crash recovery, there were some sloppy checks for this. Let us
implement accurate checks and flag an inconsistency as a hard error,
so that we can avoid further corruption of a corrupted database.
For data extraction from the corrupted database, innodb_force_recovery
can be used.
Before recovery is reading any data pages or invoking
buf_dblwr_t::recover() to recover torn pages from the
doublewrite buffer, InnoDB will have parsed the log until the
final LSN and updated log_sys.lsn to that. So, we can rely on
log_sys.lsn at all times. The doublewrite buffer recovery has been
refactored in such a way that the recv_sys.dblwr.pages may be consulted
while discovering files and their page sizes, but nothing will be
written back to data files before buf_dblwr_t::recover() is invoked.
recv_max_page_lsn, recv_lsn_checks_on: Remove.
recv_sys_t::validate_checkpoint(): Validate the write-ahead-logging
condition at the end of the recovery.
recv_dblwr_t::validate_page(): Keep track of the maximum LSN
(if we are checking a non-doublewrite copy of a page) but
do not complain LSN being in the future. The doublewrite buffer
is a special case, because it will be read early during recovery.
Besides, starting with commit 762bcb81b5bf9bbde61fed59afb26417f4ce1e86
the dblwr=true copies of pages may legitimately be "too new".
recv_dblwr_t::find_page(): Find a valid page with the smallest
FIL_PAGE_LSN that is in the valid range for recovery.
recv_dblwr_t::restore_first_page(): Replaced by find_page().
Only buf_dblwr_t::recover() will write to data files.
buf_dblwr_t::recover(): Simplify the message output. Do attempt
doublewrite recovery on user page read error. Ignore doublewrite
pages whose FIL_PAGE_LSN is outside the usable bounds. Previously,
we could wrongly recover a too new page from the doublewrite buffer.
It is unlikely that this could have lead to an actual error.
Write back all recovered pages from the doublewrite buffer here,
including for the first page of any tablespace.
buf_page_is_corrupted(): Distinguish the return values
CORRUPTED_FUTURE_LSN and CORRUPTED_OTHER.
buf_page_check_corrupt(): Return the error code DB_CORRUPTION
in case the LSN is in the future.
Datafile::read_first_page_flags(): Split from read_first_page().
Take a copy of the first page as a parameter.
recv_sys_t::free_corrupted_page(): Take the file as a parameter
and return whether a message was displayed. This avoids some duplicated
and incomplete error messages.
buf_page_t::read_complete(): Remove some redundant output and always
display the name of the corrupted file. Never return DB_FAIL;
use it only in internal error handling.
IORequest::read_complete(): Assume that buf_page_t::read_complete()
will have reported any error.
fil_space_t::set_corrupted(): Return whether this is the first time
the tablespace had been flagged as corrupted.
Datafile::validate_first_page(), fil_node_open_file_low(),
fil_node_open_file(), fil_space_t::read_page0(),
fil_node_t::read_page0(): Add a parameter for a copy of the
first page, and a parameter to indicate whether the FIL_PAGE_LSN
check should be suppressed. Before buf_dblwr_t::recover() is
invoked, we cannot validate the FIL_PAGE_LSN, but we can trust the
FSP_SPACE_FLAGS and the tablespace ID that may be present in a
potentially too new copy of a page.
Reviewed by: Debarun Banerjee
2024-10-18 09:12:47 +02:00
|
|
|
? !!buf_page_is_corrupted(false, buf, flags)
|
MDEV-12026: Implement innodb_checksum_algorithm=full_crc32
MariaDB data-at-rest encryption (innodb_encrypt_tables)
had repurposed the same unused data field that was repurposed
in MySQL 5.7 (and MariaDB 10.2) for the Split Sequence Number (SSN)
field of SPATIAL INDEX. Because of this, MariaDB was unable to
support encryption on SPATIAL INDEX pages.
Furthermore, InnoDB page checksums skipped some bytes, and there
are multiple variations and checksum algorithms. By default,
InnoDB accepts all variations of all algorithms that ever existed.
This unnecessarily weakens the page checksums.
We hereby introduce two more innodb_checksum_algorithm variants
(full_crc32, strict_full_crc32) that are special in a way:
When either setting is active, newly created data files will
carry a flag (fil_space_t::full_crc32()) that indicates that
all pages of the file will use a full CRC-32C checksum over the
entire page contents (excluding the bytes where the checksum
is stored, at the very end of the page). Such files will always
use that checksum, no matter what the parameter
innodb_checksum_algorithm is assigned to.
For old files, the old checksum algorithms will continue to be
used. The value strict_full_crc32 will be equivalent to strict_crc32
and the value full_crc32 will be equivalent to crc32.
ROW_FORMAT=COMPRESSED tables will only use the old format.
These tables do not support new features, such as larger
innodb_page_size or instant ADD/DROP COLUMN. They may be
deprecated in the future. We do not want an unnecessary
file format change for them.
The new full_crc32() format also cleans up the MariaDB tablespace
flags. We will reserve flags to store the page_compressed
compression algorithm, and to store the compressed payload length,
so that checksum can be computed over the compressed (and
possibly encrypted) stream and can be validated without
decrypting or decompressing the page.
In the full_crc32 format, there no longer are separate before-encryption
and after-encryption checksums for pages. The single checksum is
computed on the page contents that is written to the file.
We do not make the new algorithm the default for two reasons.
First, MariaDB 10.4.2 was a beta release, and the default values
of parameters should not change after beta. Second, we did not
yet implement the full_crc32 format for page_compressed pages.
This will be fixed in MDEV-18644.
This is joint work with Marko Mäkelä.
2019-02-19 20:00:00 +01:00
|
|
|
: !fil_space_verify_crypt_checksum(buf, zip_size);
|
|
|
|
|
2018-12-17 18:00:35 +01:00
|
|
|
if (is_corrupted && log_file) {
|
|
|
|
fprintf(log_file,
|
2021-07-22 16:53:43 +02:00
|
|
|
"[page id: space=" UINT32PF
|
|
|
|
", page_number=" UINT32PF "] may be corrupted;"
|
|
|
|
" key_version=" UINT32PF "\n",
|
MDEV-12026: Implement innodb_checksum_algorithm=full_crc32
MariaDB data-at-rest encryption (innodb_encrypt_tables)
had repurposed the same unused data field that was repurposed
in MySQL 5.7 (and MariaDB 10.2) for the Split Sequence Number (SSN)
field of SPATIAL INDEX. Because of this, MariaDB was unable to
support encryption on SPATIAL INDEX pages.
Furthermore, InnoDB page checksums skipped some bytes, and there
are multiple variations and checksum algorithms. By default,
InnoDB accepts all variations of all algorithms that ever existed.
This unnecessarily weakens the page checksums.
We hereby introduce two more innodb_checksum_algorithm variants
(full_crc32, strict_full_crc32) that are special in a way:
When either setting is active, newly created data files will
carry a flag (fil_space_t::full_crc32()) that indicates that
all pages of the file will use a full CRC-32C checksum over the
entire page contents (excluding the bytes where the checksum
is stored, at the very end of the page). Such files will always
use that checksum, no matter what the parameter
innodb_checksum_algorithm is assigned to.
For old files, the old checksum algorithms will continue to be
used. The value strict_full_crc32 will be equivalent to strict_crc32
and the value full_crc32 will be equivalent to crc32.
ROW_FORMAT=COMPRESSED tables will only use the old format.
These tables do not support new features, such as larger
innodb_page_size or instant ADD/DROP COLUMN. They may be
deprecated in the future. We do not want an unnecessary
file format change for them.
The new full_crc32() format also cleans up the MariaDB tablespace
flags. We will reserve flags to store the page_compressed
compression algorithm, and to store the compressed payload length,
so that checksum can be computed over the compressed (and
possibly encrypted) stream and can be validated without
decrypting or decompressing the page.
In the full_crc32 format, there no longer are separate before-encryption
and after-encryption checksums for pages. The single checksum is
computed on the page contents that is written to the file.
We do not make the new algorithm the default for two reasons.
First, MariaDB 10.4.2 was a beta release, and the default values
of parameters should not change after beta. Second, we did not
yet implement the full_crc32 format for page_compressed pages.
This will be fixed in MDEV-18644.
This is joint work with Marko Mäkelä.
2019-02-19 20:00:00 +01:00
|
|
|
space_id, cur_page_num, key_version);
|
2018-12-17 18:00:35 +01:00
|
|
|
}
|
2017-01-03 13:35:08 +01:00
|
|
|
} else {
|
|
|
|
is_corrupted = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_corrupted) {
|
MDEV-12026: Implement innodb_checksum_algorithm=full_crc32
MariaDB data-at-rest encryption (innodb_encrypt_tables)
had repurposed the same unused data field that was repurposed
in MySQL 5.7 (and MariaDB 10.2) for the Split Sequence Number (SSN)
field of SPATIAL INDEX. Because of this, MariaDB was unable to
support encryption on SPATIAL INDEX pages.
Furthermore, InnoDB page checksums skipped some bytes, and there
are multiple variations and checksum algorithms. By default,
InnoDB accepts all variations of all algorithms that ever existed.
This unnecessarily weakens the page checksums.
We hereby introduce two more innodb_checksum_algorithm variants
(full_crc32, strict_full_crc32) that are special in a way:
When either setting is active, newly created data files will
carry a flag (fil_space_t::full_crc32()) that indicates that
all pages of the file will use a full CRC-32C checksum over the
entire page contents (excluding the bytes where the checksum
is stored, at the very end of the page). Such files will always
use that checksum, no matter what the parameter
innodb_checksum_algorithm is assigned to.
For old files, the old checksum algorithms will continue to be
used. The value strict_full_crc32 will be equivalent to strict_crc32
and the value full_crc32 will be equivalent to crc32.
ROW_FORMAT=COMPRESSED tables will only use the old format.
These tables do not support new features, such as larger
innodb_page_size or instant ADD/DROP COLUMN. They may be
deprecated in the future. We do not want an unnecessary
file format change for them.
The new full_crc32() format also cleans up the MariaDB tablespace
flags. We will reserve flags to store the page_compressed
compression algorithm, and to store the compressed payload length,
so that checksum can be computed over the compressed (and
possibly encrypted) stream and can be validated without
decrypting or decompressing the page.
In the full_crc32 format, there no longer are separate before-encryption
and after-encryption checksums for pages. The single checksum is
computed on the page contents that is written to the file.
We do not make the new algorithm the default for two reasons.
First, MariaDB 10.4.2 was a beta release, and the default values
of parameters should not change after beta. Second, we did not
yet implement the full_crc32 format for page_compressed pages.
This will be fixed in MDEV-18644.
This is joint work with Marko Mäkelä.
2019-02-19 20:00:00 +01:00
|
|
|
is_corrupted = buf_page_is_corrupted(true, buf, flags);
|
2017-01-03 13:35:08 +01:00
|
|
|
}
|
2016-08-12 10:17:45 +02:00
|
|
|
|
|
|
|
return(is_corrupted);
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************//*
|
|
|
|
Check if page is doublewrite buffer or not.
|
|
|
|
@param [in] page buffer page
|
|
|
|
|
|
|
|
@retval true if page is doublewrite buffer otherwise false.
|
|
|
|
*/
|
|
|
|
static
|
|
|
|
bool
|
|
|
|
is_page_doublewritebuffer(
|
|
|
|
const byte* page)
|
|
|
|
{
|
2024-11-27 08:30:51 +01:00
|
|
|
if ((cur_page_num >= extent_size)
|
|
|
|
&& (cur_page_num < extent_size * 3)) {
|
2016-08-12 10:17:45 +02:00
|
|
|
/* page is doublewrite buffer. */
|
|
|
|
return (true);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************//*
|
|
|
|
Check if page is empty or not.
|
|
|
|
@param [in] page page to checked for empty.
|
|
|
|
@param [in] len size of page.
|
|
|
|
|
|
|
|
@retval true if page is empty.
|
|
|
|
@retval false if page is not empty.
|
|
|
|
*/
|
|
|
|
static
|
|
|
|
bool
|
|
|
|
is_page_empty(
|
|
|
|
const byte* page,
|
|
|
|
size_t len)
|
|
|
|
{
|
|
|
|
while (len--) {
|
|
|
|
if (*page++) {
|
|
|
|
return (false);
|
|
|
|
}
|
2017-08-04 12:57:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return (true);
|
2016-08-12 10:17:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************//**
|
|
|
|
Rewrite the checksum for the page.
|
|
|
|
@param [in/out] page page buffer
|
MDEV-12026: Implement innodb_checksum_algorithm=full_crc32
MariaDB data-at-rest encryption (innodb_encrypt_tables)
had repurposed the same unused data field that was repurposed
in MySQL 5.7 (and MariaDB 10.2) for the Split Sequence Number (SSN)
field of SPATIAL INDEX. Because of this, MariaDB was unable to
support encryption on SPATIAL INDEX pages.
Furthermore, InnoDB page checksums skipped some bytes, and there
are multiple variations and checksum algorithms. By default,
InnoDB accepts all variations of all algorithms that ever existed.
This unnecessarily weakens the page checksums.
We hereby introduce two more innodb_checksum_algorithm variants
(full_crc32, strict_full_crc32) that are special in a way:
When either setting is active, newly created data files will
carry a flag (fil_space_t::full_crc32()) that indicates that
all pages of the file will use a full CRC-32C checksum over the
entire page contents (excluding the bytes where the checksum
is stored, at the very end of the page). Such files will always
use that checksum, no matter what the parameter
innodb_checksum_algorithm is assigned to.
For old files, the old checksum algorithms will continue to be
used. The value strict_full_crc32 will be equivalent to strict_crc32
and the value full_crc32 will be equivalent to crc32.
ROW_FORMAT=COMPRESSED tables will only use the old format.
These tables do not support new features, such as larger
innodb_page_size or instant ADD/DROP COLUMN. They may be
deprecated in the future. We do not want an unnecessary
file format change for them.
The new full_crc32() format also cleans up the MariaDB tablespace
flags. We will reserve flags to store the page_compressed
compression algorithm, and to store the compressed payload length,
so that checksum can be computed over the compressed (and
possibly encrypted) stream and can be validated without
decrypting or decompressing the page.
In the full_crc32 format, there no longer are separate before-encryption
and after-encryption checksums for pages. The single checksum is
computed on the page contents that is written to the file.
We do not make the new algorithm the default for two reasons.
First, MariaDB 10.4.2 was a beta release, and the default values
of parameters should not change after beta. Second, we did not
yet implement the full_crc32 format for page_compressed pages.
This will be fixed in MDEV-18644.
This is joint work with Marko Mäkelä.
2019-02-19 20:00:00 +01:00
|
|
|
@param [in] flags tablespace flags
|
2016-08-12 10:17:45 +02:00
|
|
|
|
|
|
|
@retval true : do rewrite
|
|
|
|
@retval false : skip the rewrite as checksum stored match with
|
|
|
|
calculated or page is doublwrite buffer.
|
|
|
|
*/
|
2021-07-22 13:36:30 +02:00
|
|
|
static bool update_checksum(byte* page, uint32_t flags)
|
2016-08-12 10:17:45 +02:00
|
|
|
{
|
|
|
|
ib_uint32_t checksum = 0;
|
|
|
|
byte stored1[4]; /* get FIL_PAGE_SPACE_OR_CHKSUM field checksum */
|
|
|
|
byte stored2[4]; /* get FIL_PAGE_END_LSN_OLD_CHKSUM field checksum */
|
|
|
|
|
|
|
|
ut_ad(page);
|
|
|
|
/* If page is doublewrite buffer, skip the rewrite of checksum. */
|
|
|
|
if (skip_page) {
|
|
|
|
return (false);
|
|
|
|
}
|
|
|
|
|
MDEV-12026: Implement innodb_checksum_algorithm=full_crc32
MariaDB data-at-rest encryption (innodb_encrypt_tables)
had repurposed the same unused data field that was repurposed
in MySQL 5.7 (and MariaDB 10.2) for the Split Sequence Number (SSN)
field of SPATIAL INDEX. Because of this, MariaDB was unable to
support encryption on SPATIAL INDEX pages.
Furthermore, InnoDB page checksums skipped some bytes, and there
are multiple variations and checksum algorithms. By default,
InnoDB accepts all variations of all algorithms that ever existed.
This unnecessarily weakens the page checksums.
We hereby introduce two more innodb_checksum_algorithm variants
(full_crc32, strict_full_crc32) that are special in a way:
When either setting is active, newly created data files will
carry a flag (fil_space_t::full_crc32()) that indicates that
all pages of the file will use a full CRC-32C checksum over the
entire page contents (excluding the bytes where the checksum
is stored, at the very end of the page). Such files will always
use that checksum, no matter what the parameter
innodb_checksum_algorithm is assigned to.
For old files, the old checksum algorithms will continue to be
used. The value strict_full_crc32 will be equivalent to strict_crc32
and the value full_crc32 will be equivalent to crc32.
ROW_FORMAT=COMPRESSED tables will only use the old format.
These tables do not support new features, such as larger
innodb_page_size or instant ADD/DROP COLUMN. They may be
deprecated in the future. We do not want an unnecessary
file format change for them.
The new full_crc32() format also cleans up the MariaDB tablespace
flags. We will reserve flags to store the page_compressed
compression algorithm, and to store the compressed payload length,
so that checksum can be computed over the compressed (and
possibly encrypted) stream and can be validated without
decrypting or decompressing the page.
In the full_crc32 format, there no longer are separate before-encryption
and after-encryption checksums for pages. The single checksum is
computed on the page contents that is written to the file.
We do not make the new algorithm the default for two reasons.
First, MariaDB 10.4.2 was a beta release, and the default values
of parameters should not change after beta. Second, we did not
yet implement the full_crc32 format for page_compressed pages.
This will be fixed in MDEV-18644.
This is joint work with Marko Mäkelä.
2019-02-19 20:00:00 +01:00
|
|
|
const bool use_full_crc32 = fil_space_t::full_crc32(flags);
|
|
|
|
const bool iscompressed = fil_space_t::zip_size(flags);
|
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
memcpy(stored1, page + FIL_PAGE_SPACE_OR_CHKSUM, 4);
|
|
|
|
memcpy(stored2, page + physical_page_size -
|
|
|
|
FIL_PAGE_END_LSN_OLD_CHKSUM, 4);
|
|
|
|
|
|
|
|
/* Check if page is empty, exclude the checksum field */
|
|
|
|
if (is_page_empty(page + 4, physical_page_size - 12)
|
|
|
|
&& is_page_empty(page + physical_page_size - 4, 4)) {
|
|
|
|
|
|
|
|
memset(page + FIL_PAGE_SPACE_OR_CHKSUM, 0, 4);
|
|
|
|
memset(page + physical_page_size -
|
|
|
|
FIL_PAGE_END_LSN_OLD_CHKSUM, 0, 4);
|
|
|
|
|
|
|
|
goto func_exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (iscompressed) {
|
MDEV-25105 Remove innodb_checksum_algorithm values none,innodb,...
Historically, InnoDB supported a buggy page checksum algorithm that did not
compute a checksum over the full page. Later, well before MySQL 4.1
introduced .ibd files and the innodb_file_per_table option, the algorithm
was corrected and the first 4 bytes of each page were redefined to be
a checksum.
The original checksum was so slow that an option to disable page checksum
was introduced for benchmarketing purposes.
The Intel Nehalem microarchitecture introduced the SSE4.2 instruction set
extension, which includes instructions for faster computation of CRC-32C.
In MySQL 5.6 (and MariaDB 10.0), innodb_checksum_algorithm=crc32 was
implemented to make of that. As that option was changed to be the default
in MySQL 5.7, a bug was found on big-endian platforms and some work-around
code was added to weaken that checksum further. MariaDB disables that
work-around by default since MDEV-17958.
Later, SIMD-accelerated CRC-32C has been implemented in MariaDB for POWER
and ARM and also for IA-32/AMD64, making use of carry-less multiplication
where available.
Long story short, innodb_checksum_algorithm=crc32 is faster and more secure
than the pre-MySQL 5.6 checksum, called innodb_checksum_algorithm=innodb.
It should have removed any need to use innodb_checksum_algorithm=none.
The setting innodb_checksum_algorithm=crc32 is the default in
MySQL 5.7 and MariaDB Server 10.2, 10.3, 10.4. In MariaDB 10.5,
MDEV-19534 made innodb_checksum_algorithm=full_crc32 the default.
It is even faster and more secure.
The default settings in MariaDB do allow old data files to be read,
no matter if a worse checksum algorithm had been used.
(Unfortunately, before innodb_checksum_algorithm=full_crc32,
the data files did not identify which checksum algorithm is being used.)
The non-default settings innodb_checksum_algorithm=strict_crc32 or
innodb_checksum_algorithm=strict_full_crc32 would only allow CRC-32C
checksums. The incompatibility with old data files is why they are
not the default.
The newest server not to support innodb_checksum_algorithm=crc32
were MySQL 5.5 and MariaDB 5.5. Both have reached their end of life.
A valid reason for using innodb_checksum_algorithm=innodb could have
been the ability to downgrade. If it is really needed, data files
can be converted with an older version of the innochecksum utility.
Because there is no good reason to allow data files to be written
with insecure checksums, we will reject those option values:
innodb_checksum_algorithm=none
innodb_checksum_algorithm=innodb
innodb_checksum_algorithm=strict_none
innodb_checksum_algorithm=strict_innodb
Furthermore, the following innochecksum options will be removed,
because only strict crc32 will be supported:
innochecksum --strict-check=crc32
innochecksum -C crc32
innochecksum --write=crc32
innochecksum -w crc32
If a user wishes to convert a data file to use a different checksum
(so that it might be used with the no-longer-supported
MySQL 5.5 or MariaDB 5.5, which do not support IMPORT TABLESPACE
nor system tablespace format changes that were made in MariaDB 10.3),
then the innochecksum tool from MariaDB 10.2, 10.3, 10.4, 10.5 or
MySQL 5.7 can be used.
Reviewed by: Thirunarayanan Balathandayuthapani
2021-03-11 10:56:35 +01:00
|
|
|
/* ROW_FORMAT=COMPRESSED */
|
|
|
|
checksum = page_zip_calc_checksum(page, physical_page_size,
|
|
|
|
false);
|
2016-08-12 10:17:45 +02:00
|
|
|
|
|
|
|
mach_write_to_4(page + FIL_PAGE_SPACE_OR_CHKSUM, checksum);
|
|
|
|
if (is_log_enabled) {
|
2021-07-22 16:53:43 +02:00
|
|
|
fprintf(log_file, "page::" UINT32PF "; Updated checksum ="
|
|
|
|
" " UINT32PF "\n", cur_page_num, checksum);
|
2016-08-12 10:17:45 +02:00
|
|
|
}
|
|
|
|
|
MDEV-12026: Implement innodb_checksum_algorithm=full_crc32
MariaDB data-at-rest encryption (innodb_encrypt_tables)
had repurposed the same unused data field that was repurposed
in MySQL 5.7 (and MariaDB 10.2) for the Split Sequence Number (SSN)
field of SPATIAL INDEX. Because of this, MariaDB was unable to
support encryption on SPATIAL INDEX pages.
Furthermore, InnoDB page checksums skipped some bytes, and there
are multiple variations and checksum algorithms. By default,
InnoDB accepts all variations of all algorithms that ever existed.
This unnecessarily weakens the page checksums.
We hereby introduce two more innodb_checksum_algorithm variants
(full_crc32, strict_full_crc32) that are special in a way:
When either setting is active, newly created data files will
carry a flag (fil_space_t::full_crc32()) that indicates that
all pages of the file will use a full CRC-32C checksum over the
entire page contents (excluding the bytes where the checksum
is stored, at the very end of the page). Such files will always
use that checksum, no matter what the parameter
innodb_checksum_algorithm is assigned to.
For old files, the old checksum algorithms will continue to be
used. The value strict_full_crc32 will be equivalent to strict_crc32
and the value full_crc32 will be equivalent to crc32.
ROW_FORMAT=COMPRESSED tables will only use the old format.
These tables do not support new features, such as larger
innodb_page_size or instant ADD/DROP COLUMN. They may be
deprecated in the future. We do not want an unnecessary
file format change for them.
The new full_crc32() format also cleans up the MariaDB tablespace
flags. We will reserve flags to store the page_compressed
compression algorithm, and to store the compressed payload length,
so that checksum can be computed over the compressed (and
possibly encrypted) stream and can be validated without
decrypting or decompressing the page.
In the full_crc32 format, there no longer are separate before-encryption
and after-encryption checksums for pages. The single checksum is
computed on the page contents that is written to the file.
We do not make the new algorithm the default for two reasons.
First, MariaDB 10.4.2 was a beta release, and the default values
of parameters should not change after beta. Second, we did not
yet implement the full_crc32 format for page_compressed pages.
This will be fixed in MDEV-18644.
This is joint work with Marko Mäkelä.
2019-02-19 20:00:00 +01:00
|
|
|
} else if (use_full_crc32) {
|
MDEV-18644: Support full_crc32 for page_compressed
This is a follow-up task to MDEV-12026, which introduced
innodb_checksum_algorithm=full_crc32 and a simpler page format.
MDEV-12026 did not enable full_crc32 for page_compressed tables,
which we will be doing now.
This is joint work with Thirunarayanan Balathandayuthapani.
For innodb_checksum_algorithm=full_crc32 we change the
page_compressed format as follows:
FIL_PAGE_TYPE: The most significant bit will be set to indicate
page_compressed format. The least significant bits will contain
the compressed page size, rounded up to a multiple of 256 bytes.
The checksum will be stored in the last 4 bytes of the page
(whether it is the full page or a page_compressed page whose
size is determined by FIL_PAGE_TYPE), covering all preceding
bytes of the page. If encryption is used, then the page will
be encrypted between compression and computing the checksum.
For page_compressed, FIL_PAGE_LSN will not be repeated at
the end of the page.
FSP_SPACE_FLAGS (already implemented as part of MDEV-12026):
We will store the innodb_compression_algorithm that may be used
to compress pages. Previously, the choice of algorithm was written
to each compressed data page separately, and one would be unable
to know in advance which compression algorithm(s) are used.
fil_space_t::full_crc32_page_compressed_len(): Determine if the
page_compressed algorithm of the tablespace needs to know the
exact length of the compressed data. If yes, we will reserve and
write an extra byte for this right before the checksum.
buf_page_is_compressed(): Determine if a page uses page_compressed
(in any innodb_checksum_algorithm).
fil_page_decompress(): Pass also fil_space_t::flags so that the
format can be determined.
buf_page_is_zeroes(): Check if a page is full of zero bytes.
buf_page_full_crc32_is_corrupted(): Renamed from
buf_encrypted_full_crc32_page_is_corrupted(). For full_crc32,
we always simply validate the checksum to the page contents,
while the physical page size is explicitly specified by an
unencrypted part of the page header.
buf_page_full_crc32_size(): Determine the size of a full_crc32 page.
buf_dblwr_check_page_lsn(): Make this a debug-only function, because
it involves potentially costly lookups of fil_space_t.
create_table_info_t::check_table_options(),
ha_innobase::check_if_supported_inplace_alter(): Do allow the creation
of SPATIAL INDEX with full_crc32 also when page_compressed is used.
commit_cache_norebuild(): Preserve the compression algorithm when
updating the page_compression_level.
dict_tf_to_fsp_flags(): Set the flags for page compression algorithm.
FIXME: Maybe there should be a table option page_compression_algorithm
and a session variable to back it?
2019-03-18 13:08:43 +01:00
|
|
|
ulint payload = buf_page_full_crc32_size(page, NULL, NULL)
|
|
|
|
- FIL_PAGE_FCRC32_CHECKSUM;
|
2022-01-21 15:13:04 +01:00
|
|
|
checksum = my_crc32c(0, page, payload);
|
MDEV-18644: Support full_crc32 for page_compressed
This is a follow-up task to MDEV-12026, which introduced
innodb_checksum_algorithm=full_crc32 and a simpler page format.
MDEV-12026 did not enable full_crc32 for page_compressed tables,
which we will be doing now.
This is joint work with Thirunarayanan Balathandayuthapani.
For innodb_checksum_algorithm=full_crc32 we change the
page_compressed format as follows:
FIL_PAGE_TYPE: The most significant bit will be set to indicate
page_compressed format. The least significant bits will contain
the compressed page size, rounded up to a multiple of 256 bytes.
The checksum will be stored in the last 4 bytes of the page
(whether it is the full page or a page_compressed page whose
size is determined by FIL_PAGE_TYPE), covering all preceding
bytes of the page. If encryption is used, then the page will
be encrypted between compression and computing the checksum.
For page_compressed, FIL_PAGE_LSN will not be repeated at
the end of the page.
FSP_SPACE_FLAGS (already implemented as part of MDEV-12026):
We will store the innodb_compression_algorithm that may be used
to compress pages. Previously, the choice of algorithm was written
to each compressed data page separately, and one would be unable
to know in advance which compression algorithm(s) are used.
fil_space_t::full_crc32_page_compressed_len(): Determine if the
page_compressed algorithm of the tablespace needs to know the
exact length of the compressed data. If yes, we will reserve and
write an extra byte for this right before the checksum.
buf_page_is_compressed(): Determine if a page uses page_compressed
(in any innodb_checksum_algorithm).
fil_page_decompress(): Pass also fil_space_t::flags so that the
format can be determined.
buf_page_is_zeroes(): Check if a page is full of zero bytes.
buf_page_full_crc32_is_corrupted(): Renamed from
buf_encrypted_full_crc32_page_is_corrupted(). For full_crc32,
we always simply validate the checksum to the page contents,
while the physical page size is explicitly specified by an
unencrypted part of the page header.
buf_page_full_crc32_size(): Determine the size of a full_crc32 page.
buf_dblwr_check_page_lsn(): Make this a debug-only function, because
it involves potentially costly lookups of fil_space_t.
create_table_info_t::check_table_options(),
ha_innobase::check_if_supported_inplace_alter(): Do allow the creation
of SPATIAL INDEX with full_crc32 also when page_compressed is used.
commit_cache_norebuild(): Preserve the compression algorithm when
updating the page_compression_level.
dict_tf_to_fsp_flags(): Set the flags for page compression algorithm.
FIXME: Maybe there should be a table option page_compression_algorithm
and a session variable to back it?
2019-03-18 13:08:43 +01:00
|
|
|
byte* c = page + payload;
|
MDEV-12026: Implement innodb_checksum_algorithm=full_crc32
MariaDB data-at-rest encryption (innodb_encrypt_tables)
had repurposed the same unused data field that was repurposed
in MySQL 5.7 (and MariaDB 10.2) for the Split Sequence Number (SSN)
field of SPATIAL INDEX. Because of this, MariaDB was unable to
support encryption on SPATIAL INDEX pages.
Furthermore, InnoDB page checksums skipped some bytes, and there
are multiple variations and checksum algorithms. By default,
InnoDB accepts all variations of all algorithms that ever existed.
This unnecessarily weakens the page checksums.
We hereby introduce two more innodb_checksum_algorithm variants
(full_crc32, strict_full_crc32) that are special in a way:
When either setting is active, newly created data files will
carry a flag (fil_space_t::full_crc32()) that indicates that
all pages of the file will use a full CRC-32C checksum over the
entire page contents (excluding the bytes where the checksum
is stored, at the very end of the page). Such files will always
use that checksum, no matter what the parameter
innodb_checksum_algorithm is assigned to.
For old files, the old checksum algorithms will continue to be
used. The value strict_full_crc32 will be equivalent to strict_crc32
and the value full_crc32 will be equivalent to crc32.
ROW_FORMAT=COMPRESSED tables will only use the old format.
These tables do not support new features, such as larger
innodb_page_size or instant ADD/DROP COLUMN. They may be
deprecated in the future. We do not want an unnecessary
file format change for them.
The new full_crc32() format also cleans up the MariaDB tablespace
flags. We will reserve flags to store the page_compressed
compression algorithm, and to store the compressed payload length,
so that checksum can be computed over the compressed (and
possibly encrypted) stream and can be validated without
decrypting or decompressing the page.
In the full_crc32 format, there no longer are separate before-encryption
and after-encryption checksums for pages. The single checksum is
computed on the page contents that is written to the file.
We do not make the new algorithm the default for two reasons.
First, MariaDB 10.4.2 was a beta release, and the default values
of parameters should not change after beta. Second, we did not
yet implement the full_crc32 format for page_compressed pages.
This will be fixed in MDEV-18644.
This is joint work with Marko Mäkelä.
2019-02-19 20:00:00 +01:00
|
|
|
if (mach_read_from_4(c) == checksum) return false;
|
|
|
|
mach_write_to_4(c, checksum);
|
|
|
|
if (is_log_enabled) {
|
2021-07-31 22:59:58 +02:00
|
|
|
fprintf(log_file, "page::" UINT32PF "; Updated checksum"
|
MDEV-12026: Implement innodb_checksum_algorithm=full_crc32
MariaDB data-at-rest encryption (innodb_encrypt_tables)
had repurposed the same unused data field that was repurposed
in MySQL 5.7 (and MariaDB 10.2) for the Split Sequence Number (SSN)
field of SPATIAL INDEX. Because of this, MariaDB was unable to
support encryption on SPATIAL INDEX pages.
Furthermore, InnoDB page checksums skipped some bytes, and there
are multiple variations and checksum algorithms. By default,
InnoDB accepts all variations of all algorithms that ever existed.
This unnecessarily weakens the page checksums.
We hereby introduce two more innodb_checksum_algorithm variants
(full_crc32, strict_full_crc32) that are special in a way:
When either setting is active, newly created data files will
carry a flag (fil_space_t::full_crc32()) that indicates that
all pages of the file will use a full CRC-32C checksum over the
entire page contents (excluding the bytes where the checksum
is stored, at the very end of the page). Such files will always
use that checksum, no matter what the parameter
innodb_checksum_algorithm is assigned to.
For old files, the old checksum algorithms will continue to be
used. The value strict_full_crc32 will be equivalent to strict_crc32
and the value full_crc32 will be equivalent to crc32.
ROW_FORMAT=COMPRESSED tables will only use the old format.
These tables do not support new features, such as larger
innodb_page_size or instant ADD/DROP COLUMN. They may be
deprecated in the future. We do not want an unnecessary
file format change for them.
The new full_crc32() format also cleans up the MariaDB tablespace
flags. We will reserve flags to store the page_compressed
compression algorithm, and to store the compressed payload length,
so that checksum can be computed over the compressed (and
possibly encrypted) stream and can be validated without
decrypting or decompressing the page.
In the full_crc32 format, there no longer are separate before-encryption
and after-encryption checksums for pages. The single checksum is
computed on the page contents that is written to the file.
We do not make the new algorithm the default for two reasons.
First, MariaDB 10.4.2 was a beta release, and the default values
of parameters should not change after beta. Second, we did not
yet implement the full_crc32 format for page_compressed pages.
This will be fixed in MDEV-18644.
This is joint work with Marko Mäkelä.
2019-02-19 20:00:00 +01:00
|
|
|
" = %u\n", cur_page_num, checksum);
|
|
|
|
}
|
|
|
|
return true;
|
2016-08-12 10:17:45 +02:00
|
|
|
} else {
|
|
|
|
/* page is uncompressed. */
|
|
|
|
|
|
|
|
/* Store the new formula checksum */
|
MDEV-25105 Remove innodb_checksum_algorithm values none,innodb,...
Historically, InnoDB supported a buggy page checksum algorithm that did not
compute a checksum over the full page. Later, well before MySQL 4.1
introduced .ibd files and the innodb_file_per_table option, the algorithm
was corrected and the first 4 bytes of each page were redefined to be
a checksum.
The original checksum was so slow that an option to disable page checksum
was introduced for benchmarketing purposes.
The Intel Nehalem microarchitecture introduced the SSE4.2 instruction set
extension, which includes instructions for faster computation of CRC-32C.
In MySQL 5.6 (and MariaDB 10.0), innodb_checksum_algorithm=crc32 was
implemented to make of that. As that option was changed to be the default
in MySQL 5.7, a bug was found on big-endian platforms and some work-around
code was added to weaken that checksum further. MariaDB disables that
work-around by default since MDEV-17958.
Later, SIMD-accelerated CRC-32C has been implemented in MariaDB for POWER
and ARM and also for IA-32/AMD64, making use of carry-less multiplication
where available.
Long story short, innodb_checksum_algorithm=crc32 is faster and more secure
than the pre-MySQL 5.6 checksum, called innodb_checksum_algorithm=innodb.
It should have removed any need to use innodb_checksum_algorithm=none.
The setting innodb_checksum_algorithm=crc32 is the default in
MySQL 5.7 and MariaDB Server 10.2, 10.3, 10.4. In MariaDB 10.5,
MDEV-19534 made innodb_checksum_algorithm=full_crc32 the default.
It is even faster and more secure.
The default settings in MariaDB do allow old data files to be read,
no matter if a worse checksum algorithm had been used.
(Unfortunately, before innodb_checksum_algorithm=full_crc32,
the data files did not identify which checksum algorithm is being used.)
The non-default settings innodb_checksum_algorithm=strict_crc32 or
innodb_checksum_algorithm=strict_full_crc32 would only allow CRC-32C
checksums. The incompatibility with old data files is why they are
not the default.
The newest server not to support innodb_checksum_algorithm=crc32
were MySQL 5.5 and MariaDB 5.5. Both have reached their end of life.
A valid reason for using innodb_checksum_algorithm=innodb could have
been the ability to downgrade. If it is really needed, data files
can be converted with an older version of the innochecksum utility.
Because there is no good reason to allow data files to be written
with insecure checksums, we will reject those option values:
innodb_checksum_algorithm=none
innodb_checksum_algorithm=innodb
innodb_checksum_algorithm=strict_none
innodb_checksum_algorithm=strict_innodb
Furthermore, the following innochecksum options will be removed,
because only strict crc32 will be supported:
innochecksum --strict-check=crc32
innochecksum -C crc32
innochecksum --write=crc32
innochecksum -w crc32
If a user wishes to convert a data file to use a different checksum
(so that it might be used with the no-longer-supported
MySQL 5.5 or MariaDB 5.5, which do not support IMPORT TABLESPACE
nor system tablespace format changes that were made in MariaDB 10.3),
then the innochecksum tool from MariaDB 10.2, 10.3, 10.4, 10.5 or
MySQL 5.7 can be used.
Reviewed by: Thirunarayanan Balathandayuthapani
2021-03-11 10:56:35 +01:00
|
|
|
checksum = buf_calc_page_crc32(page);
|
2016-08-12 10:17:45 +02:00
|
|
|
|
|
|
|
mach_write_to_4(page + FIL_PAGE_SPACE_OR_CHKSUM, checksum);
|
|
|
|
if (is_log_enabled) {
|
2021-08-02 10:11:41 +02:00
|
|
|
fprintf(log_file, "page::" UINT32PF
|
|
|
|
"; Updated checksum = " UINT32PF "\n",
|
|
|
|
cur_page_num, checksum);
|
2016-08-12 10:17:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
mach_write_to_4(page + physical_page_size -
|
|
|
|
FIL_PAGE_END_LSN_OLD_CHKSUM,checksum);
|
|
|
|
}
|
|
|
|
|
2016-09-29 12:59:41 +02:00
|
|
|
func_exit:
|
2016-08-12 10:17:45 +02:00
|
|
|
/* The following code is to check the stored checksum with the
|
|
|
|
calculated checksum. If it matches, then return FALSE to skip
|
|
|
|
the rewrite of checksum, otherwise return TRUE. */
|
|
|
|
if (iscompressed) {
|
|
|
|
if (!memcmp(stored1, page + FIL_PAGE_SPACE_OR_CHKSUM, 4)) {
|
|
|
|
return (false);
|
|
|
|
}
|
|
|
|
return (true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!memcmp(stored1, page + FIL_PAGE_SPACE_OR_CHKSUM, 4)
|
|
|
|
&& !memcmp(stored2, page + physical_page_size -
|
|
|
|
FIL_PAGE_END_LSN_OLD_CHKSUM, 4)) {
|
|
|
|
return (false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return (true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Write the content to the file
|
|
|
|
@param[in] filename name of the file.
|
|
|
|
@param[in,out] file file pointer where content
|
|
|
|
have to be written
|
|
|
|
@param[in] buf file buffer read
|
MDEV-12026: Implement innodb_checksum_algorithm=full_crc32
MariaDB data-at-rest encryption (innodb_encrypt_tables)
had repurposed the same unused data field that was repurposed
in MySQL 5.7 (and MariaDB 10.2) for the Split Sequence Number (SSN)
field of SPATIAL INDEX. Because of this, MariaDB was unable to
support encryption on SPATIAL INDEX pages.
Furthermore, InnoDB page checksums skipped some bytes, and there
are multiple variations and checksum algorithms. By default,
InnoDB accepts all variations of all algorithms that ever existed.
This unnecessarily weakens the page checksums.
We hereby introduce two more innodb_checksum_algorithm variants
(full_crc32, strict_full_crc32) that are special in a way:
When either setting is active, newly created data files will
carry a flag (fil_space_t::full_crc32()) that indicates that
all pages of the file will use a full CRC-32C checksum over the
entire page contents (excluding the bytes where the checksum
is stored, at the very end of the page). Such files will always
use that checksum, no matter what the parameter
innodb_checksum_algorithm is assigned to.
For old files, the old checksum algorithms will continue to be
used. The value strict_full_crc32 will be equivalent to strict_crc32
and the value full_crc32 will be equivalent to crc32.
ROW_FORMAT=COMPRESSED tables will only use the old format.
These tables do not support new features, such as larger
innodb_page_size or instant ADD/DROP COLUMN. They may be
deprecated in the future. We do not want an unnecessary
file format change for them.
The new full_crc32() format also cleans up the MariaDB tablespace
flags. We will reserve flags to store the page_compressed
compression algorithm, and to store the compressed payload length,
so that checksum can be computed over the compressed (and
possibly encrypted) stream and can be validated without
decrypting or decompressing the page.
In the full_crc32 format, there no longer are separate before-encryption
and after-encryption checksums for pages. The single checksum is
computed on the page contents that is written to the file.
We do not make the new algorithm the default for two reasons.
First, MariaDB 10.4.2 was a beta release, and the default values
of parameters should not change after beta. Second, we did not
yet implement the full_crc32 format for page_compressed pages.
This will be fixed in MDEV-18644.
This is joint work with Marko Mäkelä.
2019-02-19 20:00:00 +01:00
|
|
|
@param[in] flags tablespace flags
|
2016-08-12 10:17:45 +02:00
|
|
|
@param[in,out] pos current file position.
|
|
|
|
|
|
|
|
@retval true if successfully written
|
|
|
|
@retval false if a non-recoverable error occurred
|
|
|
|
*/
|
|
|
|
static
|
|
|
|
bool
|
|
|
|
write_file(
|
|
|
|
const char* filename,
|
|
|
|
FILE* file,
|
|
|
|
byte* buf,
|
2021-07-22 13:36:30 +02:00
|
|
|
uint32_t flags,
|
2019-02-06 18:50:11 +01:00
|
|
|
fpos_t* pos)
|
2016-08-12 10:17:45 +02:00
|
|
|
{
|
|
|
|
bool do_update;
|
|
|
|
|
MDEV-12026: Implement innodb_checksum_algorithm=full_crc32
MariaDB data-at-rest encryption (innodb_encrypt_tables)
had repurposed the same unused data field that was repurposed
in MySQL 5.7 (and MariaDB 10.2) for the Split Sequence Number (SSN)
field of SPATIAL INDEX. Because of this, MariaDB was unable to
support encryption on SPATIAL INDEX pages.
Furthermore, InnoDB page checksums skipped some bytes, and there
are multiple variations and checksum algorithms. By default,
InnoDB accepts all variations of all algorithms that ever existed.
This unnecessarily weakens the page checksums.
We hereby introduce two more innodb_checksum_algorithm variants
(full_crc32, strict_full_crc32) that are special in a way:
When either setting is active, newly created data files will
carry a flag (fil_space_t::full_crc32()) that indicates that
all pages of the file will use a full CRC-32C checksum over the
entire page contents (excluding the bytes where the checksum
is stored, at the very end of the page). Such files will always
use that checksum, no matter what the parameter
innodb_checksum_algorithm is assigned to.
For old files, the old checksum algorithms will continue to be
used. The value strict_full_crc32 will be equivalent to strict_crc32
and the value full_crc32 will be equivalent to crc32.
ROW_FORMAT=COMPRESSED tables will only use the old format.
These tables do not support new features, such as larger
innodb_page_size or instant ADD/DROP COLUMN. They may be
deprecated in the future. We do not want an unnecessary
file format change for them.
The new full_crc32() format also cleans up the MariaDB tablespace
flags. We will reserve flags to store the page_compressed
compression algorithm, and to store the compressed payload length,
so that checksum can be computed over the compressed (and
possibly encrypted) stream and can be validated without
decrypting or decompressing the page.
In the full_crc32 format, there no longer are separate before-encryption
and after-encryption checksums for pages. The single checksum is
computed on the page contents that is written to the file.
We do not make the new algorithm the default for two reasons.
First, MariaDB 10.4.2 was a beta release, and the default values
of parameters should not change after beta. Second, we did not
yet implement the full_crc32 format for page_compressed pages.
This will be fixed in MDEV-18644.
This is joint work with Marko Mäkelä.
2019-02-19 20:00:00 +01:00
|
|
|
do_update = update_checksum(buf, flags);
|
2016-08-12 10:17:45 +02:00
|
|
|
|
|
|
|
if (file != stdin) {
|
|
|
|
if (do_update) {
|
|
|
|
/* Set the previous file pointer position
|
|
|
|
saved in pos to current file position. */
|
|
|
|
if (0 != fsetpos(file, pos)) {
|
|
|
|
perror("fsetpos");
|
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Store the current file position in pos */
|
|
|
|
if (0 != fgetpos(file, pos)) {
|
|
|
|
perror("fgetpos");
|
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
return(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-06 18:50:11 +01:00
|
|
|
if (physical_page_size
|
|
|
|
!= fwrite(buf, 1, physical_page_size,
|
|
|
|
file == stdin ? stdout : file)) {
|
2021-07-31 22:59:58 +02:00
|
|
|
fprintf(stderr,
|
|
|
|
"Failed to write page::" UINT32PF " to %s: %s\n",
|
2016-08-12 10:17:45 +02:00
|
|
|
cur_page_num, filename, strerror(errno));
|
|
|
|
|
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
if (file != stdin) {
|
|
|
|
fflush(file);
|
|
|
|
/* Store the current file position in pos */
|
|
|
|
if (0 != fgetpos(file, pos)) {
|
|
|
|
perror("fgetpos");
|
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return(true);
|
|
|
|
}
|
|
|
|
|
2021-06-21 13:54:26 +02:00
|
|
|
// checks using current xdes page whether the page is free
|
2021-07-31 22:59:58 +02:00
|
|
|
static inline bool is_page_free(const byte *xdes, ulint physical_page_size,
|
2021-07-22 16:53:43 +02:00
|
|
|
uint32_t page_no)
|
2021-06-21 13:54:26 +02:00
|
|
|
{
|
|
|
|
const byte *des=
|
|
|
|
xdes + XDES_ARR_OFFSET +
|
2024-11-27 08:30:51 +01:00
|
|
|
xdes_size * ((page_no & (physical_page_size - 1)) / extent_size);
|
|
|
|
return xdes_is_free(des, page_no % extent_size);
|
2021-06-21 13:54:26 +02:00
|
|
|
}
|
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
/*
|
|
|
|
Parse the page and collect/dump the information about page type
|
|
|
|
@param [in] page buffer page
|
2017-08-04 12:57:26 +02:00
|
|
|
@param [out] xdes extend descriptor page
|
2016-08-12 10:17:45 +02:00
|
|
|
@param [in] file file for diagnosis.
|
2017-08-04 12:57:26 +02:00
|
|
|
@param [in] is_encrypted tablespace is encrypted
|
2016-08-12 10:17:45 +02:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
parse_page(
|
|
|
|
const byte* page,
|
2017-08-04 12:57:26 +02:00
|
|
|
byte* xdes,
|
2016-09-29 12:59:41 +02:00
|
|
|
FILE* file,
|
2017-08-04 12:57:26 +02:00
|
|
|
bool is_encrypted)
|
2016-08-12 10:17:45 +02:00
|
|
|
{
|
2017-08-04 12:57:26 +02:00
|
|
|
unsigned long long id;
|
2021-07-22 16:53:43 +02:00
|
|
|
uint16_t undo_page_type;
|
2022-11-15 23:39:30 +01:00
|
|
|
const char *str;
|
2017-08-04 12:57:26 +02:00
|
|
|
ulint n_recs;
|
2021-07-22 16:53:43 +02:00
|
|
|
uint32_t page_no, left_page_no, right_page_no;
|
2017-08-04 12:57:26 +02:00
|
|
|
ulint data_bytes;
|
|
|
|
bool is_leaf;
|
2018-02-06 13:55:58 +01:00
|
|
|
ulint size_range_id;
|
2016-08-12 10:17:45 +02:00
|
|
|
|
|
|
|
/* Check whether page is doublewrite buffer. */
|
2022-11-15 23:39:30 +01:00
|
|
|
str = skip_page ? "Double_write_buffer" : "-";
|
2024-11-27 08:30:51 +01:00
|
|
|
page_no = mach_read_from_4(page + FIL_PAGE_OFFSET);
|
|
|
|
if (skip_freed_pages) {
|
|
|
|
const byte *des= xdes + XDES_ARR_OFFSET +
|
|
|
|
xdes_size * ((page_no & (physical_page_size - 1))
|
|
|
|
/ extent_size);
|
|
|
|
if (mach_read_from_4(des) != XDES_FSEG &&
|
|
|
|
xdes_is_free(des, page_no % extent_size)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2016-08-12 10:17:45 +02:00
|
|
|
|
2020-05-07 16:15:34 +02:00
|
|
|
switch (fil_page_get_type(page)) {
|
2016-08-12 10:17:45 +02:00
|
|
|
|
2017-08-04 12:57:26 +02:00
|
|
|
case FIL_PAGE_INDEX: {
|
2021-07-22 16:53:43 +02:00
|
|
|
uint32_t key_version = mach_read_from_4(page + FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION);
|
2016-08-12 10:17:45 +02:00
|
|
|
page_type.n_fil_page_index++;
|
2016-09-29 12:59:41 +02:00
|
|
|
|
|
|
|
/* If page is encrypted we can't read index header */
|
2017-08-04 12:57:26 +02:00
|
|
|
if (!is_encrypted) {
|
|
|
|
id = mach_read_from_8(page + PAGE_HEADER + PAGE_INDEX_ID);
|
|
|
|
n_recs = mach_read_from_2(page + PAGE_HEADER + PAGE_N_RECS);
|
|
|
|
page_no = mach_read_from_4(page + FIL_PAGE_OFFSET);
|
|
|
|
left_page_no = mach_read_from_4(page + FIL_PAGE_PREV);
|
|
|
|
right_page_no = mach_read_from_4(page + FIL_PAGE_NEXT);
|
|
|
|
ulint is_comp = mach_read_from_2(page + PAGE_HEADER + PAGE_N_HEAP) & 0x8000;
|
|
|
|
ulint level = mach_read_from_2(page + PAGE_HEADER + PAGE_LEVEL);
|
|
|
|
ulint garbage = mach_read_from_2(page + PAGE_HEADER + PAGE_GARBAGE);
|
2016-09-29 12:59:41 +02:00
|
|
|
|
|
|
|
|
2017-08-04 12:57:26 +02:00
|
|
|
data_bytes = (ulint)(mach_read_from_2(page + PAGE_HEADER + PAGE_HEAP_TOP)
|
|
|
|
- (is_comp
|
|
|
|
? PAGE_NEW_SUPREMUM_END
|
|
|
|
: PAGE_OLD_SUPREMUM_END)
|
|
|
|
- garbage);
|
2016-09-29 12:59:41 +02:00
|
|
|
|
2017-08-04 12:57:26 +02:00
|
|
|
is_leaf = (!*(const uint16*) (page + (PAGE_HEADER + PAGE_LEVEL)));
|
2016-09-29 12:59:41 +02:00
|
|
|
|
2022-03-28 18:16:14 +02:00
|
|
|
if (file) {
|
2021-07-22 16:53:43 +02:00
|
|
|
fprintf(file, "#::" UINT32PF "\t\t|\t\tIndex page\t\t\t|"
|
2017-08-04 12:57:26 +02:00
|
|
|
"\tindex id=%llu,", cur_page_num, id);
|
|
|
|
|
|
|
|
fprintf(file,
|
|
|
|
" page level=" ULINTPF
|
|
|
|
", No. of records=" ULINTPF
|
|
|
|
", garbage=" ULINTPF ", %s\n",
|
|
|
|
level, n_recs, garbage, str);
|
2016-09-29 12:59:41 +02:00
|
|
|
}
|
|
|
|
|
2017-08-04 12:57:26 +02:00
|
|
|
size_range_id = (data_bytes * SIZE_RANGES_FOR_PAGE
|
2019-02-06 18:50:11 +01:00
|
|
|
+ srv_page_size - 1) / srv_page_size;
|
2016-09-29 12:59:41 +02:00
|
|
|
|
2017-08-04 12:57:26 +02:00
|
|
|
if (size_range_id > SIZE_RANGES_FOR_PAGE + 1) {
|
|
|
|
/* data_bytes is bigger than logical_page_size */
|
|
|
|
size_range_id = SIZE_RANGES_FOR_PAGE + 1;
|
|
|
|
}
|
|
|
|
if (per_page_details) {
|
2021-07-22 16:53:43 +02:00
|
|
|
printf("index id=%llu page " UINT32PF " leaf %d n_recs " ULINTPF " data_bytes " ULINTPF
|
2017-08-04 12:57:26 +02:00
|
|
|
"\n", id, page_no, is_leaf, n_recs, data_bytes);
|
|
|
|
}
|
|
|
|
/* update per-index statistics */
|
|
|
|
{
|
2021-06-25 17:00:47 +02:00
|
|
|
per_index_stats &index = index_ids[id];
|
2021-07-31 23:19:51 +02:00
|
|
|
if (is_page_free(xdes, physical_page_size, page_no)) {
|
2017-08-04 12:57:26 +02:00
|
|
|
index.free_pages++;
|
|
|
|
return;
|
2016-09-29 12:59:41 +02:00
|
|
|
}
|
|
|
|
|
2017-08-04 12:57:26 +02:00
|
|
|
index.pages++;
|
2016-09-29 12:59:41 +02:00
|
|
|
|
2017-08-04 12:57:26 +02:00
|
|
|
if (is_leaf) {
|
|
|
|
index.leaf_pages++;
|
|
|
|
if (data_bytes > index.max_data_size) {
|
|
|
|
index.max_data_size = data_bytes;
|
|
|
|
}
|
|
|
|
struct per_page_stats pp(n_recs, data_bytes,
|
|
|
|
left_page_no, right_page_no);
|
2016-09-29 12:59:41 +02:00
|
|
|
|
2017-08-04 12:57:26 +02:00
|
|
|
index.leaves[page_no] = pp;
|
|
|
|
|
|
|
|
if (left_page_no == ULINT32_UNDEFINED) {
|
|
|
|
index.first_leaf_page = page_no;
|
|
|
|
index.count++;
|
|
|
|
}
|
2016-09-29 12:59:41 +02:00
|
|
|
}
|
|
|
|
|
2017-08-04 12:57:26 +02:00
|
|
|
index.total_n_recs += n_recs;
|
|
|
|
index.total_data_bytes += data_bytes;
|
|
|
|
index.pages_in_size_range[size_range_id] ++;
|
|
|
|
}
|
2022-03-28 18:16:14 +02:00
|
|
|
} else if (file) {
|
2021-07-22 16:53:43 +02:00
|
|
|
fprintf(file, "#::" UINT32PF "\t\t|\t\tEncrypted Index page\t\t\t|"
|
|
|
|
"\tkey_version " UINT32PF ",%s\n", cur_page_num, key_version, str);
|
2016-08-12 10:17:45 +02:00
|
|
|
}
|
2016-09-29 12:59:41 +02:00
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
break;
|
2017-08-04 12:57:26 +02:00
|
|
|
}
|
2016-08-12 10:17:45 +02:00
|
|
|
case FIL_PAGE_UNDO_LOG:
|
|
|
|
page_type.n_fil_page_undo_log++;
|
|
|
|
undo_page_type = mach_read_from_2(page +
|
|
|
|
TRX_UNDO_PAGE_HDR + TRX_UNDO_PAGE_TYPE);
|
2022-03-28 18:16:14 +02:00
|
|
|
if (file) {
|
2021-07-22 16:53:43 +02:00
|
|
|
fprintf(file, "#::" UINT32PF "\t\t|\t\tUndo log page\t\t\t|",
|
2016-08-12 10:17:45 +02:00
|
|
|
cur_page_num);
|
|
|
|
}
|
2021-06-21 11:34:07 +02:00
|
|
|
page_type.n_undo++;
|
2016-08-12 10:17:45 +02:00
|
|
|
undo_page_type = mach_read_from_2(page + TRX_UNDO_SEG_HDR +
|
|
|
|
TRX_UNDO_STATE);
|
|
|
|
switch (undo_page_type) {
|
|
|
|
case TRX_UNDO_ACTIVE:
|
|
|
|
page_type.n_undo_state_active++;
|
2022-03-28 18:16:14 +02:00
|
|
|
if (file) {
|
2016-08-12 10:17:45 +02:00
|
|
|
fprintf(file, ", %s", "Undo log of "
|
|
|
|
"an active transaction");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TRX_UNDO_CACHED:
|
|
|
|
page_type.n_undo_state_cached++;
|
2022-03-28 18:16:14 +02:00
|
|
|
if (file) {
|
2016-08-12 10:17:45 +02:00
|
|
|
fprintf(file, ", %s", "Page is "
|
|
|
|
"cached for quick reuse");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TRX_UNDO_TO_PURGE:
|
|
|
|
page_type.n_undo_state_to_purge++;
|
2022-03-28 18:16:14 +02:00
|
|
|
if (file) {
|
2016-08-12 10:17:45 +02:00
|
|
|
fprintf(file, ", %s", "Will be "
|
|
|
|
"freed in purge when all undo"
|
|
|
|
"data in it is removed");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TRX_UNDO_PREPARED:
|
|
|
|
page_type.n_undo_state_prepared++;
|
2022-03-28 18:16:14 +02:00
|
|
|
if (file) {
|
2016-08-12 10:17:45 +02:00
|
|
|
fprintf(file, ", %s", "Undo log of "
|
|
|
|
"an prepared transaction");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
page_type.n_undo_state_other++;
|
|
|
|
break;
|
|
|
|
}
|
2022-03-28 18:16:14 +02:00
|
|
|
if(file) {
|
2016-08-12 10:17:45 +02:00
|
|
|
fprintf(file, ", %s\n", str);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FIL_PAGE_INODE:
|
|
|
|
page_type.n_fil_page_inode++;
|
2022-03-28 18:16:14 +02:00
|
|
|
if (file) {
|
2021-07-22 16:53:43 +02:00
|
|
|
fprintf(file, "#::" UINT32PF "\t\t|\t\tInode page\t\t\t|"
|
2016-08-12 10:17:45 +02:00
|
|
|
"\t%s\n",cur_page_num, str);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FIL_PAGE_IBUF_FREE_LIST:
|
|
|
|
page_type.n_fil_page_ibuf_free_list++;
|
2022-03-28 18:16:14 +02:00
|
|
|
if (file) {
|
2021-07-22 16:53:43 +02:00
|
|
|
fprintf(file, "#::" UINT32PF "\t\t|\t\tInsert buffer free list"
|
2016-08-12 10:17:45 +02:00
|
|
|
" page\t|\t%s\n", cur_page_num, str);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FIL_PAGE_TYPE_ALLOCATED:
|
|
|
|
page_type.n_fil_page_type_allocated++;
|
2022-03-28 18:16:14 +02:00
|
|
|
if (file) {
|
2021-07-22 16:53:43 +02:00
|
|
|
fprintf(file, "#::" UINT32PF "\t\t|\t\tFreshly allocated "
|
2016-08-12 10:17:45 +02:00
|
|
|
"page\t\t|\t%s\n", cur_page_num, str);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FIL_PAGE_IBUF_BITMAP:
|
|
|
|
page_type.n_fil_page_ibuf_bitmap++;
|
2022-03-28 18:16:14 +02:00
|
|
|
if (file) {
|
2021-07-22 16:53:43 +02:00
|
|
|
fprintf(file, "#::" UINT32PF "\t\t|\t\tInsert Buffer "
|
2016-08-12 10:17:45 +02:00
|
|
|
"Bitmap\t\t|\t%s\n", cur_page_num, str);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FIL_PAGE_TYPE_SYS:
|
|
|
|
page_type.n_fil_page_type_sys++;
|
2022-03-28 18:16:14 +02:00
|
|
|
if (file) {
|
2021-07-22 16:53:43 +02:00
|
|
|
fprintf(file, "#::" UINT32PF "\t\t|\t\tSystem page\t\t\t|"
|
|
|
|
"\t%s\n", cur_page_num, str);
|
2016-08-12 10:17:45 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FIL_PAGE_TYPE_TRX_SYS:
|
|
|
|
page_type.n_fil_page_type_trx_sys++;
|
2022-03-28 18:16:14 +02:00
|
|
|
if (file) {
|
2021-07-22 16:53:43 +02:00
|
|
|
fprintf(file, "#::" UINT32PF "\t\t|\t\tTransaction system "
|
2016-08-12 10:17:45 +02:00
|
|
|
"page\t\t|\t%s\n", cur_page_num, str);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FIL_PAGE_TYPE_FSP_HDR:
|
|
|
|
page_type.n_fil_page_type_fsp_hdr++;
|
2022-03-28 18:16:14 +02:00
|
|
|
if (file) {
|
2021-07-22 16:53:43 +02:00
|
|
|
fprintf(file, "#::" UINT32PF "\t\t|\t\tFile Space "
|
2016-08-12 10:17:45 +02:00
|
|
|
"Header\t\t|\t%s\n", cur_page_num, str);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FIL_PAGE_TYPE_XDES:
|
|
|
|
page_type.n_fil_page_type_xdes++;
|
2022-03-28 18:16:14 +02:00
|
|
|
if (file) {
|
2021-07-22 16:53:43 +02:00
|
|
|
fprintf(file, "#::" UINT32PF "\t\t|\t\tExtent descriptor "
|
2016-08-12 10:17:45 +02:00
|
|
|
"page\t\t|\t%s\n", cur_page_num, str);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FIL_PAGE_TYPE_BLOB:
|
|
|
|
page_type.n_fil_page_type_blob++;
|
2022-03-28 18:16:14 +02:00
|
|
|
if (file) {
|
2021-07-22 16:53:43 +02:00
|
|
|
fprintf(file, "#::" UINT32PF "\t\t|\t\tBLOB page\t\t\t|\t%s\n",
|
2016-08-12 10:17:45 +02:00
|
|
|
cur_page_num, str);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FIL_PAGE_TYPE_ZBLOB:
|
|
|
|
page_type.n_fil_page_type_zblob++;
|
2022-03-28 18:16:14 +02:00
|
|
|
if (file) {
|
2021-07-22 16:53:43 +02:00
|
|
|
fprintf(file, "#::" UINT32PF "\t\t|\t\tCompressed BLOB "
|
2016-08-12 10:17:45 +02:00
|
|
|
"page\t\t|\t%s\n", cur_page_num, str);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FIL_PAGE_TYPE_ZBLOB2:
|
|
|
|
page_type.n_fil_page_type_zblob2++;
|
2022-03-28 18:16:14 +02:00
|
|
|
if (file) {
|
2021-07-22 16:53:43 +02:00
|
|
|
fprintf(file, "#::" UINT32PF "\t\t|\t\tSubsequent Compressed "
|
2016-08-12 10:17:45 +02:00
|
|
|
"BLOB page\t|\t%s\n", cur_page_num, str);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2017-08-04 12:57:26 +02:00
|
|
|
case FIL_PAGE_PAGE_COMPRESSED:
|
|
|
|
page_type.n_fil_page_type_page_compressed++;
|
2022-03-28 18:16:14 +02:00
|
|
|
if (file) {
|
2021-07-22 16:53:43 +02:00
|
|
|
fprintf(file, "#::" UINT32PF "\t\t|\t\tPage compressed "
|
2016-09-29 12:59:41 +02:00
|
|
|
"page\t|\t%s\n", cur_page_num, str);
|
2017-08-04 12:57:26 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FIL_PAGE_PAGE_COMPRESSED_ENCRYPTED:
|
|
|
|
page_type.n_fil_page_type_page_compressed_encrypted++;
|
2022-03-28 18:16:14 +02:00
|
|
|
if (file) {
|
2021-07-22 16:53:43 +02:00
|
|
|
fprintf(file, "#::" UINT32PF "\t\t|\t\tPage compressed encrypted "
|
2016-09-29 12:59:41 +02:00
|
|
|
"page\t|\t%s\n", cur_page_num, str);
|
2017-08-04 12:57:26 +02:00
|
|
|
}
|
|
|
|
break;
|
2016-08-12 10:17:45 +02:00
|
|
|
default:
|
|
|
|
page_type.n_fil_page_type_other++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
@param [in/out] file_name name of the filename
|
|
|
|
|
2018-12-21 21:06:08 +01:00
|
|
|
@retval FILE pointer if successfully created else NULL when error occurred.
|
2016-08-12 10:17:45 +02:00
|
|
|
*/
|
|
|
|
FILE*
|
|
|
|
create_file(
|
|
|
|
char* file_name)
|
|
|
|
{
|
|
|
|
FILE* file = NULL;
|
|
|
|
|
|
|
|
#ifndef _WIN32
|
|
|
|
file = fopen(file_name, "wb");
|
|
|
|
if (file == NULL) {
|
|
|
|
fprintf(stderr, "Failed to create file: %s: %s\n",
|
|
|
|
file_name, strerror(errno));
|
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
HANDLE hFile; /* handle to open file. */
|
|
|
|
int fd = 0;
|
|
|
|
hFile = CreateFile((LPCTSTR) file_name,
|
|
|
|
GENERIC_READ | GENERIC_WRITE,
|
|
|
|
FILE_SHARE_READ | FILE_SHARE_DELETE,
|
|
|
|
NULL, CREATE_NEW, NULL, NULL);
|
|
|
|
|
|
|
|
if (hFile == INVALID_HANDLE_VALUE) {
|
|
|
|
/* print the error message. */
|
|
|
|
fprintf(stderr, "Filename::%s %s\n",
|
|
|
|
file_name,
|
|
|
|
error_message(GetLastError()));
|
|
|
|
|
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get the file descriptor. */
|
|
|
|
fd= _open_osfhandle((intptr_t)hFile, _O_RDWR | _O_BINARY);
|
|
|
|
file = fdopen(fd, "wb");
|
|
|
|
#endif /* _WIN32 */
|
|
|
|
|
|
|
|
return(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Print the page type count of a tablespace.
|
|
|
|
@param [in] fil_out stream where the output goes.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
print_summary(
|
|
|
|
FILE* fil_out)
|
|
|
|
{
|
|
|
|
fprintf(fil_out, "\n================PAGE TYPE SUMMARY==============\n");
|
|
|
|
fprintf(fil_out, "#PAGE_COUNT\tPAGE_TYPE");
|
|
|
|
fprintf(fil_out, "\n===============================================\n");
|
|
|
|
fprintf(fil_out, "%8d\tIndex page\n",
|
|
|
|
page_type.n_fil_page_index);
|
|
|
|
fprintf(fil_out, "%8d\tUndo log page\n",
|
|
|
|
page_type.n_fil_page_undo_log);
|
|
|
|
fprintf(fil_out, "%8d\tInode page\n",
|
|
|
|
page_type.n_fil_page_inode);
|
|
|
|
fprintf(fil_out, "%8d\tInsert buffer free list page\n",
|
|
|
|
page_type.n_fil_page_ibuf_free_list);
|
|
|
|
fprintf(fil_out, "%8d\tFreshly allocated page\n",
|
|
|
|
page_type.n_fil_page_type_allocated);
|
|
|
|
fprintf(fil_out, "%8d\tInsert buffer bitmap\n",
|
|
|
|
page_type.n_fil_page_ibuf_bitmap);
|
|
|
|
fprintf(fil_out, "%8d\tSystem page\n",
|
|
|
|
page_type.n_fil_page_type_sys);
|
|
|
|
fprintf(fil_out, "%8d\tTransaction system page\n",
|
|
|
|
page_type.n_fil_page_type_trx_sys);
|
|
|
|
fprintf(fil_out, "%8d\tFile Space Header\n",
|
|
|
|
page_type.n_fil_page_type_fsp_hdr);
|
|
|
|
fprintf(fil_out, "%8d\tExtent descriptor page\n",
|
|
|
|
page_type.n_fil_page_type_xdes);
|
|
|
|
fprintf(fil_out, "%8d\tBLOB page\n",
|
|
|
|
page_type.n_fil_page_type_blob);
|
|
|
|
fprintf(fil_out, "%8d\tCompressed BLOB page\n",
|
|
|
|
page_type.n_fil_page_type_zblob);
|
2016-09-29 12:59:41 +02:00
|
|
|
fprintf(fil_out, "%8d\tPage compressed page\n",
|
|
|
|
page_type.n_fil_page_type_page_compressed);
|
|
|
|
fprintf(fil_out, "%8d\tPage compressed encrypted page\n",
|
|
|
|
page_type.n_fil_page_type_page_compressed_encrypted);
|
2017-08-04 12:57:26 +02:00
|
|
|
fprintf(fil_out, "%8d\tOther type of page\n",
|
2016-08-12 10:17:45 +02:00
|
|
|
page_type.n_fil_page_type_other);
|
2016-09-29 12:59:41 +02:00
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
fprintf(fil_out, "\n===============================================\n");
|
|
|
|
fprintf(fil_out, "Additional information:\n");
|
2021-06-21 11:34:07 +02:00
|
|
|
fprintf(fil_out, "Undo page type: %d\n", page_type.n_undo);
|
|
|
|
fprintf(fil_out, "Undo page state: %d active, %d cached, %d"
|
2016-08-12 10:17:45 +02:00
|
|
|
" to_purge, %d prepared, %d other\n",
|
|
|
|
page_type.n_undo_state_active,
|
|
|
|
page_type.n_undo_state_cached,
|
|
|
|
page_type.n_undo_state_to_purge,
|
|
|
|
page_type.n_undo_state_prepared,
|
|
|
|
page_type.n_undo_state_other);
|
2016-09-29 12:59:41 +02:00
|
|
|
|
|
|
|
fprintf(fil_out, "index_id\t#pages\t\t#leaf_pages\t#recs_per_page"
|
|
|
|
"\t#bytes_per_page\n");
|
|
|
|
|
2023-07-10 12:46:34 +02:00
|
|
|
for (const auto &ids : index_ids) {
|
|
|
|
const per_index_stats& index = ids.second;
|
|
|
|
if (!index.pages) {
|
|
|
|
DBUG_ASSERT(index.free_pages);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-09-29 12:59:41 +02:00
|
|
|
fprintf(fil_out, "%lld\t\t%lld\t\t%lld\t\t%lld\t\t%lld\n",
|
2023-07-10 12:46:34 +02:00
|
|
|
ids.first, index.pages, index.leaf_pages,
|
2016-09-29 12:59:41 +02:00
|
|
|
index.total_n_recs / index.pages,
|
|
|
|
index.total_data_bytes / index.pages);
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(fil_out, "\n");
|
|
|
|
fprintf(fil_out, "index_id\tpage_data_bytes_histgram(empty,...,oversized)\n");
|
|
|
|
|
|
|
|
for (std::map<unsigned long long, per_index_stats>::const_iterator it = index_ids.begin();
|
|
|
|
it != index_ids.end(); it++) {
|
|
|
|
fprintf(fil_out, "%lld\t", it->first);
|
|
|
|
const per_index_stats& index = it->second;
|
|
|
|
for (ulint i = 0; i < SIZE_RANGES_FOR_PAGE+2; i++) {
|
|
|
|
fprintf(fil_out, "\t%lld", index.pages_in_size_range[i]);
|
|
|
|
}
|
|
|
|
fprintf(fil_out, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (do_leaf) {
|
|
|
|
print_leaf_stats(fil_out);
|
|
|
|
}
|
2016-08-12 10:17:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* command line argument for innochecksum tool. */
|
|
|
|
static struct my_option innochecksum_options[] = {
|
2014-02-28 07:53:09 +01:00
|
|
|
{"help", '?', "Displays this help and exits.",
|
|
|
|
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
|
|
|
|
{"info", 'I', "Synonym for --help.",
|
|
|
|
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
|
|
|
|
{"version", 'V', "Displays version information and exits.",
|
|
|
|
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
|
|
|
|
{"verbose", 'v', "Verbose (prints progress every 5 seconds).",
|
|
|
|
&verbose, &verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
|
2017-08-04 12:57:26 +02:00
|
|
|
#ifndef DBUG_OFF
|
2019-04-29 14:05:25 +02:00
|
|
|
{"debug", '#', "Output debug log. See https://mariadb.com/kb/en/library/creating-a-trace-file/",
|
2016-08-12 10:17:45 +02:00
|
|
|
&dbug_setting, &dbug_setting, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
|
2017-08-04 12:57:26 +02:00
|
|
|
#endif /* !DBUG_OFF */
|
2016-08-12 10:17:45 +02:00
|
|
|
{"count", 'c', "Print the count of pages in the file and exits.",
|
2014-02-28 07:53:09 +01:00
|
|
|
&just_count, &just_count, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
|
|
|
|
{"start_page", 's', "Start on this page number (0 based).",
|
2021-07-22 16:53:43 +02:00
|
|
|
&start_page, &start_page, 0, GET_UINT, REQUIRED_ARG,
|
|
|
|
0, 0, FIL_NULL, 0, 1, 0},
|
2014-02-28 07:53:09 +01:00
|
|
|
{"end_page", 'e', "End at this page number (0 based).",
|
2021-07-22 16:53:43 +02:00
|
|
|
&end_page, &end_page, 0, GET_UINT, REQUIRED_ARG,
|
|
|
|
0, 0, FIL_NULL, 0, 1, 0},
|
2014-02-28 07:53:09 +01:00
|
|
|
{"page", 'p', "Check only this page (0 based).",
|
2021-07-22 16:53:43 +02:00
|
|
|
&do_page, &do_page, 0, GET_UINT, REQUIRED_ARG,
|
|
|
|
0, 0, FIL_NULL, 0, 1, 0},
|
2016-08-12 10:17:45 +02:00
|
|
|
{"no-check", 'n', "Ignore the checksum verification.",
|
|
|
|
&no_check, &no_check, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
|
|
|
|
{"allow-mismatches", 'a', "Maximum checksum mismatch allowed.",
|
|
|
|
&allow_mismatches, &allow_mismatches, 0,
|
|
|
|
GET_ULL, REQUIRED_ARG, 0, 0, ULLONG_MAX, 0, 1, 0},
|
2022-03-28 10:35:10 +02:00
|
|
|
{"write", 'w', "Rewrite the checksum.",
|
|
|
|
&do_write, &do_write, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
|
2016-08-12 10:17:45 +02:00
|
|
|
{"page-type-summary", 'S', "Display a count of each page type "
|
|
|
|
"in a tablespace.", &page_type_summary, &page_type_summary, 0,
|
|
|
|
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
|
|
|
|
{"page-type-dump", 'D', "Dump the page type info for each page in a "
|
|
|
|
"tablespace.", &page_dump_filename, &page_dump_filename, 0,
|
|
|
|
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
|
2017-08-04 12:57:26 +02:00
|
|
|
{"per-page-details", 'i', "Print out per-page detail information.",
|
|
|
|
&per_page_details, &per_page_details, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
|
2016-08-12 10:17:45 +02:00
|
|
|
{"log", 'l', "log output.",
|
|
|
|
&log_filename, &log_filename, 0,
|
|
|
|
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
|
2017-08-04 12:57:26 +02:00
|
|
|
{"leaf", 'f', "Examine leaf index pages",
|
2016-09-29 12:59:41 +02:00
|
|
|
&do_leaf, &do_leaf, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
|
|
|
|
{"merge", 'm', "leaf page count if merge given number of consecutive pages",
|
|
|
|
&n_merge, &n_merge, 0, GET_ULONG, REQUIRED_ARG, 0, 0, (longlong)10L, 0, 1, 0},
|
2024-11-27 08:30:51 +01:00
|
|
|
{"skip-freed-pages", 'r', "skip freed pages for the tablespace",
|
|
|
|
&skip_freed_pages, &skip_freed_pages, 0, GET_BOOL, NO_ARG,
|
|
|
|
0, 0, 0, 0, 0, 0},
|
2016-08-12 10:17:45 +02:00
|
|
|
|
2014-02-28 07:53:09 +01:00
|
|
|
{0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
static void usage(void)
|
|
|
|
{
|
2016-08-12 10:17:45 +02:00
|
|
|
print_version();
|
|
|
|
puts(ORACLE_WELCOME_COPYRIGHT_NOTICE("2000"));
|
|
|
|
printf("InnoDB offline file checksum utility.\n");
|
2024-11-27 08:30:51 +01:00
|
|
|
printf("Usage: %s [-c] [-r] [-s <start page>] [-e <end page>] "
|
2017-08-04 12:57:26 +02:00
|
|
|
"[-p <page>] [-i] [-v] [-a <allow mismatches>] [-n] "
|
MDEV-25105 Remove innodb_checksum_algorithm values none,innodb,...
Historically, InnoDB supported a buggy page checksum algorithm that did not
compute a checksum over the full page. Later, well before MySQL 4.1
introduced .ibd files and the innodb_file_per_table option, the algorithm
was corrected and the first 4 bytes of each page were redefined to be
a checksum.
The original checksum was so slow that an option to disable page checksum
was introduced for benchmarketing purposes.
The Intel Nehalem microarchitecture introduced the SSE4.2 instruction set
extension, which includes instructions for faster computation of CRC-32C.
In MySQL 5.6 (and MariaDB 10.0), innodb_checksum_algorithm=crc32 was
implemented to make of that. As that option was changed to be the default
in MySQL 5.7, a bug was found on big-endian platforms and some work-around
code was added to weaken that checksum further. MariaDB disables that
work-around by default since MDEV-17958.
Later, SIMD-accelerated CRC-32C has been implemented in MariaDB for POWER
and ARM and also for IA-32/AMD64, making use of carry-less multiplication
where available.
Long story short, innodb_checksum_algorithm=crc32 is faster and more secure
than the pre-MySQL 5.6 checksum, called innodb_checksum_algorithm=innodb.
It should have removed any need to use innodb_checksum_algorithm=none.
The setting innodb_checksum_algorithm=crc32 is the default in
MySQL 5.7 and MariaDB Server 10.2, 10.3, 10.4. In MariaDB 10.5,
MDEV-19534 made innodb_checksum_algorithm=full_crc32 the default.
It is even faster and more secure.
The default settings in MariaDB do allow old data files to be read,
no matter if a worse checksum algorithm had been used.
(Unfortunately, before innodb_checksum_algorithm=full_crc32,
the data files did not identify which checksum algorithm is being used.)
The non-default settings innodb_checksum_algorithm=strict_crc32 or
innodb_checksum_algorithm=strict_full_crc32 would only allow CRC-32C
checksums. The incompatibility with old data files is why they are
not the default.
The newest server not to support innodb_checksum_algorithm=crc32
were MySQL 5.5 and MariaDB 5.5. Both have reached their end of life.
A valid reason for using innodb_checksum_algorithm=innodb could have
been the ability to downgrade. If it is really needed, data files
can be converted with an older version of the innochecksum utility.
Because there is no good reason to allow data files to be written
with insecure checksums, we will reject those option values:
innodb_checksum_algorithm=none
innodb_checksum_algorithm=innodb
innodb_checksum_algorithm=strict_none
innodb_checksum_algorithm=strict_innodb
Furthermore, the following innochecksum options will be removed,
because only strict crc32 will be supported:
innochecksum --strict-check=crc32
innochecksum -C crc32
innochecksum --write=crc32
innochecksum -w crc32
If a user wishes to convert a data file to use a different checksum
(so that it might be used with the no-longer-supported
MySQL 5.5 or MariaDB 5.5, which do not support IMPORT TABLESPACE
nor system tablespace format changes that were made in MariaDB 10.3),
then the innochecksum tool from MariaDB 10.2, 10.3, 10.4, 10.5 or
MySQL 5.7 can be used.
Reviewed by: Thirunarayanan Balathandayuthapani
2021-03-11 10:56:35 +01:00
|
|
|
"[-S] [-D <page type dump>] "
|
2017-08-04 12:57:26 +02:00
|
|
|
"[-l <log>] [-l] [-m <merge pages>] <filename or [-]>\n", my_progname);
|
2019-04-29 14:05:25 +02:00
|
|
|
printf("See https://mariadb.com/kb/en/library/innochecksum/"
|
|
|
|
" for usage hints.\n");
|
2016-08-12 10:17:45 +02:00
|
|
|
my_print_help(innochecksum_options);
|
|
|
|
my_print_variables(innochecksum_options);
|
2014-02-28 07:53:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" my_bool
|
|
|
|
innochecksum_get_one_option(
|
2019-09-29 16:30:57 +02:00
|
|
|
const struct my_option *opt,
|
2024-11-27 08:30:51 +01:00
|
|
|
const char *IF_DBUG(argument,),
|
|
|
|
const char *)
|
2014-02-28 07:53:09 +01:00
|
|
|
{
|
2019-09-29 16:30:57 +02:00
|
|
|
switch (opt->id) {
|
2016-08-12 10:17:45 +02:00
|
|
|
#ifndef DBUG_OFF
|
|
|
|
case '#':
|
|
|
|
dbug_setting = argument
|
|
|
|
? argument
|
|
|
|
: IF_WIN("d:O,innochecksum.trace",
|
|
|
|
"d:o,/tmp/innochecksum.trace");
|
|
|
|
DBUG_PUSH(dbug_setting);
|
|
|
|
break;
|
|
|
|
#endif /* !DBUG_OFF */
|
|
|
|
case 'e':
|
|
|
|
use_end_page = true;
|
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
end_page = start_page = do_page;
|
|
|
|
use_end_page = true;
|
|
|
|
do_one_page = true;
|
|
|
|
break;
|
|
|
|
case 'V':
|
|
|
|
print_version();
|
2016-09-29 12:59:41 +02:00
|
|
|
my_end(0);
|
2016-08-12 10:17:45 +02:00
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
break;
|
|
|
|
case 'D':
|
|
|
|
page_type_dump = true;
|
|
|
|
break;
|
|
|
|
case 'l':
|
|
|
|
is_log_enabled = true;
|
|
|
|
break;
|
|
|
|
case 'I':
|
|
|
|
case '?':
|
|
|
|
usage();
|
2016-09-29 12:59:41 +02:00
|
|
|
my_end(0);
|
2016-08-12 10:17:45 +02:00
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
break;
|
|
|
|
}
|
2014-02-28 07:53:09 +01:00
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
return(false);
|
2015-03-03 16:38:02 +01:00
|
|
|
}
|
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
static
|
|
|
|
bool
|
|
|
|
get_options(
|
|
|
|
int *argc,
|
|
|
|
char ***argv)
|
2015-03-03 16:38:02 +01:00
|
|
|
{
|
2016-08-12 10:17:45 +02:00
|
|
|
if (handle_options(argc, argv, innochecksum_options,
|
2017-08-04 12:57:26 +02:00
|
|
|
innochecksum_get_one_option)) {
|
2016-09-29 12:59:41 +02:00
|
|
|
my_end(0);
|
2016-08-12 10:17:45 +02:00
|
|
|
exit(true);
|
2016-09-29 12:59:41 +02:00
|
|
|
}
|
2016-08-12 10:17:45 +02:00
|
|
|
|
|
|
|
/* The next arg must be the filename */
|
|
|
|
if (!*argc) {
|
|
|
|
usage();
|
2016-09-29 12:59:41 +02:00
|
|
|
my_end(0);
|
2016-08-12 10:17:45 +02:00
|
|
|
return (true);
|
|
|
|
}
|
2015-03-03 16:38:02 +01:00
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
return (false);
|
2015-03-03 16:38:02 +01:00
|
|
|
}
|
|
|
|
|
2017-08-04 12:57:26 +02:00
|
|
|
/** Check from page 0 if table is encrypted.
|
|
|
|
@param[in] filename Filename
|
|
|
|
@param[in] page Page 0
|
|
|
|
@retval true if tablespace is encrypted, false if not
|
|
|
|
*/
|
2019-02-06 18:50:11 +01:00
|
|
|
static bool check_encryption(const char* filename, const byte* page)
|
2017-08-04 12:57:26 +02:00
|
|
|
{
|
2024-11-27 08:30:51 +01:00
|
|
|
ulint offset = FSP_HEADER_OFFSET + XDES_ARR_OFFSET + xdes_size *
|
|
|
|
physical_page_size / extent_size;
|
2017-08-04 12:57:26 +02:00
|
|
|
|
|
|
|
if (memcmp(page + offset, CRYPT_MAGIC, MAGIC_SZ) != 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ulint type = mach_read_from_1(page + offset + MAGIC_SZ + 0);
|
|
|
|
|
|
|
|
if (! (type == CRYPT_SCHEME_UNENCRYPTED ||
|
|
|
|
type == CRYPT_SCHEME_1)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ulint iv_length = mach_read_from_1(page + offset + MAGIC_SZ + 1);
|
|
|
|
|
|
|
|
if (iv_length != CRYPT_SCHEME_1_IV_LEN) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-07-22 16:53:43 +02:00
|
|
|
uint32_t min_key_version = mach_read_from_4
|
2017-08-04 12:57:26 +02:00
|
|
|
(page + offset + MAGIC_SZ + 2 + iv_length);
|
|
|
|
|
2021-07-22 16:53:43 +02:00
|
|
|
uint32_t key_id = mach_read_from_4
|
2017-08-04 12:57:26 +02:00
|
|
|
(page + offset + MAGIC_SZ + 2 + iv_length + 4);
|
|
|
|
|
|
|
|
if (type == CRYPT_SCHEME_1 && is_log_enabled) {
|
2021-07-22 16:53:43 +02:00
|
|
|
fprintf(log_file,"Tablespace %s encrypted key_version " UINT32PF " key_id " UINT32PF "\n",
|
2017-08-04 12:57:26 +02:00
|
|
|
filename, min_key_version, key_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (type == CRYPT_SCHEME_1);
|
|
|
|
}
|
|
|
|
|
MDEV-12026: Implement innodb_checksum_algorithm=full_crc32
MariaDB data-at-rest encryption (innodb_encrypt_tables)
had repurposed the same unused data field that was repurposed
in MySQL 5.7 (and MariaDB 10.2) for the Split Sequence Number (SSN)
field of SPATIAL INDEX. Because of this, MariaDB was unable to
support encryption on SPATIAL INDEX pages.
Furthermore, InnoDB page checksums skipped some bytes, and there
are multiple variations and checksum algorithms. By default,
InnoDB accepts all variations of all algorithms that ever existed.
This unnecessarily weakens the page checksums.
We hereby introduce two more innodb_checksum_algorithm variants
(full_crc32, strict_full_crc32) that are special in a way:
When either setting is active, newly created data files will
carry a flag (fil_space_t::full_crc32()) that indicates that
all pages of the file will use a full CRC-32C checksum over the
entire page contents (excluding the bytes where the checksum
is stored, at the very end of the page). Such files will always
use that checksum, no matter what the parameter
innodb_checksum_algorithm is assigned to.
For old files, the old checksum algorithms will continue to be
used. The value strict_full_crc32 will be equivalent to strict_crc32
and the value full_crc32 will be equivalent to crc32.
ROW_FORMAT=COMPRESSED tables will only use the old format.
These tables do not support new features, such as larger
innodb_page_size or instant ADD/DROP COLUMN. They may be
deprecated in the future. We do not want an unnecessary
file format change for them.
The new full_crc32() format also cleans up the MariaDB tablespace
flags. We will reserve flags to store the page_compressed
compression algorithm, and to store the compressed payload length,
so that checksum can be computed over the compressed (and
possibly encrypted) stream and can be validated without
decrypting or decompressing the page.
In the full_crc32 format, there no longer are separate before-encryption
and after-encryption checksums for pages. The single checksum is
computed on the page contents that is written to the file.
We do not make the new algorithm the default for two reasons.
First, MariaDB 10.4.2 was a beta release, and the default values
of parameters should not change after beta. Second, we did not
yet implement the full_crc32 format for page_compressed pages.
This will be fixed in MDEV-18644.
This is joint work with Marko Mäkelä.
2019-02-19 20:00:00 +01:00
|
|
|
/** Verify page checksum.
|
2017-08-04 12:57:26 +02:00
|
|
|
@param[in] buf page to verify
|
2019-02-06 18:50:11 +01:00
|
|
|
@param[in] zip_size ROW_FORMAT=COMPRESSED page size, or 0
|
2017-08-04 12:57:26 +02:00
|
|
|
@param[in] is_encrypted true if tablespace is encrypted
|
|
|
|
@param[in,out] mismatch_count Number of pages failed in checksum verify
|
MDEV-12026: Implement innodb_checksum_algorithm=full_crc32
MariaDB data-at-rest encryption (innodb_encrypt_tables)
had repurposed the same unused data field that was repurposed
in MySQL 5.7 (and MariaDB 10.2) for the Split Sequence Number (SSN)
field of SPATIAL INDEX. Because of this, MariaDB was unable to
support encryption on SPATIAL INDEX pages.
Furthermore, InnoDB page checksums skipped some bytes, and there
are multiple variations and checksum algorithms. By default,
InnoDB accepts all variations of all algorithms that ever existed.
This unnecessarily weakens the page checksums.
We hereby introduce two more innodb_checksum_algorithm variants
(full_crc32, strict_full_crc32) that are special in a way:
When either setting is active, newly created data files will
carry a flag (fil_space_t::full_crc32()) that indicates that
all pages of the file will use a full CRC-32C checksum over the
entire page contents (excluding the bytes where the checksum
is stored, at the very end of the page). Such files will always
use that checksum, no matter what the parameter
innodb_checksum_algorithm is assigned to.
For old files, the old checksum algorithms will continue to be
used. The value strict_full_crc32 will be equivalent to strict_crc32
and the value full_crc32 will be equivalent to crc32.
ROW_FORMAT=COMPRESSED tables will only use the old format.
These tables do not support new features, such as larger
innodb_page_size or instant ADD/DROP COLUMN. They may be
deprecated in the future. We do not want an unnecessary
file format change for them.
The new full_crc32() format also cleans up the MariaDB tablespace
flags. We will reserve flags to store the page_compressed
compression algorithm, and to store the compressed payload length,
so that checksum can be computed over the compressed (and
possibly encrypted) stream and can be validated without
decrypting or decompressing the page.
In the full_crc32 format, there no longer are separate before-encryption
and after-encryption checksums for pages. The single checksum is
computed on the page contents that is written to the file.
We do not make the new algorithm the default for two reasons.
First, MariaDB 10.4.2 was a beta release, and the default values
of parameters should not change after beta. Second, we did not
yet implement the full_crc32 format for page_compressed pages.
This will be fixed in MDEV-18644.
This is joint work with Marko Mäkelä.
2019-02-19 20:00:00 +01:00
|
|
|
@param[in] flags tablespace flags
|
|
|
|
@retval 0 if page checksum matches or 1 if it does not match */
|
|
|
|
static int verify_checksum(
|
|
|
|
byte* buf,
|
|
|
|
bool is_encrypted,
|
|
|
|
unsigned long long* mismatch_count,
|
2021-07-22 13:36:30 +02:00
|
|
|
uint32_t flags)
|
2017-08-04 12:57:26 +02:00
|
|
|
{
|
|
|
|
int exit_status = 0;
|
MDEV-12026: Implement innodb_checksum_algorithm=full_crc32
MariaDB data-at-rest encryption (innodb_encrypt_tables)
had repurposed the same unused data field that was repurposed
in MySQL 5.7 (and MariaDB 10.2) for the Split Sequence Number (SSN)
field of SPATIAL INDEX. Because of this, MariaDB was unable to
support encryption on SPATIAL INDEX pages.
Furthermore, InnoDB page checksums skipped some bytes, and there
are multiple variations and checksum algorithms. By default,
InnoDB accepts all variations of all algorithms that ever existed.
This unnecessarily weakens the page checksums.
We hereby introduce two more innodb_checksum_algorithm variants
(full_crc32, strict_full_crc32) that are special in a way:
When either setting is active, newly created data files will
carry a flag (fil_space_t::full_crc32()) that indicates that
all pages of the file will use a full CRC-32C checksum over the
entire page contents (excluding the bytes where the checksum
is stored, at the very end of the page). Such files will always
use that checksum, no matter what the parameter
innodb_checksum_algorithm is assigned to.
For old files, the old checksum algorithms will continue to be
used. The value strict_full_crc32 will be equivalent to strict_crc32
and the value full_crc32 will be equivalent to crc32.
ROW_FORMAT=COMPRESSED tables will only use the old format.
These tables do not support new features, such as larger
innodb_page_size or instant ADD/DROP COLUMN. They may be
deprecated in the future. We do not want an unnecessary
file format change for them.
The new full_crc32() format also cleans up the MariaDB tablespace
flags. We will reserve flags to store the page_compressed
compression algorithm, and to store the compressed payload length,
so that checksum can be computed over the compressed (and
possibly encrypted) stream and can be validated without
decrypting or decompressing the page.
In the full_crc32 format, there no longer are separate before-encryption
and after-encryption checksums for pages. The single checksum is
computed on the page contents that is written to the file.
We do not make the new algorithm the default for two reasons.
First, MariaDB 10.4.2 was a beta release, and the default values
of parameters should not change after beta. Second, we did not
yet implement the full_crc32 format for page_compressed pages.
This will be fixed in MDEV-18644.
This is joint work with Marko Mäkelä.
2019-02-19 20:00:00 +01:00
|
|
|
if (is_page_corrupted(buf, is_encrypted, flags)) {
|
2021-07-22 16:53:43 +02:00
|
|
|
fprintf(stderr, "Fail: page::" UINT32PF " invalid\n",
|
2017-08-04 12:57:26 +02:00
|
|
|
cur_page_num);
|
|
|
|
|
|
|
|
(*mismatch_count)++;
|
|
|
|
|
|
|
|
if (*mismatch_count > allow_mismatches) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"Exceeded the "
|
|
|
|
"maximum allowed "
|
|
|
|
"checksum mismatch "
|
|
|
|
"count::%llu current::%llu\n",
|
|
|
|
*mismatch_count,
|
|
|
|
allow_mismatches);
|
|
|
|
|
|
|
|
exit_status = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (exit_status);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Rewrite page checksum if needed.
|
|
|
|
@param[in] filename File name
|
|
|
|
@param[in] fil_in File pointer
|
|
|
|
@param[in] buf page
|
|
|
|
@param[in] pos File position
|
|
|
|
@param[in] is_encrypted true if tablespace is encrypted
|
MDEV-12026: Implement innodb_checksum_algorithm=full_crc32
MariaDB data-at-rest encryption (innodb_encrypt_tables)
had repurposed the same unused data field that was repurposed
in MySQL 5.7 (and MariaDB 10.2) for the Split Sequence Number (SSN)
field of SPATIAL INDEX. Because of this, MariaDB was unable to
support encryption on SPATIAL INDEX pages.
Furthermore, InnoDB page checksums skipped some bytes, and there
are multiple variations and checksum algorithms. By default,
InnoDB accepts all variations of all algorithms that ever existed.
This unnecessarily weakens the page checksums.
We hereby introduce two more innodb_checksum_algorithm variants
(full_crc32, strict_full_crc32) that are special in a way:
When either setting is active, newly created data files will
carry a flag (fil_space_t::full_crc32()) that indicates that
all pages of the file will use a full CRC-32C checksum over the
entire page contents (excluding the bytes where the checksum
is stored, at the very end of the page). Such files will always
use that checksum, no matter what the parameter
innodb_checksum_algorithm is assigned to.
For old files, the old checksum algorithms will continue to be
used. The value strict_full_crc32 will be equivalent to strict_crc32
and the value full_crc32 will be equivalent to crc32.
ROW_FORMAT=COMPRESSED tables will only use the old format.
These tables do not support new features, such as larger
innodb_page_size or instant ADD/DROP COLUMN. They may be
deprecated in the future. We do not want an unnecessary
file format change for them.
The new full_crc32() format also cleans up the MariaDB tablespace
flags. We will reserve flags to store the page_compressed
compression algorithm, and to store the compressed payload length,
so that checksum can be computed over the compressed (and
possibly encrypted) stream and can be validated without
decrypting or decompressing the page.
In the full_crc32 format, there no longer are separate before-encryption
and after-encryption checksums for pages. The single checksum is
computed on the page contents that is written to the file.
We do not make the new algorithm the default for two reasons.
First, MariaDB 10.4.2 was a beta release, and the default values
of parameters should not change after beta. Second, we did not
yet implement the full_crc32 format for page_compressed pages.
This will be fixed in MDEV-18644.
This is joint work with Marko Mäkelä.
2019-02-19 20:00:00 +01:00
|
|
|
@param[in] flags tablespace flags
|
2017-08-04 12:57:26 +02:00
|
|
|
@retval 0 if checksum rewrite was successful, 1 if error was detected */
|
|
|
|
static
|
|
|
|
int
|
|
|
|
rewrite_checksum(
|
|
|
|
const char* filename,
|
|
|
|
FILE* fil_in,
|
|
|
|
byte* buf,
|
|
|
|
fpos_t* pos,
|
MDEV-12026: Implement innodb_checksum_algorithm=full_crc32
MariaDB data-at-rest encryption (innodb_encrypt_tables)
had repurposed the same unused data field that was repurposed
in MySQL 5.7 (and MariaDB 10.2) for the Split Sequence Number (SSN)
field of SPATIAL INDEX. Because of this, MariaDB was unable to
support encryption on SPATIAL INDEX pages.
Furthermore, InnoDB page checksums skipped some bytes, and there
are multiple variations and checksum algorithms. By default,
InnoDB accepts all variations of all algorithms that ever existed.
This unnecessarily weakens the page checksums.
We hereby introduce two more innodb_checksum_algorithm variants
(full_crc32, strict_full_crc32) that are special in a way:
When either setting is active, newly created data files will
carry a flag (fil_space_t::full_crc32()) that indicates that
all pages of the file will use a full CRC-32C checksum over the
entire page contents (excluding the bytes where the checksum
is stored, at the very end of the page). Such files will always
use that checksum, no matter what the parameter
innodb_checksum_algorithm is assigned to.
For old files, the old checksum algorithms will continue to be
used. The value strict_full_crc32 will be equivalent to strict_crc32
and the value full_crc32 will be equivalent to crc32.
ROW_FORMAT=COMPRESSED tables will only use the old format.
These tables do not support new features, such as larger
innodb_page_size or instant ADD/DROP COLUMN. They may be
deprecated in the future. We do not want an unnecessary
file format change for them.
The new full_crc32() format also cleans up the MariaDB tablespace
flags. We will reserve flags to store the page_compressed
compression algorithm, and to store the compressed payload length,
so that checksum can be computed over the compressed (and
possibly encrypted) stream and can be validated without
decrypting or decompressing the page.
In the full_crc32 format, there no longer are separate before-encryption
and after-encryption checksums for pages. The single checksum is
computed on the page contents that is written to the file.
We do not make the new algorithm the default for two reasons.
First, MariaDB 10.4.2 was a beta release, and the default values
of parameters should not change after beta. Second, we did not
yet implement the full_crc32 format for page_compressed pages.
This will be fixed in MDEV-18644.
This is joint work with Marko Mäkelä.
2019-02-19 20:00:00 +01:00
|
|
|
bool is_encrypted,
|
2021-07-22 13:36:30 +02:00
|
|
|
uint32_t flags)
|
2017-08-04 12:57:26 +02:00
|
|
|
{
|
MDEV-12026: Implement innodb_checksum_algorithm=full_crc32
MariaDB data-at-rest encryption (innodb_encrypt_tables)
had repurposed the same unused data field that was repurposed
in MySQL 5.7 (and MariaDB 10.2) for the Split Sequence Number (SSN)
field of SPATIAL INDEX. Because of this, MariaDB was unable to
support encryption on SPATIAL INDEX pages.
Furthermore, InnoDB page checksums skipped some bytes, and there
are multiple variations and checksum algorithms. By default,
InnoDB accepts all variations of all algorithms that ever existed.
This unnecessarily weakens the page checksums.
We hereby introduce two more innodb_checksum_algorithm variants
(full_crc32, strict_full_crc32) that are special in a way:
When either setting is active, newly created data files will
carry a flag (fil_space_t::full_crc32()) that indicates that
all pages of the file will use a full CRC-32C checksum over the
entire page contents (excluding the bytes where the checksum
is stored, at the very end of the page). Such files will always
use that checksum, no matter what the parameter
innodb_checksum_algorithm is assigned to.
For old files, the old checksum algorithms will continue to be
used. The value strict_full_crc32 will be equivalent to strict_crc32
and the value full_crc32 will be equivalent to crc32.
ROW_FORMAT=COMPRESSED tables will only use the old format.
These tables do not support new features, such as larger
innodb_page_size or instant ADD/DROP COLUMN. They may be
deprecated in the future. We do not want an unnecessary
file format change for them.
The new full_crc32() format also cleans up the MariaDB tablespace
flags. We will reserve flags to store the page_compressed
compression algorithm, and to store the compressed payload length,
so that checksum can be computed over the compressed (and
possibly encrypted) stream and can be validated without
decrypting or decompressing the page.
In the full_crc32 format, there no longer are separate before-encryption
and after-encryption checksums for pages. The single checksum is
computed on the page contents that is written to the file.
We do not make the new algorithm the default for two reasons.
First, MariaDB 10.4.2 was a beta release, and the default values
of parameters should not change after beta. Second, we did not
yet implement the full_crc32 format for page_compressed pages.
This will be fixed in MDEV-18644.
This is joint work with Marko Mäkelä.
2019-02-19 20:00:00 +01:00
|
|
|
bool is_compressed = fil_space_t::is_compressed(flags);
|
|
|
|
|
2017-08-04 12:57:26 +02:00
|
|
|
/* Rewrite checksum. Note that for encrypted and
|
|
|
|
page compressed tables this is not currently supported. */
|
MDEV-12026: Implement innodb_checksum_algorithm=full_crc32
MariaDB data-at-rest encryption (innodb_encrypt_tables)
had repurposed the same unused data field that was repurposed
in MySQL 5.7 (and MariaDB 10.2) for the Split Sequence Number (SSN)
field of SPATIAL INDEX. Because of this, MariaDB was unable to
support encryption on SPATIAL INDEX pages.
Furthermore, InnoDB page checksums skipped some bytes, and there
are multiple variations and checksum algorithms. By default,
InnoDB accepts all variations of all algorithms that ever existed.
This unnecessarily weakens the page checksums.
We hereby introduce two more innodb_checksum_algorithm variants
(full_crc32, strict_full_crc32) that are special in a way:
When either setting is active, newly created data files will
carry a flag (fil_space_t::full_crc32()) that indicates that
all pages of the file will use a full CRC-32C checksum over the
entire page contents (excluding the bytes where the checksum
is stored, at the very end of the page). Such files will always
use that checksum, no matter what the parameter
innodb_checksum_algorithm is assigned to.
For old files, the old checksum algorithms will continue to be
used. The value strict_full_crc32 will be equivalent to strict_crc32
and the value full_crc32 will be equivalent to crc32.
ROW_FORMAT=COMPRESSED tables will only use the old format.
These tables do not support new features, such as larger
innodb_page_size or instant ADD/DROP COLUMN. They may be
deprecated in the future. We do not want an unnecessary
file format change for them.
The new full_crc32() format also cleans up the MariaDB tablespace
flags. We will reserve flags to store the page_compressed
compression algorithm, and to store the compressed payload length,
so that checksum can be computed over the compressed (and
possibly encrypted) stream and can be validated without
decrypting or decompressing the page.
In the full_crc32 format, there no longer are separate before-encryption
and after-encryption checksums for pages. The single checksum is
computed on the page contents that is written to the file.
We do not make the new algorithm the default for two reasons.
First, MariaDB 10.4.2 was a beta release, and the default values
of parameters should not change after beta. Second, we did not
yet implement the full_crc32 format for page_compressed pages.
This will be fixed in MDEV-18644.
This is joint work with Marko Mäkelä.
2019-02-19 20:00:00 +01:00
|
|
|
return do_write && !is_encrypted && !is_compressed
|
|
|
|
&& !write_file(filename, fil_in, buf, flags, pos);
|
2017-08-04 12:57:26 +02:00
|
|
|
}
|
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
int main(
|
|
|
|
int argc,
|
|
|
|
char **argv)
|
2015-03-03 16:38:02 +01:00
|
|
|
{
|
2016-08-12 10:17:45 +02:00
|
|
|
/* our input file. */
|
|
|
|
FILE* fil_in = NULL;
|
|
|
|
/* our input filename. */
|
|
|
|
char* filename;
|
|
|
|
/* Buffer to store pages read. */
|
|
|
|
byte* buf = NULL;
|
2016-09-29 12:59:41 +02:00
|
|
|
byte* xdes = NULL;
|
2016-08-12 10:17:45 +02:00
|
|
|
/* bytes read count */
|
2017-09-19 19:45:17 +02:00
|
|
|
ulint bytes;
|
2016-08-12 10:17:45 +02:00
|
|
|
/* last time */
|
2019-08-15 14:29:03 +02:00
|
|
|
time_t lastt = 0;
|
2016-08-12 10:17:45 +02:00
|
|
|
/* stat, to get file size. */
|
|
|
|
#ifdef _WIN32
|
|
|
|
struct _stat64 st;
|
|
|
|
#else
|
|
|
|
struct stat st;
|
|
|
|
#endif /* _WIN32 */
|
|
|
|
|
2017-08-04 12:57:26 +02:00
|
|
|
int exit_status = 0;
|
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
/* size of file (has to be 64 bits) */
|
|
|
|
unsigned long long int size = 0;
|
|
|
|
/* number of pages in file */
|
2021-07-22 13:36:30 +02:00
|
|
|
uint32_t pages;
|
2016-08-12 10:17:45 +02:00
|
|
|
|
|
|
|
off_t offset = 0;
|
|
|
|
/* count the no. of page corrupted. */
|
2017-08-04 12:57:26 +02:00
|
|
|
unsigned long long mismatch_count = 0;
|
2016-08-12 10:17:45 +02:00
|
|
|
|
|
|
|
bool partial_page_read = false;
|
|
|
|
/* Enabled when read from stdin is done. */
|
|
|
|
bool read_from_stdin = false;
|
|
|
|
FILE* fil_page_type = NULL;
|
|
|
|
fpos_t pos;
|
|
|
|
|
|
|
|
/* enable when space_id of given file is zero. */
|
|
|
|
bool is_system_tablespace = false;
|
|
|
|
|
|
|
|
MY_INIT(argv[0]);
|
|
|
|
DBUG_ENTER("main");
|
|
|
|
DBUG_PROCESS(argv[0]);
|
|
|
|
|
|
|
|
if (get_options(&argc,&argv)) {
|
2017-08-04 12:57:26 +02:00
|
|
|
exit_status = 1;
|
|
|
|
goto my_exit;
|
2016-08-12 10:17:45 +02:00
|
|
|
}
|
2015-03-03 16:38:02 +01:00
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
if (no_check && !do_write) {
|
|
|
|
fprintf(stderr, "Error: --no-check must be associated with "
|
|
|
|
"--write option.\n");
|
2017-08-04 12:57:26 +02:00
|
|
|
exit_status = 1;
|
|
|
|
goto my_exit;
|
2016-08-12 10:17:45 +02:00
|
|
|
}
|
2015-03-03 16:38:02 +01:00
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
if (page_type_dump) {
|
|
|
|
fil_page_type = create_file(page_dump_filename);
|
|
|
|
if (!fil_page_type) {
|
2017-08-04 12:57:26 +02:00
|
|
|
exit_status = 1;
|
|
|
|
goto my_exit;
|
2016-08-12 10:17:45 +02:00
|
|
|
}
|
|
|
|
}
|
2015-03-03 16:38:02 +01:00
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
if (is_log_enabled) {
|
|
|
|
log_file = create_file(log_filename);
|
|
|
|
if (!log_file) {
|
2017-08-04 12:57:26 +02:00
|
|
|
exit_status = 1;
|
|
|
|
goto my_exit;
|
2016-08-12 10:17:45 +02:00
|
|
|
}
|
|
|
|
fprintf(log_file, "InnoDB File Checksum Utility.\n");
|
|
|
|
}
|
2015-03-03 16:38:02 +01:00
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
if (verbose) {
|
|
|
|
my_print_variables(innochecksum_options);
|
|
|
|
}
|
2015-03-03 16:38:02 +01:00
|
|
|
|
2015-01-19 11:39:17 +01:00
|
|
|
|
2019-12-05 05:42:31 +01:00
|
|
|
buf = static_cast<byte*>(aligned_malloc(UNIV_PAGE_SIZE_MAX,
|
|
|
|
UNIV_PAGE_SIZE_MAX));
|
|
|
|
xdes = static_cast<byte*>(aligned_malloc(UNIV_PAGE_SIZE_MAX,
|
|
|
|
UNIV_PAGE_SIZE_MAX));
|
2017-08-04 12:57:26 +02:00
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
/* The file name is not optional. */
|
|
|
|
for (int i = 0; i < argc; ++i) {
|
2017-08-04 12:57:26 +02:00
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
/* Reset parameters for each file. */
|
|
|
|
filename = argv[i];
|
|
|
|
memset(&page_type, 0, sizeof(innodb_page_type));
|
|
|
|
partial_page_read = false;
|
|
|
|
skip_page = false;
|
|
|
|
|
|
|
|
if (is_log_enabled) {
|
|
|
|
fprintf(log_file, "Filename = %s\n", filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*filename == '-') {
|
|
|
|
/* read from stdin. */
|
|
|
|
fil_in = stdin;
|
|
|
|
read_from_stdin = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* stat the file to get size and page count. */
|
|
|
|
if (!read_from_stdin &&
|
|
|
|
#ifdef _WIN32
|
|
|
|
_stat64(filename, &st)) {
|
|
|
|
#else
|
|
|
|
stat(filename, &st)) {
|
|
|
|
#endif /* _WIN32 */
|
|
|
|
fprintf(stderr, "Error: %s cannot be found\n",
|
|
|
|
filename);
|
|
|
|
|
2017-08-04 12:57:26 +02:00
|
|
|
exit_status = 1;
|
|
|
|
goto my_exit;
|
2016-08-12 10:17:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!read_from_stdin) {
|
|
|
|
size = st.st_size;
|
|
|
|
fil_in = open_file(filename);
|
|
|
|
/*If fil_in is NULL, terminate as some error encountered */
|
|
|
|
if(fil_in == NULL) {
|
2017-08-04 12:57:26 +02:00
|
|
|
exit_status = 1;
|
|
|
|
goto my_exit;
|
2016-08-12 10:17:45 +02:00
|
|
|
}
|
|
|
|
/* Save the current file pointer in pos variable.*/
|
|
|
|
if (0 != fgetpos(fil_in, &pos)) {
|
|
|
|
perror("fgetpos");
|
2017-08-04 12:57:26 +02:00
|
|
|
exit_status = 1;
|
|
|
|
goto my_exit;
|
2016-08-12 10:17:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read the minimum page size. */
|
2017-09-19 19:45:17 +02:00
|
|
|
bytes = fread(buf, 1, UNIV_ZIP_SIZE_MIN, fil_in);
|
2016-08-12 10:17:45 +02:00
|
|
|
partial_page_read = true;
|
|
|
|
|
|
|
|
if (bytes != UNIV_ZIP_SIZE_MIN) {
|
|
|
|
fprintf(stderr, "Error: Was not able to read the "
|
|
|
|
"minimum page size ");
|
2017-08-04 12:57:26 +02:00
|
|
|
fprintf(stderr, "of %d bytes. Bytes read was " ULINTPF "\n",
|
2016-08-12 10:17:45 +02:00
|
|
|
UNIV_ZIP_SIZE_MIN, bytes);
|
|
|
|
|
2017-08-04 12:57:26 +02:00
|
|
|
exit_status = 1;
|
|
|
|
goto my_exit;
|
2016-08-12 10:17:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* enable variable is_system_tablespace when space_id of given
|
|
|
|
file is zero. Use to skip the checksum verification and rewrite
|
|
|
|
for doublewrite pages. */
|
2019-06-28 15:19:43 +02:00
|
|
|
cur_space = mach_read_from_4(buf + FIL_PAGE_SPACE_ID);
|
|
|
|
cur_page_num = mach_read_from_4(buf + FIL_PAGE_OFFSET);
|
2016-08-12 10:17:45 +02:00
|
|
|
|
2017-08-04 12:57:26 +02:00
|
|
|
/* Determine page size, zip_size and page compression
|
|
|
|
from fsp_flags and encryption metadata from page 0 */
|
MDEV-12026: Implement innodb_checksum_algorithm=full_crc32
MariaDB data-at-rest encryption (innodb_encrypt_tables)
had repurposed the same unused data field that was repurposed
in MySQL 5.7 (and MariaDB 10.2) for the Split Sequence Number (SSN)
field of SPATIAL INDEX. Because of this, MariaDB was unable to
support encryption on SPATIAL INDEX pages.
Furthermore, InnoDB page checksums skipped some bytes, and there
are multiple variations and checksum algorithms. By default,
InnoDB accepts all variations of all algorithms that ever existed.
This unnecessarily weakens the page checksums.
We hereby introduce two more innodb_checksum_algorithm variants
(full_crc32, strict_full_crc32) that are special in a way:
When either setting is active, newly created data files will
carry a flag (fil_space_t::full_crc32()) that indicates that
all pages of the file will use a full CRC-32C checksum over the
entire page contents (excluding the bytes where the checksum
is stored, at the very end of the page). Such files will always
use that checksum, no matter what the parameter
innodb_checksum_algorithm is assigned to.
For old files, the old checksum algorithms will continue to be
used. The value strict_full_crc32 will be equivalent to strict_crc32
and the value full_crc32 will be equivalent to crc32.
ROW_FORMAT=COMPRESSED tables will only use the old format.
These tables do not support new features, such as larger
innodb_page_size or instant ADD/DROP COLUMN. They may be
deprecated in the future. We do not want an unnecessary
file format change for them.
The new full_crc32() format also cleans up the MariaDB tablespace
flags. We will reserve flags to store the page_compressed
compression algorithm, and to store the compressed payload length,
so that checksum can be computed over the compressed (and
possibly encrypted) stream and can be validated without
decrypting or decompressing the page.
In the full_crc32 format, there no longer are separate before-encryption
and after-encryption checksums for pages. The single checksum is
computed on the page contents that is written to the file.
We do not make the new algorithm the default for two reasons.
First, MariaDB 10.4.2 was a beta release, and the default values
of parameters should not change after beta. Second, we did not
yet implement the full_crc32 format for page_compressed pages.
This will be fixed in MDEV-18644.
This is joint work with Marko Mäkelä.
2019-02-19 20:00:00 +01:00
|
|
|
init_page_size(buf);
|
2016-08-12 10:17:45 +02:00
|
|
|
|
2021-07-22 13:36:30 +02:00
|
|
|
uint32_t flags = mach_read_from_4(FSP_HEADER_OFFSET + FSP_SPACE_FLAGS + buf);
|
2017-08-04 12:57:26 +02:00
|
|
|
|
2019-06-28 15:19:43 +02:00
|
|
|
if (physical_page_size == UNIV_ZIP_SIZE_MIN) {
|
|
|
|
partial_page_read = false;
|
|
|
|
} else {
|
2017-08-04 12:57:26 +02:00
|
|
|
/* Read rest of the page 0 to determine crypt_data */
|
2019-02-06 18:50:11 +01:00
|
|
|
bytes = read_file(buf, partial_page_read, physical_page_size, fil_in);
|
|
|
|
if (bytes != physical_page_size) {
|
2017-08-04 12:57:26 +02:00
|
|
|
fprintf(stderr, "Error: Was not able to read the "
|
|
|
|
"rest of the page ");
|
|
|
|
fprintf(stderr, "of " ULINTPF " bytes. Bytes read was " ULINTPF "\n",
|
2019-02-06 18:50:11 +01:00
|
|
|
physical_page_size - UNIV_ZIP_SIZE_MIN, bytes);
|
2017-08-04 12:57:26 +02:00
|
|
|
|
|
|
|
exit_status = 1;
|
|
|
|
goto my_exit;
|
|
|
|
}
|
|
|
|
partial_page_read = false;
|
|
|
|
}
|
|
|
|
|
2019-06-28 15:19:43 +02:00
|
|
|
|
2017-08-04 12:57:26 +02:00
|
|
|
/* Now that we have full page 0 in buffer, check encryption */
|
2019-02-06 18:50:11 +01:00
|
|
|
bool is_encrypted = check_encryption(filename, buf);
|
2017-08-04 12:57:26 +02:00
|
|
|
|
|
|
|
/* Verify page 0 contents. Note that we can't allow
|
|
|
|
checksum mismatch on page 0, because that would mean we
|
|
|
|
could not trust it content. */
|
|
|
|
if (!no_check) {
|
|
|
|
unsigned long long tmp_allow_mismatches = allow_mismatches;
|
|
|
|
allow_mismatches = 0;
|
|
|
|
|
MDEV-12026: Implement innodb_checksum_algorithm=full_crc32
MariaDB data-at-rest encryption (innodb_encrypt_tables)
had repurposed the same unused data field that was repurposed
in MySQL 5.7 (and MariaDB 10.2) for the Split Sequence Number (SSN)
field of SPATIAL INDEX. Because of this, MariaDB was unable to
support encryption on SPATIAL INDEX pages.
Furthermore, InnoDB page checksums skipped some bytes, and there
are multiple variations and checksum algorithms. By default,
InnoDB accepts all variations of all algorithms that ever existed.
This unnecessarily weakens the page checksums.
We hereby introduce two more innodb_checksum_algorithm variants
(full_crc32, strict_full_crc32) that are special in a way:
When either setting is active, newly created data files will
carry a flag (fil_space_t::full_crc32()) that indicates that
all pages of the file will use a full CRC-32C checksum over the
entire page contents (excluding the bytes where the checksum
is stored, at the very end of the page). Such files will always
use that checksum, no matter what the parameter
innodb_checksum_algorithm is assigned to.
For old files, the old checksum algorithms will continue to be
used. The value strict_full_crc32 will be equivalent to strict_crc32
and the value full_crc32 will be equivalent to crc32.
ROW_FORMAT=COMPRESSED tables will only use the old format.
These tables do not support new features, such as larger
innodb_page_size or instant ADD/DROP COLUMN. They may be
deprecated in the future. We do not want an unnecessary
file format change for them.
The new full_crc32() format also cleans up the MariaDB tablespace
flags. We will reserve flags to store the page_compressed
compression algorithm, and to store the compressed payload length,
so that checksum can be computed over the compressed (and
possibly encrypted) stream and can be validated without
decrypting or decompressing the page.
In the full_crc32 format, there no longer are separate before-encryption
and after-encryption checksums for pages. The single checksum is
computed on the page contents that is written to the file.
We do not make the new algorithm the default for two reasons.
First, MariaDB 10.4.2 was a beta release, and the default values
of parameters should not change after beta. Second, we did not
yet implement the full_crc32 format for page_compressed pages.
This will be fixed in MDEV-18644.
This is joint work with Marko Mäkelä.
2019-02-19 20:00:00 +01:00
|
|
|
exit_status = verify_checksum(buf, is_encrypted,
|
|
|
|
&mismatch_count, flags);
|
2017-08-04 12:57:26 +02:00
|
|
|
|
|
|
|
if (exit_status) {
|
|
|
|
fprintf(stderr, "Error: Page 0 checksum mismatch, can't continue. \n");
|
|
|
|
goto my_exit;
|
|
|
|
}
|
|
|
|
allow_mismatches = tmp_allow_mismatches;
|
|
|
|
}
|
|
|
|
|
MDEV-12026: Implement innodb_checksum_algorithm=full_crc32
MariaDB data-at-rest encryption (innodb_encrypt_tables)
had repurposed the same unused data field that was repurposed
in MySQL 5.7 (and MariaDB 10.2) for the Split Sequence Number (SSN)
field of SPATIAL INDEX. Because of this, MariaDB was unable to
support encryption on SPATIAL INDEX pages.
Furthermore, InnoDB page checksums skipped some bytes, and there
are multiple variations and checksum algorithms. By default,
InnoDB accepts all variations of all algorithms that ever existed.
This unnecessarily weakens the page checksums.
We hereby introduce two more innodb_checksum_algorithm variants
(full_crc32, strict_full_crc32) that are special in a way:
When either setting is active, newly created data files will
carry a flag (fil_space_t::full_crc32()) that indicates that
all pages of the file will use a full CRC-32C checksum over the
entire page contents (excluding the bytes where the checksum
is stored, at the very end of the page). Such files will always
use that checksum, no matter what the parameter
innodb_checksum_algorithm is assigned to.
For old files, the old checksum algorithms will continue to be
used. The value strict_full_crc32 will be equivalent to strict_crc32
and the value full_crc32 will be equivalent to crc32.
ROW_FORMAT=COMPRESSED tables will only use the old format.
These tables do not support new features, such as larger
innodb_page_size or instant ADD/DROP COLUMN. They may be
deprecated in the future. We do not want an unnecessary
file format change for them.
The new full_crc32() format also cleans up the MariaDB tablespace
flags. We will reserve flags to store the page_compressed
compression algorithm, and to store the compressed payload length,
so that checksum can be computed over the compressed (and
possibly encrypted) stream and can be validated without
decrypting or decompressing the page.
In the full_crc32 format, there no longer are separate before-encryption
and after-encryption checksums for pages. The single checksum is
computed on the page contents that is written to the file.
We do not make the new algorithm the default for two reasons.
First, MariaDB 10.4.2 was a beta release, and the default values
of parameters should not change after beta. Second, we did not
yet implement the full_crc32 format for page_compressed pages.
This will be fixed in MDEV-18644.
This is joint work with Marko Mäkelä.
2019-02-19 20:00:00 +01:00
|
|
|
if ((exit_status = rewrite_checksum(
|
|
|
|
filename, fil_in, buf,
|
|
|
|
&pos, is_encrypted, flags))) {
|
2017-08-04 12:57:26 +02:00
|
|
|
goto my_exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (page_type_dump) {
|
|
|
|
fprintf(fil_page_type,
|
|
|
|
"\n\nFilename::%s\n", filename);
|
|
|
|
fprintf(fil_page_type,
|
|
|
|
"========================================"
|
|
|
|
"======================================\n");
|
|
|
|
fprintf(fil_page_type,
|
|
|
|
"\tPAGE_NO\t\t|\t\tPAGE_TYPE\t\t"
|
|
|
|
"\t|\tEXTRA INFO\n");
|
|
|
|
fprintf(fil_page_type,
|
|
|
|
"========================================"
|
|
|
|
"======================================\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (per_page_details) {
|
2021-07-22 16:53:43 +02:00
|
|
|
printf("page " UINT32PF " ", cur_page_num);
|
2017-08-04 12:57:26 +02:00
|
|
|
}
|
|
|
|
|
2021-06-21 13:54:26 +02:00
|
|
|
memcpy(xdes, buf, physical_page_size);
|
|
|
|
|
2017-08-04 12:57:26 +02:00
|
|
|
if (page_type_summary || page_type_dump) {
|
2019-02-06 18:50:11 +01:00
|
|
|
parse_page(buf, xdes, fil_page_type, is_encrypted);
|
2017-08-04 12:57:26 +02:00
|
|
|
}
|
|
|
|
|
2021-07-31 22:59:58 +02:00
|
|
|
pages = uint32_t(size / physical_page_size);
|
2016-08-12 10:17:45 +02:00
|
|
|
|
|
|
|
if (just_count) {
|
2021-07-22 13:36:30 +02:00
|
|
|
fprintf(read_from_stdin ? stderr : stdout,
|
2021-07-22 16:53:43 +02:00
|
|
|
"Number of pages:" UINT32PF "\n", pages);
|
2016-08-12 10:17:45 +02:00
|
|
|
continue;
|
|
|
|
} else if (verbose && !read_from_stdin) {
|
|
|
|
if (is_log_enabled) {
|
|
|
|
fprintf(log_file, "file %s = %llu bytes "
|
2021-07-22 16:53:43 +02:00
|
|
|
"(" UINT32PF " pages)\n",
|
|
|
|
filename, size, pages);
|
2016-08-12 10:17:45 +02:00
|
|
|
if (do_one_page) {
|
|
|
|
fprintf(log_file, "Innochecksum: "
|
2021-07-22 16:53:43 +02:00
|
|
|
"checking page::"
|
|
|
|
UINT32PF ";\n",
|
2016-08-12 10:17:45 +02:00
|
|
|
do_page);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (is_log_enabled) {
|
|
|
|
fprintf(log_file, "Innochecksum: checking "
|
2021-07-22 16:53:43 +02:00
|
|
|
"pages in range::" UINT32PF
|
|
|
|
" to " UINT32PF "\n",
|
2016-08-12 10:17:45 +02:00
|
|
|
start_page, use_end_page ?
|
|
|
|
end_page : (pages - 1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-28 15:19:43 +02:00
|
|
|
off_t cur_offset = 0;
|
|
|
|
/* Find the first non all-zero page and fetch the
|
|
|
|
space id from there. */
|
|
|
|
while (is_page_all_zeroes(buf, physical_page_size)) {
|
|
|
|
bytes = ulong(read_file(
|
|
|
|
buf, false, physical_page_size,
|
|
|
|
fil_in));
|
|
|
|
|
|
|
|
if (feof(fil_in)) {
|
|
|
|
fprintf(stderr, "All are "
|
|
|
|
"zero-filled pages.");
|
|
|
|
goto my_exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
cur_offset++;
|
|
|
|
}
|
|
|
|
|
|
|
|
cur_space = mach_read_from_4(buf + FIL_PAGE_SPACE_ID);
|
|
|
|
is_system_tablespace = (cur_space == 0);
|
|
|
|
|
|
|
|
if (cur_offset > 0) {
|
|
|
|
/* Re-read the non-zero page to check the
|
|
|
|
checksum. So move the file pointer to
|
|
|
|
previous position and reset the page number too. */
|
|
|
|
cur_page_num = mach_read_from_4(buf + FIL_PAGE_OFFSET);
|
|
|
|
if (!start_page) {
|
|
|
|
goto first_non_zero;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
/* seek to the necessary position */
|
|
|
|
if (start_page) {
|
|
|
|
if (!read_from_stdin) {
|
|
|
|
/* If read is not from stdin, we can use
|
|
|
|
fseeko() to position the file pointer to
|
|
|
|
the desired page. */
|
|
|
|
partial_page_read = false;
|
|
|
|
|
2021-07-22 16:53:43 +02:00
|
|
|
offset = off_t(ulonglong(start_page)
|
2021-07-31 22:59:58 +02:00
|
|
|
* physical_page_size);
|
2019-02-06 18:50:11 +01:00
|
|
|
if (IF_WIN(_fseeki64,fseeko)(fil_in, offset,
|
|
|
|
SEEK_SET)) {
|
2016-08-12 10:17:45 +02:00
|
|
|
perror("Error: Unable to seek to "
|
|
|
|
"necessary offset");
|
|
|
|
|
2017-08-04 12:57:26 +02:00
|
|
|
exit_status = 1;
|
|
|
|
goto my_exit;
|
2016-08-12 10:17:45 +02:00
|
|
|
}
|
|
|
|
/* Save the current file pointer in
|
|
|
|
pos variable. */
|
|
|
|
if (0 != fgetpos(fil_in, &pos)) {
|
|
|
|
perror("fgetpos");
|
|
|
|
|
2017-08-04 12:57:26 +02:00
|
|
|
exit_status = 1;
|
|
|
|
goto my_exit;
|
2016-08-12 10:17:45 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
ulong count = 0;
|
|
|
|
|
|
|
|
while (!feof(fil_in)) {
|
|
|
|
if (start_page == count) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* We read a part of page to find the
|
|
|
|
minimum page size. We cannot reset
|
|
|
|
the file pointer to the beginning of
|
|
|
|
the page if we are reading from stdin
|
|
|
|
(fseeko() on stdin doesn't work). So
|
|
|
|
read only the remaining part of page,
|
|
|
|
if partial_page_read is enable. */
|
|
|
|
bytes = read_file(buf,
|
|
|
|
partial_page_read,
|
2019-02-06 18:50:11 +01:00
|
|
|
physical_page_size,
|
2016-08-12 10:17:45 +02:00
|
|
|
fil_in);
|
|
|
|
|
|
|
|
partial_page_read = false;
|
|
|
|
count++;
|
|
|
|
|
|
|
|
if (!bytes || feof(fil_in)) {
|
2021-07-22 16:53:43 +02:00
|
|
|
goto unexpected_eof;
|
2016-08-12 10:17:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* main checksumming loop */
|
2017-08-04 12:57:26 +02:00
|
|
|
cur_page_num = start_page ? start_page : cur_page_num + 1;
|
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
while (!feof(fil_in)) {
|
|
|
|
|
|
|
|
bytes = read_file(buf, partial_page_read,
|
2019-02-06 18:50:11 +01:00
|
|
|
physical_page_size, fil_in);
|
2016-08-12 10:17:45 +02:00
|
|
|
partial_page_read = false;
|
|
|
|
|
|
|
|
if (!bytes && feof(fil_in)) {
|
2021-07-22 16:53:43 +02:00
|
|
|
if (cur_page_num == start_page) {
|
|
|
|
unexpected_eof:
|
|
|
|
fputs("Error: Unable "
|
|
|
|
"to seek to necessary offset\n",
|
|
|
|
stderr);
|
|
|
|
|
|
|
|
exit_status = 1;
|
|
|
|
goto my_exit;
|
|
|
|
}
|
2016-08-12 10:17:45 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ferror(fil_in)) {
|
MDEV-28250 aix test case failure innodb_zip.innochecksum_3,4k,crc32,innodb
As discovered by tracing, but also presenting in AIX fseeko
documentation, seeking beyond the EOF is acceptable, as you can write
there.
To display the same error in AIX to other implementations that return
errors on seek, we take the EFBIG error code on reading and error the
same way.
An AIX truss of an aspect of the test:
truss extra/innochecksum --page=18446744073709551615 $MYSQLD_DATADIR/test/tab1.ibd
statx("./mysql-test/var/log/innodb_zip.innochecksum_3-4k,crc32,innodb/mysqld.1/data//test/tab1.ibd", 0x0FFFFFFFFFFFF610, 176, 010) = 0
kopen("./mysql-test/var/log/innodb_zip.innochecksum_3-4k,crc32,innodb/mysqld.1/data//test/tab1.ibd", O_RDONLY|O_LARGEFILE) = 3
kfcntl(3, 12, 0x00000001100006C8) = 0
kfcntl(3, F_GETFL, 0x00000001100A6CF8) = 67108864
kioctl(3, 22528, 0x0000000000000000, 0x0000000000000000) Err#25 ENOTTY
klseek(3, 0, 1, 0x0FFFFFFFFFFFF3F0) = 0
kioctl(3, 22528, 0x0000000000000000, 0x0000000000000000) Err#25 ENOTTY
kread(3, "DEADBEEF\0\0\0\0FFFFFFFF".., 4096) = 4096
klseek(3, 0, 1, 0x0FFFFFFFFFFFF450) = 0
klseek(3, 17592186040320, 0, 0x0FFFFFFFFFFFF450) = 0
klseek(3, 0, 1, 0x0FFFFFFFFFFFF3F0) = 0
kread(3, "DEADBEEF\0\0\0\0FFFFFFFF".., 4096) Err#27 EFBIG
An equivalent Linux trace:
ltrace extra/innochecksum --page=18446744073709551615 $MYSQLD_DATADIR/test/tab1.ibd
stat64(0x7fff10ea2dc3, 0x7fff10ea0670, 88, 0x8026be41) = 0
open64("./mysql-test/var/log/innodb_zip."..., 0, 02072403160) = 3
fcntl64(3, 6, 0x139f180, 1) = 0
fgetpos64(0x615000000080, 0x7fff10ea0760, 1, 0) = 0
fseeko64(0x615000000080, 0xffffffff000, 0, 5 <unfinished ...>
pthread_getspecific(0, 0x4d0eb8, 0x7fff10ea0490, 0) = 0x7f7b2806d000
<... fseeko64 resumed> ) = 0
fgetpos64(0x615000000080, 0x7fff10ea0760, 1, 1) = 0
feof(0x615000000080) = 0
feof(0x615000000080) = 1
Error: Unable to seek to necessary offset
2022-04-07 02:50:04 +02:00
|
|
|
#ifdef _AIX
|
|
|
|
/*
|
|
|
|
AIX fseeko can go past eof without error.
|
|
|
|
the error occurs on read, hence output the
|
|
|
|
same error here as would show up on other
|
|
|
|
platforms. This shows up in the mtr test
|
|
|
|
innodb_zip.innochecksum_3-4k,crc32,innodb
|
|
|
|
*/
|
|
|
|
if (errno == EFBIG) {
|
|
|
|
goto unexpected_eof;
|
|
|
|
}
|
|
|
|
#endif
|
2016-09-29 12:59:41 +02:00
|
|
|
fprintf(stderr, "Error reading " ULINTPF " bytes",
|
2019-02-06 18:50:11 +01:00
|
|
|
physical_page_size);
|
2016-08-12 10:17:45 +02:00
|
|
|
perror(" ");
|
|
|
|
|
2017-08-04 12:57:26 +02:00
|
|
|
exit_status = 1;
|
|
|
|
goto my_exit;
|
2016-08-12 10:17:45 +02:00
|
|
|
}
|
|
|
|
|
2019-02-06 18:50:11 +01:00
|
|
|
if (bytes != physical_page_size) {
|
2017-08-04 12:57:26 +02:00
|
|
|
fprintf(stderr, "Error: bytes read (" ULINTPF ") "
|
2016-09-29 12:59:41 +02:00
|
|
|
"doesn't match page size (" ULINTPF ")\n",
|
2019-02-06 18:50:11 +01:00
|
|
|
bytes, physical_page_size);
|
2017-08-04 12:57:26 +02:00
|
|
|
exit_status = 1;
|
|
|
|
goto my_exit;
|
2016-08-12 10:17:45 +02:00
|
|
|
}
|
|
|
|
|
2019-06-28 15:19:43 +02:00
|
|
|
first_non_zero:
|
2016-08-12 10:17:45 +02:00
|
|
|
if (is_system_tablespace) {
|
|
|
|
/* enable when page is double write buffer.*/
|
|
|
|
skip_page = is_page_doublewritebuffer(buf);
|
|
|
|
} else {
|
|
|
|
skip_page = false;
|
2016-09-29 12:59:41 +02:00
|
|
|
}
|
|
|
|
|
2020-05-07 16:15:34 +02:00
|
|
|
const uint16_t cur_page_type = fil_page_get_type(buf);
|
2016-09-29 12:59:41 +02:00
|
|
|
|
2017-08-04 12:57:26 +02:00
|
|
|
/* FIXME: Page compressed or Page compressed and encrypted
|
|
|
|
pages do not contain checksum. */
|
|
|
|
if (cur_page_type == FIL_PAGE_PAGE_COMPRESSED ||
|
|
|
|
cur_page_type == FIL_PAGE_PAGE_COMPRESSED_ENCRYPTED) {
|
2016-09-29 12:59:41 +02:00
|
|
|
skip_page = true;
|
2016-08-12 10:17:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If no-check is enabled, skip the
|
|
|
|
checksum verification.*/
|
2017-08-04 12:57:26 +02:00
|
|
|
if (!no_check
|
|
|
|
&& !skip_page
|
2021-07-31 23:19:51 +02:00
|
|
|
&& !is_page_free(xdes, physical_page_size, cur_page_num)
|
MDEV-12026: Implement innodb_checksum_algorithm=full_crc32
MariaDB data-at-rest encryption (innodb_encrypt_tables)
had repurposed the same unused data field that was repurposed
in MySQL 5.7 (and MariaDB 10.2) for the Split Sequence Number (SSN)
field of SPATIAL INDEX. Because of this, MariaDB was unable to
support encryption on SPATIAL INDEX pages.
Furthermore, InnoDB page checksums skipped some bytes, and there
are multiple variations and checksum algorithms. By default,
InnoDB accepts all variations of all algorithms that ever existed.
This unnecessarily weakens the page checksums.
We hereby introduce two more innodb_checksum_algorithm variants
(full_crc32, strict_full_crc32) that are special in a way:
When either setting is active, newly created data files will
carry a flag (fil_space_t::full_crc32()) that indicates that
all pages of the file will use a full CRC-32C checksum over the
entire page contents (excluding the bytes where the checksum
is stored, at the very end of the page). Such files will always
use that checksum, no matter what the parameter
innodb_checksum_algorithm is assigned to.
For old files, the old checksum algorithms will continue to be
used. The value strict_full_crc32 will be equivalent to strict_crc32
and the value full_crc32 will be equivalent to crc32.
ROW_FORMAT=COMPRESSED tables will only use the old format.
These tables do not support new features, such as larger
innodb_page_size or instant ADD/DROP COLUMN. They may be
deprecated in the future. We do not want an unnecessary
file format change for them.
The new full_crc32() format also cleans up the MariaDB tablespace
flags. We will reserve flags to store the page_compressed
compression algorithm, and to store the compressed payload length,
so that checksum can be computed over the compressed (and
possibly encrypted) stream and can be validated without
decrypting or decompressing the page.
In the full_crc32 format, there no longer are separate before-encryption
and after-encryption checksums for pages. The single checksum is
computed on the page contents that is written to the file.
We do not make the new algorithm the default for two reasons.
First, MariaDB 10.4.2 was a beta release, and the default values
of parameters should not change after beta. Second, we did not
yet implement the full_crc32 format for page_compressed pages.
This will be fixed in MDEV-18644.
This is joint work with Marko Mäkelä.
2019-02-19 20:00:00 +01:00
|
|
|
&& (exit_status = verify_checksum(
|
|
|
|
buf, is_encrypted,
|
|
|
|
&mismatch_count, flags))) {
|
2017-08-04 12:57:26 +02:00
|
|
|
goto my_exit;
|
2016-08-12 10:17:45 +02:00
|
|
|
}
|
|
|
|
|
MDEV-12026: Implement innodb_checksum_algorithm=full_crc32
MariaDB data-at-rest encryption (innodb_encrypt_tables)
had repurposed the same unused data field that was repurposed
in MySQL 5.7 (and MariaDB 10.2) for the Split Sequence Number (SSN)
field of SPATIAL INDEX. Because of this, MariaDB was unable to
support encryption on SPATIAL INDEX pages.
Furthermore, InnoDB page checksums skipped some bytes, and there
are multiple variations and checksum algorithms. By default,
InnoDB accepts all variations of all algorithms that ever existed.
This unnecessarily weakens the page checksums.
We hereby introduce two more innodb_checksum_algorithm variants
(full_crc32, strict_full_crc32) that are special in a way:
When either setting is active, newly created data files will
carry a flag (fil_space_t::full_crc32()) that indicates that
all pages of the file will use a full CRC-32C checksum over the
entire page contents (excluding the bytes where the checksum
is stored, at the very end of the page). Such files will always
use that checksum, no matter what the parameter
innodb_checksum_algorithm is assigned to.
For old files, the old checksum algorithms will continue to be
used. The value strict_full_crc32 will be equivalent to strict_crc32
and the value full_crc32 will be equivalent to crc32.
ROW_FORMAT=COMPRESSED tables will only use the old format.
These tables do not support new features, such as larger
innodb_page_size or instant ADD/DROP COLUMN. They may be
deprecated in the future. We do not want an unnecessary
file format change for them.
The new full_crc32() format also cleans up the MariaDB tablespace
flags. We will reserve flags to store the page_compressed
compression algorithm, and to store the compressed payload length,
so that checksum can be computed over the compressed (and
possibly encrypted) stream and can be validated without
decrypting or decompressing the page.
In the full_crc32 format, there no longer are separate before-encryption
and after-encryption checksums for pages. The single checksum is
computed on the page contents that is written to the file.
We do not make the new algorithm the default for two reasons.
First, MariaDB 10.4.2 was a beta release, and the default values
of parameters should not change after beta. Second, we did not
yet implement the full_crc32 format for page_compressed pages.
This will be fixed in MDEV-18644.
This is joint work with Marko Mäkelä.
2019-02-19 20:00:00 +01:00
|
|
|
if ((exit_status = rewrite_checksum(
|
|
|
|
filename, fil_in, buf,
|
|
|
|
&pos, is_encrypted, flags))) {
|
2017-08-04 12:57:26 +02:00
|
|
|
goto my_exit;
|
2016-08-12 10:17:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* end if this was the last page we were supposed to check */
|
|
|
|
if (use_end_page && (cur_page_num >= end_page)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-08-04 12:57:26 +02:00
|
|
|
if (per_page_details) {
|
2021-07-22 16:53:43 +02:00
|
|
|
printf("page " UINT32PF " ", cur_page_num);
|
2017-08-04 12:57:26 +02:00
|
|
|
}
|
|
|
|
|
2024-11-27 08:30:51 +01:00
|
|
|
if (cur_page_num % physical_page_size == 0) {
|
2021-06-21 13:54:26 +02:00
|
|
|
memcpy(xdes, buf, physical_page_size);
|
2017-08-04 12:57:26 +02:00
|
|
|
}
|
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
if (page_type_summary || page_type_dump) {
|
2019-02-06 18:50:11 +01:00
|
|
|
parse_page(buf, xdes, fil_page_type, is_encrypted);
|
2016-08-12 10:17:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* do counter increase and progress printing */
|
|
|
|
cur_page_num++;
|
2017-08-04 12:57:26 +02:00
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
if (verbose && !read_from_stdin) {
|
|
|
|
if ((cur_page_num % 64) == 0) {
|
2019-08-15 14:29:03 +02:00
|
|
|
time_t now = time(0);
|
2016-08-12 10:17:45 +02:00
|
|
|
if (!lastt) {
|
|
|
|
lastt= now;
|
2019-08-15 14:29:03 +02:00
|
|
|
} else if (now - lastt >= 1 && is_log_enabled) {
|
2021-07-22 16:53:43 +02:00
|
|
|
fprintf(log_file, "page::" UINT32PF " "
|
2016-08-12 10:17:45 +02:00
|
|
|
"okay: %.3f%% done\n",
|
|
|
|
(cur_page_num - 1),
|
2021-07-22 13:36:30 +02:00
|
|
|
(double) cur_page_num / pages * 100);
|
2016-08-12 10:17:45 +02:00
|
|
|
lastt = now;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!read_from_stdin) {
|
|
|
|
/* flcose() will flush the data and release the lock if
|
|
|
|
any acquired. */
|
|
|
|
fclose(fil_in);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Enabled for page type summary. */
|
|
|
|
if (page_type_summary) {
|
|
|
|
if (!read_from_stdin) {
|
|
|
|
fprintf(stdout, "\nFile::%s",filename);
|
|
|
|
print_summary(stdout);
|
|
|
|
} else {
|
|
|
|
print_summary(stderr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-09-19 10:30:18 +02:00
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
if (is_log_enabled) {
|
|
|
|
fclose(log_file);
|
2015-09-19 10:30:18 +02:00
|
|
|
}
|
|
|
|
|
2019-12-05 05:42:31 +01:00
|
|
|
goto common_exit;
|
2016-09-29 12:59:41 +02:00
|
|
|
|
2017-08-04 12:57:26 +02:00
|
|
|
my_exit:
|
2016-09-29 12:59:41 +02:00
|
|
|
if (!read_from_stdin && fil_in) {
|
|
|
|
fclose(fil_in);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (log_file) {
|
|
|
|
fclose(log_file);
|
|
|
|
}
|
|
|
|
|
2019-12-05 05:42:31 +01:00
|
|
|
common_exit:
|
|
|
|
aligned_free(buf);
|
|
|
|
aligned_free(xdes);
|
2017-08-04 12:57:26 +02:00
|
|
|
my_end(exit_status);
|
|
|
|
DBUG_RETURN(exit_status);
|
2014-02-28 07:53:09 +01:00
|
|
|
}
|