MySQL 26.7.0
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[in] ddl_create descriptor can be appended by concurrent DDL
453 @param[out] desc_exists descriptor already exists
454 @param[out] file_ctx if there, set to current file context
455 @return error code */
456 int get_file_from_desc(const Clone_File_Meta *file_meta, const char *data_dir,
457 bool desc_create, bool ddl_create, bool &desc_exists,
458 Clone_file_ctx *&file_ctx);
459
460 /** Rename an existing file descriptor.
461 @param[in] file_meta renamed file metadata from donor
462 @param[in] data_dir destination data directory
463 @param[out] file_ctx if there, set to current file context
464 @return error code */
465 int rename_desc(const Clone_File_Meta *file_meta, const char *data_dir,
466 Clone_file_ctx *&file_ctx);
467
468 /** Fix files renamed with ddl extension. The file name is checked against
469 existing file and added to appropriate status file.
470 @param[in] data_dir destination data directory
471 @param[in,out] file_ctx Set to correct extension
472 @return error code */
473 int fix_ddl_extension(const char *data_dir, Clone_file_ctx *file_ctx);
474
475 /** Add file descriptor to file list
476 @param[in,out] file_ctx current file context
477 @param[in] ddl_create added by DDL concurrently
478 @param[out] last_file true if this is the last data file
479 @return error code */
480 int add_file_from_desc(Clone_file_ctx *&file_ctx, bool ddl_create,
481 bool &last_file);
482
483 /** Extract file information from node and add to snapshot
484 @param[in] node file node
485 @param[in] by_ddl node is added concurrently by DDL
486 @return error code */
487 dberr_t add_node(fil_node_t *node, bool by_ddl);
488
489 /** Add page ID to to the set of pages in snapshot
490 @param[in] space_id page tablespace
491 @param[in] page_num page number within tablespace
492 @return error code */
493 int add_page(uint32_t space_id, uint32_t page_num);
494
495 /** Add redo file to snapshot
496 @param[in] file_name file name
497 @param[in] file_size file size in bytes
498 @param[in] file_offset start offset
499 @return error code. */
500 int add_redo_file(char *file_name, uint64_t file_size, uint64_t file_offset);
501
502 /** Get file metadata by index for current state
503 @param[in] index file index
504 @return file metadata entry */
506
507 /** Get clone file context by index for current state
508 @param[in] index file index
509 @return file context */
511
512 /** Get clone file context by chunk and block number.
513 @param[in] chunk_num chunk number
514 @param[in] block_num block number
515 @param[in] hint_index hint file index number to start search.
516 @return file context */
517 Clone_file_ctx *get_file_ctx(uint32_t chunk_num, uint32_t block_num,
518 uint32_t hint_index);
519
520 /** Get next block of data to transfer
521 @param[in] chunk_num current chunk
522 @param[in,out] block_num current/next block
523 @param[in,out] file_ctx current/next block file context
524 @param[out] data_offset block offset in file
525 @param[out] data_buf data buffer or NULL if transfer from file
526 @param[out] data_size size of data in bytes
527 @param[out] file_size updated file size if extended
528 @return error code */
529 int get_next_block(uint chunk_num, uint &block_num,
530 const Clone_file_ctx *&file_ctx, uint64_t &data_offset,
531 byte *&data_buf, uint32_t &data_size, uint64_t &file_size);
532
533 /** Update snapshot block size based on caller's buffer size
534 @param[in] buff_size buffer size for clone transfer */
535 void update_block_size(uint buff_size);
536
537 /** @return chunk size in bytes. */
538 inline uint32_t get_chunk_size() const {
539 return chunk_size() * UNIV_PAGE_SIZE;
540 }
541
542 /** @return number of blocks per chunk for different states. */
543 uint32_t get_blocks_per_chunk() const;
544
545 /** Check if copy snapshot
546 @return true if snapshot is for copy */
547 bool is_copy() const { return (m_snapshot_handle_type == CLONE_HDL_COPY); }
548
549 /** Update file size when file is extended during page copy
550 @param[in] file_index current file index
551 @param[in] file_size new file size */
552 void update_file_size(uint32_t file_index, uint64_t file_size);
553
554 /** Encrypt tablespace key in header page with master key.
555 @param[in] page_size page size descriptor
556 @param[in,out] page_data page data to update
557 @return true, if successful. */
558 bool encrypt_key_in_header(const page_size_t &page_size, byte *page_data);
559
560 /** Encrypt tablespace key in header page with master key.
561 @param[in,out] log_header page data to update
562 @param[in] header_len length of log header
563 @return true, if successful. */
564 bool encrypt_key_in_log_header(byte *log_header, uint32_t header_len);
565
566 /** Decrypt tablespace key in header page with master key.
567 @param[in] file_meta clone file metadata
568 @param[in] page_size page size descriptor
569 @param[in,out] page_data page data to update */
570 void decrypt_key_in_header(const Clone_File_Meta *file_meta,
571 const page_size_t &page_size, byte *&page_data);
572
573 /** @return maximum blocks to transfer with file pinned. */
574 uint32_t get_max_blocks_pin() const;
575
576 /** Skip all blocks belonging to currently deleted file context.
577 @param[in] chunk_num current chunk
578 @param[in,out] block_num current, next block */
579 void skip_deleted_blocks(uint32_t chunk_num, uint32_t &block_num);
580
581 private:
582 /** Allow DDL file operation after 64 pages. */
583 const static uint32_t S_MAX_PAGES_PIN = 64;
584
585 /** Allow DDL file operation after every block (1M data by default) */
586 const static uint32_t S_MAX_BLOCKS_PIN = 1;
587
588 /** File name allocation size base. */
589 const static size_t S_FILE_NAME_BASE_LEN = 256;
590
591 /** Various wait types related to snapshot state. */
592 enum class Wait_type {
593 /* DDL- limited wait if clone is waiting for another DDL. */
595 /* DDL- Wait till snapshot state transition is over. */
597 /* DDL- Wait till PAGE COPY state is over. */
599 /* Clone - Wait till there are no blockers for state transition. */
601 /*DDL - Wait till the waiting clone threads are active. This are
602 clone threads from last DDL and useful to prevent starvation. */
604 /* DDL - Wait till all threads have closed active data files. */
606 /* Clone - Wait till DDL file operation is complete. */
608 };
609
610#ifdef UNIV_DEBUG
611 /** Debug sync Wait during state transition. */
613#endif /* UNIV_DEBUG */
614
615 /** Update deleted state of a file if not yet done.
616 @param[in,out] file_ctx file context
617 @return true, if updated state */
618 bool update_deleted_state(Clone_file_ctx *file_ctx);
619
620 /** Get clone data file context by chunk number.
621 @param[in] chunk_num chunk number
622 @param[in] hint_index hint file index number to start search.
623 @return file context */
624 Clone_file_ctx *get_data_file_ctx(uint32_t chunk_num, uint32_t hint_index);
625
626 /** Get clone page file context by chunk number and block number.
627 @param[in] chunk_num chunk number
628 @param[in] block_num block number
629 @return file context */
630 Clone_file_ctx *get_page_file_ctx(uint32_t chunk_num, uint32_t block_num);
631
632 /** Get clone redo file context by chunk number.
633 @param[in] chunk_num chunk number
634 @param[in] hint_index hint file index number to start search.
635 @return file context */
636 Clone_file_ctx *get_redo_file_ctx(uint32_t chunk_num, uint32_t hint_index);
637
638 /** Legacy low-level path construction helper.
639 This method preserves the historical path building behavior and performs
640 no containment validation on the computed result. New code should not call
641 it directly; use build_file_path() instead.
642 @param[in] data_dir destination data directory
643 @param[in] file_desc file metadata from donor
644 @param[out] file_path computed destination path
645 @return error code (0 on success) */
646 int build_file_path_unsafe(const char *data_dir,
647 const Clone_File_Meta *file_desc,
648 std::string &file_path);
649
650 /** Get wait information string based on wait type.
651 @param[in] wait_type wait type
652 @return wait information string. */
653 const char *wait_string(Wait_type wait_type) const;
654
655 /** Wait for various operations based on type.
656 @param[in] type wait type
657 @param[in] ctx file context when relevant
658 @param[in] no_wait return with error if needs to wait
659 @param[in] check_intr check for interrupt during wait
660 @return mysql error code. */
661 int wait(Wait_type type, const Clone_file_ctx *ctx, bool no_wait,
662 bool check_intr);
663
664 /** During wait get relevant message string for logging.
665 @param[in] wait_type wait type
666 @param[out] info notification to log while waiting
667 @param[out] error error message to log on timeout */
668 void get_wait_mesg(Wait_type wait_type, std::string &info,
669 std::string &error);
670
671 /** Block clone state transition. Clone must wait.
672 @param[in] type type of DDL notification
673 @param[in] space space ID for the ddl operation
674 @param[in] no_wait return with error if needs to wait
675 @param[in] check_intr check for interrupt during wait`
676 @param[out] error mysql error code
677 @return true iff clone state change is blocked. */
679 bool no_wait, bool check_intr, int &error);
680
681 /** Unblock clone state transition. */
683
684 /** Get next file state while being modified by ddl.
685 @param[in] type ddl notification type
686 @param[in] begin true, if DDL begin notification
687 false, if DDL end notification
688 @return target file state. */
690 bool begin);
691
692 /** Handle files for DDL begin notification.
693 @param[in] type type of DDL notification
694 @param[in] space space ID for the ddl operation
695 @param[in] no_wait return with error if needs to wait
696 @param[in] check_intr check for interrupt during wait
697 @return mysql error code */
698 int begin_ddl_file(Clone_notify::Type type, space_id_t space, bool no_wait,
699 bool check_intr);
700
701 /** Handle files for DDL end notification.
702 @param[in] type type of DDL notification
703 @param[in] space space ID for the ddl operation */
705
706 /** Synchronize snapshot with binary log and GTID.
707 @param[in] cbk alert callback for long wait
708 @return error code. */
710
711 /** Make sure that the trx sys page binary log position correctly reflects
712 all transactions committed to innodb. It updates binary log position
713 in transaction sys page, if required. The caller must ensure that any new
714 transaction is committed in order of binary log.
715 @return error code. */
717
718 /** Wait for already prepared binlog transactions to end.
719 @return error code. */
721
722 /** Wait for a transaction to end.
723 @param[in] thd current THD
724 @param[in] trx_id transaction to wait for
725 @return error code. */
726 int wait_trx_end(THD *thd, trx_id_t trx_id);
727
728 /** Begin state transition before waiting for DDL. */
731 /* Update number of clones to transit to new state. Set this prior to
732 waiting for DDLs blocking state transfer. This would help a new DDL to
733 find if clone is blocked by other DDL before state transition. */
735 }
736
737 /** Begin state transition.
738 @param[in] new_state state to transit to */
741 m_snapshot_next_state = new_state;
742 /* Move to next state. This is ok as the snapshot
743 mutex is not released till transition is ended, This
744 could change later when we ideally should release
745 the snapshot mutex during transition. */
747 }
748
749 /** End state transition. */
750 void end_transit() {
754 }
755
756 /** Check if state transition is in progress
757 @return true during state transition */
758 bool in_transit_state() const {
761 }
762
763 /** @return true, if waiting before starting transition. Generally the
764 case when some DDL blocks state transition. */
765 bool in_transit_wait() const {
767 return (!in_transit_state() && m_num_clones_transit != 0);
768 }
769
770 /** Start redo archiving.
771 @return error code */
773
774 /** Initialize snapshot state for file copy
775 @param[in] new_state state to move for apply
776 @return error code */
777 int init_file_copy(Snapshot_State new_state);
778
779 /** Initialize disk byte estimate. */
780 void init_disk_estimate();
781
782 /** Initialize snapshot state for page copy
783 @param[in] new_state state to move for apply
784 @param[in] page_buffer temporary buffer to copy page IDs
785 @param[in] page_buffer_len buffer length
786 @return error code */
787 int init_page_copy(Snapshot_State new_state, byte *page_buffer,
788 uint page_buffer_len);
789
790 /** Initialize snapshot state for redo copy
791 @param[in] new_state state to move for apply
792 @param[in] cbk alert callback for long wait
793 @return error code */
795
796 /** Initialize state while applying cloned data
797 @param[in] state_desc snapshot state descriptor
798 @return error code */
799 int init_apply_state(Clone_Desc_State *state_desc);
800
801 /** Extend and flush files after copying data
802 @param[in] flush_redo if true flush redo, otherwise data
803 @return error code */
804 int extend_and_flush_files(bool flush_redo);
805
806 /** Create file descriptor and add to current file list
807 @param[in] data_dir destination data directory
808 @param[in] file_meta file metadata from donor
809 @param[in] is_ddl if ddl temporary file
810 @param[out] file_ctx file context
811 @return error code */
812 int create_desc(const char *data_dir, const Clone_File_Meta *file_meta,
813 bool is_ddl, Clone_file_ctx *&file_ctx);
814
815 /** Get file context for current chunk
816 @param[in] file_vector clone file vector
817 @param[in] chunk_num current chunk number
818 @param[in] start_index index for starting the search
819 @return file context */
820 Clone_file_ctx *get_file(Clone_File_Vec &file_vector, uint32_t chunk_num,
821 uint32_t start_index);
822
823 /** Get next page from buffer pool
824 @param[in] chunk_num current chunk
825 @param[in,out] block_num current, next block
826 @param[in,out] file_ctx current, next block file context
827 @param[out] data_offset offset in file
828 @param[out] data_buf page data
829 @param[out] data_size page data size
830 @param[out] file_size updated file size if extended
831 @return error code */
832 int get_next_page(uint chunk_num, uint &block_num,
833 const Clone_file_ctx *&file_ctx, uint64_t &data_offset,
834 byte *&data_buf, uint32_t &data_size, uint64_t &file_size);
835
836 /** Get page from buffer pool and make ready for write
837 @param[in] page_id page ID chunk
838 @param[in] page_size page size descriptor
839 @param[in] file_ctx clone file context
840 @param[out] page_data data page
841 @param[out] data_size page size in bytes
842 @return error code */
843 int get_page_for_write(const page_id_t &page_id, const page_size_t &page_size,
844 const Clone_file_ctx *file_ctx, byte *&page_data,
845 uint &data_size);
846
847 /* Make page ready for flush by updating LSN anc checksum
848 @param[in] page_size page size descriptor
849 @param[in] page_lsn LSN to update the page with
850 @param[in,out] page_data data page */
851 void page_update_for_flush(const page_size_t &page_size, lsn_t page_lsn,
852 byte *&page_data);
853
854 /** Build file metadata entry
855 @param[in] file_name name of the file
856 @param[in] file_size file size in bytes
857 @param[in] file_offset start offset
858 @param[in] num_chunks total number of chunks in the file
859 @return file context */
860 Clone_file_ctx *build_file(const char *file_name, uint64_t file_size,
861 uint64_t file_offset, uint &num_chunks);
862
863 /** Allocate and set clone file name.
864 @param[in,out] file_meta file metadata
865 @param[in] file_name file name
866 @return true iff successful. */
867 bool build_file_name(Clone_File_Meta *file_meta, const char *file_name);
868
869 /** Add buffer pool dump file to the file list
870 @return error code */
871 int add_buf_pool_file();
872
873 /** Add file to snapshot
874 @param[in] name file name
875 @param[in] size_bytes file size in bytes
876 @param[in] alloc_bytes allocation size on disk for sparse file
877 @param[in] node file node
878 @param[in] by_ddl node is added concurrently by DDL
879 @return error code. */
880 int add_file(const char *name, uint64_t size_bytes, uint64_t alloc_bytes,
881 fil_node_t *node, bool by_ddl);
882
883 /** Check if file context has been changed by ddl.
884 @param[in] node tablespace file node
885 @param[out] file_ctx file context if exists
886 @return true iff file is created or modified by DDL. */
887 bool file_ctx_changed(const fil_node_t *node, Clone_file_ctx *&file_ctx);
888
889 /** Get chunk size
890 @return chunk size in pages */
891 inline uint32_t chunk_size() const {
892 auto size = static_cast<uint32_t>(ut_2_exp(m_chunk_size_pow2));
893 return size;
894 }
895
896 /** Get block size for file copy
897 @return block size in pages */
898 uint32_t block_size() {
900 auto size = static_cast<uint32_t>(ut_2_exp(m_block_size_pow2));
901
902 return size;
903 }
904
905 /** Get number of blocks per chunk for file copy
906 @return blocks per chunk */
907 inline uint32_t blocks_per_chunk() const {
909 return (1 << (m_chunk_size_pow2 - m_block_size_pow2));
910 }
911
912 /** Update system file name from configuration.
913 @param[in] replace if replacing current data directory
914 @param[in] file_meta file descriptor
915 @param[in,out] file_name file name to update
916 @return error code */
917 int update_sys_file_name(bool replace, const Clone_File_Meta *file_meta,
918 std::string &file_name);
919
920 /** Build file name along with path for cloned data files.
921 @param[in] data_dir clone data directory
922 @param[in] file_desc file descriptor
923 @param[out] file_path built file path if returned 0
924 @return error code (0 on success) */
925 int build_file_path(const char *data_dir, const Clone_File_Meta *file_desc,
926 std::string &file_path);
927
928 /** Build file context from file path.
929 @param[in] extn file extension type
930 @param[in] file_meta file descriptor
931 @param[in] file_path data file along with path
932 @param[out] file_ctx created file context
933 @return error code */
935 const Clone_File_Meta *file_meta,
936 const std::string &file_path, Clone_file_ctx *&file_ctx);
937
938 /** Check for existing file and if clone extension is needed. This function
939 has the side effect to add undo file indexes.
940 @param[in] replace if data directory is replaced
941 @param[in] undo_file if undo tablespace file
942 @param[in] redo_file if redo file
943 @param[in] data_file_index index of file
944 @param[in] data_file data file name
945 @param[out] extn file extension needs to be used
946 @return error code */
947 int handle_existing_file(bool replace, bool undo_file, bool redo_file,
948 uint32_t data_file_index,
949 const std::string &data_file,
951
952 /** Validate donor-provided file index for the current snapshot state.
953 @param[in] file_index donor-provided file index
954 @param[in] ddl_create true if DDL may append a new data file
955 @return error code */
956 int validate_file_index(uint32_t file_index, bool ddl_create) const;
957
958 /** @return number of data files to transfer. */
959 inline size_t num_data_files() const { return m_data_file_vector.size(); }
960
961 /** @return number of redo files to transfer. */
962 inline size_t num_redo_files() const { return m_redo_file_vector.size(); }
963
964 private:
965 /** @name Snapshot type and ID */
966
967 /** Snapshot handle type */
969
970 /** Clone type */
972
973 /** Unique snapshot ID */
975
976 /** Index in global snapshot array */
978
979 /** @name Snapshot State */
980
981 /** Mutex to handle access by concurrent clones */
982 mutable ib_mutex_t m_snapshot_mutex;
983
984 /** Number of blockers for state change. Usually DDLs for short duration. */
986
987 /** Set to true only if clone is aborted after error. */
989
990 /** Number of clones attached to this snapshot */
992
993 /** Number of clones in in state transition */
995
996 /** Current state */
998
999 /** Next state to move to. Set only during state transfer. */
1001
1002 /** @name Snapshot data block */
1003
1004 /** Memory allocation heap */
1006
1007 /** Chunk size in power of 2 */
1009
1010 /** Block size in power of 2 */
1012
1013 /** Number of chunks in current state */
1015
1016 /** Maximum file name length observed till now. */
1018
1019 /** @name Snapshot file data */
1020
1021 /** All data files for transfer */
1023
1024 /** Map space ID to file vector index */
1026
1027 /** Total number of data chunks */
1029
1030 /** Number of bytes on disk. */
1032
1033 /** Index into m_data_file_vector for all undo files. */
1034 std::vector<int> m_undo_file_indexes;
1035
1036 /** @name Snapshot page data */
1037
1038 /** Page archiver client */
1040
1041 /** Set of unique page IDs */
1043
1044 /** Sorted page IDs to transfer */
1046
1047 /** Number of pages to transfer */
1049
1050 /** Number of duplicate pages found */
1052
1053 /** @name Snapshot redo data */
1054
1055 /** redo log archiver client */
1057
1058 /** All archived redo files to transfer */
1060
1061 /** Start offset in first redo file */
1063
1064 /** Redo header block */
1066
1067 /** Redo header size */
1069
1070 /** Redo trailer block */
1072
1073 /** Redo trailer size */
1075
1076 /** Redo trailer block offset */
1078
1079 /** Archived redo file size */
1081
1082 /** Total number of redo data chunks */
1084
1085 /** Enable PFS monitoring */
1087
1088 /** Performance Schema accounting object to monitor stage progress */
1090};
1091
1092#endif /* CLONE_SNAPSHOT_INCLUDE */
uint32_t space_id_t
Tablespace identifier.
Definition: api0api.h:49
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:757
int init_redo_archiving()
Start redo archiving.
Definition: clone0copy.cc:123
const char * wait_string(Wait_type wait_type) const
Get wait information string based on wait type.
Definition: clone0snapshot.cc:1242
uint m_num_duplicate_pages
Number of duplicate pages found.
Definition: clone0snapshot.h:1051
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:1538
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:462
uint64_t m_redo_start_offset
Start offset in first redo file.
Definition: clone0snapshot.h:1062
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:113
size_t num_redo_files() const
Definition: clone0snapshot.h:962
uint m_redo_header_size
Redo header size.
Definition: clone0snapshot.h:1068
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:803
uint32_t block_size()
Get block size for file copy.
Definition: clone0snapshot.h:898
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:765
ib_mutex_t m_snapshot_mutex
Mutex to handle access by concurrent clones.
Definition: clone0snapshot.h:982
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:788
uint m_num_current_chunks
Number of chunks in current state.
Definition: clone0snapshot.h:1014
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:923
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:369
int pin_file(Clone_file_ctx *file_ctx, bool &handle_delete)
Wait for concurrent DDL file operation and pin file.
Definition: clone0snapshot.cc:1612
mem_heap_t * m_snapshot_heap
Memory allocation heap.
Definition: clone0snapshot.h:1005
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:1206
Clone_File_Vec m_data_file_vector
All data files for transfer.
Definition: clone0snapshot.h:1022
size_t m_max_file_name_len
Maximum file name length observed till now.
Definition: clone0snapshot.h:1017
uint32_t get_max_blocks_pin() const
Definition: clone0snapshot.cc:988
uint m_num_clones_transit
Number of clones in in state transition.
Definition: clone0snapshot.h:994
size_t num_data_files() const
Definition: clone0snapshot.h:959
uint32_t chunk_size() const
Get chunk size.
Definition: clone0snapshot.h:891
uint32_t m_num_blockers
Number of blockers for state change.
Definition: clone0snapshot.h:985
static const size_t S_FILE_NAME_BASE_LEN
File name allocation size base.
Definition: clone0snapshot.h:589
static const uint32_t S_MAX_BLOCKS_PIN
Allow DDL file operation after every block (1M data by default)
Definition: clone0snapshot.h:586
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:949
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:755
dberr_t add_node(fil_node_t *node, bool by_ddl)
Extract file information from node and add to snapshot.
Definition: clone0copy.cc:870
uint64_t m_data_bytes_disk
Number of bytes on disk.
Definition: clone0snapshot.h:1031
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:758
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:552
void begin_transit(Snapshot_State new_state)
Begin state transition.
Definition: clone0snapshot.h:739
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:1056
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:1279
int add_file_from_desc(Clone_file_ctx *&file_ctx, bool ddl_create, bool &last_file)
Add file descriptor to file list.
Definition: clone0apply.cc:569
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:612
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:988
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: clone0copy.cc:248
Clone_Monitor m_monitor
Performance Schema accounting object to monitor stage progress.
Definition: clone0snapshot.h:1089
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:843
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:482
Snapshot_State m_snapshot_state
Current state.
Definition: clone0snapshot.h:997
void unblock_state_change()
Unblock clone state transition.
Definition: clone0snapshot.cc:1435
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:263
int update_binlog_position()
Make sure that the trx sys page binary log position correctly reflects all transactions committed to ...
Definition: clone0copy.cc:358
std::function< int(Clone_file_ctx *)> File_Cbk_Func
Definition: clone0snapshot.h:391
bool is_copy() const
Check if copy snapshot.
Definition: clone0snapshot.h:547
Clone_File_Map m_data_file_map
Map space ID to file vector index.
Definition: clone0snapshot.h:1025
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:993
uint m_snapshot_arr_idx
Index in global snapshot array.
Definition: clone0snapshot.h:977
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:1032
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:453
Clone_Page_Set m_page_set
Set of unique page IDs.
Definition: clone0snapshot.h:1042
Page_Arch_Client_Ctx m_page_ctx
Page archiver client.
Definition: clone0snapshot.h:1039
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:164
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:1484
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:1381
byte * m_redo_trailer
Redo trailer block.
Definition: clone0snapshot.h:1071
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:185
Clone_Handle_Type m_snapshot_handle_type
Snapshot handle type.
Definition: clone0snapshot.h:968
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:1440
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:1059
bool build_file_name(Clone_File_Meta *file_meta, const char *file_name)
Allocate and set clone file name.
Definition: clone0copy.cc:584
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:1014
std::vector< int > m_undo_file_indexes
Index into m_data_file_vector for all undo files.
Definition: clone0snapshot.h:1034
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:1094
uint32_t get_chunk_size() const
Definition: clone0snapshot.h:538
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:1045
uint32_t blocks_per_chunk() const
Get number of blocks per chunk for file copy.
Definition: clone0snapshot.h:907
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:737
Ha_clone_type m_snapshot_type
Clone type.
Definition: clone0snapshot.h:971
void begin_transit_ddl_wait()
Begin state transition before waiting for DDL.
Definition: clone0snapshot.h:729
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:529
uint m_num_redo_chunks
Total number of redo data chunks.
Definition: clone0snapshot.h:1083
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:683
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:474
static const uint32_t S_MAX_PAGES_PIN
Allow DDL file operation after 64 pages.
Definition: clone0snapshot.h:583
int add_buf_pool_file()
Add buffer pool dump file to the file list.
Definition: clone0copy.cc:91
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:663
int get_file_from_desc(const Clone_File_Meta *file_meta, const char *data_dir, bool desc_create, bool ddl_create, bool &desc_exists, Clone_file_ctx *&file_ctx)
Add file metadata entry at destination.
Definition: clone0apply.cc:72
int init_apply_state(Clone_Desc_State *state_desc)
Initialize state while applying cloned data.
Definition: clone0apply.cc:1768
int init_page_copy(Snapshot_State new_state, byte *page_buffer, uint page_buffer_len)
Initialize snapshot state for page copy.
Definition: clone0copy.cc:255
bool is_aborted() const
Definition: clone0snapshot.cc:237
uint m_num_clones
Number of clones attached to this snapshot.
Definition: clone0snapshot.h:991
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:1737
void debug_wait_state_transit()
Debug sync Wait during state transition.
Definition: clone0copy.cc:173
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:1011
uint64_t m_redo_file_size
Archived redo file size.
Definition: clone0snapshot.h:1080
Snapshot_State m_snapshot_next_state
Next state to move to.
Definition: clone0snapshot.h:1000
void skip_deleted_blocks(uint32_t chunk_num, uint32_t &block_num)
Skip all blocks belonging to currently deleted file context.
Definition: clone0snapshot.cc:635
uint m_num_data_chunks
Total number of data chunks.
Definition: clone0snapshot.h:1028
int extend_and_flush_files(bool flush_redo)
Extend and flush files after copying data.
Definition: clone0apply.cc:1818
uint m_num_pages
Number of pages to transfer.
Definition: clone0snapshot.h:1048
~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:410
Wait_type
Various wait types related to snapshot state.
Definition: clone0snapshot.h:592
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:1008
int synchronize_binlog_gtid(Clone_Alert_Func cbk)
Synchronize snapshot with binary log and GTID.
Definition: clone0copy.cc:340
bool update_deleted_state(Clone_file_ctx *file_ctx)
Update deleted state of a file if not yet done.
Definition: clone0snapshot.cc:1598
byte * m_redo_header
Redo header block.
Definition: clone0snapshot.h:1065
uint64_t m_snapshot_id
Unique snapshot ID.
Definition: clone0snapshot.h:974
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:1086
int fix_ddl_extension(const char *data_dir, Clone_file_ctx *file_ctx)
Fix files renamed with ddl extension.
Definition: clone0apply.cc:140
uint m_redo_trailer_size
Redo trailer size.
Definition: clone0snapshot.h:1074
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:630
void end_transit()
End state transition.
Definition: clone0snapshot.h:750
bool blocks_clone(const Clone_file_ctx *file_ctx)
Check if DDL needs to block clone operation.
Definition: clone0snapshot.cc:1460
uint64_t m_redo_trailer_offset
Redo trailer block offset.
Definition: clone0snapshot.h:1077
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:1019
void end_ddl_state(Clone_notify::Type type, space_id_t space)
DDL notification after the operation.
Definition: clone0snapshot.cc:1195
int validate_file_index(uint32_t file_index, bool ddl_create) const
Validate donor-provided file index for the current snapshot state.
Definition: clone0apply.cc:44
Type
Notification type.
Definition: clone0api.h:178
Redo Log archiver client context.
Definition: arch0log.h:48
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
Node of a tablespace encapsulating handle required for any IO operations on this node.
Definition: fil0fil.h:177
Page identifier.
Definition: buf0types.h:191
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.
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
bool index(const std::string &value, const String &search_for, uint32_t *idx)
Definition: contains.h:76
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:45
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:991
@ HA_CLONE_BLOCKING
Caller must block all write operation to the SE.
Definition: handler.h:993
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:922
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:1070
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
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
The info structure stored at the beginning of a heap block.
Definition: mem0mem.h:295
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:291
#define ut_a(EXPR)
Abort execution if EXPR does not evaluate to nonzero.
Definition: ut0dbg.h:97
#define mutex_own(M)
Checks that the current thread owns the mutex.
Definition: ut0mutex.h:166
#define mutex_exit(M)
Definition: ut0mutex.h:122
#define mutex_enter(M)
Definition: ut0mutex.h:116
static uint32_t ut_2_exp(uint32_t n)
Calculates 2 to power n.