1 /*****************************************************************************
2 
3 Copyright (c) 1996, 2018, Oracle and/or its affiliates. All Rights Reserved.
4 
5 This program is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License, version 2.0, as published by the
7 Free Software Foundation.
8 
9 This program is also distributed with certain software (including but not
10 limited to OpenSSL) that is licensed under separate terms, as designated in a
11 particular file or component or in included license documentation. The authors
12 of MySQL hereby grant you an additional permission to link the program and
13 your derivative works with the separately licensed software that they have
14 included with MySQL.
15 
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
19 for more details.
20 
21 You should have received a copy of the GNU General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc.,
23 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
24 
25 *****************************************************************************/
26 
27 #include "my_inttypes.h"
28 
29 class THD;
30 struct TABLE;
31 
32 /* This is used only during upgrade. We don't use ids
33 from DICT_HDR during upgrade because unlike bootstrap case,
34 the ids are moved after user table creation.  Since we
35 want to create dictionary tables with fixed ids, we use
36 in-memory counter for upgrade */
37 extern uint32_t dd_upgrade_indexes_num;
38 
39 namespace dd {
40 class Table;
41 class Tablespace;
42 }  // namespace dd
43 
44 /** Migrate table from InnoDB Dictionary (INNODB SYS_*) tables to new Data
45 Dictionary. Since FTS tables contain table_id in their physical file name
46 and during upgrade we reserve DICT_MAX_DD_TABLES for dictionary tables.
47 So we rename FTS tablespace files
48 @param[in]	thd		Server thread object
49 @param[in]	db_name		database name
50 @param[in]	table_name	table name
51 @param[in,out]	dd_table	new dictionary table object to be filled
52 @param[in]	srv_table	server table object
53 @return false on success, true on failure. */
54 bool dd_upgrade_table(THD *thd, const char *db_name, const char *table_name,
55                       dd::Table *dd_table, TABLE *srv_table);
56 
57 /** Migrate tablespace entries from InnoDB SYS_TABLESPACES to new data
58 dictionary. FTS Tablespaces are not registered as they are handled differently.
59 FTS tablespaces have table_id in their name and we increment table_id of each
60 table by DICT_MAX_DD_TABLES
61 @param[in,out]	thd		THD
62 @return MySQL error code*/
63 int dd_upgrade_tablespace(THD *thd);
64 
65 /** Add server and space version number to tablespace while upgrading.
66 @param[in]	space_id		space id of tablespace
67 @param[in]	server_version_only	leave space version unchanged
68 @return false on success, true on failure. */
69 bool upgrade_space_version(const uint32 space_id, bool server_version_only);
70 
71 /** Add server version number to tablespace while upgrading.
72 @param[in]	tablespace		dd::Tablespace
73 @return false on success, true on failure. */
74 bool upgrade_space_version(dd::Tablespace *tablespace);
75 
76 /** Upgrade innodb undo logs after upgrade. Also increment the table_id
77 offset by DICT_MAX_DD_TABLES. This offset increment is because the
78 first 256 table_ids are reserved for dictionary
79 @param[in,out]	thd		THD
80 @return MySQL error code*/
81 int dd_upgrade_logs(THD *thd);
82 
83 /** If upgrade is successful, this API is used to flush innodb
84 dirty pages to disk. In case of server crash, this function
85 sets storage engine for rollback any changes.
86 @param[in,out]	thd		THD
87 @param[in]	failed_upgrade	true when upgrade failed
88 @return MySQL error code*/
89 int dd_upgrade_finish(THD *thd, bool failed_upgrade);
90