MySQL 8.0.32
Source Code Documentation
row0import.cc File Reference

Import a tablespace to a running instance. More...

#include <errno.h>
#include <my_aes.h>
#include <sys/types.h>
#include <memory>
#include <vector>
#include "sql/dd/types/column_type_element.h"
#include "btr0pcur.h"
#include "dict0boot.h"
#include "dict0crea.h"
#include "dict0dd.h"
#include "dict0upgrade.h"
#include "ha_prototypes.h"
#include "ibuf0ibuf.h"
#include "lob0first.h"
#include "lob0impl.h"
#include "lob0lob.h"
#include "lob0pages.h"
#include "log0chkp.h"
#include "pars0pars.h"
#include "que0que.h"
#include "row0import.h"
#include "row0mysql.h"
#include "row0quiesce.h"
#include "row0sel.h"
#include "row0upd.h"
#include "sql/mysqld.h"
#include "srv0start.h"
#include "ut0new.h"
#include "zlob0first.h"
#include "my_dbug.h"

Classes

struct  row_stats_t
 For gathering stats on records during phase I. More...
 
struct  row_index_t
 Index information required by IMPORT. More...
 
struct  row_import
 Meta data required by IMPORT. More...
 
class  RecIterator
 Use the page cursor to iterate over records in a block. More...
 
class  IndexPurge
 Class that purges delete marked records from indexes, both secondary and cluster. More...
 
class  AbstractCallback
 Functor that is called for each physical page that is read from the tablespace file. More...
 
struct  FetchIndexRootPages
 Try and determine the index root pages by checking if the next/prev pointers are both FIL_NULL. More...
 
struct  FetchIndexRootPages::Index
 Index information gathered from the .ibd file. More...
 
class  PageConverter
 

Functions

size_t IO_BUFFER_SIZE (size_t m, size_t n)
 The size of the buffer to use for IO. More...
 
static void row_import_discard_changes (row_prebuilt_t *prebuilt, trx_t *trx, dberr_t err)
 Clean up after import tablespace failure, this function will acquire the dictionary latches on behalf of the transaction if the transaction hasn't already acquired them. More...
 
static dberr_t row_import_cleanup (row_prebuilt_t *prebuilt, trx_t *trx, dberr_t err)
 Clean up after import tablespace. More...
 
static dberr_t row_import_error (row_prebuilt_t *prebuilt, trx_t *trx, dberr_t err)
 Report error during tablespace import. More...
 
static dberr_t row_import_adjust_root_pages_of_secondary_indexes (trx_t *trx, dict_table_t *table, const row_import &cfg)
 Adjust the root page index node and leaf node segment headers, update with the new space id. More...
 
static dberr_t row_import_set_sys_max_row_id (row_prebuilt_t *prebuilt, dict_table_t *table)
 Ensure that dict_sys->row_id exceeds SELECT MAX(DB_ROW_ID). More...
 
static dberr_t row_import_cfg_read_string (FILE *file, byte *ptr, ulint max_len)
 Read the a string from the meta data file. More...
 
static dberr_t row_import_cfg_read_index_fields (FILE *file, THD *thd, row_index_t *index, row_import *cfg)
 Write the meta data (index user fields) config file. More...
 
static dberr_t row_import_read_index_data (FILE *file, THD *thd, row_import *cfg)
 Read the index names and root page numbers of the indexes and set the values. More...
 
static dberr_t row_import_read_indexes (FILE *file, THD *thd, row_import *cfg)
 Set the index root page number for v1 format. More...
 
static byterow_import_read_bytes (FILE *file, size_t length)
 Read specified bytes from the meta data file. More...
 
static dberr_t row_import_read_default_values (FILE *file, dict_col_t *col, mem_heap_t **heap, bool *read)
 Read the metadata config file. More...
 
static dberr_t row_import_read_dropped_col_metadata (dd::Table *table_def, FILE *file, THD *thd, dict_col_t *col, const char *col_name)
 Read dd::Column metadata for the dropped table. More...
 
static dberr_t row_import_read_columns (dd::Table *table_def, FILE *file, THD *thd, row_import *cfg)
 Read the meta data (table columns) config file. More...
 
static dberr_t row_import_read_v1 (FILE *file, THD *thd, row_import *cfg)
 Read the contents of the <tablespace>.cfg file. More...
 
static dberr_t row_import_read_v2 (FILE *file, THD *thd, row_import *cfg)
 Read tablespace flags and compression type info from <tablespace>.cfg file. More...
 
static dberr_t row_import_read_common (dd::Table *table_def, FILE *file, THD *thd, row_import *cfg)
 Read the contents of the <tablespace>.cfg file. More...
 
static dberr_t row_import_read_meta_data (dict_table_t *table, dd::Table *table_def, FILE *file, THD *thd, row_import &cfg)
 Read the contents of the <tablespace>.cfg file. More...
 
static dberr_t row_import_read_cfg (dict_table_t *table, dd::Table *table_def, THD *thd, row_import &cfg)
 Read the contents of the <tablename>.cfg file. More...
 
static dberr_t row_import_read_encryption_data (dict_table_t *table, FILE *file, THD *thd)
 Read the contents of the .cfp file. More...
 
static dberr_t row_import_read_cfp (dict_table_t *table, THD *thd, row_import &import)
 Read the contents of the .cfp file. More...
 
dberr_t row_import_check_corruption (dict_table_t *table, THD *thd, bool missing)
 Check the correctness of clustered index of imported table. More...
 
dberr_t row_import_for_mysql (dict_table_t *table, dd::Table *table_def, row_prebuilt_t *prebuilt)
 Imports a tablespace. More...
 

Detailed Description

Import a tablespace to a running instance.

Created 2012-02-08 by Sunny Bains.

Function Documentation

◆ IO_BUFFER_SIZE()

size_t IO_BUFFER_SIZE ( size_t  m,
size_t  n 
)
inline

The size of the buffer to use for IO.

Note: os_file_read() doesn't expect reads to fail. If you set the buffer size to be greater than a multiple of the file size then it will assert. TODO: Fix this limitation of the IO functions.

Parameters
mpage size of the tablespace.
npage size of the tablespace.
Return values
numberof pages

◆ row_import_adjust_root_pages_of_secondary_indexes()

static dberr_t row_import_adjust_root_pages_of_secondary_indexes ( trx_t trx,
dict_table_t table,
const row_import cfg 
)
static

Adjust the root page index node and leaf node segment headers, update with the new space id.

For all the table's secondary indexes.

Returns
error code
Parameters
trxin: transaction used for the import
tablein: table the indexes belong to
cfgImport context

◆ row_import_cfg_read_index_fields()

static dberr_t row_import_cfg_read_index_fields ( FILE *  file,
THD thd,
row_index_t index,
row_import cfg 
)
static

Write the meta data (index user fields) config file.

Returns
DB_SUCCESS or error code.
Parameters
filein: file to write to
thdin/out: session
indexIndex being read in
cfgin/out: meta-data read

◆ row_import_cfg_read_string()

static dberr_t row_import_cfg_read_string ( FILE *  file,
byte ptr,
ulint  max_len 
)
static

Read the a string from the meta data file.

Returns
DB_SUCCESS or error code.
Parameters
filein/out: File to read from
ptrout: string to read
max_lenin: maximum length of the output buffer in bytes

◆ row_import_check_corruption()

dberr_t row_import_check_corruption ( dict_table_t table,
THD thd,
bool  missing 
)

Check the correctness of clustered index of imported table.

Once there is corruption found, the IMPORT would be refused. This can help to detect the missing .cfg file for a table with instant added columns.

Parameters
[in,out]tableInnoDB table object
[in,out]thdMySQL session variable
[in]missingtrue if .cfg file is missing
Returns
DB_SUCCESS or error code.

◆ row_import_cleanup()

static dberr_t row_import_cleanup ( row_prebuilt_t prebuilt,
trx_t trx,
dberr_t  err 
)
static

Clean up after import tablespace.

Parameters
prebuiltin/out: prebuilt from handler
trxin/out: transaction for import
errin: error code

◆ row_import_discard_changes()

static void row_import_discard_changes ( row_prebuilt_t prebuilt,
trx_t trx,
dberr_t  err 
)
static

Clean up after import tablespace failure, this function will acquire the dictionary latches on behalf of the transaction if the transaction hasn't already acquired them.

Parameters
prebuiltin/out: prebuilt from handler
trxin/out: transaction for import
errin: error code

◆ row_import_error()

static dberr_t row_import_error ( row_prebuilt_t prebuilt,
trx_t trx,
dberr_t  err 
)
static

Report error during tablespace import.

Parameters
prebuiltin/out: prebuilt from handler
trxin/out: transaction for import
errin: error code

◆ row_import_for_mysql()

dberr_t row_import_for_mysql ( dict_table_t table,
dd::Table table_def,
row_prebuilt_t prebuilt 
)

Imports a tablespace.

The space id in the .ibd file must match the space id of the table in the data dictionary.

Parameters
[in]tabletable
[in]table_defdd table
[in]prebuiltprebuilt struct in MySQL
Returns
error code or DB_SUCCESS

◆ row_import_read_bytes()

static byte * row_import_read_bytes ( FILE *  file,
size_t  length 
)
static

Read specified bytes from the meta data file.

Parameters
[in]filefile to read from
[in]lengthlength of bytes to read
Returns
the bytes stream, caller has to free the memory if not nullptr

◆ row_import_read_cfg()

static dberr_t row_import_read_cfg ( dict_table_t table,
dd::Table table_def,
THD thd,
row_import cfg 
)
static

Read the contents of the <tablename>.cfg file.

Parameters
[in]tabletable
[in]table_defdd table
[in]thdsession
[in,out]cfgcontents of the .cfg file
Returns
DB_SUCCESS or error code.

◆ row_import_read_cfp()

static dberr_t row_import_read_cfp ( dict_table_t table,
THD thd,
row_import import 
)
static

Read the contents of the .cfp file.

Parameters
[in]tabletable
[in]thdsession
[in,out]importmeta data
Returns
DB_SUCCESS or error code.

◆ row_import_read_columns()

static dberr_t row_import_read_columns ( dd::Table table_def,
FILE *  file,
THD thd,
row_import cfg 
)
static

Read the meta data (table columns) config file.

Deserialise the contents of dict_col_t structure, along with the column name.

Parameters
[in,out]table_defTable definition
[in]filefile to read from
[in]thdsession
[in]cfgmeta-data read

◆ row_import_read_common()

static dberr_t row_import_read_common ( dd::Table table_def,
FILE *  file,
THD thd,
row_import cfg 
)
static

Read the contents of the <tablespace>.cfg file.

Parameters
[in]table_defTable definition
[in]filefile to read from
[in]thdsession
[in,out]cfgmeta data
Returns
DB_SUCCESS or error code.

◆ row_import_read_default_values()

static dberr_t row_import_read_default_values ( FILE *  file,
dict_col_t col,
mem_heap_t **  heap,
bool *  read 
)
static

Read the metadata config file.

Deserialise the contents of dict_col_t::instant_default if exists. Refer to row_quiesce_write_default_value() for the format details.

Parameters
[in]filefile to read from
[in,out]colcolumn whose default value to read
[in,out]heapmemory heap to store default value
[in,out]readtrue if default value read

◆ row_import_read_dropped_col_metadata()

static dberr_t row_import_read_dropped_col_metadata ( dd::Table table_def,
FILE *  file,
THD thd,
dict_col_t col,
const char *  col_name 
)
static

Read dd::Column metadata for the dropped table.

Parameters
[in,out]table_defTable definition
[in]filefile to read from
[in]thdsession
[in]coldict_col_t
[in]col_namename of the columns

◆ row_import_read_encryption_data()

static dberr_t row_import_read_encryption_data ( dict_table_t table,
FILE *  file,
THD thd 
)
static

Read the contents of the .cfp file.

Parameters
[in]tabletable
[in]filefile to read from
[in]thdsession
Returns
DB_SUCCESS or error code.

◆ row_import_read_index_data()

static dberr_t row_import_read_index_data ( FILE *  file,
THD thd,
row_import cfg 
)
static

Read the index names and root page numbers of the indexes and set the values.

Row format [root_page_no, len of str, str ... ]

Returns
DB_SUCCESS or error code.
Parameters
filein: File to read from
thdin: session
cfgin/out: meta-data read

◆ row_import_read_indexes()

static dberr_t row_import_read_indexes ( FILE *  file,
THD thd,
row_import cfg 
)
static

Set the index root page number for v1 format.

Returns
DB_SUCCESS or error code.
Parameters
filein: File to read from
thdin: session
cfgin/out: meta-data read

◆ row_import_read_meta_data()

static dberr_t row_import_read_meta_data ( dict_table_t table,
dd::Table table_def,
FILE *  file,
THD thd,
row_import cfg 
)
static

Read the contents of the <tablespace>.cfg file.

Parameters
[in]tabledict table
[in]table_defTable definition
[in]fileFile to read from
[in]thdsession
[out]cfgcontents of the .cfg file
Returns
DB_SUCCESS or error code.

◆ row_import_read_v1()

static dberr_t row_import_read_v1 ( FILE *  file,
THD thd,
row_import cfg 
)
static

Read the contents of the <tablespace>.cfg file.

Returns
DB_SUCCESS or error code.
Parameters
filein: File to read from
thdin: session
cfgout: meta data

◆ row_import_read_v2()

static dberr_t row_import_read_v2 ( FILE *  file,
THD thd,
row_import cfg 
)
static

Read tablespace flags and compression type info from <tablespace>.cfg file.

Parameters
[in]fileFile to read from
[in]thdsession
[in,out]cfgmeta data
Returns
DB_SUCCESS or error code.

◆ row_import_set_sys_max_row_id()

static dberr_t row_import_set_sys_max_row_id ( row_prebuilt_t prebuilt,
dict_table_t table 
)
static

Ensure that dict_sys->row_id exceeds SELECT MAX(DB_ROW_ID).

Returns
error code
Parameters
prebuiltin/out: prebuilt from handler
tablein: table to import