MySQL 8.0.40
Source Code Documentation
log0ddl.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 2017, 2024, Oracle and/or its affiliates.
4
5Portions of this file contain modifications contributed and copyrighted by
6Google, Inc. Those modifications are gratefully acknowledged and are described
7briefly in the InnoDB documentation. The contributions by Google are
8incorporated with their permission, and subject to the conditions contained in
9the file COPYING.Google.
10
11This program is free software; you can redistribute it and/or modify it under
12the terms of the GNU General Public License, version 2.0, as published by the
13Free Software Foundation.
14
15This program is designed to work with certain software (including
16but not limited to OpenSSL) that is licensed under separate terms,
17as designated in a particular file or component or in included license
18documentation. The authors of MySQL hereby grant you an additional
19permission to link the program and your derivative works with the
20separately licensed software that they have either included with
21the program or referenced in the documentation.
22
23This program is distributed in the hope that it will be useful, but WITHOUT
24ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
25FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
26for more details.
27
28You should have received a copy of the GNU General Public License along with
29this program; if not, write to the Free Software Foundation, Inc.,
3051 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
31
32*****************************************************************************/
33
34/** @file include/log0ddl.h
35 DDL log
36
37 Created 12/1/2016 Shaohua Wang
38 *******************************************************/
39
40#ifndef log0ddl_h
41#define log0ddl_h
42
43/** DDL log types defined as uint32_t because it costs 4 bytes in
44mysql.innodb_ddl_log. */
45enum class Log_Type : uint32_t {
46 /** Smallest log type */
47 SMALLEST_LOG = 1,
48
49 /** Drop an index tree */
50 FREE_TREE_LOG = 1,
51
52 /** Delete a file */
54
55 /** Rename a file */
57
58 /** Drop the entry in innodb_table_metadata */
60
61 /** Rename table in dict cache. */
63
64 /** Remove a table from dict cache */
66
67 /** Alter Encrypt a tablespace */
69
70 /** Alter Unencrypt a tablespace */
72
73 /** Biggest log type */
75};
76
77/** DDL log record */
79 public:
80 /** Constructor. */
81 DDL_Record();
82
83 /** Destructor. */
85
86 /** Get the id of the DDL log record.
87 @return id of the record. */
88 ulint get_id() const { return (m_id); }
89
90 /** Set the id for the DDL log record.
91 @param[in] id id of the record. */
92 void set_id(ulint id) { m_id = id; }
93
94 /** Get the type of operation to perform
95 for the DDL log record.
96 @return type of the record. */
97 Log_Type get_type() const { return (m_type); }
98
99 /** Set the type for the DDL log record.
100 @param[in] type set the record type.*/
102
103 /** Get the thread id for the DDL log record.
104 @return thread id of the DDL log record. */
105 ulint get_thread_id() const { return (m_thread_id); }
106
107 /** Set the thread id for the DDL log record.
108 @param[in] thread_id thread id. */
110
111 /** Get the space_id present in the DDL log record.
112 @return space_id in the DDL log record. */
113 space_id_t get_space_id() const { return (m_space_id); }
114
115 /** Set the space id for the DDL log record.
116 @param[in] space space id. */
117 void set_space_id(space_id_t space) { m_space_id = space; }
118
119 /** Get the page no present in the DDL log record.
120 @return page_no */
121 page_no_t get_page_no() const { return (m_page_no); }
122
123 /** Set the page number for the DDL log record.
124 @param[in] page_no page number. */
125 void set_page_no(page_no_t page_no) { m_page_no = page_no; }
126
127 /** Get the index id present in the DDL log record.
128 @return index id. */
129 ulint get_index_id() const { return (m_index_id); }
130
131 /** Set the index id for the DDL log record.
132 @param[in] index_id index id. */
133 void set_index_id(ulint index_id) { m_index_id = index_id; }
134
135 /** Get the table id present in the DDL log record.
136 @return table id from the record. */
137 table_id_t get_table_id() const { return (m_table_id); }
138
139 /** Set the table if for the DDL log record.
140 @param[in] table_id table id. */
141 void set_table_id(table_id_t table_id) { m_table_id = table_id; }
142
143 /** Set deletability of this record.
144 @param[in] deletable deletability. */
145 void set_deletable(bool deletable) { m_deletable = deletable; }
146
147 /** If this record can be deleted.
148 @return true if record is deletable. */
149 bool get_deletable() const { return (m_deletable); }
150
151 /** Get encryption operation type */
153 auto type = get_type();
154
157 }
160 }
161
162 /** Get the old file path/name present in the DDL log record.
163 @return old file path/name. */
164 const char *get_old_file_path() const { return (m_old_file_path); }
165
166 /** Set the old file path from the name for the DDL log record.
167 @param[in] name old file name. */
168 void set_old_file_path(const char *name);
169
170 /** Copy the data and set it in old file path
171 @param[in] data data to be set
172 @param[in] len length of the data. */
173 void set_old_file_path(const byte *data, ulint len);
174
175 /** Get the new file path/name present in the DDL log record.
176 @return new file path/name. */
177 const char *get_new_file_path() const { return (m_new_file_path); }
178
179 /** Set the new file path/name for the DDL log record.
180 @param[in] name name to be set. */
181 void set_new_file_path(const char *name);
182
183 /** Copy the data and set it in new file path.
184 @param[in] data data to be set
185 @param[in] len length of the data. */
186 void set_new_file_path(const byte *data, ulint len);
187
188 /** Print the DDL record to specified output stream
189 @param[in,out] out output stream
190 @return output stream */
191 std::ostream &print(std::ostream &out) const;
192
193 private:
194 /** Log id */
196
197 /** Log type */
199
200 /** Thread id */
202
203 /** Tablespace id */
205
206 /** Index root page */
208
209 /** Index id */
211
212 /** Table id */
214
215 /** Tablespace file path for DELETE, Old tablespace file path
216 for RENAME */
218
219 /** New tablespace file name for RENAME */
221
222 /** memory heap object used for storing file name. */
224
225 /** If this record can be deleted */
227};
228
229/** Forward declaration */
230class THD;
231struct que_thr_t;
232struct dtuple_t;
233
234/** Array of DDL records */
235using DDL_Records = std::vector<DDL_Record *>;
236
237/** Wrapper of mysql.innodb_ddl_log table. Accessing to this table doesn't
238require row lock because thread could only access/modify its own ddl records. */
240 public:
241 /** Constructor. */
243
244 /** Constructor and it initializes transaction and query thread.
245 Once trx is passed in, make sure destructor is called before the
246 trx commits.
247 @param[in,out] trx Transaction */
248 explicit DDL_Log_Table(trx_t *trx);
249
250 /** Destructor. */
252
253 /** Insert the DDL log record into the innodb_ddl_log table.
254 This is thread safe.
255 @param[in] record Record to be inserted.
256 @return DB_SUCCESS or error. */
258
259 /** Search for all records of specified thread_id. The records
260 are kept in reverse order.
261 This is thread safe. Because different threads have different thread
262 ids, there should not be any conflict with update.
263 @param[in] thread_id thread id to search
264 @param[out] records DDL_Records of the specified thread id
265 @return DB_SUCCESS or error. */
267
268 /** Do a reverse scan on the table to fetch all the record.
269 This is only called during recovery
270 @param[out] records DDL_Records of the whole table
271 @return DB_SUCCESS or error. */
273
274 /** Delete the innodb_ddl_log record of specified ID.
275 This is thread safe. One thread will only remove its ddl record.
276 @param[in] id ID of the DDL_Record
277 @return DB_SUCCESS or error. */
278 dberr_t remove(ulint id);
279
280 /** Delete specified DDL_Records from innodb_ddl_log.
281 This is thread safe. Different threads have their own ddl records
282 to delete. And this could be called during recovery.
283 @param[in] records DDL_Record(s) to be deleted
284 @return DB_SUCCESS or error. */
285 dberr_t remove(const DDL_Records &records);
286
287 private:
288 /** Set the query thread using graph. */
289 void start_query_thread();
290
291 /** Stop the query thread. */
292 void stop_query_thread();
293
294 /** Create tuple for the innodb_ddl_log table.
295 It is used for insert operation.
296 @param[in] record DDL log record. */
297 void create_tuple(const DDL_Record &record);
298
299 /** Create tuple for the given index. Used for search by id
300 (and following delete)
301 @param[in] id Thread id/ id of the record
302 @param[in] index Clustered index or secondary index. */
303 void create_tuple(ulint id, const dict_index_t *index);
304
305 /** Convert the innodb_ddl_log index record to DDL_Record.
306 @param[in] is_clustered true if this is clustered index record,
307 otherwise the secondary index record
308 @param[in] rec index record
309 @param[in] offsets index record offset
310 @param[in,out] record to store the innodb_ddl_log record. */
311 void convert_to_ddl_record(bool is_clustered, rec_t *rec,
312 const ulint *offsets, DDL_Record &record);
313
314 /** Parse the index record and get 'ID'.
315 @param[in] index index where the record resides
316 @param[in] rec index rec
317 @param[in] offsets offsets of the index.
318 @return id of the record. */
319 ulint parse_id(const dict_index_t *index, rec_t *rec, const ulint *offsets);
320
321 /** Set the given field of the innodb_ddl_log record from given data.
322 @param[in] data data to be set
323 @param[in] offset column of the ddl record
324 @param[in] len length of the data
325 @param[in,out] record DDL_Record to set */
326 void set_field(const byte *data, ulint offset, ulint len, DDL_Record &record);
327
328 /** Fetch the value from given offset.
329 @param[in] data value to be retrieved from data
330 @param[in] offset offset of the column
331 @return value of the given offset. */
332 ulint fetch_value(const byte *data, ulint offset);
333
334 /** Search specified index by specified ID
335 @param[in] id ID to search
336 @param[in] index index to search
337 @param[in,out] records DDL_Record(s) got by the search
338 @return DB_SUCCESS or error */
339 dberr_t search_by_id(ulint id, dict_index_t *index, DDL_Records &records);
340
341 private:
342 /** Column number of mysql.innodb_ddl_log.id. */
343 static constexpr unsigned s_id_col_no = 0;
344
345 /** Column length of mysql.innodb_ddl_log.id. */
346 static constexpr unsigned s_id_col_len = 8;
347
348 /** Column number of mysql.innodb_ddl_log.thread_id. */
349 static constexpr unsigned s_thread_id_col_no = 1;
350
351 /** Column length of mysql.innodb_ddl_log.thread_id. */
352 static constexpr unsigned s_thread_id_col_len = 8;
353
354 /** Column number of mysql.innodb_ddl_log.type. */
355 static constexpr unsigned s_type_col_no = 2;
356
357 /** Column length of mysql.innodb_ddl_log.type. */
358 static constexpr unsigned s_type_col_len = 4;
359
360 /** Column number of mysql.innodb_ddl_log.space_id. */
361 static constexpr unsigned s_space_id_col_no = 3;
362
363 /** Column length of mysql.innodb_ddl_log.space_id. */
364 static constexpr unsigned s_space_id_col_len = 4;
365
366 /** Column number of mysql.innodb_ddl_log.page_no. */
367 static constexpr unsigned s_page_no_col_no = 4;
368
369 /** Column length of mysql.innodb_ddl_log.page_no. */
370 static constexpr unsigned s_page_no_col_len = 4;
371
372 /** Column number of mysql.innodb_ddl_log.index_id. */
373 static constexpr unsigned s_index_id_col_no = 5;
374
375 /** Column length of mysql.innodb_ddl_log.index_id. */
376 static constexpr unsigned s_index_id_col_len = 8;
377
378 /** Column number of mysql.innodb_ddl_log.table_id. */
379 static constexpr unsigned s_table_id_col_no = 6;
380
381 /** Column length of mysql.innodb_ddl_log.table_id. */
382 static constexpr unsigned s_table_id_col_len = 8;
383
384 /** Column number of mysql.innodb_ddl_log.old_file_path. */
385 static constexpr unsigned s_old_file_path_col_no = 7;
386
387 /** Column number of mysql.innodb_ddl_log.new_file_path. */
388 static constexpr unsigned s_new_file_path_col_no = 8;
389
390 /** innodb_ddl_log table. */
392
393 /** Tuple used for insert, search, delete operation. */
395
396 /** Transaction used for insert, delete operation. */
398
399 /** Dummy query thread. */
401
402 /** Heap to store the m_tuple, m_thr and all
403 operation on mysql.innodb_ddl_log table. */
405};
406
407/** Class to write and replay ddl logs */
408class Log_DDL {
409 public:
410 /** Constructor */
411 Log_DDL();
412
413 /** Deconstructor */
414 ~Log_DDL() = default;
415
416 /** Write DDL log for freeing B-tree
417 @param[in,out] trx transaction
418 @param[in] index dict index
419 @param[in] is_drop_table true if this is drop table
420 @return DB_SUCCESS or error */
422 bool is_drop_table);
423
424 /** Write DDL log for deleting tablespace file
425 @param[in,out] trx transaction
426 @param[in] table dict table
427 @param[in] space_id tablespace id
428 @param[in] file_path file path
429 @param[in] is_drop flag whether dropping tablespace
430 @param[in] dict_locked true if dict_sys mutex is held
431 @return DB_SUCCESS or error */
433 space_id_t space_id, const char *file_path,
434 bool is_drop, bool dict_locked);
435
436 /** Write a RENAME log record
437 @param[in] space_id tablespace id
438 @param[in] old_file_path file path after rename
439 @param[in] new_file_path file path before rename
440 @return DB_SUCCESS or error */
441 dberr_t write_rename_space_log(space_id_t space_id, const char *old_file_path,
442 const char *new_file_path);
443
444 /** Find alter encrypt record for the tablespace.
445 @param[in] space_id space_id
446 return log record if exists, null otherwise */
448
449 /** Write an ALTER ENCRYPT Tablespace DDL log record
450 @param[in] space_id tablespace id
451 @param[in] type encryption operation type
452 @param[out] existing_rec alter_encrypt ddl record, nullptr if none
453 @return DB_SUCCESS or error */
456 DDL_Record *existing_rec);
457
458 /** Write a DROP log to indicate the entry in innodb_table_metadata
459 should be removed for specified table
460 @param[in,out] trx transaction
461 @param[in] table_id table ID
462 @return DB_SUCCESS or error */
463 dberr_t write_drop_log(trx_t *trx, const table_id_t table_id);
464
465 /** Write a RENAME table log record
466 @param[in] table dict table
467 @param[in] old_name table name after rename
468 @param[in] new_name table name before rename
469 @return DB_SUCCESS or error */
470 dberr_t write_rename_table_log(dict_table_t *table, const char *old_name,
471 const char *new_name);
472
473 /** Write a REMOVE cache log record
474 @param[in,out] trx transaction
475 @param[in] table dict table
476 @return DB_SUCCESS or error */
478
479 /** Replay DDL log record
480 @param[in,out] record DDL log record
481 return DB_SUCCESS or error */
483
484 /** Replay and clean DDL logs after DDL transaction
485 commints or rollbacks.
486 @param[in] thd mysql thread
487 @return DB_SUCCESS or error */
488 dberr_t post_ddl(THD *thd);
489
490 /** Recover in server startup.
491 Scan innodb_ddl_log table, and replay all log entries.
492 Note: redo log should be applied, and DD transactions
493 should be recovered before calling this function.
494 @return DB_SUCCESS or error */
496
497 /** Is it in ddl recovery in server startup.
498 @return true if it's in ddl recover */
499 static bool is_in_recovery() { return (s_in_recovery); }
500
501 private:
502 /** Insert a FREE log record
503 @param[in,out] trx transaction
504 @param[in] index dict index
505 @param[in] id log id
506 @param[in] thread_id thread id
507 @return DB_SUCCESS or error */
509 uint64_t id, ulint thread_id);
510
511 /** Replay FREE log(free B-tree if exist)
512 @param[in] space_id tablespace id
513 @param[in] page_no root page no
514 @param[in] index_id index id */
515 void replay_free_tree_log(space_id_t space_id, page_no_t page_no,
516 ulint index_id);
517
518 /** Insert a DELETE log record
519 @param[in,out] trx transaction
520 @param[in] id log id
521 @param[in] thread_id thread id
522 @param[in] space_id tablespace id
523 @param[in] file_path file path
524 @param[in] dict_locked true if dict_sys mutex is held
525 @return DB_SUCCESS or error */
527 space_id_t space_id, const char *file_path,
528 bool dict_locked);
529
530 /** Replay DELETE log(delete file if exist)
531 @param[in] space_id tablespace id
532 @param[in] file_path file path */
533 void replay_delete_space_log(space_id_t space_id, const char *file_path);
534
535 /** Insert a RENAME log record
536 @param[in] id log id
537 @param[in] thread_id thread id
538 @param[in] space_id tablespace id
539 @param[in] old_file_path file path after rename
540 @param[in] new_file_path file path before rename
541 @return DB_SUCCESS or error */
543 space_id_t space_id,
544 const char *old_file_path,
545 const char *new_file_path);
546
547 /** Replay RENAME log
548 @param[in] space_id tablespace id
549 @param[in] old_file_path old file path
550 @param[in] new_file_path new file path */
551 void replay_rename_space_log(space_id_t space_id, const char *old_file_path,
552 const char *new_file_path);
553
554 /** Insert an ALTER ENCRYPT TABLESPACE log record
555 @param[in] id log id
556 @param[in] thread_id thread id
557 @param[in] space_id tablespace id
558 @param[in] type encryption operation type
559 @param[out] existing_rec alter_encrypt ddl record, nullptr if none
560 @return DB_SUCCESS or error */
562 space_id_t space_id,
564 DDL_Record *existing_rec);
565
566 /** Replay an ALTER ENCRYPT TABLESPACE log record
567 @param[in] record DDL Record
568 @return DB_SUCCESS or error */
570
571 /** Insert a DROP log record
572 @param[in,out] trx transaction
573 @param[in] id log id
574 @param[in] thread_id thread id
575 @param[in] table_id table id
576 @return DB_SUCCESS or error */
577 dberr_t insert_drop_log(trx_t *trx, uint64_t id, ulint thread_id,
578 const table_id_t table_id);
579
580 /** Replay DROP log
581 @param[in] table_id table id */
582 void replay_drop_log(const table_id_t table_id);
583
584 /** Insert a RENAME TABLE log record
585 @param[in] id log id
586 @param[in] thread_id thread id
587 @param[in] table_id table id
588 @param[in] old_name table name after rename
589 @param[in] new_name table name before rename
590 @return DB_SUCCESS or error */
592 table_id_t table_id, const char *old_name,
593 const char *new_name);
594
595 /** Relay RENAME TABLE log
596 @param[in] old_name old name
597 @param[in] new_name new name */
598 void replay_rename_table_log(const char *old_name, const char *new_name);
599
600 /** Insert a REMOVE cache log record
601 @param[in] id log id
602 @param[in] thread_id thread id
603 @param[in] table_id table id
604 @param[in] table_name table name
605 @return DB_SUCCESS or error */
607 table_id_t table_id, const char *table_name);
608
609 /** Relay remove cache log
610 @param[in] table_id table id
611 @param[in] table_name table name */
612 void replay_remove_cache_log(table_id_t table_id, const char *table_name);
613
614 /** Delete log record by id
615 @param[in] trx transaction instance
616 @param[in] id log id
617 @param[in] dict_locked true if dict_sys mutex is held,
618 otherwise false
619 @return DB_SUCCESS or error */
620 dberr_t delete_by_id(trx_t *trx, uint64_t id, bool dict_locked);
621
622 /** Scan, replay and delete log records by thread id
623 @param[in] thread_id thread id
624 @return DB_SUCCESS or error */
626
627 /** Delete the log records present in the list.
628 @param[in] records DDL_Records where the IDs are got
629 @return DB_SUCCESS or error. */
631
632 /** Scan, replay and delete all log records
633 @return DB_SUCCESS or error */
635
636 /** Get next autoinc counter by increasing 1 for innodb_ddl_log
637 @return new next counter */
638 inline uint64_t next_id();
639
640 /** Check if we need to skip ddl log for a table.
641 @param[in] table dict table
642 @param[in] thd mysql thread
643 @return true if should skip, otherwise false */
644 inline bool skip(const dict_table_t *table, THD *thd);
645
646 private:
647 /** Whether in recover(replay) ddl log in startup. */
648 static bool s_in_recovery;
649};
650
651/** Object to handle Log_DDL */
652extern Log_DDL *log_ddl;
653
654/** Close the DDL log system */
656
657#ifdef UNIV_DEBUG
658struct SYS_VAR;
659
660/** Used by SET GLOBAL innodb_ddl_log_crash_counter_reset_debug = 1; */
662
663/** Reset all crash injection counters. It's used by:
664 SET GLOBAL innodb_ddl_log_crash_reset_debug = 1 (0).
665@param[in] thd thread handle
666@param[in] var pointer to system variable
667@param[in] var_ptr where the formal string goes
668@param[in] save immediate result from check function */
669void ddl_log_crash_reset(THD *thd, SYS_VAR *var, void *var_ptr,
670 const void *save);
671#endif /* UNIV_DEBUG */
672
673#endif /* log0ddl_h */
uint32_t space_id_t
Tablespace identifier.
Definition: api0api.h:52
uint32_t page_no_t
Page number.
Definition: api0api.h:50
Wrapper of mysql.innodb_ddl_log table.
Definition: log0ddl.h:239
dberr_t search(ulint thread_id, DDL_Records &records)
Search for all records of specified thread_id.
Definition: log0ddl.cc:666
static constexpr unsigned s_page_no_col_no
Column number of mysql.innodb_ddl_log.page_no.
Definition: log0ddl.h:367
static constexpr unsigned s_thread_id_col_len
Column length of mysql.innodb_ddl_log.thread_id.
Definition: log0ddl.h:352
mem_heap_t * m_heap
Heap to store the m_tuple, m_thr and all operation on mysql.innodb_ddl_log table.
Definition: log0ddl.h:404
static constexpr unsigned s_index_id_col_len
Column length of mysql.innodb_ddl_log.index_id.
Definition: log0ddl.h:376
static constexpr unsigned s_table_id_col_len
Column length of mysql.innodb_ddl_log.table_id.
Definition: log0ddl.h:382
static constexpr unsigned s_id_col_no
Column number of mysql.innodb_ddl_log.id.
Definition: log0ddl.h:343
static constexpr unsigned s_index_id_col_no
Column number of mysql.innodb_ddl_log.index_id.
Definition: log0ddl.h:373
void set_field(const byte *data, ulint offset, ulint len, DDL_Record &record)
Set the given field of the innodb_ddl_log record from given data.
Definition: log0ddl.cc:558
static constexpr unsigned s_table_id_col_no
Column number of mysql.innodb_ddl_log.table_id.
Definition: log0ddl.h:379
static constexpr unsigned s_space_id_col_no
Column number of mysql.innodb_ddl_log.space_id.
Definition: log0ddl.h:361
dberr_t search_all(DDL_Records &records)
Do a reverse scan on the table to fetch all the record.
Definition: log0ddl.cc:627
dict_table_t * m_table
innodb_ddl_log table.
Definition: log0ddl.h:391
que_thr_t * m_thr
Dummy query thread.
Definition: log0ddl.h:400
dberr_t search_by_id(ulint id, dict_index_t *index, DDL_Records &records)
Search specified index by specified ID.
Definition: log0ddl.cc:687
static constexpr unsigned s_page_no_col_len
Column length of mysql.innodb_ddl_log.page_no.
Definition: log0ddl.h:370
static constexpr unsigned s_space_id_col_len
Column length of mysql.innodb_ddl_log.space_id.
Definition: log0ddl.h:364
static constexpr unsigned s_thread_id_col_no
Column number of mysql.innodb_ddl_log.thread_id.
Definition: log0ddl.h:349
static constexpr unsigned s_old_file_path_col_no
Column number of mysql.innodb_ddl_log.old_file_path.
Definition: log0ddl.h:385
ulint parse_id(const dict_index_t *index, rec_t *rec, const ulint *offsets)
Parse the index record and get 'ID'.
Definition: log0ddl.cc:547
static constexpr unsigned s_type_col_len
Column length of mysql.innodb_ddl_log.type.
Definition: log0ddl.h:358
static constexpr unsigned s_id_col_len
Column length of mysql.innodb_ddl_log.id.
Definition: log0ddl.h:346
static constexpr unsigned s_new_file_path_col_no
Column number of mysql.innodb_ddl_log.new_file_path.
Definition: log0ddl.h:388
dtuple_t * m_tuple
Tuple used for insert, search, delete operation.
Definition: log0ddl.h:394
dberr_t insert(const DDL_Record &record)
Insert the DDL log record into the innodb_ddl_log table.
Definition: log0ddl.cc:462
void stop_query_thread()
Stop the query thread.
Definition: log0ddl.cc:340
void create_tuple(const DDL_Record &record)
Create tuple for the innodb_ddl_log table.
Definition: log0ddl.cc:346
static constexpr unsigned s_type_col_no
Column number of mysql.innodb_ddl_log.type.
Definition: log0ddl.h:355
trx_t * m_trx
Transaction used for insert, delete operation.
Definition: log0ddl.h:397
DDL_Log_Table()
Constructor.
Definition: log0ddl.cc:317
ulint fetch_value(const byte *data, ulint offset)
Fetch the value from given offset.
Definition: log0ddl.cc:603
~DDL_Log_Table()
Destructor.
Definition: log0ddl.cc:328
dberr_t remove(ulint id)
Delete the innodb_ddl_log record of specified ID.
Definition: log0ddl.cc:730
void start_query_thread()
Set the query thread using graph.
Definition: log0ddl.cc:333
void convert_to_ddl_record(bool is_clustered, rec_t *rec, const ulint *offsets, DDL_Record &record)
Convert the innodb_ddl_log index record to DDL_Record.
Definition: log0ddl.cc:522
DDL log record.
Definition: log0ddl.h:78
ulint m_id
Log id.
Definition: log0ddl.h:195
ulint m_thread_id
Thread id.
Definition: log0ddl.h:201
const char * get_new_file_path() const
Get the new file path/name present in the DDL log record.
Definition: log0ddl.h:177
Log_Type m_type
Log type.
Definition: log0ddl.h:198
Log_Type get_type() const
Get the type of operation to perform for the DDL log record.
Definition: log0ddl.h:97
page_no_t get_page_no() const
Get the page no present in the DDL log record.
Definition: log0ddl.h:121
void set_new_file_path(const char *name)
Set the new file path/name for the DDL log record.
Definition: log0ddl.cc:186
void set_index_id(ulint index_id)
Set the index id for the DDL log record.
Definition: log0ddl.h:133
table_id_t get_table_id() const
Get the table id present in the DDL log record.
Definition: log0ddl.h:137
void set_table_id(table_id_t table_id)
Set the table if for the DDL log record.
Definition: log0ddl.h:141
space_id_t get_space_id() const
Get the space_id present in the DDL log record.
Definition: log0ddl.h:113
void set_page_no(page_no_t page_no)
Set the page number for the DDL log record.
Definition: log0ddl.h:125
Encryption::Progress get_encryption_type() const
Get encryption operation type.
Definition: log0ddl.h:152
~DDL_Record()
Destructor.
Definition: log0ddl.cc:161
void set_type(Log_Type type)
Set the type for the DDL log record.
Definition: log0ddl.h:101
ulint get_id() const
Get the id of the DDL log record.
Definition: log0ddl.h:88
ulint m_index_id
Index id.
Definition: log0ddl.h:210
mem_heap_t * m_heap
memory heap object used for storing file name.
Definition: log0ddl.h:223
DDL_Record()
Constructor.
Definition: log0ddl.cc:149
bool get_deletable() const
If this record can be deleted.
Definition: log0ddl.h:149
char * m_old_file_path
Tablespace file path for DELETE, Old tablespace file path for RENAME.
Definition: log0ddl.h:217
space_id_t m_space_id
Tablespace id.
Definition: log0ddl.h:204
void set_deletable(bool deletable)
Set deletability of this record.
Definition: log0ddl.h:145
table_id_t m_table_id
Table id.
Definition: log0ddl.h:213
void set_id(ulint id)
Set the id for the DDL log record.
Definition: log0ddl.h:92
page_no_t m_page_no
Index root page.
Definition: log0ddl.h:207
ulint get_index_id() const
Get the index id present in the DDL log record.
Definition: log0ddl.h:129
void set_thread_id(ulint thread_id)
Set the thread id for the DDL log record.
Definition: log0ddl.h:109
void set_space_id(space_id_t space)
Set the space id for the DDL log record.
Definition: log0ddl.h:117
const char * get_old_file_path() const
Get the old file path/name present in the DDL log record.
Definition: log0ddl.h:164
bool m_deletable
If this record can be deleted.
Definition: log0ddl.h:226
std::ostream & print(std::ostream &out) const
Print the DDL record to specified output stream.
Definition: log0ddl.cc:205
void set_old_file_path(const char *name)
Set the old file path from the name for the DDL log record.
Definition: log0ddl.cc:167
ulint get_thread_id() const
Get the thread id for the DDL log record.
Definition: log0ddl.h:105
char * m_new_file_path
New tablespace file name for RENAME.
Definition: log0ddl.h:220
Progress
Encryption progress type.
Definition: os0enc.h:80
Class to write and replay ddl logs.
Definition: log0ddl.h:408
void replay_drop_log(const table_id_t table_id)
Replay DROP log.
Definition: log0ddl.cc:1804
dberr_t replay(DDL_Record &record)
Replay DDL log record.
Definition: log0ddl.cc:1576
dberr_t insert_rename_space_log(uint64_t id, ulint thread_id, space_id_t space_id, const char *old_file_path, const char *new_file_path)
Insert a RENAME log record.
Definition: log0ddl.cc:1119
void replay_rename_space_log(space_id_t space_id, const char *old_file_path, const char *new_file_path)
Replay RENAME log.
Definition: log0ddl.cc:1722
~Log_DDL()=default
Deconstructor.
DDL_Record * find_alter_encrypt_record(space_id_t space_id)
Find alter encrypt record for the tablespace.
Definition: log0ddl.cc:1156
dberr_t write_rename_space_log(space_id_t space_id, const char *old_file_path, const char *new_file_path)
Write a RENAME log record.
Definition: log0ddl.cc:1065
dberr_t post_ddl(THD *thd)
Replay and clean DDL logs after DDL transaction commints or rollbacks.
Definition: log0ddl.cc:1905
dberr_t insert_free_tree_log(trx_t *trx, const dict_index_t *index, uint64_t id, ulint thread_id)
Insert a FREE log record.
Definition: log0ddl.cc:920
dberr_t recover()
Recover in server startup.
Definition: log0ddl.cc:1942
dberr_t delete_by_id(trx_t *trx, uint64_t id, bool dict_locked)
Delete log record by id.
Definition: log0ddl.cc:1442
dberr_t write_free_tree_log(trx_t *trx, const dict_index_t *index, bool is_drop_table)
Write DDL log for freeing B-tree.
Definition: log0ddl.cc:853
Log_DDL()
Constructor.
Definition: log0ddl.cc:830
dberr_t write_alter_encrypt_space_log(space_id_t space_id, Encryption::Progress type, DDL_Record *existing_rec)
Write an ALTER ENCRYPT Tablespace DDL log record.
Definition: log0ddl.cc:1167
dberr_t insert_alter_encrypt_space_log(uint64_t id, ulint thread_id, space_id_t space_id, Encryption::Progress type, DDL_Record *existing_rec)
Insert an ALTER ENCRYPT TABLESPACE log record.
Definition: log0ddl.cc:1211
void replay_rename_table_log(const char *old_name, const char *new_name)
Relay RENAME TABLE log.
Definition: log0ddl.cc:1813
uint64_t next_id()
Get next autoinc counter by increasing 1 for innodb_ddl_log.
Definition: log0ddl.cc:835
dberr_t insert_delete_space_log(trx_t *trx, uint64_t id, ulint thread_id, space_id_t space_id, const char *file_path, bool dict_locked)
Insert a DELETE log record.
Definition: log0ddl.cc:1016
dberr_t write_drop_log(trx_t *trx, const table_id_t table_id)
Write a DROP log to indicate the entry in innodb_table_metadata should be removed for specified table...
Definition: log0ddl.cc:1258
bool skip(const dict_table_t *table, THD *thd)
Check if we need to skip ddl log for a table.
Definition: log0ddl.cc:847
dberr_t insert_remove_cache_log(uint64_t id, ulint thread_id, table_id_t table_id, const char *table_name)
Insert a REMOVE cache log record.
Definition: log0ddl.cc:1412
dberr_t replay_by_thread_id(ulint thread_id)
Scan, replay and delete log records by thread id.
Definition: log0ddl.cc:1506
dberr_t write_rename_table_log(dict_table_t *table, const char *old_name, const char *new_name)
Write a RENAME table log record.
Definition: log0ddl.cc:1313
static bool is_in_recovery()
Is it in ddl recovery in server startup.
Definition: log0ddl.h:499
dberr_t delete_by_ids(DDL_Records &records)
Delete the log records present in the list.
Definition: log0ddl.cc:1539
dberr_t insert_rename_table_log(uint64_t id, ulint thread_id, table_id_t table_id, const char *old_name, const char *new_name)
Insert a RENAME TABLE log record.
Definition: log0ddl.cc:1345
void replay_remove_cache_log(table_id_t table_id, const char *table_name)
Relay remove cache log.
Definition: log0ddl.cc:1873
void replay_delete_space_log(space_id_t space_id, const char *file_path)
Replay DELETE log(delete file if exist)
Definition: log0ddl.cc:1659
dberr_t insert_drop_log(trx_t *trx, uint64_t id, ulint thread_id, const table_id_t table_id)
Insert a DROP log record.
Definition: log0ddl.cc:1283
dberr_t write_delete_space_log(trx_t *trx, const dict_table_t *table, space_id_t space_id, const char *file_path, bool is_drop, bool dict_locked)
Write DDL log for deleting tablespace file.
Definition: log0ddl.cc:961
dberr_t replay_alter_encrypt_space_log(DDL_Record &record)
Replay an ALTER ENCRYPT TABLESPACE log record.
Definition: log0ddl.cc:1777
dberr_t write_remove_cache_log(trx_t *trx, dict_table_t *table)
Write a REMOVE cache log record.
Definition: log0ddl.cc:1382
dberr_t replay_all()
Scan, replay and delete all log records.
Definition: log0ddl.cc:1474
static bool s_in_recovery
Whether in recover(replay) ddl log in startup.
Definition: log0ddl.h:648
void replay_free_tree_log(space_id_t space_id, page_no_t page_no, ulint index_id)
Replay FREE log(free B-tree if exist)
Definition: log0ddl.cc:1625
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:34
dberr_t
Definition: db0err.h:39
ib_id_t table_id_t
Table or partition identifier (unique within an InnoDB instance).
Definition: dict0types.h:232
Log_Type
DDL log types defined as uint32_t because it costs 4 bytes in mysql.innodb_ddl_log.
Definition: log0ddl.h:45
@ BIGGEST_LOG
Biggest log type.
@ ALTER_UNENCRYPT_TABLESPACE_LOG
Alter Unencrypt a tablespace.
@ DROP_LOG
Drop the entry in innodb_table_metadata.
@ REMOVE_CACHE_LOG
Remove a table from dict cache.
@ SMALLEST_LOG
Smallest log type.
@ DELETE_SPACE_LOG
Delete a file.
@ RENAME_SPACE_LOG
Rename a file.
@ RENAME_TABLE_LOG
Rename table in dict cache.
@ ALTER_ENCRYPT_TABLESPACE_LOG
Alter Encrypt a tablespace.
@ FREE_TREE_LOG
Drop an index tree.
std::vector< DDL_Record * > DDL_Records
Array of DDL records.
Definition: log0ddl.h:235
void ddl_log_close()
Close the DDL log system.
Definition: log0ddl.h:655
void ddl_log_crash_reset(THD *thd, SYS_VAR *var, void *var_ptr, const void *save)
Reset all crash injection counters.
Definition: log0ddl.cc:126
bool innodb_ddl_log_crash_reset_debug
Used by SET GLOBAL innodb_ddl_log_crash_counter_reset_debug = 1;.
Definition: log0ddl.cc:74
Log_DDL * log_ddl
Object to handle Log_DDL.
Definition: log0ddl.cc:62
static my_thread_id thread_id
Definition: my_thr_init.cc:63
static int record
Definition: mysqltest.cc:188
const char * table_name
Definition: rules_table_service.cc:56
void delete_(T *ptr) noexcept
Releases storage which has been dynamically allocated through any of the ut::new*() variants.
Definition: ut0new.h:810
byte rec_t
Definition: rem0types.h:41
required string type
Definition: replication_group_member_actions.proto:34
case opt name
Definition: sslopt-case.h:33
Definition: plugin.h:67
Data structure for an index.
Definition: dict0mem.h:1046
Data structure for a database table.
Definition: dict0mem.h:1909
Structure for an SQL data tuple of fields (logical record)
Definition: data0data.h:694
The info structure stored at the beginning of a heap block.
Definition: mem0mem.h:302
Definition: que0que.h:242
Definition: trx0trx.h:675
unsigned long int ulint
Definition: univ.i:406
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:69
unsigned long id[MAX_DEAD]
Definition: xcom_base.cc:510