MySQL 9.0.0
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 bool validate() const;
189
190 /** Print the DDL record to specified output stream
191 @param[in,out] out output stream
192 @return output stream */
193 std::ostream &print(std::ostream &out) const;
194
195 private:
196 /** Log id */
198
199 /** Log type */
201
202 /** Thread id */
204
205 /** Tablespace id */
207
208 /** Index root page */
210
211 /** Index id */
213
214 /** Table id */
216
217 /** Tablespace file path for DELETE, Old tablespace file path
218 for RENAME */
220
221 /** New tablespace file name for RENAME */
223
224 /** memory heap object used for storing file name. */
226
227 /** If this record can be deleted */
229};
230
231inline bool DDL_Record::validate() const {
234 return true;
235}
236
237/** Forward declaration */
238class THD;
239struct que_thr_t;
240struct dtuple_t;
241
242/** Array of DDL records */
243using DDL_Records = std::vector<DDL_Record *>;
244
245/** Wrapper of mysql.innodb_ddl_log table. Accessing to this table doesn't
246require row lock because thread could only access/modify its own ddl records. */
248 public:
249 /** Constructor. */
251
252 /** Constructor and it initializes transaction and query thread.
253 Once trx is passed in, make sure destructor is called before the
254 trx commits.
255 @param[in,out] trx Transaction */
256 explicit DDL_Log_Table(trx_t *trx);
257
258 /** Destructor. */
260
261 /** Insert the DDL log record into the innodb_ddl_log table.
262 This is thread safe.
263 @param[in] record Record to be inserted.
264 @return DB_SUCCESS or error. */
266
267 /** Search for all records of specified thread_id. The records
268 are kept in reverse order.
269 This is thread safe. Because different threads have different thread
270 ids, there should not be any conflict with update.
271 @param[in] thread_id thread id to search
272 @param[out] records DDL_Records of the specified thread id
273 @return DB_SUCCESS or error. */
275
276 /** Do a reverse scan on the table to fetch all the record.
277 This is only called during recovery
278 @param[out] records DDL_Records of the whole table
279 @return DB_SUCCESS or error. */
281
282 /** Delete the innodb_ddl_log record of specified ID.
283 This is thread safe. One thread will only remove its ddl record.
284 @param[in] id ID of the DDL_Record
285 @return DB_SUCCESS or error. */
286 dberr_t remove(ulint id);
287
288 /** Delete specified DDL_Records from innodb_ddl_log.
289 This is thread safe. Different threads have their own ddl records
290 to delete. And this could be called during recovery.
291 @param[in] records DDL_Record(s) to be deleted
292 @return DB_SUCCESS or error. */
293 dberr_t remove(const DDL_Records &records);
294
295 private:
296 /** Set the query thread using graph. */
297 void start_query_thread();
298
299 /** Stop the query thread. */
300 void stop_query_thread();
301
302 /** Create tuple for the innodb_ddl_log table.
303 It is used for insert operation.
304 @param[in] record DDL log record. */
305 void create_tuple(const DDL_Record &record);
306
307 /** Create tuple for the given index. Used for search by id
308 (and following delete)
309 @param[in] id Thread id/ id of the record
310 @param[in] index Clustered index or secondary index. */
311 void create_tuple(ulint id, const dict_index_t *index);
312
313 /** Convert the innodb_ddl_log index record to DDL_Record.
314 @param[in] is_clustered true if this is clustered index record,
315 otherwise the secondary index record
316 @param[in] rec index record
317 @param[in] offsets index record offset
318 @param[in,out] record to store the innodb_ddl_log record. */
319 void convert_to_ddl_record(bool is_clustered, rec_t *rec,
320 const ulint *offsets, DDL_Record &record);
321
322 /** Parse the index record and get 'ID'.
323 @param[in] index index where the record resides
324 @param[in] rec index rec
325 @param[in] offsets offsets of the index.
326 @return id of the record. */
327 ulint parse_id(const dict_index_t *index, rec_t *rec, const ulint *offsets);
328
329 /** Set the given field of the innodb_ddl_log record from given data.
330 @param[in] data data to be set
331 @param[in] offset column of the ddl record
332 @param[in] len length of the data
333 @param[in,out] record DDL_Record to set */
334 void set_field(const byte *data, ulint offset, ulint len, DDL_Record &record);
335
336 /** Fetch the value from given offset.
337 @param[in] data value to be retrieved from data
338 @param[in] offset offset of the column
339 @return value of the given offset. */
340 ulint fetch_value(const byte *data, ulint offset);
341
342 /** Search specified index by specified ID
343 @param[in] id ID to search
344 @param[in] index index to search
345 @param[in,out] records DDL_Record(s) got by the search
346 @return DB_SUCCESS or error */
347 dberr_t search_by_id(ulint id, dict_index_t *index, DDL_Records &records);
348
349 private:
350 /** Column number of mysql.innodb_ddl_log.id. */
351 static constexpr unsigned s_id_col_no = 0;
352
353 /** Column length of mysql.innodb_ddl_log.id. */
354 static constexpr unsigned s_id_col_len = 8;
355
356 /** Column number of mysql.innodb_ddl_log.thread_id. */
357 static constexpr unsigned s_thread_id_col_no = 1;
358
359 /** Column length of mysql.innodb_ddl_log.thread_id. */
360 static constexpr unsigned s_thread_id_col_len = 8;
361
362 /** Column number of mysql.innodb_ddl_log.type. */
363 static constexpr unsigned s_type_col_no = 2;
364
365 /** Column length of mysql.innodb_ddl_log.type. */
366 static constexpr unsigned s_type_col_len = 4;
367
368 /** Column number of mysql.innodb_ddl_log.space_id. */
369 static constexpr unsigned s_space_id_col_no = 3;
370
371 /** Column length of mysql.innodb_ddl_log.space_id. */
372 static constexpr unsigned s_space_id_col_len = 4;
373
374 /** Column number of mysql.innodb_ddl_log.page_no. */
375 static constexpr unsigned s_page_no_col_no = 4;
376
377 /** Column length of mysql.innodb_ddl_log.page_no. */
378 static constexpr unsigned s_page_no_col_len = 4;
379
380 /** Column number of mysql.innodb_ddl_log.index_id. */
381 static constexpr unsigned s_index_id_col_no = 5;
382
383 /** Column length of mysql.innodb_ddl_log.index_id. */
384 static constexpr unsigned s_index_id_col_len = 8;
385
386 /** Column number of mysql.innodb_ddl_log.table_id. */
387 static constexpr unsigned s_table_id_col_no = 6;
388
389 /** Column length of mysql.innodb_ddl_log.table_id. */
390 static constexpr unsigned s_table_id_col_len = 8;
391
392 /** Column number of mysql.innodb_ddl_log.old_file_path. */
393 static constexpr unsigned s_old_file_path_col_no = 7;
394
395 /** Column number of mysql.innodb_ddl_log.new_file_path. */
396 static constexpr unsigned s_new_file_path_col_no = 8;
397
398 /** innodb_ddl_log table. */
400
401 /** Tuple used for insert, search, delete operation. */
403
404 /** Transaction used for insert, delete operation. */
406
407 /** Dummy query thread. */
409
410 /** Heap to store the m_tuple, m_thr and all
411 operation on mysql.innodb_ddl_log table. */
413};
414
415/** Class to write and replay ddl logs */
416class Log_DDL {
417 public:
418 /** Constructor */
419 Log_DDL();
420
421 /** Deconstructor */
422 ~Log_DDL() = default;
423
424 /** Write DDL log for freeing B-tree
425 @param[in,out] trx transaction
426 @param[in] index dict index
427 @param[in] is_drop_table true if this is drop table
428 @return DB_SUCCESS or error */
430 bool is_drop_table);
431
432 /** Write DDL log for deleting tablespace file
433 @param[in,out] trx transaction
434 @param[in] table dict table
435 @param[in] space_id tablespace id
436 @param[in] file_path file path
437 @param[in] is_drop flag whether dropping tablespace
438 @param[in] dict_locked true if dict_sys mutex is held
439 @return DB_SUCCESS or error */
441 space_id_t space_id, const char *file_path,
442 bool is_drop, bool dict_locked);
443
444 /** Write a RENAME log record
445 @param[in] space_id tablespace id
446 @param[in] old_file_path file path after rename
447 @param[in] new_file_path file path before rename
448 @return DB_SUCCESS or error */
449 dberr_t write_rename_space_log(space_id_t space_id, const char *old_file_path,
450 const char *new_file_path);
451
452 /** Find alter encrypt record for the tablespace.
453 @param[in] space_id space_id
454 return log record if exists, null otherwise */
456
457 /** Write an ALTER ENCRYPT Tablespace DDL log record
458 @param[in] space_id tablespace id
459 @param[in] type encryption operation type
460 @param[out] existing_rec alter_encrypt ddl record, nullptr if none
461 @return DB_SUCCESS or error */
464 DDL_Record *existing_rec);
465
466 /** Write a DROP log to indicate the entry in innodb_table_metadata
467 should be removed for specified table
468 @param[in,out] trx transaction
469 @param[in] table_id table ID
470 @return DB_SUCCESS or error */
471 dberr_t write_drop_log(trx_t *trx, const table_id_t table_id);
472
473 /** Write a RENAME table log record
474 @param[in] table dict table
475 @param[in] old_name table name after rename
476 @param[in] new_name table name before rename
477 @return DB_SUCCESS or error */
478 dberr_t write_rename_table_log(dict_table_t *table, const char *old_name,
479 const char *new_name);
480
481 /** Write a REMOVE cache log record
482 @param[in,out] trx transaction
483 @param[in] table dict table
484 @return DB_SUCCESS or error */
486
487 /** Replay DDL log record
488 @param[in,out] record DDL log record
489 return DB_SUCCESS or error */
491
492 /** Replay and clean DDL logs after DDL transaction
493 commints or rollbacks.
494 @param[in] thd mysql thread
495 @return DB_SUCCESS or error */
496 dberr_t post_ddl(THD *thd);
497
498 /** Recover in server startup.
499 Scan innodb_ddl_log table, and replay all log entries.
500 Note: redo log should be applied, and DD transactions
501 should be recovered before calling this function.
502 @return DB_SUCCESS or error */
504
505 /** Is it in ddl recovery in server startup.
506 @return true if it's in ddl recover */
507 static bool is_in_recovery() { return (s_in_recovery); }
508
509 private:
510 /** Insert a FREE log record
511 @param[in,out] trx transaction
512 @param[in] index dict index
513 @param[in] id log id
514 @param[in] thread_id thread id
515 @return DB_SUCCESS or error */
517 uint64_t id, ulint thread_id);
518
519 /** Replay FREE log(free B-tree if exist)
520 @param[in] space_id tablespace id
521 @param[in] page_no root page no
522 @param[in] index_id index id */
523 void replay_free_tree_log(space_id_t space_id, page_no_t page_no,
524 ulint index_id);
525
526 /** Insert a DELETE log record
527 @param[in,out] trx transaction
528 @param[in] id log id
529 @param[in] thread_id thread id
530 @param[in] space_id tablespace id
531 @param[in] file_path file path
532 @param[in] dict_locked true if dict_sys mutex is held
533 @return DB_SUCCESS or error */
535 space_id_t space_id, const char *file_path,
536 bool dict_locked);
537
538 /** Replay DELETE log(delete file if exist)
539 @param[in] space_id tablespace id
540 @param[in] file_path file path */
541 void replay_delete_space_log(space_id_t space_id, const char *file_path);
542
543 /** Insert a RENAME log record
544 @param[in] id log id
545 @param[in] thread_id thread id
546 @param[in] space_id tablespace id
547 @param[in] old_file_path file path after rename
548 @param[in] new_file_path file path before rename
549 @return DB_SUCCESS or error */
551 space_id_t space_id,
552 const char *old_file_path,
553 const char *new_file_path);
554
555 /** Replay RENAME log
556 @param[in] space_id tablespace id
557 @param[in] old_file_path old file path
558 @param[in] new_file_path new file path */
559 void replay_rename_space_log(space_id_t space_id, const char *old_file_path,
560 const char *new_file_path);
561
562 /** Insert an ALTER ENCRYPT TABLESPACE log record
563 @param[in] id log id
564 @param[in] thread_id thread id
565 @param[in] space_id tablespace id
566 @param[in] type encryption operation type
567 @param[out] existing_rec alter_encrypt ddl record, nullptr if none
568 @return DB_SUCCESS or error */
570 space_id_t space_id,
572 DDL_Record *existing_rec);
573
574 /** Replay an ALTER ENCRYPT TABLESPACE log record
575 @param[in] record DDL Record
576 @return DB_SUCCESS or error */
578
579 /** Insert a DROP log record
580 @param[in,out] trx transaction
581 @param[in] id log id
582 @param[in] thread_id thread id
583 @param[in] table_id table id
584 @return DB_SUCCESS or error */
585 dberr_t insert_drop_log(trx_t *trx, uint64_t id, ulint thread_id,
586 const table_id_t table_id);
587
588 /** Replay DROP log
589 @param[in] table_id table id */
590 void replay_drop_log(const table_id_t table_id);
591
592 /** Insert a RENAME TABLE log record
593 @param[in] id log id
594 @param[in] thread_id thread id
595 @param[in] table_id table id
596 @param[in] old_name table name after rename
597 @param[in] new_name table name before rename
598 @return DB_SUCCESS or error */
600 table_id_t table_id, const char *old_name,
601 const char *new_name);
602
603 /** Relay RENAME TABLE log
604 @param[in] old_name old name
605 @param[in] new_name new name */
606 void replay_rename_table_log(const char *old_name, const char *new_name);
607
608 /** Insert a REMOVE cache log record
609 @param[in] id log id
610 @param[in] thread_id thread id
611 @param[in] table_id table id
612 @param[in] table_name table name
613 @return DB_SUCCESS or error */
615 table_id_t table_id, const char *table_name);
616
617 /** Relay remove cache log
618 @param[in] table_id table id
619 @param[in] table_name table name */
620 void replay_remove_cache_log(table_id_t table_id, const char *table_name);
621
622 /** Delete log record by id
623 @param[in] trx transaction instance
624 @param[in] id log id
625 @param[in] dict_locked true if dict_sys mutex is held,
626 otherwise false
627 @return DB_SUCCESS or error */
628 dberr_t delete_by_id(trx_t *trx, uint64_t id, bool dict_locked);
629
630 /** Scan, replay and delete log records by thread id
631 @param[in] thread_id thread id
632 @return DB_SUCCESS or error */
634
635 /** Delete the log records present in the list.
636 @param[in] records DDL_Records where the IDs are got
637 @return DB_SUCCESS or error. */
639
640 /** Scan, replay and delete all log records
641 @return DB_SUCCESS or error */
643
644 /** Get next autoinc counter by increasing 1 for innodb_ddl_log
645 @return new next counter */
646 inline uint64_t next_id();
647
648 /** Check if we need to skip ddl log for a table.
649 @param[in] table dict table
650 @param[in] thd mysql thread
651 @return true if should skip, otherwise false */
652 inline bool skip(const dict_table_t *table, THD *thd);
653
654 private:
655 /** Whether in recover(replay) ddl log in startup. */
656 static bool s_in_recovery;
657};
658
659/** Object to handle Log_DDL */
660extern Log_DDL *log_ddl;
661
662/** Close the DDL log system */
664
665#ifdef UNIV_DEBUG
666struct SYS_VAR;
667
668/** Used by SET GLOBAL innodb_ddl_log_crash_counter_reset_debug = 1; */
670
671/** Reset all crash injection counters. It's used by:
672 SET GLOBAL innodb_ddl_log_crash_reset_debug = 1 (0).
673@param[in] thd thread handle
674@param[in] var pointer to system variable
675@param[in] var_ptr where the formal string goes
676@param[in] save immediate result from check function */
677void ddl_log_crash_reset(THD *thd, SYS_VAR *var, void *var_ptr,
678 const void *save);
679#endif /* UNIV_DEBUG */
680
681#endif /* log0ddl_h */
uint32_t space_id_t
Tablespace identifier.
Definition: api0api.h:47
uint32_t page_no_t
Page number.
Definition: api0api.h:45
Wrapper of mysql.innodb_ddl_log table.
Definition: log0ddl.h:247
dberr_t search(ulint thread_id, DDL_Records &records)
Search for all records of specified thread_id.
Definition: log0ddl.cc:672
static constexpr unsigned s_page_no_col_no
Column number of mysql.innodb_ddl_log.page_no.
Definition: log0ddl.h:375
static constexpr unsigned s_thread_id_col_len
Column length of mysql.innodb_ddl_log.thread_id.
Definition: log0ddl.h:360
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:412
static constexpr unsigned s_index_id_col_len
Column length of mysql.innodb_ddl_log.index_id.
Definition: log0ddl.h:384
static constexpr unsigned s_table_id_col_len
Column length of mysql.innodb_ddl_log.table_id.
Definition: log0ddl.h:390
static constexpr unsigned s_id_col_no
Column number of mysql.innodb_ddl_log.id.
Definition: log0ddl.h:351
static constexpr unsigned s_index_id_col_no
Column number of mysql.innodb_ddl_log.index_id.
Definition: log0ddl.h:381
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:564
static constexpr unsigned s_table_id_col_no
Column number of mysql.innodb_ddl_log.table_id.
Definition: log0ddl.h:387
static constexpr unsigned s_space_id_col_no
Column number of mysql.innodb_ddl_log.space_id.
Definition: log0ddl.h:369
dberr_t search_all(DDL_Records &records)
Do a reverse scan on the table to fetch all the record.
Definition: log0ddl.cc:633
dict_table_t * m_table
innodb_ddl_log table.
Definition: log0ddl.h:399
que_thr_t * m_thr
Dummy query thread.
Definition: log0ddl.h:408
dberr_t search_by_id(ulint id, dict_index_t *index, DDL_Records &records)
Search specified index by specified ID.
Definition: log0ddl.cc:693
static constexpr unsigned s_page_no_col_len
Column length of mysql.innodb_ddl_log.page_no.
Definition: log0ddl.h:378
static constexpr unsigned s_space_id_col_len
Column length of mysql.innodb_ddl_log.space_id.
Definition: log0ddl.h:372
static constexpr unsigned s_thread_id_col_no
Column number of mysql.innodb_ddl_log.thread_id.
Definition: log0ddl.h:357
static constexpr unsigned s_old_file_path_col_no
Column number of mysql.innodb_ddl_log.old_file_path.
Definition: log0ddl.h:393
ulint parse_id(const dict_index_t *index, rec_t *rec, const ulint *offsets)
Parse the index record and get 'ID'.
Definition: log0ddl.cc:553
static constexpr unsigned s_type_col_len
Column length of mysql.innodb_ddl_log.type.
Definition: log0ddl.h:366
static constexpr unsigned s_id_col_len
Column length of mysql.innodb_ddl_log.id.
Definition: log0ddl.h:354
static constexpr unsigned s_new_file_path_col_no
Column number of mysql.innodb_ddl_log.new_file_path.
Definition: log0ddl.h:396
dtuple_t * m_tuple
Tuple used for insert, search, delete operation.
Definition: log0ddl.h:402
dberr_t insert(const DDL_Record &record)
Insert the DDL log record into the innodb_ddl_log table.
Definition: log0ddl.cc:467
void stop_query_thread()
Stop the query thread.
Definition: log0ddl.cc:345
void create_tuple(const DDL_Record &record)
Create tuple for the innodb_ddl_log table.
Definition: log0ddl.cc:351
static constexpr unsigned s_type_col_no
Column number of mysql.innodb_ddl_log.type.
Definition: log0ddl.h:363
trx_t * m_trx
Transaction used for insert, delete operation.
Definition: log0ddl.h:405
DDL_Log_Table()
Constructor.
Definition: log0ddl.cc:322
ulint fetch_value(const byte *data, ulint offset)
Fetch the value from given offset.
Definition: log0ddl.cc:609
~DDL_Log_Table()
Destructor.
Definition: log0ddl.cc:333
dberr_t remove(ulint id)
Delete the innodb_ddl_log record of specified ID.
Definition: log0ddl.cc:736
void start_query_thread()
Set the query thread using graph.
Definition: log0ddl.cc:338
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:528
DDL log record.
Definition: log0ddl.h:78
ulint m_id
Log id.
Definition: log0ddl.h:197
ulint m_thread_id
Thread id.
Definition: log0ddl.h:203
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:200
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:191
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:166
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:212
mem_heap_t * m_heap
memory heap object used for storing file name.
Definition: log0ddl.h:225
DDL_Record()
Constructor.
Definition: log0ddl.cc:154
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:219
bool validate() const
Definition: log0ddl.h:231
space_id_t m_space_id
Tablespace id.
Definition: log0ddl.h:206
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:215
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:209
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:228
std::ostream & print(std::ostream &out) const
Print the DDL record to specified output stream.
Definition: log0ddl.cc:210
void set_old_file_path(const char *name)
Set the old file path from the name for the DDL log record.
Definition: log0ddl.cc:172
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:222
Progress
Encryption progress type.
Definition: os0enc.h:80
Class to write and replay ddl logs.
Definition: log0ddl.h:416
void replay_drop_log(const table_id_t table_id)
Replay DROP log.
Definition: log0ddl.cc:1840
dberr_t replay(DDL_Record &record)
Replay DDL log record.
Definition: log0ddl.cc:1612
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:1125
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:1758
~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:1162
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:1071
dberr_t post_ddl(THD *thd)
Replay and clean DDL logs after DDL transaction commints or rollbacks.
Definition: log0ddl.cc:1941
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:926
dberr_t recover()
Recover in server startup.
Definition: log0ddl.cc:1978
dberr_t delete_by_id(trx_t *trx, uint64_t id, bool dict_locked)
Delete log record by id.
Definition: log0ddl.cc:1448
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:859
Log_DDL()
Constructor.
Definition: log0ddl.cc:836
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:1173
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:1217
void replay_rename_table_log(const char *old_name, const char *new_name)
Relay RENAME TABLE log.
Definition: log0ddl.cc:1849
uint64_t next_id()
Get next autoinc counter by increasing 1 for innodb_ddl_log.
Definition: log0ddl.cc:841
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:1022
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:1264
bool skip(const dict_table_t *table, THD *thd)
Check if we need to skip ddl log for a table.
Definition: log0ddl.cc:853
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:1418
dberr_t replay_by_thread_id(ulint thread_id)
Scan, replay and delete log records by thread id.
Definition: log0ddl.cc:1517
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:1319
static bool is_in_recovery()
Is it in ddl recovery in server startup.
Definition: log0ddl.h:507
dberr_t delete_by_ids(DDL_Records &records)
Delete the log records present in the list.
Definition: log0ddl.cc:1575
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:1351
void replay_remove_cache_log(table_id_t table_id, const char *table_name)
Relay remove cache log.
Definition: log0ddl.cc:1909
void replay_delete_space_log(space_id_t space_id, const char *file_path)
Replay DELETE log(delete file if exist)
Definition: log0ddl.cc:1695
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:1289
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:967
dberr_t replay_alter_encrypt_space_log(DDL_Record &record)
Replay an ALTER ENCRYPT TABLESPACE log record.
Definition: log0ddl.cc:1813
dberr_t write_remove_cache_log(trx_t *trx, dict_table_t *table)
Write a REMOVE cache log record.
Definition: log0ddl.cc:1388
dberr_t replay_all()
Scan, replay and delete all log records.
Definition: log0ddl.cc:1480
static bool s_in_recovery
Whether in recover(replay) ddl log in startup.
Definition: log0ddl.h:656
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:1661
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
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:243
void ddl_log_close()
Close the DDL log system.
Definition: log0ddl.h:663
void ddl_log_crash_reset(THD *thd, SYS_VAR *var, void *var_ptr, const void *save)
Reset all crash injection counters.
Definition: log0ddl.cc:130
bool innodb_ddl_log_crash_reset_debug
Used by SET GLOBAL innodb_ddl_log_crash_counter_reset_debug = 1;.
Definition: log0ddl.cc:75
Log_DDL * log_ddl
Object to handle Log_DDL.
Definition: log0ddl.cc:63
static my_thread_id thread_id
Definition: my_thr_init.cc:63
static int record
Definition: mysqltest.cc:195
static PFS_engine_table_share_proxy table
Definition: pfs.cc:61
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:29
Definition: plugin.h:69
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:684
The info structure stored at the beginning of a heap block.
Definition: mem0mem.h:302
Definition: que0que.h:242
Definition: trx0trx.h:684
unsigned long int ulint
Definition: univ.i:406
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:105
#define ut_a(EXPR)
Abort execution if EXPR does not evaluate to nonzero.
Definition: ut0dbg.h:93
unsigned long id[MAX_DEAD]
Definition: xcom_base.cc:510