MySQL 26.7.0
Source Code Documentation
log0ddl.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 2017, 2026, 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#include "dict0types.h" /* table_id_t */
44#include "mem0mem.h" /* mem_heap_t */
45
46/** DDL log types defined as uint32_t because it costs 4 bytes in
47mysql.innodb_ddl_log. */
48enum class Log_Type : uint32_t {
49 /** Smallest log type */
50 SMALLEST_LOG = 1,
51
52 /** Drop an index tree */
53 FREE_TREE_LOG = 1,
54
55 /** Delete a file */
57
58 /** Rename a file */
60
61 /** Drop the entry in innodb_table_metadata */
63
64 /** Rename table in dict cache. */
66
67 /** Remove a table from dict cache */
69
70 /** Alter Encrypt a tablespace */
72
73 /** Alter Unencrypt a tablespace */
75
76 /** For Atomic DROP/CREATE SCHEMA implementation */
78
79 /** Biggest log type */
81};
82
83/** DDL log record */
85 public:
86 /** Constructor. */
87 DDL_Record();
88
89 /** Destructor. */
91
92 /** Get the id of the DDL log record.
93 @return id of the record. */
94 ulint get_id() const { return (m_id); }
95
96 /** Set the id for the DDL log record.
97 @param[in] id id of the record. */
98 void set_id(ulint id) { m_id = id; }
99
100 /** Get the type of operation to perform
101 for the DDL log record.
102 @return type of the record. */
103 Log_Type get_type() const { return (m_type); }
104
105 /** Set the type for the DDL log record.
106 @param[in] type set the record type.*/
108
109 /** Get the thread id for the DDL log record.
110 @return thread id of the DDL log record. */
111 ulint get_thread_id() const { return (m_thread_id); }
112
113 /** Set the thread id for the DDL log record.
114 @param[in] thread_id thread id. */
116
117 /** Get the space_id present in the DDL log record.
118 @return space_id in the DDL log record. */
119 space_id_t get_space_id() const { return (m_space_id); }
120
121 /** Set the space id for the DDL log record.
122 @param[in] space space id. */
123 void set_space_id(space_id_t space) { m_space_id = space; }
124
125 /** Get the page no present in the DDL log record.
126 @return page_no */
127 page_no_t get_page_no() const { return (m_page_no); }
128
129 /** Set the page number for the DDL log record.
130 @param[in] page_no page number. */
131 void set_page_no(page_no_t page_no) { m_page_no = page_no; }
132
133 /** Get the index id present in the DDL log record.
134 @return index id. */
135 ulint get_index_id() const { return (m_index_id); }
136
137 /** Set the index id for the DDL log record.
138 @param[in] index_id index id. */
139 void set_index_id(ulint index_id) { m_index_id = index_id; }
140
141 /** Get the table id present in the DDL log record.
142 @return table id from the record. */
143 table_id_t get_table_id() const { return (m_table_id); }
144
145 /** Set the table if for the DDL log record.
146 @param[in] table_id table id. */
147 void set_table_id(table_id_t table_id) { m_table_id = table_id; }
148
149 /** Set deletability of this record.
150 @param[in] deletable deletability. */
151 void set_deletable(bool deletable) { m_deletable = deletable; }
152
153 /** If this record can be deleted.
154 @return true if record is deletable. */
155 bool get_deletable() const { return (m_deletable); }
156
157 /** Get encryption operation type */
159 auto type = get_type();
160
163 }
166 }
167
168 /** Get the old file path/name present in the DDL log record.
169 @return old file path/name. */
170 const char *get_old_file_path() const { return (m_old_file_path); }
171
172 /** Set the old file path from the name for the DDL log record.
173 @param[in] name old file name. */
174 void set_old_file_path(const char *name);
175
176 /** Copy the data and set it in old file path
177 @param[in] data data to be set
178 @param[in] len length of the data. */
179 void set_old_file_path(const byte *data, ulint len);
180
181 /** Get the new file path/name present in the DDL log record.
182 @return new file path/name. */
183 const char *get_new_file_path() const { return (m_new_file_path); }
184
185 /** Set the new file path/name for the DDL log record.
186 @param[in] name name to be set. */
187 void set_new_file_path(const char *name);
188
189 /** Copy the data and set it in new file path.
190 @param[in] data data to be set
191 @param[in] len length of the data. */
192 void set_new_file_path(const byte *data, ulint len);
193
194 bool validate() const;
195
196 /** Print the DDL record to specified output stream
197 @param[in,out] out output stream
198 @return output stream */
199 std::ostream &print(std::ostream &out) const;
200
201 private:
202 /** Log id */
204
205 /** Log type */
207
208 /** Thread id */
210
211 /** Tablespace id */
213
214 /** Index root page */
216
217 /** Index id */
219
220 /** Table id */
222
223 /** Tablespace file path for DELETE, Old tablespace file path
224 for RENAME */
226
227 /** New tablespace file name for RENAME */
229
230 /** memory heap object used for storing file name. */
232
233 /** If this record can be deleted */
235};
236
237inline bool DDL_Record::validate() const {
240 return true;
241}
242
243/** Forward declaration */
244class THD;
245struct que_thr_t;
246struct dtuple_t;
247
248/** Array of DDL records */
249using DDL_Records = std::vector<DDL_Record *>;
250
251/** Wrapper of mysql.innodb_ddl_log table. Accessing to this table doesn't
252require row lock because thread could only access/modify its own ddl records. */
254 public:
255 /** Constructor. */
257
258 /** Constructor and it initializes transaction and query thread.
259 Once trx is passed in, make sure destructor is called before the
260 trx commits.
261 @param[in,out] trx Transaction */
262 explicit DDL_Log_Table(trx_t *trx);
263
264 /** Destructor. */
266
267 /** Insert the DDL log record into the innodb_ddl_log table.
268 This is thread safe.
269 @param[in] record Record to be inserted.
270 @return DB_SUCCESS or error. */
272
273 /** Search for all records of specified thread_id. The records
274 are kept in reverse order.
275 This is thread safe. Because different threads have different thread
276 ids, there should not be any conflict with update.
277 @param[in] thread_id thread id to search
278 @param[out] records DDL_Records of the specified thread id
279 @return DB_SUCCESS or error. */
281
282 /** Do a reverse scan on the table to fetch all the record.
283 This is only called during recovery
284 @param[out] records DDL_Records of the whole table
285 @return DB_SUCCESS or error. */
287
288 /** Delete the innodb_ddl_log record of specified ID.
289 This is thread safe. One thread will only remove its ddl record.
290 @param[in] id ID of the DDL_Record
291 @return DB_SUCCESS or error. */
292 dberr_t remove(ulint id);
293
294 /** Delete specified DDL_Records from innodb_ddl_log.
295 This is thread safe. Different threads have their own ddl records
296 to delete. And this could be called during recovery.
297 @param[in] records DDL_Record(s) to be deleted
298 @return DB_SUCCESS or error. */
299 dberr_t remove(const DDL_Records &records);
300
301 private:
302 /** Set the query thread using graph. */
303 void start_query_thread();
304
305 /** Stop the query thread. */
306 void stop_query_thread();
307
308 /** Create tuple for the innodb_ddl_log table.
309 It is used for insert operation.
310 @param[in] record DDL log record. */
311 void create_tuple(const DDL_Record &record);
312
313 /** Create tuple for the given index. Used for search by id
314 (and following delete)
315 @param[in] id Thread id/ id of the record
316 @param[in] index Clustered index or secondary index. */
317 void create_tuple(ulint id, const dict_index_t *index);
318
319 /** Convert the innodb_ddl_log index record to DDL_Record.
320 @param[in] is_clustered true if this is clustered index record,
321 otherwise the secondary index record
322 @param[in] rec index record
323 @param[in] offsets index record offset
324 @param[in,out] record to store the innodb_ddl_log record. */
325 void convert_to_ddl_record(bool is_clustered, rec_t *rec,
326 const ulint *offsets, DDL_Record &record);
327
328 /** Parse the index record and get 'ID'.
329 @param[in] index index where the record resides
330 @param[in] rec index rec
331 @param[in] offsets offsets of the index.
332 @return id of the record. */
333 ulint parse_id(const dict_index_t *index, rec_t *rec, const ulint *offsets);
334
335 /** Set the given field of the innodb_ddl_log record from given data.
336 @param[in] data data to be set
337 @param[in] offset column of the ddl record
338 @param[in] len length of the data
339 @param[in,out] record DDL_Record to set */
340 void set_field(const byte *data, ulint offset, ulint len, DDL_Record &record);
341
342 /** Fetch the value from given offset.
343 @param[in] data value to be retrieved from data
344 @param[in] offset offset of the column
345 @return value of the given offset. */
346 ulint fetch_value(const byte *data, ulint offset);
347
348 /** Search specified index by specified ID
349 @param[in] id ID to search
350 @param[in] index index to search
351 @param[in,out] records DDL_Record(s) got by the search
352 @return DB_SUCCESS or error */
354
355 private:
356 /** Column number of mysql.innodb_ddl_log.id. */
357 static constexpr unsigned s_id_col_no = 0;
358
359 /** Column length of mysql.innodb_ddl_log.id. */
360 static constexpr unsigned s_id_col_len = 8;
361
362 /** Column number of mysql.innodb_ddl_log.thread_id. */
363 static constexpr unsigned s_thread_id_col_no = 1;
364
365 /** Column length of mysql.innodb_ddl_log.thread_id. */
366 static constexpr unsigned s_thread_id_col_len = 8;
367
368 /** Column number of mysql.innodb_ddl_log.type. */
369 static constexpr unsigned s_type_col_no = 2;
370
371 /** Column length of mysql.innodb_ddl_log.type. */
372 static constexpr unsigned s_type_col_len = 4;
373
374 /** Column number of mysql.innodb_ddl_log.space_id. */
375 static constexpr unsigned s_space_id_col_no = 3;
376
377 /** Column length of mysql.innodb_ddl_log.space_id. */
378 static constexpr unsigned s_space_id_col_len = 4;
379
380 /** Column number of mysql.innodb_ddl_log.page_no. */
381 static constexpr unsigned s_page_no_col_no = 4;
382
383 /** Column length of mysql.innodb_ddl_log.page_no. */
384 static constexpr unsigned s_page_no_col_len = 4;
385
386 /** Column number of mysql.innodb_ddl_log.index_id. */
387 static constexpr unsigned s_index_id_col_no = 5;
388
389 /** Column length of mysql.innodb_ddl_log.index_id. */
390 static constexpr unsigned s_index_id_col_len = 8;
391
392 /** Column number of mysql.innodb_ddl_log.table_id. */
393 static constexpr unsigned s_table_id_col_no = 6;
394
395 /** Column length of mysql.innodb_ddl_log.table_id. */
396 static constexpr unsigned s_table_id_col_len = 8;
397
398 /** Column number of mysql.innodb_ddl_log.old_file_path. */
399 static constexpr unsigned s_old_file_path_col_no = 7;
400
401 /** Column number of mysql.innodb_ddl_log.new_file_path. */
402 static constexpr unsigned s_new_file_path_col_no = 8;
403
404 /** innodb_ddl_log table. */
406
407 /** Tuple used for insert, search, delete operation. */
409
410 /** Transaction used for insert, delete operation. */
412
413 /** Dummy query thread. */
415
416 /** Heap to store the m_tuple, m_thr and all
417 operation on mysql.innodb_ddl_log table. */
419};
420
421/** Class to write and replay ddl logs */
422class Log_DDL {
423 public:
424 /** Constructor */
425 Log_DDL();
426
427 /** Deconstructor */
428 ~Log_DDL() = default;
429
430 /** Write DDL log for freeing B-tree
431 @param[in,out] trx transaction
432 @param[in] index dict index
433 @param[in] is_drop_table true if this is drop table
434 @return DB_SUCCESS or error */
436 bool is_drop_table);
437
438 /** Write DDL log for deleting tablespace file
439 @param[in,out] trx transaction
440 @param[in] table dict table
441 @param[in] space_id tablespace id
442 @param[in] file_path file path
443 @param[in] is_drop flag whether dropping tablespace
444 @param[in] dict_locked true if dict_sys mutex is held
445 @return DB_SUCCESS or error */
447 space_id_t space_id, const char *file_path,
448 bool is_drop, bool dict_locked);
449
450 /** Write a RENAME log record
451 @param[in] space_id tablespace id
452 @param[in] old_file_path file path after rename
453 @param[in] new_file_path file path before rename
454 @return DB_SUCCESS or error */
455 dberr_t write_rename_space_log(space_id_t space_id, const char *old_file_path,
456 const char *new_file_path);
457
458 /** Find alter encrypt record for the tablespace.
459 @param[in] space_id space_id
460 return log record if exists, null otherwise */
462
463 /** Write an ALTER ENCRYPT Tablespace DDL log record
464 @param[in] space_id tablespace id
465 @param[in] type encryption operation type
466 @param[out] existing_rec alter_encrypt ddl record, nullptr if none
467 @return DB_SUCCESS or error */
470 DDL_Record *existing_rec);
471
472 /** Write a DROP log to indicate the entry in innodb_table_metadata
473 should be removed for specified table
474 @param[in,out] trx transaction
475 @param[in] table_id table ID
476 @return DB_SUCCESS or error */
477 dberr_t write_drop_log(trx_t *trx, const table_id_t table_id);
478
479 /** Write a RENAME table log record
480 @param[in] table dict table
481 @param[in] old_name table name after rename
482 @param[in] new_name table name before rename
483 @return DB_SUCCESS or error */
484 dberr_t write_rename_table_log(dict_table_t *table, const char *old_name,
485 const char *new_name);
486
487 /** Write a REMOVE cache log record
488 @param[in,out] trx transaction
489 @param[in] table dict table
490 @return DB_SUCCESS or error */
492
493 /** Write a DELETE_SCHEMA_DIRECTORY_LOG
494 @param[in,out] trx transaction
495 @param[in] schema_directory_path path to the database directory
496 @param[in] is_drop_schema is it DROP SCHEMA query
497 @return DB_SUCCESS or error */
499 const char *schema_directory_path,
500 const bool is_drop_schema);
501
502 /** Replay DDL log record
503 @param[in,out] record DDL log record
504 return DB_SUCCESS or error */
506
507 /** Replay and clean DDL logs after DDL transaction
508 commints or rollbacks.
509 @param[in] thd mysql thread
510 @return DB_SUCCESS or error */
511 dberr_t post_ddl(THD *thd);
512
513 /** Recover in server startup.
514 Scan innodb_ddl_log table, and replay all log entries.
515 Note: redo log should be applied, and DD transactions
516 should be recovered before calling this function.
517 @return DB_SUCCESS or error */
519
520 /** Is it in ddl recovery in server startup.
521 @return true if it's in ddl recover */
522 static bool is_in_recovery() { return (s_in_recovery); }
523
524 private:
525 /** Insert a FREE log record
526 @param[in,out] trx transaction
527 @param[in] index dict index
528 @param[in] id log id
529 @param[in] thread_id thread id
530 @return DB_SUCCESS or error */
532 uint64_t id, ulint thread_id);
533
534 /** Replay FREE log(free B-tree if exist)
535 @param[in] space_id tablespace id
536 @param[in] page_no root page no
537 @param[in] index_id index id */
538 void replay_free_tree_log(space_id_t space_id, page_no_t page_no,
539 ulint index_id);
540
541 /** Insert a DELETE log record
542 @param[in,out] trx transaction
543 @param[in] id log id
544 @param[in] thread_id thread id
545 @param[in] space_id tablespace id
546 @param[in] file_path file path
547 @param[in] dict_locked true if dict_sys mutex is held
548 @return DB_SUCCESS or error */
550 space_id_t space_id, const char *file_path,
551 bool dict_locked);
552
553 /** Replay DELETE log(delete file if exist)
554 @param[in] space_id tablespace id
555 @param[in] file_path file path */
556 void replay_delete_space_log(space_id_t space_id, const char *file_path);
557
558 /** Insert a RENAME log record
559 @param[in] id log id
560 @param[in] thread_id thread id
561 @param[in] space_id tablespace id
562 @param[in] old_file_path file path after rename
563 @param[in] new_file_path file path before rename
564 @return DB_SUCCESS or error */
566 space_id_t space_id,
567 const char *old_file_path,
568 const char *new_file_path);
569
570 /** Replay RENAME log
571 @param[in] space_id tablespace id
572 @param[in] old_file_path old file path
573 @param[in] new_file_path new file path */
574 void replay_rename_space_log(space_id_t space_id, const char *old_file_path,
575 const char *new_file_path);
576
577 /** Insert an ALTER ENCRYPT TABLESPACE log record
578 @param[in] id log id
579 @param[in] thread_id thread id
580 @param[in] space_id tablespace id
581 @param[in] type encryption operation type
582 @param[out] existing_rec alter_encrypt ddl record, nullptr if none
583 @return DB_SUCCESS or error */
585 space_id_t space_id,
587 DDL_Record *existing_rec);
588
589 /** Replay an ALTER ENCRYPT TABLESPACE log record
590 @param[in] record DDL Record
591 @return DB_SUCCESS or error */
593
594 /** Insert a DROP log record
595 @param[in,out] trx transaction
596 @param[in] id log id
597 @param[in] thread_id thread id
598 @param[in] table_id table id
599 @return DB_SUCCESS or error */
600 dberr_t insert_drop_log(trx_t *trx, uint64_t id, ulint thread_id,
601 const table_id_t table_id);
602
603 /** Replay DROP log
604 @param[in] table_id table id */
605 void replay_drop_log(const table_id_t table_id);
606
607 /** Insert a RENAME TABLE log record
608 @param[in] id log id
609 @param[in] thread_id thread id
610 @param[in] table_id table id
611 @param[in] old_name table name after rename
612 @param[in] new_name table name before rename
613 @return DB_SUCCESS or error */
615 table_id_t table_id, const char *old_name,
616 const char *new_name);
617
618 /** Relay RENAME TABLE log
619 @param[in] old_name old name
620 @param[in] new_name new name */
621 void replay_rename_table_log(const char *old_name, const char *new_name);
622
623 /** Insert a REMOVE cache log record
624 @param[in] id log id
625 @param[in] thread_id thread id
626 @param[in] table_id table id
627 @param[in] table_name table name
628 @return DB_SUCCESS or error */
630 table_id_t table_id, const char *table_name);
631
632 /** Relay remove cache log
633 @param[in] table_id table id
634 @param[in] table_name table name */
635 void replay_remove_cache_log(table_id_t table_id, const char *table_name);
636
637 /** Insert a DELETE_SCHEMA_DIRECTORY_LOG
638 @param[in,out] trx transaction
639 @param[in] id record id
640 @param[in] thread_id thread id
641 @param[in] schema_directory_path path to the schema directory
642 @return DB_SUCCESS or not */
645 const char *schema_directory_path);
646
647 /** Replay a DELETE_SCHEMA_DIRECTORY_LOG
648 @param schema_directory_path path to the schema directory
649 @return DB_SUCCESS or not */
650 dberr_t replay_delete_schema_directory_log(const char *schema_directory_path);
651
652 /** Delete log record by id
653 @param[in] trx transaction instance
654 @param[in] id log id
655 @param[in] dict_locked true if dict_sys mutex is held,
656 otherwise false
657 @return DB_SUCCESS or error */
658 dberr_t delete_by_id(trx_t *trx, uint64_t id, bool dict_locked);
659
660 /** Scan, replay and delete log records by thread id
661 @param[in] thread_id thread id
662 @return DB_SUCCESS or error */
664
665 /** Delete the log records present in the list.
666 @param[in] records DDL_Records where the IDs are got
667 @return DB_SUCCESS or error. */
669
670 /** Scan, replay and delete all log records
671 @return DB_SUCCESS or error */
673
674 /** Get next autoinc counter by increasing 1 for innodb_ddl_log
675 @return new next counter */
676 inline uint64_t next_id();
677
678 /** Check if we need to skip ddl log for a table.
679 @param[in] table dict table
680 @param[in] thd mysql thread
681 @return true if should skip, otherwise false */
682 inline bool skip(const dict_table_t *table, THD *thd);
683
684 private:
685 /** Whether in recover(replay) ddl log in startup. */
686 static bool s_in_recovery;
687};
688
689/** Object to handle Log_DDL */
690extern Log_DDL *log_ddl;
691
692/** Close the DDL log system */
694
695#ifdef UNIV_DEBUG
696struct SYS_VAR;
697
698/** Used by SET GLOBAL innodb_ddl_log_crash_counter_reset_debug = 1; */
700
701/** Reset all crash injection counters. It's used by:
702 SET GLOBAL innodb_ddl_log_crash_reset_debug = 1 (0).
703@param[in] thd thread handle
704@param[in] var pointer to system variable
705@param[in] var_ptr where the formal string goes
706@param[in] save immediate result from check function */
707void ddl_log_crash_reset(THD *thd, SYS_VAR *var, void *var_ptr,
708 const void *save);
709#endif /* UNIV_DEBUG */
710
711#endif /* log0ddl_h */
uint32_t space_id_t
Tablespace identifier.
Definition: api0api.h:49
uint32_t page_no_t
Page number.
Definition: api0api.h:47
Wrapper of mysql.innodb_ddl_log table.
Definition: log0ddl.h:253
dberr_t search(ulint thread_id, DDL_Records &records)
Search for all records of specified thread_id.
Definition: log0ddl.cc:681
static constexpr unsigned s_page_no_col_no
Column number of mysql.innodb_ddl_log.page_no.
Definition: log0ddl.h:381
static constexpr unsigned s_thread_id_col_len
Column length of mysql.innodb_ddl_log.thread_id.
Definition: log0ddl.h:366
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:418
static constexpr unsigned s_index_id_col_len
Column length of mysql.innodb_ddl_log.index_id.
Definition: log0ddl.h:390
static constexpr unsigned s_table_id_col_len
Column length of mysql.innodb_ddl_log.table_id.
Definition: log0ddl.h:396
static constexpr unsigned s_id_col_no
Column number of mysql.innodb_ddl_log.id.
Definition: log0ddl.h:357
static constexpr unsigned s_index_id_col_no
Column number of mysql.innodb_ddl_log.index_id.
Definition: log0ddl.h:387
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:573
static constexpr unsigned s_table_id_col_no
Column number of mysql.innodb_ddl_log.table_id.
Definition: log0ddl.h:393
static constexpr unsigned s_space_id_col_no
Column number of mysql.innodb_ddl_log.space_id.
Definition: log0ddl.h:375
dberr_t search_all(DDL_Records &records)
Do a reverse scan on the table to fetch all the record.
Definition: log0ddl.cc:642
dict_table_t * m_table
innodb_ddl_log table.
Definition: log0ddl.h:405
que_thr_t * m_thr
Dummy query thread.
Definition: log0ddl.h:414
dberr_t search_by_id(ulint id, dict_index_t *index, DDL_Records &records)
Search specified index by specified ID.
Definition: log0ddl.cc:702
static constexpr unsigned s_page_no_col_len
Column length of mysql.innodb_ddl_log.page_no.
Definition: log0ddl.h:384
static constexpr unsigned s_space_id_col_len
Column length of mysql.innodb_ddl_log.space_id.
Definition: log0ddl.h:378
static constexpr unsigned s_thread_id_col_no
Column number of mysql.innodb_ddl_log.thread_id.
Definition: log0ddl.h:363
static constexpr unsigned s_old_file_path_col_no
Column number of mysql.innodb_ddl_log.old_file_path.
Definition: log0ddl.h:399
ulint parse_id(const dict_index_t *index, rec_t *rec, const ulint *offsets)
Parse the index record and get 'ID'.
Definition: log0ddl.cc:562
static constexpr unsigned s_type_col_len
Column length of mysql.innodb_ddl_log.type.
Definition: log0ddl.h:372
static constexpr unsigned s_id_col_len
Column length of mysql.innodb_ddl_log.id.
Definition: log0ddl.h:360
static constexpr unsigned s_new_file_path_col_no
Column number of mysql.innodb_ddl_log.new_file_path.
Definition: log0ddl.h:402
dtuple_t * m_tuple
Tuple used for insert, search, delete operation.
Definition: log0ddl.h:408
dberr_t insert(const DDL_Record &record)
Insert the DDL log record into the innodb_ddl_log table.
Definition: log0ddl.cc:476
void stop_query_thread()
Stop the query thread.
Definition: log0ddl.cc:354
void create_tuple(const DDL_Record &record)
Create tuple for the innodb_ddl_log table.
Definition: log0ddl.cc:360
static constexpr unsigned s_type_col_no
Column number of mysql.innodb_ddl_log.type.
Definition: log0ddl.h:369
trx_t * m_trx
Transaction used for insert, delete operation.
Definition: log0ddl.h:411
DDL_Log_Table()
Constructor.
Definition: log0ddl.cc:331
ulint fetch_value(const byte *data, ulint offset)
Fetch the value from given offset.
Definition: log0ddl.cc:618
~DDL_Log_Table()
Destructor.
Definition: log0ddl.cc:342
dberr_t remove(ulint id)
Delete the innodb_ddl_log record of specified ID.
Definition: log0ddl.cc:745
void start_query_thread()
Set the query thread using graph.
Definition: log0ddl.cc:347
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:537
DDL log record.
Definition: log0ddl.h:84
ulint m_id
Log id.
Definition: log0ddl.h:203
ulint m_thread_id
Thread id.
Definition: log0ddl.h:209
const char * get_new_file_path() const
Get the new file path/name present in the DDL log record.
Definition: log0ddl.h:183
Log_Type m_type
Log type.
Definition: log0ddl.h:206
Log_Type get_type() const
Get the type of operation to perform for the DDL log record.
Definition: log0ddl.h:103
page_no_t get_page_no() const
Get the page no present in the DDL log record.
Definition: log0ddl.h:127
void set_new_file_path(const char *name)
Set the new file path/name for the DDL log record.
Definition: log0ddl.cc:195
void set_index_id(ulint index_id)
Set the index id for the DDL log record.
Definition: log0ddl.h:139
table_id_t get_table_id() const
Get the table id present in the DDL log record.
Definition: log0ddl.h:143
void set_table_id(table_id_t table_id)
Set the table if for the DDL log record.
Definition: log0ddl.h:147
space_id_t get_space_id() const
Get the space_id present in the DDL log record.
Definition: log0ddl.h:119
void set_page_no(page_no_t page_no)
Set the page number for the DDL log record.
Definition: log0ddl.h:131
Encryption::Progress get_encryption_type() const
Get encryption operation type.
Definition: log0ddl.h:158
~DDL_Record()
Destructor.
Definition: log0ddl.cc:170
void set_type(Log_Type type)
Set the type for the DDL log record.
Definition: log0ddl.h:107
ulint get_id() const
Get the id of the DDL log record.
Definition: log0ddl.h:94
ulint m_index_id
Index id.
Definition: log0ddl.h:218
mem_heap_t * m_heap
memory heap object used for storing file name.
Definition: log0ddl.h:231
DDL_Record()
Constructor.
Definition: log0ddl.cc:158
bool get_deletable() const
If this record can be deleted.
Definition: log0ddl.h:155
char * m_old_file_path
Tablespace file path for DELETE, Old tablespace file path for RENAME.
Definition: log0ddl.h:225
bool validate() const
Definition: log0ddl.h:237
space_id_t m_space_id
Tablespace id.
Definition: log0ddl.h:212
void set_deletable(bool deletable)
Set deletability of this record.
Definition: log0ddl.h:151
table_id_t m_table_id
Table id.
Definition: log0ddl.h:221
void set_id(ulint id)
Set the id for the DDL log record.
Definition: log0ddl.h:98
page_no_t m_page_no
Index root page.
Definition: log0ddl.h:215
ulint get_index_id() const
Get the index id present in the DDL log record.
Definition: log0ddl.h:135
void set_thread_id(ulint thread_id)
Set the thread id for the DDL log record.
Definition: log0ddl.h:115
void set_space_id(space_id_t space)
Set the space id for the DDL log record.
Definition: log0ddl.h:123
const char * get_old_file_path() const
Get the old file path/name present in the DDL log record.
Definition: log0ddl.h:170
bool m_deletable
If this record can be deleted.
Definition: log0ddl.h:234
std::ostream & print(std::ostream &out) const
Print the DDL record to specified output stream.
Definition: log0ddl.cc:214
void set_old_file_path(const char *name)
Set the old file path from the name for the DDL log record.
Definition: log0ddl.cc:176
ulint get_thread_id() const
Get the thread id for the DDL log record.
Definition: log0ddl.h:111
char * m_new_file_path
New tablespace file name for RENAME.
Definition: log0ddl.h:228
Progress
Encryption progress type.
Definition: os0enc.h:80
Class to write and replay ddl logs.
Definition: log0ddl.h:422
void replay_drop_log(const table_id_t table_id)
Replay DROP log.
Definition: log0ddl.cc:1943
dberr_t replay(DDL_Record &record)
Replay DDL log record.
Definition: log0ddl.cc:1727
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:1239
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:1875
~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:1276
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:1185
dberr_t post_ddl(THD *thd)
Replay and clean DDL logs after DDL transaction commints or rollbacks.
Definition: log0ddl.cc:2043
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:1040
dberr_t recover()
Recover in server startup.
Definition: log0ddl.cc:2080
dberr_t delete_by_id(trx_t *trx, uint64_t id, bool dict_locked)
Delete log record by id.
Definition: log0ddl.cc:1562
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:971
Log_DDL()
Constructor.
Definition: log0ddl.cc:845
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:1287
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:1331
dberr_t replay_delete_schema_directory_log(const char *schema_directory_path)
Replay a DELETE_SCHEMA_DIRECTORY_LOG.
Definition: log0ddl.cc:938
dberr_t insert_delete_schema_directory_log(trx_t *trx, uint64_t id, ulint thread_id, const char *schema_directory_path)
Insert a DELETE_SCHEMA_DIRECTORY_LOG.
Definition: log0ddl.cc:902
void replay_rename_table_log(const char *old_name, const char *new_name)
Relay RENAME TABLE log.
Definition: log0ddl.cc:1952
uint64_t next_id()
Get next autoinc counter by increasing 1 for innodb_ddl_log.
Definition: log0ddl.cc:850
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:1136
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:1378
bool skip(const dict_table_t *table, THD *thd)
Check if we need to skip ddl log for a table.
Definition: log0ddl.cc:862
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:1532
dberr_t replay_by_thread_id(ulint thread_id)
Scan, replay and delete log records by thread id.
Definition: log0ddl.cc:1632
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:1433
static bool is_in_recovery()
Is it in ddl recovery in server startup.
Definition: log0ddl.h:522
dberr_t delete_by_ids(DDL_Records &records)
Delete the log records present in the list.
Definition: log0ddl.cc:1690
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:1465
void replay_remove_cache_log(table_id_t table_id, const char *table_name)
Relay remove cache log.
Definition: log0ddl.cc:2011
void replay_delete_space_log(space_id_t space_id, const char *file_path)
Replay DELETE log(delete file if exist)
Definition: log0ddl.cc:1814
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:1403
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:1081
dberr_t replay_alter_encrypt_space_log(DDL_Record &record)
Replay an ALTER ENCRYPT TABLESPACE log record.
Definition: log0ddl.cc:1916
dberr_t write_delete_schema_directory_log(trx_t *trx, const char *schema_directory_path, const bool is_drop_schema)
Write a DELETE_SCHEMA_DIRECTORY_LOG.
Definition: log0ddl.cc:869
dberr_t write_remove_cache_log(trx_t *trx, dict_table_t *table)
Write a REMOVE cache log record.
Definition: log0ddl.cc:1502
dberr_t replay_all()
Scan, replay and delete all log records.
Definition: log0ddl.cc:1594
static bool s_in_recovery
Whether in recover(replay) ddl log in startup.
Definition: log0ddl.h:686
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:1780
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
Data dictionary global types.
ib_id_t table_id_t
Table or partition identifier (unique within an InnoDB instance).
Definition: dict0types.h:216
Log_Type
DDL log types defined as uint32_t because it costs 4 bytes in mysql.innodb_ddl_log.
Definition: log0ddl.h:48
@ 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.
@ DELETE_SCHEMA_DIRECTORY_LOG
For Atomic DROP/CREATE SCHEMA implementation.
@ 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:249
void ddl_log_close()
Close the DDL log system.
Definition: log0ddl.h:693
void ddl_log_crash_reset(THD *thd, SYS_VAR *var, void *var_ptr, const void *save)
Reset all crash injection counters.
Definition: log0ddl.cc:134
bool innodb_ddl_log_crash_reset_debug
Used by SET GLOBAL innodb_ddl_log_crash_counter_reset_debug = 1;.
Definition: log0ddl.cc:79
Log_DDL * log_ddl
Object to handle Log_DDL.
Definition: log0ddl.cc:67
The memory management.
static my_thread_id thread_id
Definition: my_thr_init.cc:60
static int record
Definition: mysqltest.cc:195
static PFS_engine_table_share_proxy table
Definition: pfs.cc:61
bool index(const std::string &value, const String &search_for, uint32_t *idx)
Definition: contains.h:76
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:651
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: system_variables_bits.h:153
Data structure for an index.
Definition: dict0mem.h:1069
Data structure for a database table.
Definition: dict0mem.h:1927
Structure for an SQL data tuple of fields (logical record)
Definition: data0data.h:706
The info structure stored at the beginning of a heap block.
Definition: mem0mem.h:295
Definition: que0que.h:242
Definition: trx0trx.h:670
unsigned long int ulint
Definition: univ.i:403
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:109
#define ut_a(EXPR)
Abort execution if EXPR does not evaluate to nonzero.
Definition: ut0dbg.h:97
unsigned long id[MAX_DEAD]
Definition: xcom_base.cc:510