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