MySQL 8.0.40
Source Code Documentation
clone0snapshot.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 2017, 2024, Oracle and/or its affiliates.
4
5This program is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License, version 2.0, as published by the
7Free Software Foundation.
8
9This program is designed to work with certain software (including
10but not limited to OpenSSL) that is licensed under separate terms,
11as designated in a particular file or component or in included license
12documentation. The authors of MySQL hereby grant you an additional
13permission to link the program and your derivative works with the
14separately licensed software that they have either included with
15the program or referenced in the documentation.
16
17This program is distributed in the hope that it will be useful, but WITHOUT
18ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
20for more details.
21
22You should have received a copy of the GNU General Public License along with
23this program; if not, write to the Free Software Foundation, Inc.,
2451 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
26*****************************************************************************/
27
28/** @file include/clone0snapshot.h
29 Database Physical Snapshot
30
31 *******************************************************/
32
33#ifndef CLONE_SNAPSHOT_INCLUDE
34#define CLONE_SNAPSHOT_INCLUDE
35
36#include "univ.i"
37
38#include "arch0log.h"
39#include "arch0page.h"
40#include "clone0api.h"
41#include "clone0desc.h"
42#include "clone0monitor.h"
43#include "fil0fil.h"
44#include "sql/handler.h"
45
46#include <map>
47#include <vector>
48
50 /** File state:
51 [CREATED] -------------> [DROPPING] --> [DROPPED] --> [DROPPED_HANDLED]
52 | ^
53 | |
54 ----> [RENAMING] -> [RENAMED]
55 | |
56 <------------
57 */
58 enum class State {
59 /* Invalid state. */
60 NONE,
61 /* File is being dropped. */
63 /* File is being renamed. */
65 /* Newly created file or pre-existing before clone. */
66 CREATED,
67 /* File is renamed during clone. */
68 RENAMED,
69 /* File is deleted during clone. */
70 DROPPED,
71 /* File is deleted and chunk information is handled. */
73 };
74
75 /** File extension to use with name. */
76 enum class Extension {
77 /* No extension. */
78 NONE,
79 /* Replace extension - clone file to be replaced during recovery. */
80 REPLACE,
81 /* DDL extension - temporary extension used during rename. */
82 DDL
83 };
84
85 /** Initialize file state.
86 @param[in] extn file name extension */
87 void init(Extension extn) {
89 m_extension = extn;
90
91 m_pin.store(0);
92 m_modified_ddl = false;
93 m_waiting = 0;
94
96
97 m_meta.init();
98 }
99
100 /** Get file name with extension.
101 @param[out] name file name. */
102 void get_file_name(std::string &name) const;
103
104 /** Mark file added by DDL.
105 @param[in] next_state next snapshot state */
106 void set_ddl(Snapshot_State next_state) {
107 m_modified_ddl = true;
108 m_next_state = next_state;
109 }
110
111 /** @return true iff added or modified by ddl in previous state.
112 @param[in] state current snapshot state */
113 bool by_ddl(Snapshot_State state) const {
114 return m_modified_ddl && (state <= m_next_state);
115 }
116
117 /** Start waiting for DDL */
118 void begin_wait() { ++m_waiting; }
119
120 /** Finish waiting for DDL */
121 void end_wait() {
122 ut_a(m_waiting > 0);
123 --m_waiting;
124 }
125
126 /** @return true, iff there are waiting clone tasks. */
127 bool is_waiting() const { return (m_waiting > 0); }
128
129 /** Pin the file. */
130 void pin() { ++m_pin; }
131
132 /** Unpin the file. */
133 void unpin() {
134 ut_a(m_pin > 0);
135 --m_pin;
136 }
137
138 /** @return true, iff clone tasks are using the file. */
139 bool is_pinned() const { return (m_pin.load() > 0); }
140
141 /** @return true, iff DDL is modifying file. */
142 bool modifying() const {
143 State state = m_state.load();
144 return (state == State::RENAMING || state == State::DROPPING);
145 }
146
147 /** @return true, iff DDL is deleting file. */
148 bool deleting() const {
149 State state = m_state.load();
150 return (state == State::DROPPING);
151 }
152
153 /** @return true, iff file is already deleted. */
154 bool deleted() const {
155 State state = m_state.load();
156 return (state == State::DROPPED || state == State::DROPPED_HANDLED);
157 }
158
159 /** @return true, iff file is already renamed. */
160 bool renamed() const {
161 State state = m_state.load();
162 return (state == State::RENAMED);
163 }
164
165 /** @return file metadata. */
167
168 /** @return file metadata for read. */
169 const Clone_File_Meta *get_file_meta_read() const { return &m_meta; }
170
171 /** File metadata state. Modified by DDL commands. Protected by snapshot
172 mutex. Atomic operation helps clone to skip mutex when no ddl. */
173 std::atomic<State> m_state;
174
175 /** File name extension. */
177
178 private:
179 /** Pin count incremented and decremented by clone tasks to synchronize with
180 concurrent DDL. Protected by snapshot mutex. */
181 std::atomic<uint32_t> m_pin;
182
183 /** Waiting count incremented and decremented by clone tasks while waiting
184 DDL file operation in progress. Protected by snapshot mutex. */
185 uint32_t m_waiting;
186
187 /** true, if file created or modified after clone is started. */
188 bool m_modified_ddl{false};
189
190 /** Next state when ddl last modified file. */
192
193 /** File metadata. */
195};
196
197/** Vector type for storing clone files */
198using Clone_File_Vec = std::vector<Clone_file_ctx *>;
199
200/** Map type for mapping space ID to clone file index */
201using Clone_File_Map = std::map<space_id_t, uint>;
202
203/** Page identified by space and page number */
205 /** Tablespace ID */
206 uint32_t m_space_id;
207
208 /** Page number within tablespace */
209 uint32_t m_page_no;
210};
211
212/** Comparator for storing sorted page ID. */
214 /** Less than operator for page ID.
215 @param[in] page1 first page
216 @param[in] page2 second page
217 @return true, if page1 is less than page2 */
218 inline bool operator()(const Clone_Page &page1,
219 const Clone_Page &page2) const {
220 if (page1.m_space_id < page2.m_space_id) {
221 return (true);
222 }
223
224 if (page1.m_space_id == page2.m_space_id &&
225 page1.m_page_no < page2.m_page_no) {
226 return (true);
227 }
228 return (false);
229 }
230};
231
232/** Vector type for storing clone page IDs */
233using Clone_Page_Vec = std::vector<Clone_Page>;
234
235/** Set for storing unique page IDs. */
236using Clone_Page_Set = std::set<Clone_Page, Less_Clone_Page>;
237
238/** Clone handle type */
240 /** Clone Handle for COPY */
242
243 /** Clone Handle for APPLY */
246
247/** Default chunk size in power of 2 in unit of pages.
248Chunks are reserved by each thread for multi-threaded clone. For 16k page
249size, chunk size is 64M. */
251
252/** Default block size in power of 2 in unit of pages.
253Data transfer callback is invoked once for each block. This is also
254the maximum size of data that would be re-send if clone is stopped
255and resumed. For 16k page size, block size is 1M. */
257
258/** Maximum block size in power of 2 in unit of pages.
259For 16k page size, maximum block size is 64M. */
261
262/** Dynamic database snapshot: Holds metadata and handle to data */
264 public:
265 /** RAII style guard for begin & end of snapshot state transition. */
267 public:
268 /** Constructor to begin state transition.
269 @param[in,out] snapshot Clone Snapshot
270 @param[in] new_state State to transit */
271 explicit State_transit(Clone_Snapshot *snapshot, Snapshot_State new_state);
272
273 /** Destructor to end state transition. */
275
276 /** @return error code */
277 int get_error() const { return m_error; }
278
279 /** Disable copy construction */
280 State_transit(State_transit const &) = delete;
281
282 /** Disable assignment */
284
285 private:
286 /** Clone Snapshot */
288
289 /** Saved error while beginning transition. */
291 };
292
293 /** Construct snapshot
294 @param[in] hdl_type copy, apply
295 @param[in] clone_type clone type
296 @param[in] arr_idx index in global array
297 @param[in] snap_id unique snapshot ID */
299 uint arr_idx, uint64_t snap_id);
300
301 /** Release contexts and free heap */
303
304 /** DDL notification before the operation.
305 @param[in] type type of DDL notification
306 @param[in] space space ID for the ddl operation
307 @param[in] no_wait return with error if needs to wait
308 @param[in] check_intr check for interrupt during wait
309 @param[out] error mysql error code
310 @return true iff clone state change is blocked. */
311 bool begin_ddl_state(Clone_notify::Type type, space_id_t space, bool no_wait,
312 bool check_intr, int &error);
313
314 /** DDL notification after the operation.
315 @param[in] type type of DDL notification
316 @param[in] space space ID for the ddl operation */
318
319 /** Wait for concurrent DDL file operation and pin file.
320 @param[in,out] file_ctx file context
321 @param[out] handle_delete if caller needs to handle deleted state
322 @return mysql error code. */
323 int pin_file(Clone_file_ctx *file_ctx, bool &handle_delete);
324
325 /** Unpin a file.
326 @param[in,out] file_ctx file context */
327 void unpin_file(Clone_file_ctx *file_ctx) { file_ctx->unpin(); }
328
329 /** Check if DDL needs to block clone operation.
330 @param[in] file_ctx file context
331 @return true iff clone operation needs to be blocked. */
332 bool blocks_clone(const Clone_file_ctx *file_ctx);
333
334 /** @return estimated bytes on disk */
335 uint64_t get_disk_estimate() const { return (m_data_bytes_disk); }
336
337 /** Get unique snapshot identifier
338 @return snapshot ID */
339 uint64_t get_id() { return (m_snapshot_id); }
340
341 /** Get snapshot index in global array
342 @return array index */
344
345 /** Get performance schema accounting object used to monitor stage
346 progress.
347 @return PFS stage object */
349
350 /** Get snapshot heap used for allocation during clone.
351 @return heap */
354 return (m_snapshot_heap);
355 }
356
357 /* Release snapshot heap */
359 heap = nullptr;
361 }
362
363 /** Get snapshot state
364 @return state */
366
367 /** Get the redo file size for the snapshot
368 @return redo file size */
369 uint64_t get_redo_file_size() { return (m_redo_file_size); }
370
371 /** Get total number of chunks for current state
372 @return number of data chunks */
374
375 /** Get maximum file length seen till now
376 @return file name length */
378
379 /** Get maximum buffer size required for clone
380 @return maximum dynamic buffer */
382 uint ret_len = 0;
383
385 ret_len = static_cast<uint>(2 * UNIV_PAGE_SIZE);
386 }
387
388 return (ret_len);
389 }
390
391 using File_Cbk_Func = std::function<int(Clone_file_ctx *)>;
392
393 /** Iterate through all files in current state
394 @param[in] func callback function
395 @return error code */
396 int iterate_files(File_Cbk_Func &&func);
397
398 /** Iterate through all data files
399 @param[in] func callback function
400 @return error code */
402
403 /** Iterate through all redo files
404 @param[in] func callback function
405 @return error code */
407
408 /** Fill state descriptor from snapshot
409 @param[in] do_estimate estimate data bytes to transfer
410 @param[out] state_desc snapshot state descriptor */
411 void get_state_info(bool do_estimate, Clone_Desc_State *state_desc);
412
413 /** Set state information during apply
414 @param[in] state_desc snapshot state descriptor */
415 void set_state_info(Clone_Desc_State *state_desc);
416
417 /** Get next state based on snapshot type
418 @return next state */
420
421 /** Try to attach to snapshot
422 @param[in] hdl_type copy, apply
423 @param[in] pfs_monitor enable PFS monitoring
424 @return true if successfully attached */
425 bool attach(Clone_Handle_Type hdl_type, bool pfs_monitor);
426
427 /** Detach from snapshot. */
428 void detach();
429
430 /** Set current snapshot aborted state. Used in error cases before exiting
431 clone to make sure any DDL notifier exits waiting. */
432 void set_abort();
433
434 /** @return true, iff clone has aborted. */
435 bool is_aborted() const;
436
437 /** Start transition to new state
438 @param[in] state_desc descriptor for next state
439 @param[in] new_state state to move for apply
440 @param[in] temp_buffer buffer used for collecting page IDs
441 @param[in] temp_buffer_len buffer length
442 @param[in] cbk alter callback for long wait
443 @return error code */
444 int change_state(Clone_Desc_State *state_desc, Snapshot_State new_state,
445 byte *temp_buffer, uint temp_buffer_len,
446 Clone_Alert_Func cbk);
447
448 /** Add file metadata entry at destination
449 @param[in] file_meta file metadata from donor
450 @param[in] data_dir destination data directory
451 @param[in] desc_create create if doesn't exist
452 @param[out] desc_exists descriptor already exists
453 @param[out] file_ctx if there, set to current file context
454 @return error code */
455 int get_file_from_desc(const Clone_File_Meta *file_meta, const char *data_dir,
456 bool desc_create, bool &desc_exists,
457 Clone_file_ctx *&file_ctx);
458
459 /** Rename an existing file descriptor.
460 @param[in] file_meta renamed file metadata from donor
461 @param[in] data_dir destination data directory
462 @param[out] file_ctx if there, set to current file context
463 @return error code */
464 int rename_desc(const Clone_File_Meta *file_meta, const char *data_dir,
465 Clone_file_ctx *&file_ctx);
466
467 /** Fix files renamed with ddl extension. The file name is checked against
468 existing file and added to appropriate status file.
469 @param[in] data_dir destination data directory
470 @param[in,out] file_ctx Set to correct extension
471 @return error code */
472 int fix_ddl_extension(const char *data_dir, Clone_file_ctx *file_ctx);
473
474 /** Add file descriptor to file list
475 @param[in,out] file_ctx current file context
476 @param[in] ddl_create added by DDL concurrently
477 @return true, if it is the last file. */
478 bool add_file_from_desc(Clone_file_ctx *&file_ctx, bool ddl_create);
479
480 /** Extract file information from node and add to snapshot
481 @param[in] node file node
482 @param[in] by_ddl node is added concurrently by DDL
483 @return error code */
484 dberr_t add_node(fil_node_t *node, bool by_ddl);
485
486 /** Add page ID to to the set of pages in snapshot
487 @param[in] space_id page tablespace
488 @param[in] page_num page number within tablespace
489 @return error code */
490 int add_page(uint32_t space_id, uint32_t page_num);
491
492 /** Add redo file to snapshot
493 @param[in] file_name file name
494 @param[in] file_size file size in bytes
495 @param[in] file_offset start offset
496 @return error code. */
497 int add_redo_file(char *file_name, uint64_t file_size, uint64_t file_offset);
498
499 /** Get file metadata by index for current state
500 @param[in] index file index
501 @return file metadata entry */
503
504 /** Get clone file context by index for current state
505 @param[in] index file index
506 @return file context */
508
509 /** Get clone file context by chunk and block number.
510 @param[in] chunk_num chunk number
511 @param[in] block_num block number
512 @param[in] hint_index hint file index number to start search.
513 @return file context */
514 Clone_file_ctx *get_file_ctx(uint32_t chunk_num, uint32_t block_num,
515 uint32_t hint_index);
516
517 /** Get next block of data to transfer
518 @param[in] chunk_num current chunk
519 @param[in,out] block_num current/next block
520 @param[in,out] file_ctx current/next block file context
521 @param[out] data_offset block offset in file
522 @param[out] data_buf data buffer or NULL if transfer from file
523 @param[out] data_size size of data in bytes
524 @param[out] file_size updated file size if extended
525 @return error code */
526 int get_next_block(uint chunk_num, uint &block_num,
527 const Clone_file_ctx *&file_ctx, uint64_t &data_offset,
528 byte *&data_buf, uint32_t &data_size, uint64_t &file_size);
529
530 /** Update snapshot block size based on caller's buffer size
531 @param[in] buff_size buffer size for clone transfer */
532 void update_block_size(uint buff_size);
533
534 /** @return chunk size in bytes. */
535 inline uint32_t get_chunk_size() const {
536 return chunk_size() * UNIV_PAGE_SIZE;
537 }
538
539 /** @return number of blocks per chunk for different states. */
540 uint32_t get_blocks_per_chunk() const;
541
542 /** Check if copy snapshot
543 @return true if snapshot is for copy */
544 bool is_copy() const { return (m_snapshot_handle_type == CLONE_HDL_COPY); }
545
546 /** Update file size when file is extended during page copy
547 @param[in] file_index current file index
548 @param[in] file_size new file size */
549 void update_file_size(uint32_t file_index, uint64_t file_size);
550
551 /** Encrypt tablespace key in header page with master key.
552 @param[in] page_size page size descriptor
553 @param[in,out] page_data page data to update
554 @return true, if successful. */
555 bool encrypt_key_in_header(const page_size_t &page_size, byte *page_data);
556
557 /** Encrypt tablespace key in header page with master key.
558 @param[in,out] log_header page data to update
559 @param[in] header_len length of log header
560 @return true, if successful. */
561 bool encrypt_key_in_log_header(byte *log_header, uint32_t header_len);
562
563 /** Decrypt tablespace key in header page with master key.
564 @param[in] file_meta clone file metadata
565 @param[in] page_size page size descriptor
566 @param[in,out] page_data page data to update */
567 void decrypt_key_in_header(const Clone_File_Meta *file_meta,
568 const page_size_t &page_size, byte *&page_data);
569
570 /** @return maximum blocks to transfer with file pinned. */
571 uint32_t get_max_blocks_pin() const;
572
573 /** Skip all blocks belonging to currently deleted file context.
574 @param[in] chunk_num current chunk
575 @param[in,out] block_num current, next block */
576 void skip_deleted_blocks(uint32_t chunk_num, uint32_t &block_num);
577
578 private:
579 /** Allow DDL file operation after 64 pages. */
580 const static uint32_t S_MAX_PAGES_PIN = 64;
581
582 /** Allow DDL file operation after every block (1M data by default) */
583 const static uint32_t S_MAX_BLOCKS_PIN = 1;
584
585 /** File name allocation size base. */
586 const static size_t S_FILE_NAME_BASE_LEN = 256;
587
588 /** Various wait types related to snapshot state. */
589 enum class Wait_type {
590 /* DDL- limited wait if clone is waiting for another DDL. */
592 /* DDL- Wait till snapshot state transition is over. */
594 /* DDL- Wait till PAGE COPY state is over. */
596 /* Clone - Wait till there are no blockers for state transition. */
598 /*DDL - Wait till the waiting clone threads are active. This are
599 clone threads from last DDL and useful to prevent starvation. */
601 /* DDL - Wait till all threads have closed active data files. */
603 /* Clone - Wait till DDL file operation is complete. */
605 };
606
607#ifdef UNIV_DEBUG
608 /** Debug sync Wait during state transition. */
610#endif /* UNIV_DEBUG */
611
612 /** Update deleted state of a file if not yet done.
613 @param[in,out] file_ctx file context
614 @return true, if updated state */
615 bool update_deleted_state(Clone_file_ctx *file_ctx);
616
617 /** Get clone data file context by chunk number.
618 @param[in] chunk_num chunk number
619 @param[in] hint_index hint file index number to start search.
620 @return file context */
621 Clone_file_ctx *get_data_file_ctx(uint32_t chunk_num, uint32_t hint_index);
622
623 /** Get clone page file context by chunk number and block number.
624 @param[in] chunk_num chunk number
625 @param[in] block_num block number
626 @return file context */
627 Clone_file_ctx *get_page_file_ctx(uint32_t chunk_num, uint32_t block_num);
628
629 /** Get clone redo file context by chunk number.
630 @param[in] chunk_num chunk number
631 @param[in] hint_index hint file index number to start search.
632 @return file context */
633 Clone_file_ctx *get_redo_file_ctx(uint32_t chunk_num, uint32_t hint_index);
634
635 /** Get wait information string based on wait type.
636 @param[in] wait_type wait type
637 @return wait information string. */
638 const char *wait_string(Wait_type wait_type) const;
639
640 /** Wait for various operations based on type.
641 @param[in] type wait type
642 @param[in] ctx file context when relevant
643 @param[in] no_wait return with error if needs to wait
644 @param[in] check_intr check for interrupt during wait
645 @return mysql error code. */
646 int wait(Wait_type type, const Clone_file_ctx *ctx, bool no_wait,
647 bool check_intr);
648
649 /** During wait get relevant message string for logging.
650 @param[in] wait_type wait type
651 @param[out] info notification to log while waiting
652 @param[out] error error message to log on timeout */
653 void get_wait_mesg(Wait_type wait_type, std::string &info,
654 std::string &error);
655
656 /** Block clone state transition. Clone must wait.
657 @param[in] type type of DDL notification
658 @param[in] space space ID for the ddl operation
659 @param[in] no_wait return with error if needs to wait
660 @param[in] check_intr check for interrupt during wait`
661 @param[out] error mysql error code
662 @return true iff clone state change is blocked. */
664 bool no_wait, bool check_intr, int &error);
665
666 /** Unblock clone state transition. */
668
669 /** Get next file state while being modified by ddl.
670 @param[in] type ddl notification type
671 @param[in] begin true, if DDL begin notification
672 false, if DDL end notification
673 @return target file state. */
675 bool begin);
676
677 /** Handle files for DDL begin notification.
678 @param[in] type type of DDL notification
679 @param[in] space space ID for the ddl operation
680 @param[in] no_wait return with error if needs to wait
681 @param[in] check_intr check for interrupt during wait
682 @return mysql error code */
683 int begin_ddl_file(Clone_notify::Type type, space_id_t space, bool no_wait,
684 bool check_intr);
685
686 /** Handle files for DDL end notification.
687 @param[in] type type of DDL notification
688 @param[in] space space ID for the ddl operation */
690
691 /** Synchronize snapshot with binary log and GTID.
692 @param[in] cbk alert callback for long wait
693 @return error code. */
695
696 /** Make sure that the trx sys page binary log position correctly reflects
697 all transactions committed to innodb. It updates binary log position
698 in transaction sys page, if required. The caller must ensure that any new
699 transaction is committed in order of binary log.
700 @return error code. */
702
703 /** Wait for already prepared binlog transactions to end.
704 @return error code. */
706
707 /** Wait for a transaction to end.
708 @param[in] thd current THD
709 @param[in] trx_id transaction to wait for
710 @return error code. */
711 int wait_trx_end(THD *thd, trx_id_t trx_id);
712
713 /** Begin state transition before waiting for DDL. */
716 /* Update number of clones to transit to new state. Set this prior to
717 waiting for DDLs blocking state transfer. This would help a new DDL to
718 find if clone is blocked by other DDL before state transition. */
720 }
721
722 /** Begin state transition.
723 @param[in] new_state state to transit to */
726 m_snapshot_next_state = new_state;
727 /* Move to next state. This is ok as the snapshot
728 mutex is not released till transition is ended, This
729 could change later when we ideally should release
730 the snapshot mutex during transition. */
732 }
733
734 /** End state transition. */
735 void end_transit() {
739 }
740
741 /** Check if state transition is in progress
742 @return true during state transition */
743 bool in_transit_state() const {
746 }
747
748 /** @return true, if waiting before starting transition. Generally the
749 case when some DDL blocks state transition. */
750 bool in_transit_wait() const {
752 return (!in_transit_state() && m_num_clones_transit != 0);
753 }
754
755 /** Start redo archiving.
756 @return error code */
758
759 /** Initialize snapshot state for file copy
760 @param[in] new_state state to move for apply
761 @return error code */
762 int init_file_copy(Snapshot_State new_state);
763
764 /** Initialize disk byte estimate. */
766 /* Initial size is set to the redo file size on disk. */
769 }
770
771 /** Initialize snapshot state for page copy
772 @param[in] new_state state to move for apply
773 @param[in] page_buffer temporary buffer to copy page IDs
774 @param[in] page_buffer_len buffer length
775 @return error code */
776 int init_page_copy(Snapshot_State new_state, byte *page_buffer,
777 uint page_buffer_len);
778
779 /** Initialize snapshot state for redo copy
780 @param[in] new_state state to move for apply
781 @param[in] cbk alert callback for long wait
782 @return error code */
784
785 /** Initialize state while applying cloned data
786 @param[in] state_desc snapshot state descriptor
787 @return error code */
788 int init_apply_state(Clone_Desc_State *state_desc);
789
790 /** Extend and flush files after copying data
791 @param[in] flush_redo if true flush redo, otherwise data
792 @return error code */
793 int extend_and_flush_files(bool flush_redo);
794
795 /** Create file descriptor and add to current file list
796 @param[in] data_dir destination data directory
797 @param[in] file_meta file metadata from donor
798 @param[in] is_ddl if ddl temporary file
799 @param[out] file_ctx file context
800 @return error code */
801 int create_desc(const char *data_dir, const Clone_File_Meta *file_meta,
802 bool is_ddl, Clone_file_ctx *&file_ctx);
803
804 /** Get file context for current chunk
805 @param[in] file_vector clone file vector
806 @param[in] chunk_num current chunk number
807 @param[in] start_index index for starting the search
808 @return file context */
809 Clone_file_ctx *get_file(Clone_File_Vec &file_vector, uint32_t chunk_num,
810 uint32_t start_index);
811
812 /** Get next page from buffer pool
813 @param[in] chunk_num current chunk
814 @param[in,out] block_num current, next block
815 @param[in,out] file_ctx current, next block file context
816 @param[out] data_offset offset in file
817 @param[out] data_buf page data
818 @param[out] data_size page data size
819 @param[out] file_size updated file size if extended
820 @return error code */
821 int get_next_page(uint chunk_num, uint &block_num,
822 const Clone_file_ctx *&file_ctx, uint64_t &data_offset,
823 byte *&data_buf, uint32_t &data_size, uint64_t &file_size);
824
825 /** Get page from buffer pool and make ready for write
826 @param[in] page_id page ID chunk
827 @param[in] page_size page size descriptor
828 @param[in] file_ctx clone file context
829 @param[out] page_data data page
830 @param[out] data_size page size in bytes
831 @return error code */
832 int get_page_for_write(const page_id_t &page_id, const page_size_t &page_size,
833 const Clone_file_ctx *file_ctx, byte *&page_data,
834 uint &data_size);
835
836 /* Make page ready for flush by updating LSN anc checksum
837 @param[in] page_size page size descriptor
838 @param[in] page_lsn LSN to update the page with
839 @param[in,out] page_data data page */
840 void page_update_for_flush(const page_size_t &page_size, lsn_t page_lsn,
841 byte *&page_data);
842
843 /** Build file metadata entry
844 @param[in] file_name name of the file
845 @param[in] file_size file size in bytes
846 @param[in] file_offset start offset
847 @param[in] num_chunks total number of chunks in the file
848 @return file context */
849 Clone_file_ctx *build_file(const char *file_name, uint64_t file_size,
850 uint64_t file_offset, uint &num_chunks);
851
852 /** Allocate and set clone file name.
853 @param[in,out] file_meta file metadata
854 @param[in] file_name file name
855 @return true iff successful. */
856 bool build_file_name(Clone_File_Meta *file_meta, const char *file_name);
857
858 /** Add buffer pool dump file to the file list
859 @return error code */
860 int add_buf_pool_file();
861
862 /** Add file to snapshot
863 @param[in] name file name
864 @param[in] size_bytes file size in bytes
865 @param[in] alloc_bytes allocation size on disk for sparse file
866 @param[in] node file node
867 @param[in] by_ddl node is added concurrently by DDL
868 @return error code. */
869 int add_file(const char *name, uint64_t size_bytes, uint64_t alloc_bytes,
870 fil_node_t *node, bool by_ddl);
871
872 /** Check if file context has been changed by ddl.
873 @param[in] node tablespace file node
874 @param[out] file_ctx file context if exists
875 @return true iff file is created or modified by DDL. */
876 bool file_ctx_changed(const fil_node_t *node, Clone_file_ctx *&file_ctx);
877
878 /** Get chunk size
879 @return chunk size in pages */
880 inline uint32_t chunk_size() const {
881 auto size = static_cast<uint32_t>(ut_2_exp(m_chunk_size_pow2));
882 return size;
883 }
884
885 /** Get block size for file copy
886 @return block size in pages */
887 uint32_t block_size() {
889 auto size = static_cast<uint32_t>(ut_2_exp(m_block_size_pow2));
890
891 return size;
892 }
893
894 /** Get number of blocks per chunk for file copy
895 @return blocks per chunk */
896 inline uint32_t blocks_per_chunk() const {
898 return (1 << (m_chunk_size_pow2 - m_block_size_pow2));
899 }
900
901 /** Update system file name from configuration.
902 @param[in] replace if replacing current data directory
903 @param[in] file_meta file descriptor
904 @param[in,out] file_name file name to update
905 @return error code */
906 int update_sys_file_name(bool replace, const Clone_File_Meta *file_meta,
907 std::string &file_name);
908
909 /** Build file name along with path for cloned data files.
910 @param[in] data_dir clone data directory
911 @param[in] file_desc file descriptor
912 @param[out] file_path built file path if returned 0
913 @return error code (0 on success) */
914 int build_file_path(const char *data_dir, const Clone_File_Meta *file_desc,
915 std::string &file_path);
916
917 /** Build file context from file path.
918 @param[in] extn file extension type
919 @param[in] file_meta file descriptor
920 @param[in] file_path data file along with path
921 @param[out] file_ctx created file context
922 @return error code */
924 const Clone_File_Meta *file_meta,
925 const std::string &file_path, Clone_file_ctx *&file_ctx);
926
927 /** Check for existing file and if clone extension is needed. This function
928 has the side effect to add undo file indexes.
929 @param[in] replace if data directory is replaced
930 @param[in] undo_file if undo tablespace file
931 @param[in] redo_file if redo file
932 @param[in] data_file_index index of file
933 @param[in] data_file data file name
934 @param[out] extn file extension needs to be used
935 @return error code */
936 int handle_existing_file(bool replace, bool undo_file, bool redo_file,
937 uint32_t data_file_index,
938 const std::string &data_file,
940
941 /** @return number of data files to transfer. */
942 inline size_t num_data_files() const { return m_data_file_vector.size(); }
943
944 /** @return number of redo files to transfer. */
945 inline size_t num_redo_files() const { return m_redo_file_vector.size(); }
946
947 private:
948 /** @name Snapshot type and ID */
949
950 /** Snapshot handle type */
952
953 /** Clone type */
955
956 /** Unique snapshot ID */
958
959 /** Index in global snapshot array */
961
962 /** @name Snapshot State */
963
964 /** Mutex to handle access by concurrent clones */
965 mutable ib_mutex_t m_snapshot_mutex;
966
967 /** Number of blockers for state change. Usually DDLs for short duration. */
969
970 /** Set to true only if clone is aborted after error. */
972
973 /** Number of clones attached to this snapshot */
975
976 /** Number of clones in in state transition */
978
979 /** Current state */
981
982 /** Next state to move to. Set only during state transfer. */
984
985 /** @name Snapshot data block */
986
987 /** Memory allocation heap */
989
990 /** Chunk size in power of 2 */
992
993 /** Block size in power of 2 */
995
996 /** Number of chunks in current state */
998
999 /** Maximum file name length observed till now. */
1001
1002 /** @name Snapshot file data */
1003
1004 /** All data files for transfer */
1006
1007 /** Map space ID to file vector index */
1009
1010 /** Total number of data chunks */
1012
1013 /** Number of bytes on disk. */
1015
1016 /** Index into m_data_file_vector for all undo files. */
1017 std::vector<int> m_undo_file_indexes;
1018
1019 /** @name Snapshot page data */
1020
1021 /** Page archiver client */
1023
1024 /** Set of unique page IDs */
1026
1027 /** Sorted page IDs to transfer */
1029
1030 /** Number of pages to transfer */
1032
1033 /** Number of duplicate pages found */
1035
1036 /** @name Snapshot redo data */
1037
1038 /** redo log archiver client */
1040
1041 /** All archived redo files to transfer */
1043
1044 /** Start offset in first redo file */
1046
1047 /** Redo header block */
1049
1050 /** Redo header size */
1052
1053 /** Redo trailer block */
1055
1056 /** Redo trailer size */
1058
1059 /** Redo trailer block offset */
1061
1062 /** Archived redo file size */
1064
1065 /** Total number of redo data chunks */
1067
1068 /** Enable PFS monitoring */
1070
1071 /** Performance Schema accounting object to monitor stage progress */
1073};
1074
1075#endif /* CLONE_SNAPSHOT_INCLUDE */
uint32_t space_id_t
Tablespace identifier.
Definition: api0api.h:52
Innodb interface for log archive.
Innodb interface for modified page archive.
Class used to report CLONE progress via Performance Schema.
Definition: clone0monitor.h:46
RAII style guard for begin & end of snapshot state transition.
Definition: clone0snapshot.h:266
Clone_Snapshot * m_snapshot
Clone Snapshot.
Definition: clone0snapshot.h:287
State_transit(State_transit const &)=delete
Disable copy construction.
State_transit & operator=(State_transit const &)=delete
Disable assignment.
~State_transit()
Destructor to end state transition.
Definition: clone0snapshot.cc:270
int get_error() const
Definition: clone0snapshot.h:277
State_transit(Clone_Snapshot *snapshot, Snapshot_State new_state)
Constructor to begin state transition.
Definition: clone0snapshot.cc:248
int m_error
Saved error while beginning transition.
Definition: clone0snapshot.h:290
Dynamic database snapshot: Holds metadata and handle to data.
Definition: clone0snapshot.h:263
bool encrypt_key_in_header(const page_size_t &page_size, byte *page_data)
Encrypt tablespace key in header page with master key.
Definition: clone0snapshot.cc:759
int init_redo_archiving()
Start redo archiving.
Definition: clone0copy.cc:122
const char * wait_string(Wait_type wait_type) const
Get wait information string based on wait type.
Definition: clone0snapshot.cc:1244
uint m_num_duplicate_pages
Number of duplicate pages found.
Definition: clone0snapshot.h:1034
mem_heap_t * lock_heap()
Get snapshot heap used for allocation during clone.
Definition: clone0snapshot.h:352
void get_state_info(bool do_estimate, Clone_Desc_State *state_desc)
Fill state descriptor from snapshot.
Definition: clone0snapshot.cc:97
void end_ddl_file(Clone_notify::Type type, space_id_t space)
Handle files for DDL end notification.
Definition: clone0snapshot.cc:1542
uint32_t get_blocks_per_chunk() const
Definition: clone0snapshot.cc:529
uint64_t get_id()
Get unique snapshot identifier.
Definition: clone0snapshot.h:339
int wait_for_binlog_prepared_trx()
Wait for already prepared binlog transactions to end.
Definition: clone0copy.cc:454
uint64_t m_redo_start_offset
Start offset in first redo file.
Definition: clone0snapshot.h:1045
uint get_dyn_buffer_length()
Get maximum buffer size required for clone.
Definition: clone0snapshot.h:381
int rename_desc(const Clone_File_Meta *file_meta, const char *data_dir, Clone_file_ctx *&file_ctx)
Rename an existing file descriptor.
Definition: clone0apply.cc:77
size_t num_redo_files() const
Definition: clone0snapshot.h:945
uint m_redo_header_size
Redo header size.
Definition: clone0snapshot.h:1051
Clone_Monitor & get_clone_monitor()
Get performance schema accounting object used to monitor stage progress.
Definition: clone0snapshot.h:348
void page_update_for_flush(const page_size_t &page_size, lsn_t page_lsn, byte *&page_data)
Definition: clone0snapshot.cc:805
uint32_t block_size()
Get block size for file copy.
Definition: clone0snapshot.h:887
Clone_Snapshot(Clone_Handle_Type hdl_type, Ha_clone_type clone_type, uint arr_idx, uint64_t snap_id)
Construct snapshot.
Definition: clone0snapshot.cc:45
bool in_transit_wait() const
Definition: clone0snapshot.h:750
ib_mutex_t m_snapshot_mutex
Mutex to handle access by concurrent clones.
Definition: clone0snapshot.h:965
void decrypt_key_in_header(const Clone_File_Meta *file_meta, const page_size_t &page_size, byte *&page_data)
Decrypt tablespace key in header page with master key.
Definition: clone0snapshot.cc:790
uint m_num_current_chunks
Number of chunks in current state.
Definition: clone0snapshot.h:997
int add_page(uint32_t space_id, uint32_t page_num)
Add page ID to to the set of pages in snapshot.
Definition: clone0copy.cc:915
int pin_file(Clone_file_ctx *file_ctx, bool &handle_delete)
Wait for concurrent DDL file operation and pin file.
Definition: clone0snapshot.cc:1616
mem_heap_t * m_snapshot_heap
Memory allocation heap.
Definition: clone0snapshot.h:988
void get_wait_mesg(Wait_type wait_type, std::string &info, std::string &error)
During wait get relevant message string for logging.
Definition: clone0snapshot.cc:1208
Clone_File_Vec m_data_file_vector
All data files for transfer.
Definition: clone0snapshot.h:1005
size_t m_max_file_name_len
Maximum file name length observed till now.
Definition: clone0snapshot.h:1000
uint32_t get_max_blocks_pin() const
Definition: clone0snapshot.cc:990
uint m_num_clones_transit
Number of clones in in state transition.
Definition: clone0snapshot.h:977
size_t num_data_files() const
Definition: clone0snapshot.h:942
uint32_t chunk_size() const
Get chunk size.
Definition: clone0snapshot.h:880
uint32_t m_num_blockers
Number of blockers for state change.
Definition: clone0snapshot.h:968
static const size_t S_FILE_NAME_BASE_LEN
File name allocation size base.
Definition: clone0snapshot.h:586
static const uint32_t S_MAX_BLOCKS_PIN
Allow DDL file operation after every block (1M data by default)
Definition: clone0snapshot.h:583
void release_heap(mem_heap_t *&heap)
Definition: clone0snapshot.h:358
int add_redo_file(char *file_name, uint64_t file_size, uint64_t file_offset)
Add redo file to snapshot.
Definition: clone0copy.cc:941
bool add_file_from_desc(Clone_file_ctx *&file_ctx, bool ddl_create)
Add file descriptor to file list.
Definition: clone0apply.cc:502
int add_file(const char *name, uint64_t size_bytes, uint64_t alloc_bytes, fil_node_t *node, bool by_ddl)
Add file to snapshot.
Definition: clone0copy.cc:747
dberr_t add_node(fil_node_t *node, bool by_ddl)
Extract file information from node and add to snapshot.
Definition: clone0copy.cc:862
uint64_t m_data_bytes_disk
Number of bytes on disk.
Definition: clone0snapshot.h:1014
int get_next_block(uint chunk_num, uint &block_num, const Clone_file_ctx *&file_ctx, uint64_t &data_offset, byte *&data_buf, uint32_t &data_size, uint64_t &file_size)
Get next block of data to transfer.
Definition: clone0snapshot.cc:350
bool in_transit_state() const
Check if state transition is in progress.
Definition: clone0snapshot.h:743
uint get_index()
Get snapshot index in global array.
Definition: clone0snapshot.h:343
Snapshot_State get_state()
Get snapshot state.
Definition: clone0snapshot.h:365
uint64_t get_disk_estimate() const
Definition: clone0snapshot.h:335
int change_state(Clone_Desc_State *state_desc, Snapshot_State new_state, byte *temp_buffer, uint temp_buffer_len, Clone_Alert_Func cbk)
Start transition to new state.
Definition: clone0snapshot.cc:554
void begin_transit(Snapshot_State new_state)
Begin state transition.
Definition: clone0snapshot.h:724
uint get_num_chunks()
Get total number of chunks for current state.
Definition: clone0snapshot.h:373
Log_Arch_Client_Ctx m_redo_ctx
redo log archiver client
Definition: clone0snapshot.h:1039
int wait(Wait_type type, const Clone_file_ctx *ctx, bool no_wait, bool check_intr)
Wait for various operations based on type.
Definition: clone0snapshot.cc:1283
Clone_file_ctx * get_file(Clone_File_Vec &file_vector, uint32_t chunk_num, uint32_t start_index)
Get file context for current chunk.
Definition: clone0snapshot.cc:614
void set_abort()
Set current snapshot aborted state.
Definition: clone0snapshot.cc:242
bool m_aborted
Set to true only if clone is aborted after error.
Definition: clone0snapshot.h:971
Clone_File_Meta * get_file_by_index(uint index)
Get file metadata by index for current state.
Definition: clone0snapshot.cc:281
void init_disk_estimate()
Initialize disk byte estimate.
Definition: clone0snapshot.h:765
Clone_Monitor m_monitor
Performance Schema accounting object to monitor stage progress.
Definition: clone0snapshot.h:1072
int get_page_for_write(const page_id_t &page_id, const page_size_t &page_size, const Clone_file_ctx *file_ctx, byte *&page_data, uint &data_size)
Get page from buffer pool and make ready for write.
Definition: clone0snapshot.cc:846
Snapshot_State get_next_state()
Get next state based on snapshot type.
Definition: clone0snapshot.cc:176
int init_redo_copy(Snapshot_State new_state, Clone_Alert_Func cbk)
Initialize snapshot state for redo copy.
Definition: clone0copy.cc:474
Snapshot_State m_snapshot_state
Current state.
Definition: clone0snapshot.h:980
void unblock_state_change()
Unblock clone state transition.
Definition: clone0snapshot.cc:1439
int handle_existing_file(bool replace, bool undo_file, bool redo_file, uint32_t data_file_index, const std::string &data_file, Clone_file_ctx::Extension &extn)
Check for existing file and if clone extension is needed.
Definition: clone0apply.cc:217
int update_binlog_position()
Make sure that the trx sys page binary log position correctly reflects all transactions committed to ...
Definition: clone0copy.cc:350
std::function< int(Clone_file_ctx *)> File_Cbk_Func
Definition: clone0snapshot.h:391
bool is_copy() const
Check if copy snapshot.
Definition: clone0snapshot.h:544
Clone_File_Map m_data_file_map
Map space ID to file vector index.
Definition: clone0snapshot.h:1008
Clone_file_ctx * get_file_ctx(uint32_t chunk_num, uint32_t block_num, uint32_t hint_index)
Get clone file context by chunk and block number.
Definition: clone0snapshot.cc:995
uint m_snapshot_arr_idx
Index in global snapshot array.
Definition: clone0snapshot.h:960
Clone_file_ctx * get_page_file_ctx(uint32_t chunk_num, uint32_t block_num)
Get clone page file context by chunk number and block number.
Definition: clone0snapshot.cc:1034
int get_file_from_desc(const Clone_File_Meta *file_meta, const char *data_dir, bool desc_create, bool &desc_exists, Clone_file_ctx *&file_ctx)
Add file metadata entry at destination.
Definition: clone0apply.cc:43
int build_file_path(const char *data_dir, const Clone_File_Meta *file_desc, std::string &file_path)
Build file name along with path for cloned data files.
Definition: clone0apply.cc:323
Clone_Page_Set m_page_set
Set of unique page IDs.
Definition: clone0snapshot.h:1025
Page_Arch_Client_Ctx m_page_ctx
Page archiver client.
Definition: clone0snapshot.h:1022
int update_sys_file_name(bool replace, const Clone_File_Meta *file_meta, std::string &file_name)
Update system file name from configuration.
Definition: clone0apply.cc:119
int begin_ddl_file(Clone_notify::Type type, space_id_t space, bool no_wait, bool check_intr)
Handle files for DDL begin notification.
Definition: clone0snapshot.cc:1488
bool block_state_change(Clone_notify::Type type, space_id_t space, bool no_wait, bool check_intr, int &error)
Block clone state transition.
Definition: clone0snapshot.cc:1385
byte * m_redo_trailer
Redo trailer block.
Definition: clone0snapshot.h:1054
bool attach(Clone_Handle_Type hdl_type, bool pfs_monitor)
Try to attach to snapshot.
Definition: clone0snapshot.cc:208
int init_file_copy(Snapshot_State new_state)
Initialize snapshot state for file copy.
Definition: clone0copy.cc:184
Clone_Handle_Type m_snapshot_handle_type
Snapshot handle type.
Definition: clone0snapshot.h:951
Clone_file_ctx::State get_target_file_state(Clone_notify::Type type, bool begin)
Get next file state while being modified by ddl.
Definition: clone0snapshot.cc:1444
void detach()
Detach from snapshot.
Definition: clone0snapshot.cc:225
Clone_File_Vec m_redo_file_vector
All archived redo files to transfer.
Definition: clone0snapshot.h:1042
bool build_file_name(Clone_File_Meta *file_meta, const char *file_name)
Allocate and set clone file name.
Definition: clone0copy.cc:576
void set_state_info(Clone_Desc_State *state_desc)
Set state information during apply.
Definition: clone0snapshot.cc:137
Clone_file_ctx * get_data_file_ctx(uint32_t chunk_num, uint32_t hint_index)
Get clone data file context by chunk number.
Definition: clone0snapshot.cc:1016
std::vector< int > m_undo_file_indexes
Index into m_data_file_vector for all undo files.
Definition: clone0snapshot.h:1017
bool begin_ddl_state(Clone_notify::Type type, space_id_t space, bool no_wait, bool check_intr, int &error)
DDL notification before the operation.
Definition: clone0snapshot.cc:1096
uint32_t get_chunk_size() const
Definition: clone0snapshot.h:535
int iterate_redo_files(File_Cbk_Func &&func)
Iterate through all redo files.
Definition: clone0snapshot.cc:340
Clone_Page_Vec m_page_vector
Sorted page IDs to transfer.
Definition: clone0snapshot.h:1028
uint32_t blocks_per_chunk() const
Get number of blocks per chunk for file copy.
Definition: clone0snapshot.h:896
bool encrypt_key_in_log_header(byte *log_header, uint32_t header_len)
Encrypt tablespace key in header page with master key.
Definition: clone0snapshot.cc:739
Ha_clone_type m_snapshot_type
Clone type.
Definition: clone0snapshot.h:954
void begin_transit_ddl_wait()
Begin state transition before waiting for DDL.
Definition: clone0snapshot.h:714
int create_desc(const char *data_dir, const Clone_File_Meta *file_meta, bool is_ddl, Clone_file_ctx *&file_ctx)
Create file descriptor and add to current file list.
Definition: clone0apply.cc:462
uint m_num_redo_chunks
Total number of redo data chunks.
Definition: clone0snapshot.h:1066
bool file_ctx_changed(const fil_node_t *node, Clone_file_ctx *&file_ctx)
Check if file context has been changed by ddl.
Definition: clone0copy.cc:675
int build_file_ctx(Clone_file_ctx::Extension extn, const Clone_File_Meta *file_meta, const std::string &file_path, Clone_file_ctx *&file_ctx)
Build file context from file path.
Definition: clone0apply.cc:407
static const uint32_t S_MAX_PAGES_PIN
Allow DDL file operation after 64 pages.
Definition: clone0snapshot.h:580
int add_buf_pool_file()
Add buffer pool dump file to the file list.
Definition: clone0copy.cc:90
int get_next_page(uint chunk_num, uint &block_num, const Clone_file_ctx *&file_ctx, uint64_t &data_offset, byte *&data_buf, uint32_t &data_size, uint64_t &file_size)
Get next page from buffer pool.
Definition: clone0snapshot.cc:665
int init_apply_state(Clone_Desc_State *state_desc)
Initialize state while applying cloned data.
Definition: clone0apply.cc:1673
int init_page_copy(Snapshot_State new_state, byte *page_buffer, uint page_buffer_len)
Initialize snapshot state for page copy.
Definition: clone0copy.cc:247
bool is_aborted() const
Definition: clone0snapshot.cc:237
uint m_num_clones
Number of clones attached to this snapshot.
Definition: clone0snapshot.h:974
void unpin_file(Clone_file_ctx *file_ctx)
Unpin a file.
Definition: clone0snapshot.h:327
uint64_t get_redo_file_size()
Get the redo file size for the snapshot.
Definition: clone0snapshot.h:369
int iterate_files(File_Cbk_Func &&func)
Iterate through all files in current state.
Definition: clone0snapshot.cc:312
void update_file_size(uint32_t file_index, uint64_t file_size)
Update file size when file is extended during page copy.
Definition: clone0apply.cc:1642
void debug_wait_state_transit()
Debug sync Wait during state transition.
Definition: clone0copy.cc:172
size_t get_max_file_name_length()
Get maximum file length seen till now.
Definition: clone0snapshot.h:377
void update_block_size(uint buff_size)
Update snapshot block size based on caller's buffer size.
Definition: clone0snapshot.cc:511
uint m_block_size_pow2
Block size in power of 2.
Definition: clone0snapshot.h:994
uint64_t m_redo_file_size
Archived redo file size.
Definition: clone0snapshot.h:1063
Snapshot_State m_snapshot_next_state
Next state to move to.
Definition: clone0snapshot.h:983
void skip_deleted_blocks(uint32_t chunk_num, uint32_t &block_num)
Skip all blocks belonging to currently deleted file context.
Definition: clone0snapshot.cc:637
uint m_num_data_chunks
Total number of data chunks.
Definition: clone0snapshot.h:1011
int extend_and_flush_files(bool flush_redo)
Extend and flush files after copying data.
Definition: clone0apply.cc:1723
uint m_num_pages
Number of pages to transfer.
Definition: clone0snapshot.h:1031
~Clone_Snapshot()
Release contexts and free heap.
Definition: clone0snapshot.cc:84
int wait_trx_end(THD *thd, trx_id_t trx_id)
Wait for a transaction to end.
Definition: clone0copy.cc:402
Wait_type
Various wait types related to snapshot state.
Definition: clone0snapshot.h:589
Clone_file_ctx * get_file_ctx_by_index(uint index)
Get clone file context by index for current state.
Definition: clone0snapshot.cc:290
uint m_chunk_size_pow2
Chunk size in power of 2.
Definition: clone0snapshot.h:991
int synchronize_binlog_gtid(Clone_Alert_Func cbk)
Synchronize snapshot with binary log and GTID.
Definition: clone0copy.cc:332
bool update_deleted_state(Clone_file_ctx *file_ctx)
Update deleted state of a file if not yet done.
Definition: clone0snapshot.cc:1602
byte * m_redo_header
Redo header block.
Definition: clone0snapshot.h:1048
uint64_t m_snapshot_id
Unique snapshot ID.
Definition: clone0snapshot.h:957
int iterate_data_files(File_Cbk_Func &&func)
Iterate through all data files.
Definition: clone0snapshot.cc:328
bool m_enable_pfs
Enable PFS monitoring.
Definition: clone0snapshot.h:1069
int fix_ddl_extension(const char *data_dir, Clone_file_ctx *file_ctx)
Fix files renamed with ddl extension.
Definition: clone0apply.cc:95
uint m_redo_trailer_size
Redo trailer size.
Definition: clone0snapshot.h:1057
Clone_file_ctx * build_file(const char *file_name, uint64_t file_size, uint64_t file_offset, uint &num_chunks)
Build file metadata entry.
Definition: clone0copy.cc:622
void end_transit()
End state transition.
Definition: clone0snapshot.h:735
bool blocks_clone(const Clone_file_ctx *file_ctx)
Check if DDL needs to block clone operation.
Definition: clone0snapshot.cc:1464
uint64_t m_redo_trailer_offset
Redo trailer block offset.
Definition: clone0snapshot.h:1060
Clone_file_ctx * get_redo_file_ctx(uint32_t chunk_num, uint32_t hint_index)
Get clone redo file context by chunk number.
Definition: clone0snapshot.cc:1021
void end_ddl_state(Clone_notify::Type type, space_id_t space)
DDL notification after the operation.
Definition: clone0snapshot.cc:1197
Type
Notification type.
Definition: clone0api.h:182
Redo Log archiver client context.
Definition: arch0log.h:48
os_offset_t current_physical_capacity() const
Provides maximum limitation for space occupied on disk.
Definition: log0files_capacity.cc:529
Dirty page archiver client context.
Definition: arch0page.h:170
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:34
Page identifier.
Definition: buf0types.h:207
Page size descriptor.
Definition: page0size.h:50
Innodb Clone Interface.
Innodb clone descriptors.
Snapshot_State
Snapshot state transfer during clone.
Definition: clone0desc.h:93
@ CLONE_SNAPSHOT_DONE
Snapshot state at end after finishing transfer.
Definition: clone0desc.h:110
@ CLONE_SNAPSHOT_NONE
Invalid state.
Definition: clone0desc.h:95
Performance Schema stage instrumentation to monitor clone progress.
std::function< int()> Clone_Alert_Func
Function to alert caller for long wait.
Definition: clone0monitor.h:43
std::vector< Clone_file_ctx * > Clone_File_Vec
Vector type for storing clone files.
Definition: clone0snapshot.h:198
std::vector< Clone_Page > Clone_Page_Vec
Vector type for storing clone page IDs.
Definition: clone0snapshot.h:233
const uint SNAPSHOT_MAX_BLOCK_SIZE_POW2
Maximum block size in power of 2 in unit of pages.
Definition: clone0snapshot.h:260
const uint SNAPSHOT_DEF_CHUNK_SIZE_POW2
Default chunk size in power of 2 in unit of pages.
Definition: clone0snapshot.h:250
Clone_Handle_Type
Clone handle type.
Definition: clone0snapshot.h:239
@ CLONE_HDL_APPLY
Clone Handle for APPLY.
Definition: clone0snapshot.h:244
@ CLONE_HDL_COPY
Clone Handle for COPY.
Definition: clone0snapshot.h:241
std::set< Clone_Page, Less_Clone_Page > Clone_Page_Set
Set for storing unique page IDs.
Definition: clone0snapshot.h:236
std::map< space_id_t, uint > Clone_File_Map
Map type for mapping space ID to clone file index.
Definition: clone0snapshot.h:201
const uint SNAPSHOT_DEF_BLOCK_SIZE_POW2
Default block size in power of 2 in unit of pages.
Definition: clone0snapshot.h:256
dberr_t
Definition: db0err.h:39
The low-level file system.
log_t * log_sys
Redo log system (singleton).
Definition: log0log.cc:435
uint64_t lsn_t
Type used for all log sequence number storage and arithmetic.
Definition: log0types.h:63
static size_t file_size
Definition: mysql_config_editor.cc:71
Log info(cout, "NOTE")
static bool replace
Definition: mysqlimport.cc:66
std::string file_name(Log_file_id file_id)
Provides name of the log file with the given file id, e.g.
Definition: log0pre_8_0_30.cc:94
wait_type
Definition: socket_constants.h:86
required string type
Definition: replication_group_member_actions.proto:34
Ha_clone_type
Clone operation types.
Definition: handler.h:960
@ HA_CLONE_BLOCKING
Caller must block all write operation to the SE.
Definition: handler.h:962
case opt name
Definition: sslopt-case.h:33
CLONE_DESC_STATE: Descriptor for current snapshot state.
Definition: clone0desc.h:439
Clone file information.
Definition: clone0desc.h:486
void init()
Definition: clone0desc.cc:1072
Page identified by space and page number.
Definition: clone0snapshot.h:204
uint32_t m_page_no
Page number within tablespace.
Definition: clone0snapshot.h:209
uint32_t m_space_id
Tablespace ID.
Definition: clone0snapshot.h:206
Definition: clone0snapshot.h:49
void end_wait()
Finish waiting for DDL.
Definition: clone0snapshot.h:121
void set_ddl(Snapshot_State next_state)
Mark file added by DDL.
Definition: clone0snapshot.h:106
bool is_waiting() const
Definition: clone0snapshot.h:127
bool modifying() const
Definition: clone0snapshot.h:142
void unpin()
Unpin the file.
Definition: clone0snapshot.h:133
const Clone_File_Meta * get_file_meta_read() const
Definition: clone0snapshot.h:169
Extension
File extension to use with name.
Definition: clone0snapshot.h:76
bool deleting() const
Definition: clone0snapshot.h:148
uint32_t m_waiting
Waiting count incremented and decremented by clone tasks while waiting DDL file operation in progress...
Definition: clone0snapshot.h:185
std::atomic< uint32_t > m_pin
Pin count incremented and decremented by clone tasks to synchronize with concurrent DDL.
Definition: clone0snapshot.h:181
bool renamed() const
Definition: clone0snapshot.h:160
void pin()
Pin the file.
Definition: clone0snapshot.h:130
bool deleted() const
Definition: clone0snapshot.h:154
Clone_File_Meta m_meta
File metadata.
Definition: clone0snapshot.h:194
bool by_ddl(Snapshot_State state) const
Definition: clone0snapshot.h:113
void get_file_name(std::string &name) const
Get file name with extension.
Definition: clone0snapshot.cc:1072
Snapshot_State m_next_state
Next state when ddl last modified file.
Definition: clone0snapshot.h:191
Clone_File_Meta * get_file_meta()
Definition: clone0snapshot.h:166
State
File state: [CREATED] ----------—> [DROPPING] --> [DROPPED] --> [DROPPED_HANDLED] | ^ | | -—> [RENAMI...
Definition: clone0snapshot.h:58
std::atomic< State > m_state
File metadata state.
Definition: clone0snapshot.h:173
void init(Extension extn)
Initialize file state.
Definition: clone0snapshot.h:87
Extension m_extension
File name extension.
Definition: clone0snapshot.h:176
void begin_wait()
Start waiting for DDL.
Definition: clone0snapshot.h:118
bool m_modified_ddl
true, if file created or modified after clone is started.
Definition: clone0snapshot.h:188
bool is_pinned() const
Definition: clone0snapshot.h:139
Definition: ut0mutex.h:128
Comparator for storing sorted page ID.
Definition: clone0snapshot.h:213
bool operator()(const Clone_Page &page1, const Clone_Page &page2) const
Less than operator for page ID.
Definition: clone0snapshot.h:218
File node of a tablespace or the log data space.
Definition: fil0fil.h:155
ib_mutex_t limits_mutex
Mutex which protects fields: available_for_checkpoint_lsn, requested_checkpoint_lsn.
Definition: log0sys.h:596
Log_files_capacity m_capacity
Capacity limits for the redo log.
Definition: log0sys.h:431
The info structure stored at the beginning of a heap block.
Definition: mem0mem.h:302
ib_id_t trx_id_t
Transaction identifier (DB_TRX_ID, DATA_TRX_ID)
Definition: trx0types.h:138
unsigned int uint
Definition: uca9-dump.cc:75
Version control for database, common definitions, and include files.
#define UNIV_PAGE_SIZE
The universal page size of the database.
Definition: univ.i:294
#define UT_LOCATION_HERE
Definition: ut0core.h:47
#define ut_a(EXPR)
Abort execution if EXPR does not evaluate to nonzero.
Definition: ut0dbg.h:57
#define mutex_own(M)
Checks that the current thread owns the mutex.
Definition: ut0mutex.h:165
#define mutex_exit(M)
Definition: ut0mutex.h:123
#define mutex_enter(M)
Definition: ut0mutex.h:117
static uint32_t ut_2_exp(uint32_t n)
Calculates 2 to power n.