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