MySQL 8.4.11
Source Code Documentation
clone0snapshot.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 2017, 2026, 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 */
343 uint get_index() { return (m_snapshot_arr_idx); }
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 /** Legacy low-level path construction helper.
636 This method preserves the historical path building behavior and performs
637 no containment validation on the computed result. New code should not call
638 it directly; use build_file_path() instead.
639 @param[in] data_dir destination data directory
640 @param[in] file_desc file metadata from donor
641 @param[out] file_path computed destination path
642 @return error code (0 on success) */
643 int build_file_path_unsafe(const char *data_dir,
644 const Clone_File_Meta *file_desc,
645 std::string &file_path);
646
647 /** Get wait information string based on wait type.
648 @param[in] wait_type wait type
649 @return wait information string. */
650 const char *wait_string(Wait_type wait_type) const;
651
652 /** Wait for various operations based on type.
653 @param[in] type wait type
654 @param[in] ctx file context when relevant
655 @param[in] no_wait return with error if needs to wait
656 @param[in] check_intr check for interrupt during wait
657 @return mysql error code. */
658 int wait(Wait_type type, const Clone_file_ctx *ctx, bool no_wait,
659 bool check_intr);
660
661 /** During wait get relevant message string for logging.
662 @param[in] wait_type wait type
663 @param[out] info notification to log while waiting
664 @param[out] error error message to log on timeout */
665 void get_wait_mesg(Wait_type wait_type, std::string &info,
666 std::string &error);
667
668 /** Block clone state transition. Clone must wait.
669 @param[in] type type of DDL notification
670 @param[in] space space ID for the ddl operation
671 @param[in] no_wait return with error if needs to wait
672 @param[in] check_intr check for interrupt during wait`
673 @param[out] error mysql error code
674 @return true iff clone state change is blocked. */
676 bool no_wait, bool check_intr, int &error);
677
678 /** Unblock clone state transition. */
680
681 /** Get next file state while being modified by ddl.
682 @param[in] type ddl notification type
683 @param[in] begin true, if DDL begin notification
684 false, if DDL end notification
685 @return target file state. */
687 bool begin);
688
689 /** Handle files for DDL begin notification.
690 @param[in] type type of DDL notification
691 @param[in] space space ID for the ddl operation
692 @param[in] no_wait return with error if needs to wait
693 @param[in] check_intr check for interrupt during wait
694 @return mysql error code */
695 int begin_ddl_file(Clone_notify::Type type, space_id_t space, bool no_wait,
696 bool check_intr);
697
698 /** Handle files for DDL end notification.
699 @param[in] type type of DDL notification
700 @param[in] space space ID for the ddl operation */
702
703 /** Synchronize snapshot with binary log and GTID.
704 @param[in] cbk alert callback for long wait
705 @return error code. */
707
708 /** Make sure that the trx sys page binary log position correctly reflects
709 all transactions committed to innodb. It updates binary log position
710 in transaction sys page, if required. The caller must ensure that any new
711 transaction is committed in order of binary log.
712 @return error code. */
714
715 /** Wait for already prepared binlog transactions to end.
716 @return error code. */
718
719 /** Wait for a transaction to end.
720 @param[in] thd current THD
721 @param[in] trx_id transaction to wait for
722 @return error code. */
723 int wait_trx_end(THD *thd, trx_id_t trx_id);
724
725 /** Begin state transition before waiting for DDL. */
728 /* Update number of clones to transit to new state. Set this prior to
729 waiting for DDLs blocking state transfer. This would help a new DDL to
730 find if clone is blocked by other DDL before state transition. */
732 }
733
734 /** Begin state transition.
735 @param[in] new_state state to transit to */
738 m_snapshot_next_state = new_state;
739 /* Move to next state. This is ok as the snapshot
740 mutex is not released till transition is ended, This
741 could change later when we ideally should release
742 the snapshot mutex during transition. */
744 }
745
746 /** End state transition. */
747 void end_transit() {
751 }
752
753 /** Check if state transition is in progress
754 @return true during state transition */
755 bool in_transit_state() const {
758 }
759
760 /** @return true, if waiting before starting transition. Generally the
761 case when some DDL blocks state transition. */
762 bool in_transit_wait() const {
764 return (!in_transit_state() && m_num_clones_transit != 0);
765 }
766
767 /** Start redo archiving.
768 @return error code */
770
771 /** Initialize snapshot state for file copy
772 @param[in] new_state state to move for apply
773 @return error code */
774 int init_file_copy(Snapshot_State new_state);
775
776 /** Initialize disk byte estimate. */
778 /* Initial size is set to the redo file size on disk. */
781 }
782
783 /** Initialize snapshot state for page copy
784 @param[in] new_state state to move for apply
785 @param[in] page_buffer temporary buffer to copy page IDs
786 @param[in] page_buffer_len buffer length
787 @return error code */
788 int init_page_copy(Snapshot_State new_state, byte *page_buffer,
789 uint page_buffer_len);
790
791 /** Initialize snapshot state for redo copy
792 @param[in] new_state state to move for apply
793 @param[in] cbk alert callback for long wait
794 @return error code */
796
797 /** Initialize state while applying cloned data
798 @param[in] state_desc snapshot state descriptor
799 @return error code */
800 int init_apply_state(Clone_Desc_State *state_desc);
801
802 /** Extend and flush files after copying data
803 @param[in] flush_redo if true flush redo, otherwise data
804 @return error code */
805 int extend_and_flush_files(bool flush_redo);
806
807 /** Create file descriptor and add to current file list
808 @param[in] data_dir destination data directory
809 @param[in] file_meta file metadata from donor
810 @param[in] is_ddl if ddl temporary file
811 @param[out] file_ctx file context
812 @return error code */
813 int create_desc(const char *data_dir, const Clone_File_Meta *file_meta,
814 bool is_ddl, Clone_file_ctx *&file_ctx);
815
816 /** Get file context for current chunk
817 @param[in] file_vector clone file vector
818 @param[in] chunk_num current chunk number
819 @param[in] start_index index for starting the search
820 @return file context */
821 Clone_file_ctx *get_file(Clone_File_Vec &file_vector, uint32_t chunk_num,
822 uint32_t start_index);
823
824 /** Get next page from buffer pool
825 @param[in] chunk_num current chunk
826 @param[in,out] block_num current, next block
827 @param[in,out] file_ctx current, next block file context
828 @param[out] data_offset offset in file
829 @param[out] data_buf page data
830 @param[out] data_size page data size
831 @param[out] file_size updated file size if extended
832 @return error code */
833 int get_next_page(uint chunk_num, uint &block_num,
834 const Clone_file_ctx *&file_ctx, uint64_t &data_offset,
835 byte *&data_buf, uint32_t &data_size, uint64_t &file_size);
836
837 /** Get page from buffer pool and make ready for write
838 @param[in] page_id page ID chunk
839 @param[in] page_size page size descriptor
840 @param[in] file_ctx clone file context
841 @param[out] page_data data page
842 @param[out] data_size page size in bytes
843 @return error code */
844 int get_page_for_write(const page_id_t &page_id, const page_size_t &page_size,
845 const Clone_file_ctx *file_ctx, byte *&page_data,
846 uint &data_size);
847
848 /* Make page ready for flush by updating LSN anc checksum
849 @param[in] page_size page size descriptor
850 @param[in] page_lsn LSN to update the page with
851 @param[in,out] page_data data page */
852 void page_update_for_flush(const page_size_t &page_size, lsn_t page_lsn,
853 byte *&page_data);
854
855 /** Build file metadata entry
856 @param[in] file_name name of the file
857 @param[in] file_size file size in bytes
858 @param[in] file_offset start offset
859 @param[in] num_chunks total number of chunks in the file
860 @return file context */
861 Clone_file_ctx *build_file(const char *file_name, uint64_t file_size,
862 uint64_t file_offset, uint &num_chunks);
863
864 /** Allocate and set clone file name.
865 @param[in,out] file_meta file metadata
866 @param[in] file_name file name
867 @return true iff successful. */
868 bool build_file_name(Clone_File_Meta *file_meta, const char *file_name);
869
870 /** Add buffer pool dump file to the file list
871 @return error code */
872 int add_buf_pool_file();
873
874 /** Add file to snapshot
875 @param[in] name file name
876 @param[in] size_bytes file size in bytes
877 @param[in] alloc_bytes allocation size on disk for sparse file
878 @param[in] node file node
879 @param[in] by_ddl node is added concurrently by DDL
880 @return error code. */
881 int add_file(const char *name, uint64_t size_bytes, uint64_t alloc_bytes,
882 fil_node_t *node, bool by_ddl);
883
884 /** Check if file context has been changed by ddl.
885 @param[in] node tablespace file node
886 @param[out] file_ctx file context if exists
887 @return true iff file is created or modified by DDL. */
888 bool file_ctx_changed(const fil_node_t *node, Clone_file_ctx *&file_ctx);
889
890 /** Get chunk size
891 @return chunk size in pages */
892 inline uint32_t chunk_size() const {
893 auto size = static_cast<uint32_t>(ut_2_exp(m_chunk_size_pow2));
894 return size;
895 }
896
897 /** Get block size for file copy
898 @return block size in pages */
899 uint32_t block_size() {
901 auto size = static_cast<uint32_t>(ut_2_exp(m_block_size_pow2));
902
903 return size;
904 }
905
906 /** Get number of blocks per chunk for file copy
907 @return blocks per chunk */
908 inline uint32_t blocks_per_chunk() const {
910 return (1 << (m_chunk_size_pow2 - m_block_size_pow2));
911 }
912
913 /** Update system file name from configuration.
914 @param[in] replace if replacing current data directory
915 @param[in] file_meta file descriptor
916 @param[in,out] file_name file name to update
917 @return error code */
918 int update_sys_file_name(bool replace, const Clone_File_Meta *file_meta,
919 std::string &file_name);
920
921 /** Build file name along with path for cloned data files.
922 @param[in] data_dir clone data directory
923 @param[in] file_desc file descriptor
924 @param[out] file_path built file path if returned 0
925 @return error code (0 on success) */
926 int build_file_path(const char *data_dir, const Clone_File_Meta *file_desc,
927 std::string &file_path);
928
929 /** Build file context from file path.
930 @param[in] extn file extension type
931 @param[in] file_meta file descriptor
932 @param[in] file_path data file along with path
933 @param[out] file_ctx created file context
934 @return error code */
936 const Clone_File_Meta *file_meta,
937 const std::string &file_path, Clone_file_ctx *&file_ctx);
938
939 /** Check for existing file and if clone extension is needed. This function
940 has the side effect to add undo file indexes.
941 @param[in] replace if data directory is replaced
942 @param[in] undo_file if undo tablespace file
943 @param[in] redo_file if redo file
944 @param[in] data_file_index index of file
945 @param[in] data_file data file name
946 @param[out] extn file extension needs to be used
947 @return error code */
948 int handle_existing_file(bool replace, bool undo_file, bool redo_file,
949 uint32_t data_file_index,
950 const std::string &data_file,
952
953 /** @return number of data files to transfer. */
954 inline size_t num_data_files() const { return m_data_file_vector.size(); }
955
956 /** @return number of redo files to transfer. */
957 inline size_t num_redo_files() const { return m_redo_file_vector.size(); }
958
959 private:
960 /** @name Snapshot type and ID */
961
962 /** Snapshot handle type */
964
965 /** Clone type */
967
968 /** Unique snapshot ID */
970
971 /** Index in global snapshot array */
973
974 /** @name Snapshot State */
975
976 /** Mutex to handle access by concurrent clones */
977 mutable ib_mutex_t m_snapshot_mutex;
978
979 /** Number of blockers for state change. Usually DDLs for short duration. */
981
982 /** Set to true only if clone is aborted after error. */
984
985 /** Number of clones attached to this snapshot */
987
988 /** Number of clones in in state transition */
990
991 /** Current state */
993
994 /** Next state to move to. Set only during state transfer. */
996
997 /** @name Snapshot data block */
998
999 /** Memory allocation heap */
1001
1002 /** Chunk size in power of 2 */
1004
1005 /** Block size in power of 2 */
1007
1008 /** Number of chunks in current state */
1010
1011 /** Maximum file name length observed till now. */
1013
1014 /** @name Snapshot file data */
1015
1016 /** All data files for transfer */
1018
1019 /** Map space ID to file vector index */
1021
1022 /** Total number of data chunks */
1024
1025 /** Number of bytes on disk. */
1027
1028 /** Index into m_data_file_vector for all undo files. */
1029 std::vector<int> m_undo_file_indexes;
1030
1031 /** @name Snapshot page data */
1032
1033 /** Page archiver client */
1035
1036 /** Set of unique page IDs */
1038
1039 /** Sorted page IDs to transfer */
1041
1042 /** Number of pages to transfer */
1044
1045 /** Number of duplicate pages found */
1047
1048 /** @name Snapshot redo data */
1049
1050 /** redo log archiver client */
1052
1053 /** All archived redo files to transfer */
1055
1056 /** Start offset in first redo file */
1058
1059 /** Redo header block */
1061
1062 /** Redo header size */
1064
1065 /** Redo trailer block */
1067
1068 /** Redo trailer size */
1070
1071 /** Redo trailer block offset */
1073
1074 /** Archived redo file size */
1076
1077 /** Total number of redo data chunks */
1079
1080 /** Enable PFS monitoring */
1082
1083 /** Performance Schema accounting object to monitor stage progress */
1085};
1086
1087#endif /* CLONE_SNAPSHOT_INCLUDE */
uint32_t space_id_t
Tablespace identifier.
Definition: api0api.h:48
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:1046
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:1057
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:957
uint m_redo_header_size
Redo header size.
Definition: clone0snapshot.h:1063
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:899
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:762
ib_mutex_t m_snapshot_mutex
Mutex to handle access by concurrent clones.
Definition: clone0snapshot.h:977
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:1009
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 build_file_path_unsafe(const char *data_dir, const Clone_File_Meta *file_desc, std::string &file_path)
Legacy low-level path construction helper.
Definition: clone0apply.cc:323
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:1000
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:1017
size_t m_max_file_name_len
Maximum file name length observed till now.
Definition: clone0snapshot.h:1012
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:989
size_t num_data_files() const
Definition: clone0snapshot.h:954
uint32_t chunk_size() const
Get chunk size.
Definition: clone0snapshot.h:892
uint32_t m_num_blockers
Number of blockers for state change.
Definition: clone0snapshot.h:980
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:522
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:1026
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:755
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:736
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:1051
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:983
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:777
Clone_Monitor m_monitor
Performance Schema accounting object to monitor stage progress.
Definition: clone0snapshot.h:1084
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:992
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:1020
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:972
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:407
Clone_Page_Set m_page_set
Set of unique page IDs.
Definition: clone0snapshot.h:1037
Page_Arch_Client_Ctx m_page_ctx
Page archiver client.
Definition: clone0snapshot.h:1034
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:1066
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:963
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:1054
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:1029
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:1040
uint32_t blocks_per_chunk() const
Get number of blocks per chunk for file copy.
Definition: clone0snapshot.h:908
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:966
void begin_transit_ddl_wait()
Begin state transition before waiting for DDL.
Definition: clone0snapshot.h:726
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:482
uint m_num_redo_chunks
Total number of redo data chunks.
Definition: clone0snapshot.h:1078
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:427
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:1705
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:986
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:1674
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:1006
uint64_t m_redo_file_size
Archived redo file size.
Definition: clone0snapshot.h:1075
Snapshot_State m_snapshot_next_state
Next state to move to.
Definition: clone0snapshot.h:995
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:1023
int extend_and_flush_files(bool flush_redo)
Extend and flush files after copying data.
Definition: clone0apply.cc:1755
uint m_num_pages
Number of pages to transfer.
Definition: clone0snapshot.h:1043
~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:1003
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:1060
uint64_t m_snapshot_id
Unique snapshot ID.
Definition: clone0snapshot.h:969
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:1081
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:1069
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:747
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:1072
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:36
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:72
static bool replace
Definition: mysqlimport.cc:70
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
const char * begin(const char *const c)
Definition: base64.h:44
size_t size(const char *const c)
Definition: base64.h:46
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:967
@ HA_CLONE_BLOCKING
Caller must block all write operation to the SE.
Definition: handler.h:969
case opt name
Definition: sslopt-case.h:29
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:179
ib_mutex_t limits_mutex
Mutex which protects fields: available_for_checkpoint_lsn, requested_checkpoint_lsn.
Definition: log0sys.h:600
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
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:73
#define ut_a(EXPR)
Abort execution if EXPR does not evaluate to nonzero.
Definition: ut0dbg.h:93
#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.