1 /***************************************************************************** 2 3 Copyright (c) 2011, 2016, Oracle and/or its affiliates. All Rights Reserved. 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License, version 2.0, 7 as published by the Free Software Foundation. 8 9 This program is also distributed with certain software (including 10 but not limited to OpenSSL) that is licensed under separate terms, 11 as designated in a particular file or component or in included license 12 documentation. The authors of MySQL hereby grant you an additional 13 permission to link the program and your derivative works with the 14 separately licensed software that they have included with MySQL. 15 16 This program is distributed in the hope that it will be useful, 17 but WITHOUT ANY WARRANTY; without even the implied warranty of 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 GNU General Public License, version 2.0, 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 Street, Suite 500, Boston, MA 02110-1335 USA 24 25 *****************************************************************************/ 26 27 /**************************************************//** 28 @file include/row0log.h 29 Modification log for online index creation and online table rebuild 30 31 Created 2011-05-26 Marko Makela 32 *******************************************************/ 33 34 #ifndef row0log_h 35 #define row0log_h 36 37 #include "univ.i" 38 #include "mtr0types.h" 39 #include "row0types.h" 40 #include "rem0types.h" 41 #include "data0types.h" 42 #include "dict0types.h" 43 #include "trx0types.h" 44 #include "que0types.h" 45 46 /******************************************************//** 47 Allocate the row log for an index and flag the index 48 for online creation. 49 @retval true if success, false if not */ 50 UNIV_INTERN 51 bool 52 row_log_allocate( 53 /*=============*/ 54 dict_index_t* index, /*!< in/out: index */ 55 dict_table_t* table, /*!< in/out: new table being rebuilt, 56 or NULL when creating a secondary index */ 57 bool same_pk,/*!< in: whether the definition of the 58 PRIMARY KEY has remained the same */ 59 const dtuple_t* add_cols, 60 /*!< in: default values of 61 added columns, or NULL */ 62 const ulint* col_map,/*!< in: mapping of old column 63 numbers to new ones, or NULL if !table */ 64 const char* path) /*!< in: where to create temporary file */ 65 MY_ATTRIBUTE((nonnull(1), warn_unused_result)); 66 67 /******************************************************//** 68 Free the row log for an index that was being created online. */ 69 UNIV_INTERN 70 void 71 row_log_free( 72 /*=========*/ 73 row_log_t*& log) /*!< in,own: row log */ 74 MY_ATTRIBUTE((nonnull)); 75 76 /******************************************************//** 77 Free the row log for an index on which online creation was aborted. */ 78 UNIV_INLINE 79 void 80 row_log_abort_sec( 81 /*==============*/ 82 dict_index_t* index) /*!< in/out: index (x-latched) */ 83 MY_ATTRIBUTE((nonnull)); 84 85 /******************************************************//** 86 Try to log an operation to a secondary index that is 87 (or was) being created. 88 @retval true if the operation was logged or can be ignored 89 @retval false if online index creation is not taking place */ 90 UNIV_INLINE 91 bool 92 row_log_online_op_try( 93 /*==================*/ 94 dict_index_t* index, /*!< in/out: index, S or X latched */ 95 const dtuple_t* tuple, /*!< in: index tuple */ 96 trx_id_t trx_id) /*!< in: transaction ID for insert, 97 or 0 for delete */ 98 MY_ATTRIBUTE((nonnull, warn_unused_result)); 99 /******************************************************//** 100 Logs an operation to a secondary index that is (or was) being created. */ 101 UNIV_INTERN 102 void 103 row_log_online_op( 104 /*==============*/ 105 dict_index_t* index, /*!< in/out: index, S or X latched */ 106 const dtuple_t* tuple, /*!< in: index tuple */ 107 trx_id_t trx_id) /*!< in: transaction ID for insert, 108 or 0 for delete */ 109 UNIV_COLD MY_ATTRIBUTE((nonnull)); 110 111 /******************************************************//** 112 Gets the error status of the online index rebuild log. 113 @return DB_SUCCESS or error code */ 114 UNIV_INTERN 115 dberr_t 116 row_log_table_get_error( 117 /*====================*/ 118 const dict_index_t* index) /*!< in: clustered index of a table 119 that is being rebuilt online */ 120 MY_ATTRIBUTE((nonnull, warn_unused_result)); 121 122 /******************************************************//** 123 Logs a delete operation to a table that is being rebuilt. 124 This will be merged in row_log_table_apply_delete(). */ 125 UNIV_INTERN 126 void 127 row_log_table_delete( 128 /*=================*/ 129 const rec_t* rec, /*!< in: clustered index leaf page record, 130 page X-latched */ 131 dict_index_t* index, /*!< in/out: clustered index, S-latched 132 or X-latched */ 133 const ulint* offsets,/*!< in: rec_get_offsets(rec,index) */ 134 const byte* sys) /*!< in: DB_TRX_ID,DB_ROLL_PTR that should 135 be logged, or NULL to use those in rec */ 136 UNIV_COLD MY_ATTRIBUTE((nonnull(1,2,3))); 137 138 /******************************************************//** 139 Logs an update operation to a table that is being rebuilt. 140 This will be merged in row_log_table_apply_update(). */ 141 UNIV_INTERN 142 void 143 row_log_table_update( 144 /*=================*/ 145 const rec_t* rec, /*!< in: clustered index leaf page record, 146 page X-latched */ 147 dict_index_t* index, /*!< in/out: clustered index, S-latched 148 or X-latched */ 149 const ulint* offsets,/*!< in: rec_get_offsets(rec,index) */ 150 const dtuple_t* old_pk) /*!< in: row_log_table_get_pk() 151 before the update */ 152 UNIV_COLD MY_ATTRIBUTE((nonnull(1,2,3))); 153 154 /******************************************************//** 155 Constructs the old PRIMARY KEY and DB_TRX_ID,DB_ROLL_PTR 156 of a table that is being rebuilt. 157 @return tuple of PRIMARY KEY,DB_TRX_ID,DB_ROLL_PTR in the rebuilt table, 158 or NULL if the PRIMARY KEY definition does not change */ 159 UNIV_INTERN 160 const dtuple_t* 161 row_log_table_get_pk( 162 /*=================*/ 163 const rec_t* rec, /*!< in: clustered index leaf page record, 164 page X-latched */ 165 dict_index_t* index, /*!< in/out: clustered index, S-latched 166 or X-latched */ 167 const ulint* offsets,/*!< in: rec_get_offsets(rec,index), 168 or NULL */ 169 byte* sys, /*!< out: DB_TRX_ID,DB_ROLL_PTR for 170 row_log_table_delete(), or NULL */ 171 mem_heap_t** heap) /*!< in/out: memory heap where allocated */ 172 UNIV_COLD MY_ATTRIBUTE((nonnull(1,2,5), warn_unused_result)); 173 174 /******************************************************//** 175 Logs an insert to a table that is being rebuilt. 176 This will be merged in row_log_table_apply_insert(). */ 177 UNIV_INTERN 178 void 179 row_log_table_insert( 180 /*=================*/ 181 const rec_t* rec, /*!< in: clustered index leaf page record, 182 page X-latched */ 183 dict_index_t* index, /*!< in/out: clustered index, S-latched 184 or X-latched */ 185 const ulint* offsets)/*!< in: rec_get_offsets(rec,index) */ 186 UNIV_COLD MY_ATTRIBUTE((nonnull)); 187 /******************************************************//** 188 Notes that a BLOB is being freed during online ALTER TABLE. */ 189 UNIV_INTERN 190 void 191 row_log_table_blob_free( 192 /*====================*/ 193 dict_index_t* index, /*!< in/out: clustered index, X-latched */ 194 ulint page_no)/*!< in: starting page number of the BLOB */ 195 UNIV_COLD MY_ATTRIBUTE((nonnull)); 196 /******************************************************//** 197 Notes that a BLOB is being allocated during online ALTER TABLE. */ 198 UNIV_INTERN 199 void 200 row_log_table_blob_alloc( 201 /*=====================*/ 202 dict_index_t* index, /*!< in/out: clustered index, X-latched */ 203 ulint page_no)/*!< in: starting page number of the BLOB */ 204 UNIV_COLD MY_ATTRIBUTE((nonnull)); 205 /******************************************************//** 206 Apply the row_log_table log to a table upon completing rebuild. 207 @return DB_SUCCESS, or error code on failure */ 208 UNIV_INTERN 209 dberr_t 210 row_log_table_apply( 211 /*================*/ 212 que_thr_t* thr, /*!< in: query graph */ 213 dict_table_t* old_table, 214 /*!< in: old table */ 215 struct TABLE* table) /*!< in/out: MySQL table 216 (for reporting duplicates) */ 217 MY_ATTRIBUTE((nonnull, warn_unused_result)); 218 219 /******************************************************//** 220 Get the latest transaction ID that has invoked row_log_online_op() 221 during online creation. 222 @return latest transaction ID, or 0 if nothing was logged */ 223 UNIV_INTERN 224 trx_id_t 225 row_log_get_max_trx( 226 /*================*/ 227 dict_index_t* index) /*!< in: index, must be locked */ 228 MY_ATTRIBUTE((nonnull, warn_unused_result)); 229 230 /******************************************************//** 231 Merge the row log to the index upon completing index creation. 232 @return DB_SUCCESS, or error code on failure */ 233 UNIV_INTERN 234 dberr_t 235 row_log_apply( 236 /*==========*/ 237 trx_t* trx, /*!< in: transaction (for checking if 238 the operation was interrupted) */ 239 dict_index_t* index, /*!< in/out: secondary index */ 240 struct TABLE* table) /*!< in/out: MySQL table 241 (for reporting duplicates) */ 242 MY_ATTRIBUTE((nonnull, warn_unused_result)); 243 244 #ifndef UNIV_NONINL 245 #include "row0log.ic" 246 #endif 247 248 #endif /* row0log.h */ 249